Skip to content

Commit 4a103a1

Browse files
committed
AES: tighten AEAD input validation
1 parent 6596419 commit 4a103a1

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

wolfcrypt/src/aes.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10062,8 +10062,11 @@ int wc_AesGcmEncrypt(Aes* aes, byte* out, const byte* in, word32 sz,
1006210062
int ret;
1006310063

1006410064
/* argument checks */
10065-
if (aes == NULL || authTagSz > WC_AES_BLOCK_SIZE || ivSz == 0 ||
10066-
((authTagSz > 0) && (authTag == NULL)) ||
10065+
/* If sz is non-zero, both in and out must be set; if sz is 0, in and
10066+
* out are don't cares (GMAC case), matching wc_AesGcmDecrypt. */
10067+
if (aes == NULL || iv == NULL || ivSz == 0 ||
10068+
(sz != 0 && (in == NULL || out == NULL)) ||
10069+
authTag == NULL || authTagSz > WC_AES_BLOCK_SIZE ||
1006710070
((authInSz > 0) && (authIn == NULL)))
1006810071
{
1006910072
return BAD_FUNC_ARG;
@@ -17140,7 +17143,8 @@ int wc_AesEaxEncryptFinal(AesEax* eax, byte* authTag, word32 authTagSz)
1714017143
int ret;
1714117144
word32 i;
1714217145

17143-
if (eax == NULL || authTag == NULL || authTagSz > WC_AES_BLOCK_SIZE) {
17146+
if (eax == NULL || authTag == NULL || authTagSz == 0 ||
17147+
authTagSz > WC_AES_BLOCK_SIZE) {
1714417148
return BAD_FUNC_ARG;
1714517149
}
1714617150

@@ -17197,7 +17201,8 @@ int wc_AesEaxDecryptFinal(AesEax* eax,
1719717201
byte authTag[WC_AES_BLOCK_SIZE];
1719817202
#endif
1719917203

17200-
if (eax == NULL || authIn == NULL || authInSz > WC_AES_BLOCK_SIZE) {
17204+
if (eax == NULL || authIn == NULL || authInSz == 0 ||
17205+
authInSz > WC_AES_BLOCK_SIZE) {
1720117206
return BAD_FUNC_ARG;
1720217207
}
1720317208

0 commit comments

Comments
 (0)