Skip to content

Commit d9beafb

Browse files
committed
Check tag size in wc_AesEaxDecryptFinal
1 parent 4bb9883 commit d9beafb

2 files changed

Lines changed: 49 additions & 1 deletion

File tree

wolfcrypt/src/aes.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16823,6 +16823,11 @@ int wc_AesEaxDecryptAuth(const byte* key, word32 keySz, byte* out,
1682316823
return BAD_FUNC_ARG;
1682416824
}
1682516825

16826+
if (authTagSz < WOLFSSL_MIN_AUTH_TAG_SZ
16827+
|| authTagSz > WC_AES_BLOCK_SIZE) {
16828+
return BAD_FUNC_ARG;
16829+
}
16830+
1682616831
#if defined(WOLFSSL_SMALL_STACK)
1682716832
if ((eax = (AesEax *)XMALLOC(sizeof(AesEax),
1682816833
NULL,
@@ -17171,7 +17176,8 @@ int wc_AesEaxDecryptFinal(AesEax* eax,
1717117176
byte authTag[WC_AES_BLOCK_SIZE];
1717217177
#endif
1717317178

17174-
if (eax == NULL || authIn == NULL || authInSz > WC_AES_BLOCK_SIZE) {
17179+
if (eax == NULL || authIn == NULL || authInSz > WC_AES_BLOCK_SIZE
17180+
|| authInSz < WOLFSSL_MIN_AUTH_TAG_SZ) {
1717517181
return BAD_FUNC_ARG;
1717617182
}
1717717183

wolfcrypt/test/test.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19486,6 +19486,48 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_eax_test(void)
1948619486
}
1948719487

1948819488
}
19489+
19490+
/* Regression test: wc_AesEaxDecryptAuth must reject authTagSz below
19491+
* WOLFSSL_MIN_AUTH_TAG_SZ (including zero), otherwise an attacker could
19492+
* bypass tag verification by supplying an empty tag. */
19493+
#if WOLFSSL_MIN_AUTH_TAG_SZ > 0
19494+
{
19495+
byte zero_ct[16];
19496+
byte zero_pt[16];
19497+
byte zero_tag[16];
19498+
XMEMSET(zero_ct, 0, sizeof(zero_ct));
19499+
XMEMSET(zero_tag, 0, sizeof(zero_tag));
19500+
19501+
ret = wc_AesEaxDecryptAuth(vectors[0].key,
19502+
(word32)vectors[0].key_length,
19503+
zero_pt,
19504+
zero_ct, (word32)sizeof(zero_ct),
19505+
vectors[0].iv,
19506+
(word32)vectors[0].iv_length,
19507+
zero_tag, 0,
19508+
vectors[0].aad,
19509+
(word32)vectors[0].aad_length);
19510+
if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
19511+
return WC_TEST_RET_ENC_EC(ret);
19512+
}
19513+
19514+
#if WOLFSSL_MIN_AUTH_TAG_SZ > 1
19515+
ret = wc_AesEaxDecryptAuth(vectors[0].key,
19516+
(word32)vectors[0].key_length,
19517+
zero_pt,
19518+
zero_ct, (word32)sizeof(zero_ct),
19519+
vectors[0].iv,
19520+
(word32)vectors[0].iv_length,
19521+
zero_tag, WOLFSSL_MIN_AUTH_TAG_SZ - 1,
19522+
vectors[0].aad,
19523+
(word32)vectors[0].aad_length);
19524+
if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
19525+
return WC_TEST_RET_ENC_EC(ret);
19526+
}
19527+
#endif
19528+
}
19529+
#endif /* WOLFSSL_MIN_AUTH_TAG_SZ > 0 */
19530+
1948919531
return 0;
1949019532
}
1949119533

0 commit comments

Comments
 (0)