summaryrefslogtreecommitdiffstats
path: root/crypto/evp/e_sm4.c
diff options
context:
space:
mode:
authorPauli <pauli@openssl.org>2021-06-07 09:28:49 +1000
committerPauli <pauli@openssl.org>2021-06-08 19:32:17 +1000
commit042f8f70cb8fb21445ed20d07e2624d5a2bba4e4 (patch)
tree71fec2fcb66df66cabee06ed2b28f6c8f5a38530 /crypto/evp/e_sm4.c
parentb0a0ab07b4313cc893b17880b4399bdb804837c5 (diff)
evp: fix improper use of negative value issues
Coverity issues 1485662, 1485663 & 1485664. Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15635)
Diffstat (limited to 'crypto/evp/e_sm4.c')
-rw-r--r--crypto/evp/e_sm4.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/crypto/evp/e_sm4.c b/crypto/evp/e_sm4.c
index 39bec569f7..abd603015c 100644
--- a/crypto/evp/e_sm4.c
+++ b/crypto/evp/e_sm4.c
@@ -74,9 +74,14 @@ IMPLEMENT_BLOCK_CIPHER(sm4, ks, sm4, EVP_SM4_KEY, NID_sm4,
static int sm4_ctr_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
const unsigned char *in, size_t len)
{
- unsigned int num = EVP_CIPHER_CTX_get_num(ctx);
+ int n = EVP_CIPHER_CTX_get_num(ctx);
+ unsigned int num;
EVP_SM4_KEY *dat = EVP_C_DATA(EVP_SM4_KEY, ctx);
+ if (n < 0)
+ return 0;
+ num = (unsigned int)n;
+
CRYPTO_ctr128_encrypt(in, out, len, &dat->ks, ctx->iv,
EVP_CIPHER_CTX_buf_noconst(ctx), &num,
(block128_f)ossl_sm4_encrypt);