Skip to content

Commit bf492eb

Browse files
authored
Merge pull request #10175 from yosuke-wolfssl/f_2205
Fix authTagSz validation
2 parents e73b255 + d48fc18 commit bf492eb

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

wolfcrypt/src/aes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12596,7 +12596,7 @@ int wc_AesGcmDecryptFinal(Aes* aes, const byte* authTag, word32 authTagSz)
1259612596

1259712597
/* Check validity of parameters. */
1259812598
if ((aes == NULL) || (authTag == NULL) || (authTagSz > WC_AES_BLOCK_SIZE) ||
12599-
(authTagSz == 0)) {
12599+
(authTagSz < WOLFSSL_MIN_AUTH_TAG_SZ)) {
1260012600
ret = BAD_FUNC_ARG;
1260112601
}
1260212602

wolfcrypt/test/test.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18362,6 +18362,21 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_test(void)
1836218362
ERROR_OUT(WC_TEST_RET_ENC_NC, out);
1836318363
#endif
1836418364

18365+
/* Regression test: wc_AesGcmDecryptFinal must reject authTagSz below
18366+
* WOLFSSL_MIN_AUTH_TAG_SZ, consistent with wc_AesGcmDecrypt and
18367+
* wc_AesGcmEncryptFinal. */
18368+
#if defined(HAVE_AES_DECRYPT) && WOLFSSL_MIN_AUTH_TAG_SZ > 1
18369+
ret = wc_AesGcmDecryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
18370+
if (ret != 0)
18371+
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
18372+
ret = wc_AesGcmDecryptUpdate(enc, resultP, c1, sizeof(c1), a, sizeof(a));
18373+
if (ret != 0)
18374+
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
18375+
ret = wc_AesGcmDecryptFinal(enc, t1, WOLFSSL_MIN_AUTH_TAG_SZ - 1);
18376+
if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
18377+
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
18378+
#endif /* HAVE_AES_DECRYPT && WOLFSSL_MIN_AUTH_TAG_SZ > 1 */
18379+
1836518380
/* alen is the size to pass in with each update. */
1836618381
for (alen = 1; alen < WC_AES_BLOCK_SIZE + 1; alen++) {
1836718382
ret = wc_AesGcmEncryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));

0 commit comments

Comments
 (0)