diff --git a/crypto/evp/e_aria.c b/crypto/evp/e_aria.c index f3a68eb09d..3e64e45f89 100644 --- a/crypto/evp/e_aria.c +++ b/crypto/evp/e_aria.c @@ -171,7 +171,7 @@ static int aria_ctr_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t len) { unsigned int num = EVP_CIPHER_CTX_num(ctx); - EVP_ARIA_KEY *dat = EVP_C_DATA(EVP_ARIA_KEY,ctx); + EVP_ARIA_KEY *dat = EVP_C_DATA(EVP_ARIA_KEY, ctx); CRYPTO_ctr128_encrypt(in, out, len, &dat->ks, ctx->iv, EVP_CIPHER_CTX_buf_noconst(ctx), &num, diff --git a/crypto/evp/e_camellia.c b/crypto/evp/e_camellia.c index 0d338b8b2f..3e7cd76934 100644 --- a/crypto/evp/e_camellia.c +++ b/crypto/evp/e_camellia.c @@ -316,9 +316,13 @@ static int camellia_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, static int camellia_ctr_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t len) { - unsigned int num = EVP_CIPHER_CTX_num(ctx); + int snum = EVP_CIPHER_CTX_num(ctx); + unsigned int num; EVP_CAMELLIA_KEY *dat = EVP_C_DATA(EVP_CAMELLIA_KEY,ctx); + if (snum < 0) + return 0; + num = snum; if (dat->stream.ctr) CRYPTO_ctr128_encrypt_ctr32(in, out, len, &dat->ks, ctx->iv, EVP_CIPHER_CTX_buf_noconst(ctx), &num, diff --git a/crypto/idea/i_cfb64.c b/crypto/idea/i_cfb64.c index b9db1639cf..a477799edf 100644 --- a/crypto/idea/i_cfb64.c +++ b/crypto/idea/i_cfb64.c @@ -33,6 +33,11 @@ void IDEA_cfb64_encrypt(const unsigned char *in, unsigned char *out, unsigned long ti[2]; unsigned char *iv, c, cc; + if (n < 0) { + *num = -1; + return; + } + iv = (unsigned char *)ivec; if (encrypt) { while (l--) { diff --git a/crypto/idea/i_ofb64.c b/crypto/idea/i_ofb64.c index 89ac18ce91..246886bdc4 100644 --- a/crypto/idea/i_ofb64.c +++ b/crypto/idea/i_ofb64.c @@ -35,6 +35,11 @@ void IDEA_ofb64_encrypt(const unsigned char *in, unsigned char *out, unsigned char *iv; int save = 0; + if (n < 0) { + *num = -1; + return; + } + iv = (unsigned char *)ivec; n2l(iv, v0); n2l(iv, v1); diff --git a/crypto/modes/cfb128.c b/crypto/modes/cfb128.c index fa94f047b5..f9c3c60536 100644 --- a/crypto/modes/cfb128.c +++ b/crypto/modes/cfb128.c @@ -30,6 +30,11 @@ void CRYPTO_cfb128_encrypt(const unsigned char *in, unsigned char *out, unsigned int n; size_t l = 0; + if (*num < 0) { + /* There is no good way to signal an error return from here */ + *num = -1; + return; + } n = *num; if (enc) { diff --git a/crypto/modes/ctr128.c b/crypto/modes/ctr128.c index b902ee9b0b..2147751c58 100644 --- a/crypto/modes/ctr128.c +++ b/crypto/modes/ctr128.c @@ -155,7 +155,7 @@ void CRYPTO_ctr128_encrypt_ctr32(const unsigned char *in, unsigned char *out, { unsigned int n, ctr32; - n = *num; + n = *num; while (n && len) { *(out++) = *(in++) ^ ecount_buf[n]; diff --git a/crypto/modes/ofb128.c b/crypto/modes/ofb128.c index 829d724e2a..0b21380208 100644 --- a/crypto/modes/ofb128.c +++ b/crypto/modes/ofb128.c @@ -29,6 +29,11 @@ void CRYPTO_ofb128_encrypt(const unsigned char *in, unsigned char *out, unsigned int n; size_t l = 0; + if (*num < 0) { + /* There is no good way to signal an error return from here */ + *num = -1; + return; + } n = *num; #if !defined(OPENSSL_SMALL_FOOTPRINT)