mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-05-06 16:36:16 +08:00
Update aead.c
Fix bug in GCM tmp buffer size
This commit is contained in:
12
src/aead.c
12
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) {
|
||||
|
||||
Reference in New Issue
Block a user