From 871dc9c19b3e7956c332231488e5cd6c4aff88d8 Mon Sep 17 00:00:00 2001 From: kaleb-himes Date: Fri, 21 Jun 2024 15:53:18 -0400 Subject: [PATCH] Implement peer review feedback --- wolfcrypt/src/aes.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/wolfcrypt/src/aes.c b/wolfcrypt/src/aes.c index 915b22dbb0..dc07259c6e 100644 --- a/wolfcrypt/src/aes.c +++ b/wolfcrypt/src/aes.c @@ -10643,11 +10643,6 @@ static WARN_UNUSED_RESULT int roll_auth( word32 remainder; int ret; - /* Sanity check on authIn to prevent segfault in xorbuf() where - * variable 'in' is dereferenced as the mask 'm' in misc.c */ - if (in == NULL) - return BAD_FUNC_ARG; - /* encode the length in */ if (inSz <= 0xFEFF) { authLenSz = 2; @@ -10766,6 +10761,11 @@ int wc_AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz, authTagSz > AES_BLOCK_SIZE) return BAD_FUNC_ARG; + /* Sanity check on authIn to prevent segfault in xorbuf() where + * variable 'in' is dereferenced as the mask 'm' in misc.c */ + if (authIn == NULL && authInSz > 0) + return BAD_FUNC_ARG; + /* sanity check on tag size */ if (wc_AesCcmCheckTagSize((int)authTagSz) != 0) { return BAD_FUNC_ARG; @@ -10908,6 +10908,12 @@ int wc_AesCcmDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz, authTagSz > AES_BLOCK_SIZE) return BAD_FUNC_ARG; + /* Sanity check on authIn to prevent segfault in xorbuf() where + * variable 'in' is dereferenced as the mask 'm' in misc.c */ + if (authIn == NULL && authInSz > 0) + return BAD_FUNC_ARG; + + /* sanity check on tag size */ if (wc_AesCcmCheckTagSize((int)authTagSz) != 0) { return BAD_FUNC_ARG;