Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 38 additions & 32 deletions wolfcrypt/src/aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -16779,8 +16779,9 @@ int wc_AesEaxEncryptAuth(const byte* key, word32 keySz, byte* out,
int ret;
int eaxInited = 0;

if (key == NULL || out == NULL || in == NULL || nonce == NULL
|| authTag == NULL || authIn == NULL) {
if (key == NULL || nonce == NULL || authTag == NULL
|| (inSz > 0 && (out == NULL || in == NULL))
|| (authInSz > 0 && authIn == NULL)) {
return BAD_FUNC_ARG;
}

Expand Down Expand Up @@ -16842,8 +16843,9 @@ int wc_AesEaxDecryptAuth(const byte* key, word32 keySz, byte* out,
int ret;
int eaxInited = 0;

if (key == NULL || out == NULL || in == NULL || nonce == NULL
|| authTag == NULL || authIn == NULL) {
if (key == NULL || nonce == NULL || authTag == NULL
|| (inSz > 0 && (out == NULL || in == NULL))
|| (authInSz > 0 && authIn == NULL)) {
return BAD_FUNC_ARG;
}

Expand Down Expand Up @@ -17031,24 +17033,26 @@ int wc_AesEaxEncryptUpdate(AesEax* eax, byte* out,
{
int ret;

if (eax == NULL || out == NULL || in == NULL) {
if (eax == NULL || (inSz > 0 && (out == NULL || in == NULL))) {
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wc_AesEaxEncryptUpdate still doesn't validate authIn when authInSz > 0. If the function later CMAC-updates AAD when authInSz is non-zero, passing authIn == NULL will result in a NULL dereference. Fix by extending the argument validation to also require authIn != NULL when authInSz > 0 (mirroring the one-shot Auth functions).

Suggested change
if (eax == NULL || (inSz > 0 && (out == NULL || in == NULL))) {
if (eax == NULL || (inSz > 0 && (out == NULL || in == NULL)) ||
(authInSz > 0 && authIn == NULL)) {

Copilot uses AI. Check for mistakes.
return BAD_FUNC_ARG;
}

/*
* Encrypt the plaintext using AES CTR
* C = CTR(M)
*/
if ((ret = wc_AesCtrEncrypt(&eax->aes, out, in, inSz)) != 0) {
return ret;
}
if (inSz > 0) {
/*
* Encrypt the plaintext using AES CTR
* C = CTR(M)
*/
if ((ret = wc_AesCtrEncrypt(&eax->aes, out, in, inSz)) != 0) {
return ret;
}

/*
* update OMAC with new ciphertext
* C' = OMAC^2_K(C)
*/
if ((ret = wc_CmacUpdate(&eax->ciphertextCmac, out, inSz)) != 0) {
return ret;
/*
* update OMAC with new ciphertext
* C' = OMAC^2_K(C)
*/
if ((ret = wc_CmacUpdate(&eax->ciphertextCmac, out, inSz)) != 0) {
return ret;
}
}

/* If there exists new auth data, update the OMAC for that as well */
Expand Down Expand Up @@ -17076,24 +17080,26 @@ int wc_AesEaxDecryptUpdate(AesEax* eax, byte* out,
{
int ret;

if (eax == NULL || out == NULL || in == NULL) {
if (eax == NULL || (inSz > 0 && (out == NULL || in == NULL))) {
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wc_AesEaxDecryptUpdate has the same gap as EncryptUpdate: there is no guard ensuring authIn != NULL when authInSz > 0. If the function proceeds to CMAC-update AAD for non-zero authInSz, this can crash. Add a length-gated NULL check for authIn in the argument validation.

Suggested change
if (eax == NULL || (inSz > 0 && (out == NULL || in == NULL))) {
if (eax == NULL || (inSz > 0 && (out == NULL || in == NULL)) ||
(authInSz > 0 && authIn == NULL)) {

Copilot uses AI. Check for mistakes.
return BAD_FUNC_ARG;
}

/*
* Decrypt the plaintext using AES CTR
* C = CTR(M)
*/
if ((ret = wc_AesCtrEncrypt(&eax->aes, out, in, inSz)) != 0) {
return ret;
}
if (inSz > 0) {
/*
* Decrypt the plaintext using AES CTR
* C = CTR(M)
*/
if ((ret = wc_AesCtrEncrypt(&eax->aes, out, in, inSz)) != 0) {
return ret;
}

/*
* update OMAC with new ciphertext
* C' = OMAC^2_K(C)
*/
if ((ret = wc_CmacUpdate(&eax->ciphertextCmac, in, inSz)) != 0) {
return ret;
/*
* update OMAC with new ciphertext
* C' = OMAC^2_K(C)
*/
if ((ret = wc_CmacUpdate(&eax->ciphertextCmac, in, inSz)) != 0) {
return ret;
}
}

/* If there exists new auth data, update the OMAC for that as well */
Expand Down
Loading