Repository navigation
x86-64 AES-NI/VAES GCM and OCB key setups and CMAC finish: a working space of the size the code uses, without secret residue - #4939
Merged
Conversation
…ace of the size the code uses
The AES-NI and VAES implementations of vg_aes_ctr32, vg_aes_encrypt_blocks
and vg_aes_expand_key_scratch never touch their scratch buffers, yet their
callers set aside 2-2.5 KB for them, and the residue analysis cannot place
the callees' stores through advancing data pointers, so the scrub tails
wiped the whole frame (145-161 stores). Each now also gives its contract
without a scratch buffer (Ctr32Impl.free, BlocksImpl.free,
AesNi.Key.expandKey3X86_64; the existing proofs, generalized over the
scratch region, cover both), and over those:
* vg_aes_gcm_init_{aesni,vaes}: a 176-byte working space (the block T and
the saved registers it writes itself), same code; tail 161 -> 12 / 6 stores.
* vg_aes_ocb_init_{aesni,vaes}: 24 bytes (the saved registers); 161 -> 2 / 1.
* vg_cmac_aes_finish_{aesni,vaes}: 16 bytes, vg_cmac_aes_finalize's counter
block, passed as scratch - 2048 (finishF); 145 -> 2 / 1.
The finalize proof (FPre) is generalized over the writable part of its
scratch buffer, with a contract finalizeX86_64F of the counter block alone;
the 2304/2560-byte contracts and the baseline instances are unchanged. These
six functions now prove NoResidue and leave ci/residue_allowlist.txt.
No contract in Spec/ and nothing in TCB/ changes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa
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.
This PR converts six x86-64 functions to prove
NoResidue, removing their 6 lines fromci/residue_allowlist.txt(−6/+0):vg_aes_gcm_init_{aesni,vaes}vg_aes_ocb_init_{aesni,vaes}vg_cmac_aes_finish_{aesni,vaes}It gives each a stack working space of the size its code uses, so their scrub tails are small. No trust change: nothing under
TCB/orSpec/changes, and no existing contract is weakened.Why
#4901 converted these functions at first, then dropped them: wiping their 2.3–2.6 KB working space (
withStackScratch 2312/2568, sized for every implementation) on every call cost too much. At 64 B, AES-NI CMAC was 54–87% slower, and OCB and GCM encryption 11–40% slower.The AES-NI and VAES callees (ctr32, encrypt-blocks, key expansion) never touch that scratch. Their code uses only:
[96,112)and[128,176), 176 of 2560 bytes;[0,24);The analysis still selected the whole frame, because the callees store through advancing data pointers it cannot place. That makes every byte of the frame possibly secret. As in #4937 for TDEA-CMAC, the fix is a smaller frame.
The change
AesNi.ctr32X86_64FandProof.Aes.blocksX86_64F, alongside the existingexpandKey3X86_64.Prewith any trailing regions. Decryption's scratch facts move toPreS.Ctr32Impl.freeandBlocksImpl.freefields.Fvariants of the wp, CT, verified and framed proofs reuse the old structure.save_ok/restore_ok/exit_oktake any working space of at least 176 bytes.finishFcode passesscratch - 2048to finalize, with a 24-byte frame.FPreis generalized over finalize's writable scratch region, with a new contractfinalizeX86_64F.FPre.Ctr32Residue.leanandBlocksResidue.lean, which build in seconds; x86-64 AES key expansion, CFB8, ECB encryption and GCM prepare return without secret residue #4901's took about 150 s.Scrub.leanfiles for GCM, OCB and the CMAC stream.freeis present and the old registration otherwise.vg_aes_gcm_init_aesni/_vaesvg_aes_ocb_init_aesni/_vaesvg_cmac_aes_finish_aesni/_vaesWhat stays listed
vg_cmac_aes_finish: the scalar ctr32 really uses about 2 KB of the scratch (round keys up tor9+1920).vg_cmac_aes_absorb_aesni: the same approach should work. A trial analysis gives a 56-byte frame with a 4-granule wipe. It needs the same rework of the absorb proofs (AbsorbCorrect,AbsorbBlocks,UArgs) and a scratch-freeupdate_aesnicontract, left for a follow-up.Checks
lake build(all modules),Emit.leanandEmit.lean --check: pass.--base origin/mainwhere it applies): pass.check_lean_public_imports.py: pass.cargo fmt --checkandcargo clippy --all-targets -- -D warnings: pass.cargo testwith Wycheproof, with every CPU feature and withVG_CPU_FEATURES=none: pass.Speed
Benchmarks run 42952046134: x86-64, AES-128 GCM and OCB encryption and AES-128 CMAC (the benchmarks that showed #4901's regressions) against
16824a76c, in all 15 configurations that choose among the implementations, one interleaved run.aes,avx,avx2,ssse3andaes,avx,avx2,pclmulqdq,ssse3,vaes. Configurations that run the same AES-NI finish, such asaes,avx,avx2,pclmulqdq,ssse3,vpclmulqdq, are 5.1% faster, and the tail adds 1–2 stores. So this spread looks like noise from one run, not a cost of the change. x86-64 AES key expansion, CFB8, ECB encryption and GCM prepare return without secret residue #4901's first attempt had CMAC at 64 B 54–87% slower.🤖 Generated with Claude Code
https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa