Repository navigation
crypto/cryptosoft: do not skip an IV byte in the CMAC authenc path - #21930
Merged
Merged
Conversation
swcr_authenc() assumed that a composite request without an explicit IV carries the IV at the start of the source buffer, so it advanced crd_skip by the block size and shortened crd_len by the same amount. The CMAC cipher xform has no IV (ivsize 0) and a block size of 1, so for a plain AES-CMAC request the message was truncated by one byte and the MAC was computed over len-1 bytes: the NIST 16-byte vector returned f212d4c2154c8766de60c18c98fa0c93 instead of the RFC 4493 value 070a16b46b4d4144f79bdd9dd04a287c. The empty-message case only passed by luck, because the negative length kept the loop from running at all. Only apply the prepended-IV adjustment when the xform actually has an IV (ivsize > 0); leave the skip and length untouched otherwise. Signed-off-by: makejian <makejian@xiaomi.com>
ThePassionate
requested review from
jerpelea and
xiaoxiang781216
as code owners
November 17, 2026 06:46
|
xiaoxiang781216
approved these changes
Nov 17, 2026
GUIDINGLI
approved these changes
Nov 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
f212d4c2154c8766de60c18c98fa0c93instead of070a16b46b4d4144f79bdd9dd04a287c. The pre-existingaescmactest in nuttx-apps fails on its second case on unmodified master.Root cause, in
swcr_authenc():crd_skipwas advanced byexf->blocksizeandcrd_lenwas shortened by the same amount. The AES-CMAC cipher xform has no IV (ivsize0) and a block size of 1, so a plain CMAC request gotskip = 1, len = len - 1.buf + iand ignorescrd_skipentirely, so the MAC is computed over the firstlen - 1bytes 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.ivsize > 0, and the existing chachapoly test (explicit IV) passes unchanged.Testing
Board sim:crypto (nuttx master 4bf334e). 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:(The success message of the upstream aescmac test prints
aescbc- a copy-paste in the test itself; the four cases above are the AES-CMAC vectors of RFC 4493 / NIST SP 800-38B.)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>..HEADpasses.