nxp hashcrypt: validate AES ECB/CBC args and zero-length - #11261
nxp hashcrypt: validate AES ECB/CBC args and zero-length#11261night1rider wants to merge 1 commit into
Conversation
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11261
Scan targets checked: wolfcrypt-port-bugs
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
|
Can one of the admins verify this patch? |
|
jenkins retest this please |
9404b05 to
db1fb36
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates the NXP HASHCRYPT AES port implementation to behave more defensively, aligning ECB/CBC argument handling with other wolfCrypt AES mode implementations (notably returning early on sz == 0 and rejecting NULL pointers).
Changes:
- Added
NULLargument validation (aes,in,out) for AES ECB encrypt/decrypt. - Added
NULLargument validation (aes,in,out) for AES CBC encrypt/decrypt. - Added early return on
sz == 0for ECB/CBC to avoid unnecessary key setup and CBC IV copying.
Suppressed comments (3)
wolfcrypt/src/port/nxp/hashcrypt_port.c:244
- ECB mode requires
szto be a multiple of the AES block size. Without validating this, callers can pass a non-block-multiple size and get a genericWC_HW_Einstead ofBAD_LENGTH_E, and behavior depends on the HAL implementation.
if (sz == 0)
return 0;
ret = _hashcrypt_set_key(aes);
wolfcrypt/src/port/nxp/hashcrypt_port.c:268
- CBC mode requires
szto be a multiple of the AES block size. Without a block-size check,XMEMCPY(aes->reg, out + sz - 16, 16)can underflow whensz < 16and cause out-of-bounds reads/writes.
if (sz == 0)
return 0;
ret = _hashcrypt_set_key(aes);
wolfcrypt/src/port/nxp/hashcrypt_port.c:294
- CBC mode requires
szto be a multiple of the AES block size. Without validating this,XMEMCPY(tmp_iv, in + sz - 16, 16)can read before the start ofinwhensz < 16, causing out-of-bounds access.
if (sz == 0)
return 0;
ret = _hashcrypt_set_key(aes);
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Reject NULL aes/in/out with BAD_FUNC_ARG and return early on zero length before key setup and the sz-16 IV copy, matching wc_AesCtrEncrypt.
db1fb36 to
34df6e1
Compare
Reject NULL aes/in/out with BAD_FUNC_ARG and return early on zero length before key setup and the sz-16 IV copy, matching wc_AesCtrEncrypt.