Repository navigation
crypto: add AES-192/256-CBC, cipher streaming, arbitrary GCM IV and AES-256-CMAC - #21957
Open
ThePassionate wants to merge 5 commits into
Open
ThePassionate wants to merge 5 commits into
ThePassionate wants to merge 5 commits into
Conversation
ThePassionate
requested review from
jerpelea,
pkarashchenko,
simbit18 and
xiaoxiang781216
as code owners
November 17, 2026 13:48
|
xiaoxiang781216
previously approved these changes
Nov 17, 2026
GUIDINGLI
previously approved these changes
Nov 17, 2026
CRYPTO_AES_192_CBC and CRYPTO_AES_256_CBC are accepted by cryptodev and the mbedtls aes_alt picks them for 24/32 byte keys, but cryptosoft only registered the 128-bit variant, so such a session matched no driver and failed with -EINVAL. enc_xform_aes already keys 128/192/256, so wire the two ids through newsession, freesession, process and the advertised algorithm table. Signed-off-by: makejian <makejian@xiaomi.com>
cryptodev_op() only propagated COP_FLAG_UPDATE to the hash descriptor, never to the cipher descriptor, so a cipher session restarted its IV/counter through exf->reinit() on every chunked request and a split operation never matched the one-shot result. Set CRD_F_UPDATE on crde as well. Give the plain AES xform a reinit method that keeps the running CBC IV inside AES_CTX, keep the unused CTR keystream tail in the key schedule so a request ending mid-block is continued by the next one, and copy the OFB/CFB IV into the key schedule instead of storing a pointer to the per-request descriptor, which goes stale once the request returns. swcr_encdec() no longer writes the chain IV back through crp_iv for ciphers with a reinit method: for those ivp still points at the input IV, so the copy was a no-op that would fault on a read-only IV buffer. Signed-off-by: makejian <makejian@xiaomi.com>
cryptodev rejected CRYPTO_AES_GCM_16, so GCM was unreachable through /dev/crypto, and the GMAC session keys carried a salt convention that no in-tree user exercises. Export it with plain 16/24/32-byte AES keys: 1) enc_xform reinit takes the IV length, so the cipher side derives its own counter block instead of swcr hard-coding the 96-bit layout. 2) aes_gcm_j0() derives J0 per NIST SP 800-38D 7.1, IV || 0^31 || 1 for a 96-bit IV and GHASH_H(IV || 0^s || 0^64 || [len(IV)]64) otherwise. aes_gmac_reinit() and aes_gcm_reinit() share it, and aes_gmac_final() no longer forces J0[15] = 1. 3) swcr_authenc() passes crp_ivlen to both reinit hooks and hands AAD to the MAC unpadded, so it may be split over several requests; an empty update closes the AAD before the first payload block, and the length block is computed from the accumulated aad/payload lengths. The MAC context is kept in the session across requests. 4) COP_FLAG_UPDATE_AAD is propagated to the hash descriptor, matching the userspace contract of an AAD-only first request. The keystream tail keeping in aes_ctr_crypt() from the previous commit makes a payload request ending mid-block continuable on the same session. Signed-off-by: makejian <makejian@xiaomi.com>
CRYPTO_AES_256_CMAC is a defined cryptodev algorithm id, but the software backend only registered the 128-bit variant and aes_cmac_setkey() hard-coded a 16-byte key schedule, so a 256-bit session failed with -EINVAL and any 32-byte key would have been truncated. Give aes_cmac_setkey() the key length, add auth_hash_cmac_aes_256 and wire CRYPTO_AES_256_CMAC (new id 45) through cryptodev, swcr newsession/freesession/authenc/process and the advertised algorithm table. Signed-off-by: makejian <makejian@xiaomi.com>
Blank line after declarations and brace placement only, in functions touched by the nearby commits; no semantic change. Signed-off-by: makejian <makejian@xiaomi.com>
ThePassionate
dismissed stale reviews from GUIDINGLI and xiaoxiang781216
via
November 18, 2026 01:04
b145632
ThePassionate
force-pushed
the
crypto-sym-capabilities
branch
from
November 18, 2026 01:04
5f202e9 to
b145632
Compare
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
Four symmetric-crypto capabilities that the software crypto driver is missing, plus a style cleanup:
CRYPTO_AES_192_CBC/CRYPTO_AES_256_CBCvariant by key length, so 24/32-byte keys stop being created as AES-128-CBC sessions.cryptodev_op()only setCRD_F_UPDATEon the hash descriptor, so a cipher session re-initialized its key stream/IV on every request and streaming a cipher through/dev/cryptowas impossible. The flag now reaches the cipher descriptor, AES-CTR keeps a byte-level keystream tail across requests (8-byte chunks of a block work), and CBC/OFB/CFB carry the IV in the key schedule between update steps. Split requests must keep passing the IV, as the existing blfcbc test already does.CRYPTO_AES_GCM_16was never accepted byCIOCGSESSION(the CTR session ABI carves a nonce out of the key). GCM now takes a plain 16/24/32-byte key, derives the pre-counter block through GHASH for non-96-bit IVs, and the authenc path is reworked to the three-stepUPDATE_AAD/UPDATE/ final flow with the MAC context kept in the session. The old prepended-IV adjustment inswcr_authenc()(the region guarded in crypto/cryptosoft: do not skip an IV byte in the CMAC authenc path #21930) is removed entirely; if crypto/cryptosoft: do not skip an IV byte in the CMAC authenc path #21930 lands first the rebase here is trivial. A zero-length update is a no-op instead of faulting.CRYPTO_AES_256_CMACid (45) with the 256-bit CMAC variant; the 128/256 selection follows the key length.Impact
crypto/,include/crypto/only. New algorithm id 45 (CRYPTO_ALGORITHM_MAX44 -> 45); no existing id or ABI changes. CTR keeps its nonce-in-key session ABI, so existing users (aes_alt, aesctr test) are unaffected.Testing
Board sim:sim/crypto (nuttx master e9eefaa), with the companion test PR in nuttx-apps:
aescbc: 6 vectors (4x RFC 3602 AES-128 + NIST SP 800-38A 192/256), each as one-shot and as a 16-byte-block update chain -aescbc test vector 0..5 okaesctr: 9 vectors, each as one-shot and as an 8-byte-chunk update chain (keystream tail across block boundaries) - all OKaesgcm: round trip plus known-answer check of ciphertext and tag for a 96-bit and an 8-byte IV (GCM spec test case 4 parameters; the 8-byte IV exercises the GHASH pre-counter block). The expected values match an independent host implementation (python cryptography) and the published spec values for the 96-bit case.aescmac: 8/8 - the four 128-bit and four 256-bit NIST vectors (the 128-bit 16-byte case also passes here because the authenc rework removes the one-byte truncation that crypto/cryptosoft: do not skip an IV byte in the CMAC authenc path #21930 fixes)Regression: des3cbc, aesxts, chacha20, chachapoly, hmac (35 vectors), hash (incl. huge-block and unaligned), crc32, pbkdf2, poly1305, castcbc, blfcbc, ecdsa (p256 keygen/sign/verify), dhm all pass unchanged. The
rsatest does not finish on sim within 25 minutes - that is pre-existing master behavior (bn-based modular exponentiation), unchanged by this series and fixed by #21939.tools/checkpatch.sh -c -u -m -g <base>..HEADpasses;tools/refresh.sh --silent sim:sim/cryptoreports no defconfig change.