-
Notifications
You must be signed in to change notification settings - Fork 991
20260616-aes-fixes #10709
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
20260616-aes-fixes #10709
Changes from all commits
5def276
1070384
9d15bc7
881fe76
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12808,6 +12808,18 @@ int wc_AesGcmEncryptUpdate(Aes* aes, byte* out, const byte* in, word32 sz, | |
| ret = MISSING_IV; | ||
| } | ||
|
|
||
| /* Prevent overflow of aes->cSz and ->aSz. Per NIST SP 800-38D section | ||
| * 5.2.1.1, the maximum allowed ciphertext limit is 2^32 - 2 blocks, but we | ||
| * currently pass around the cumulative sizes in bytes as word32s, so we | ||
| * can't currently support the maximum allowed. | ||
| */ | ||
| if ((ret == 0) && | ||
|
Frauschi marked this conversation as resolved.
|
||
| ((aes->cSz > WOLFSSL_MAX_32BIT - sz) || | ||
| (aes->aSz > WOLFSSL_MAX_32BIT - authInSz))) | ||
| { | ||
| ret = AES_GCM_OVERFLOW_E; | ||
| } | ||
|
|
||
| if ((ret == 0) && aes->ctrSet && (aes->aSz == 0) && (aes->cSz == 0)) { | ||
| aes->invokeCtr[0]++; | ||
| if (aes->invokeCtr[0] == 0) { | ||
|
|
@@ -12950,6 +12962,18 @@ int wc_AesGcmDecryptUpdate(Aes* aes, byte* out, const byte* in, word32 sz, | |
| ret = MISSING_IV; | ||
| } | ||
|
|
||
| /* Prevent overflow of aes->cSz and ->aSz. Per NIST SP 800-38D section | ||
| * 5.2.1.1, the maximum allowed ciphertext limit is 2^32 - 2 blocks, but we | ||
| * currently pass around the cumulative sizes in bytes as word32s, so we | ||
| * can't currently support the maximum allowed. | ||
| */ | ||
| if ((ret == 0) && | ||
| ((aes->cSz > WOLFSSL_MAX_32BIT - sz) || | ||
| (aes->aSz > WOLFSSL_MAX_32BIT - authInSz))) | ||
| { | ||
| ret = AES_GCM_OVERFLOW_E; | ||
| } | ||
|
|
||
| if (ret == 0) { | ||
| /* Decrypt with AAD and/or cipher text. */ | ||
| #ifdef WOLFSSL_AESNI | ||
|
|
@@ -13360,6 +13384,18 @@ int wc_AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz, | |
| return status; | ||
| } | ||
|
|
||
| { | ||
| word32 lenSz = (word32)WC_AES_BLOCK_SIZE - 1U - nonceSz; | ||
| /* With a large nonce, B[] runs out of room to represent inSz, and beyond | ||
| * that, the counter itself can wrap. | ||
| */ | ||
| if ((lenSz < sizeof(inSz)) && | ||
| (inSz >= ((word32)1 << (lenSz * 8)))) | ||
| { | ||
| return AES_CCM_OVERFLOW_E; | ||
| } | ||
| } | ||
|
|
||
| status = wolfSSL_CryptHwMutexLock(); | ||
| if (status != 0) | ||
| return status; | ||
|
|
@@ -13394,6 +13430,18 @@ int wc_AesCcmDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz, | |
| return status; | ||
| } | ||
|
|
||
| { | ||
| word32 lenSz = (word32)WC_AES_BLOCK_SIZE - 1U - nonceSz; | ||
| /* With a large nonce, B[] runs out of room to represent inSz, and beyond | ||
| * that, the counter itself can wrap. | ||
| */ | ||
| if ((lenSz < sizeof(inSz)) && | ||
| (inSz >= ((word32)1 << (lenSz * 8)))) | ||
| { | ||
| return AES_CCM_OVERFLOW_E; | ||
| } | ||
| } | ||
|
|
||
| status = wolfSSL_CryptHwMutexLock(); | ||
| if (status != 0) | ||
| return status; | ||
|
|
@@ -13586,6 +13634,17 @@ int wc_AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz, | |
| return BAD_FUNC_ARG; | ||
| } | ||
|
|
||
| lenSz = (byte)(WC_AES_BLOCK_SIZE - 1U - nonceSz); | ||
|
|
||
| /* With a large nonce, B[] runs out of room to represent inSz, and beyond | ||
| * that, the counter itself can wrap. | ||
| */ | ||
| if ((lenSz < sizeof(inSz)) && | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 [Low] Reused AES_CCM_OVERFLOW_E error string is about 'invocation counter', not input length The new CCM checks return Fix: Consider broadening the error string (e.g. 'AES-CCM length/counter overflow') so it covers the input-size case, or document the dual meaning. Not blocking.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error string does need updating. Have made a note and will fix in a follow-up PR, or if this one needs another spin for a substantive reason, will fix it here.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 [Low] Raw sizeof in mixed-signedness comparison deviates from function's wordSz convention · convention The new check Fix: Use the existing
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not something to fix. The same new code pattern is used at 10 different code points, with widely varying local context. |
||
| (inSz >= ((word32)1 << (lenSz * 8)))) | ||
| { | ||
| return AES_CCM_OVERFLOW_E; | ||
| } | ||
|
|
||
| #ifdef WOLF_CRYPTO_CB | ||
| #ifndef WOLF_CRYPTO_CB_FIND | ||
| if (aes->devId != INVALID_DEVID) | ||
|
|
@@ -13602,7 +13661,7 @@ int wc_AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz, | |
|
|
||
| XMEMSET(A, 0, sizeof(A)); | ||
| XMEMCPY(B+1, nonce, nonceSz); | ||
| lenSz = (byte)(WC_AES_BLOCK_SIZE - 1U - nonceSz); | ||
|
|
||
| B[0] = (byte)((authInSz > 0 ? 64 : 0) | ||
| + (8 * (((byte)authTagSz - 2) / 2)) | ||
| + (lenSz - 1)); | ||
|
|
@@ -13739,6 +13798,17 @@ int wc_AesCcmDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz, | |
| return BAD_FUNC_ARG; | ||
| } | ||
|
|
||
| lenSz = (byte)(WC_AES_BLOCK_SIZE - 1U - nonceSz); | ||
|
|
||
| /* With a large nonce, B[] runs out of room to represent inSz, and beyond | ||
| * that, the counter itself can wrap. | ||
| */ | ||
| if ((lenSz < sizeof(inSz)) && | ||
| (inSz >= ((word32)1 << (lenSz * 8)))) | ||
| { | ||
| return AES_CCM_OVERFLOW_E; | ||
| } | ||
|
|
||
| #ifdef WOLF_CRYPTO_CB | ||
| #ifndef WOLF_CRYPTO_CB_FIND | ||
| if (aes->devId != INVALID_DEVID) | ||
|
|
@@ -13757,7 +13827,6 @@ int wc_AesCcmDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz, | |
| oSz = inSz; | ||
| XMEMSET(A, 0, sizeof A); | ||
| XMEMCPY(B+1, nonce, nonceSz); | ||
| lenSz = (byte)(WC_AES_BLOCK_SIZE - 1U - nonceSz); | ||
|
|
||
| B[0] = (byte)(lenSz - 1U); | ||
| for (i = 0; i < lenSz; i++) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.