ThePassionate opened a new pull request, #21930: URL: https://github.com/apache/nuttx/pull/21930
## Summary The software AES-CMAC computation through a composite cryptodev session is wrong for every message that carries data: the 16-byte NIST SP 800-38B / RFC 4493 vector returns `f212d4c2154c8766de60c18c98fa0c93` instead of `070a16b46b4d4144f79bdd9dd04a287c`. The pre-existing `aescmac` test in nuttx-apps fails on its second case on unmodified master. Root cause, in `swcr_authenc()`: * A composite request without an explicit IV was assumed to carry the IV at the start of the source buffer, so `crd_skip` was advanced by `exf->blocksize` and `crd_len` was shortened by the same amount. The AES-CMAC cipher xform has no IV (`ivsize` 0) and a block size of 1, so a plain CMAC request got `skip = 1, len = len - 1`. * The data loop then copies from `buf + i` and ignores `crd_skip` entirely, so the MAC is computed over the **first** `len - 1` bytes of the message instead of the full message. The empty-message case passes only by luck: the length becomes negative and the loop does not run at all. Fix: only apply the prepended-IV adjustment when the xform actually has an IV (`ivsize > 0`); leave skip and length untouched otherwise. One line, no behavior change for the xforms that do carry a prepended IV. ## Impact * `crypto/cryptosoft.c`, one line. No interface change. * Fixes every CMAC-via-composite-session computation of non-empty messages. * The GCM/GMAC/ChaCha20-Poly1305 composite paths are unchanged: they either use an explicit IV or have `ivsize > 0`, and the existing chachapoly test (explicit IV) passes unchanged. ## Testing Board sim:crypto (nuttx master 4bf334e4623). Before the fix, `aescmac` (nuttx-apps) stops at case 2 (the 16-byte vector) with the wrong digest above; after the fix all four NIST cases pass: ``` nsh> aescmac aescbc test 0 ok (0-byte message, bb1d6929...) aescbc test 1 ok (16-byte message, 070a16b4... <- was f212d4c2...) aescbc test 2 ok (20-byte message, d1d67b76...) aescbc test 3 ok (64-byte message, 51f0bea7...) ``` The wrong value is reproducible analytically: AES-CMAC over the first 15 bytes of the 16-byte vector with the same key yields exactly `f212d4c2...`, confirming the one-byte truncation. Regression: aescbc, hmac (20 vectors), chacha20 and chachapoly pass unchanged. `tools/checkpatch.sh -c -u -m -g <base>..HEAD` passes. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
