From a3aa4e31042afcc1e1eec8853864e1a82e5d7db4 Mon Sep 17 00:00:00 2001 From: Zhi Guan Date: Mon, 13 Mar 2023 15:47:01 +0800 Subject: [PATCH] Update aead.c Fix bug in GCM tmp buffer size --- src/aead.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/aead.c b/src/aead.c index a18036f1..7dcbe73c 100644 --- a/src/aead.c +++ b/src/aead.c @@ -123,7 +123,7 @@ int sm4_cbc_sm3_hmac_decrypt_update(SM4_CBC_SM3_HMAC_CTX *ctx, const uint8_t *in } if (inlen <= SM3_HMAC_SIZE) { - uint8_t tmp[32]; + uint8_t tmp[SM3_HMAC_SIZE]; sm3_hmac_update(&ctx->mac_ctx, ctx->mac, inlen); if (sm4_cbc_decrypt_update(&ctx->enc_ctx, ctx->mac, inlen, out, outlen) != 1) { error_print(); @@ -132,7 +132,7 @@ int sm4_cbc_sm3_hmac_decrypt_update(SM4_CBC_SM3_HMAC_CTX *ctx, const uint8_t *in len = SM3_HMAC_SIZE - inlen; memcpy(tmp, ctx->mac + inlen, len); memcpy(tmp + len, in, inlen); - memcpy(ctx->mac, tmp, 32); + memcpy(ctx->mac, tmp, SM3_HMAC_SIZE); } else { sm3_hmac_update(&ctx->mac_ctx, ctx->mac, SM3_HMAC_SIZE); if (sm4_cbc_decrypt_update(&ctx->enc_ctx, ctx->mac, SM3_HMAC_SIZE, out, outlen) != 1) { @@ -285,7 +285,7 @@ int sm4_ctr_sm3_hmac_decrypt_update(SM4_CTR_SM3_HMAC_CTX *ctx, const uint8_t *in } if (inlen <= SM3_HMAC_SIZE) { - uint8_t tmp[32]; + uint8_t tmp[SM3_HMAC_SIZE]; sm3_hmac_update(&ctx->mac_ctx, ctx->mac, inlen); if (sm4_ctr_decrypt_update(&ctx->enc_ctx, ctx->mac, inlen, out, outlen) != 1) { error_print(); @@ -294,7 +294,7 @@ int sm4_ctr_sm3_hmac_decrypt_update(SM4_CTR_SM3_HMAC_CTX *ctx, const uint8_t *in len = SM3_HMAC_SIZE - inlen; memcpy(tmp, ctx->mac + inlen, len); memcpy(tmp + len, in, inlen); - memcpy(ctx->mac, tmp, 32); + memcpy(ctx->mac, tmp, SM3_HMAC_SIZE); } else { sm3_hmac_update(&ctx->mac_ctx, ctx->mac, SM3_HMAC_SIZE); if (sm4_ctr_decrypt_update(&ctx->enc_ctx, ctx->mac, SM3_HMAC_SIZE, out, outlen) != 1) { @@ -475,7 +475,7 @@ int sm4_gcm_decrypt_update(SM4_GCM_CTX *ctx, const uint8_t *in, size_t inlen, ui } if (inlen <= ctx->taglen) { - uint8_t tmp[32]; + uint8_t tmp[GHASH_SIZE]; ghash_update(&ctx->mac_ctx, ctx->mac, inlen); if (sm4_ctr_decrypt_update(&ctx->enc_ctx, ctx->mac, inlen, out, outlen) != 1) { error_print(); @@ -484,7 +484,7 @@ int sm4_gcm_decrypt_update(SM4_GCM_CTX *ctx, const uint8_t *in, size_t inlen, ui len = ctx->taglen - inlen; memcpy(tmp, ctx->mac + inlen, len); memcpy(tmp + len, in, inlen); - memcpy(ctx->mac, tmp, 32); + memcpy(ctx->mac, tmp, GHASH_SIZE); } else { ghash_update(&ctx->mac_ctx, ctx->mac, ctx->taglen); if (sm4_ctr_decrypt_update(&ctx->enc_ctx, ctx->mac, ctx->taglen, out, outlen) != 1) {