Repository navigation
x86-64 AES key expansion, CFB8, ECB encryption and GCM prepare return without secret residue - #4901
Merged
Merged
Conversation
…M prepare and CMAC finish return without secret residue
Follow each with scrubTail where the residue analysis handles its code,
proving NoResidue, and drop their 20 lines from ci/residue_allowlist.txt:
* vg_aes_expand_key, vg_aes_expand_key_aesni (Proof/Aes/X86_64/Scrub.lean).
* vg_aes_gcm_prepare and its _pclmul_avx, _vpclmul, _vpclmul_avx512
variants (Proof/Gcm/X86_64/PrepareScrub.lean).
* Over the AES-NI and VAES block implementations, through new optional
analyses on BlocksImpl (cfb8EncRes, cfb8DecRes, ecbEncRes, ocbInitRes,
given in Variants/AesBlocks/X86_64.lean from BlocksResidue.lean):
vg_aes_cfb8_{en,de}crypt_{aesni,vaes}, vg_aes_ecb_encrypt_{aesni,vaes},
vg_aes_ocb_init_{aesni,vaes} (ModesScrub.lean, AesEcb/X86_64.lean).
* Over the implementations of vg_aes_ctr32, through new optional analyses
on Ctr32Impl (cmacFinishRes, gcmInitRes, from Ctr32Residue.lean):
vg_cmac_aes_finish{,_aesni,_vaes} and vg_aes_gcm_init_{aesni,vaes}
(on Aes.X86_64.gcmInitCode, equal to init_framed's code).
* vg_cmac_aes_absorb_aesni, through a new optional UpdateImpl.absorbRes.
postOut_of_local_pre (Proof/Aes/X86_64/Scrub.lean) gives PostOut for the
key setups, whose postconditions read only the key context for the key
lengths the precondition allows.
Left listed: vg_aes_cfb128_{en,de}crypt_{aesni,vaes} and vg_aes_ofb_{aesni,vaes}
(their _final functions call them by name), vg_aes_gcm_stream_init*,
vg_aes_gcm_stream_aad* (vg_aes_gcm_seal_gather_prepared* calls them by name),
vg_aes_gcm_wipe_prepared* (it branches on the power count, which its contract
leaks only as flagLeak), vg_aes_cbc_encrypt_aesni (its registration states
`written`, which withScrub does not take).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa
reaperhulk
marked this pull request as draft
November 10, 2026 08:58
Benchmarks showed that converting vg_cmac_aes_finish{,_aesni,_vaes},
vg_cmac_aes_absorb_aesni, vg_aes_gcm_init_{aesni,vaes} and
vg_aes_ocb_init_{aesni,vaes} cost 50-130 ns per call: each wipes its
2.3-2.6 KB withStackScratch buffer on return. Restore their registrations
and allowlist lines as on main, and delete what only they used
(Ctr32Impl.cmacFinishRes/gcmInitRes, UpdateImpl.absorbRes,
BlocksImpl.ocbInitRes and its analyses, gcmInitCode, postOut_of_local_pre,
Proof/Aes/X86_64/Ctr32Residue.lean, Proof/AesGcm/X86_64/Scrub.lean and
Proof/CmacAes/Stream/X86_64/Scrub.lean). Key expansion, GCM prepare,
CFB8 and ECB encryption stay converted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa
reaperhulk
marked this pull request as ready for review
November 10, 2026 09:49
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.
Continues the x86-64 residue burn-down (#4836). It converts 12 AES functions to prove
NoResidue, and removes their 12 lines fromci/residue_allowlist.txt(−12/+0). No trust change: nothing underTCB/orSpec/changes.What is converted
Key expansion:
vg_aes_expand_keyandvg_aes_expand_key_aesni(Proof/Aes/X86_64/Scrub.lean).GCM prepare:
vg_aes_gcm_prepare,_pclmul_avx,_vpclmuland_vpclmul_avx512(Proof/Gcm/X86_64/PrepareScrub.lean).Over the block implementations (
BlocksImpl):vg_aes_cfb8_{en,de}crypt_{aesni,vaes}vg_aes_ecb_encrypt_{aesni,vaes}BlocksImplgets three optional analysis fields:cfb8EncRes,cfb8DecResandecbEncRes. They are set inProof/Variants/AesBlocks/X86_64.leanfromProof/Aes/X86_64/BlocksResidue.lean. The registrations are inProof/Aes/X86_64/ModesScrub.lean, and ECB's inProof/AesEcb/X86_64.lean.What stays listed and why
init,absorb,finish), GCMinitand OCBinit: these take a 2.3–2.6 KB stack scratch (withStackScratch 2312/2568), sized for every implementation. The analysis cannot bound what the callee leaves in it, so a scrub wipes all of it, about 145–160 16-byte stores per call.cmac_aes_finish,cmac_aes_absorb_aesni,gcm_initandocb_init. Benchmarks run 42786235913 measured, with AES-NI at 64 B:vg_aes_cfb128_{en,de}crypt_{aesni,vaes}andvg_aes_ofb_{aesni,vaes}: their_finalfunctions call them.vg_aes_gcm_stream_init*andvg_aes_gcm_stream_aad*:vg_aes_gcm_seal_gather_prepared*calls them. Their analyses pass, so a later PR can give the callers the unscrubbed code under its own name.vg_aes_gcm_wipe_prepared{,_avx}: the code branches on the power count, which the contract does not let it leak.vg_aes_cbc_encrypt_aesni: its registration writes a scratch buffer (written), whichwithScrubdoes not support yet.vg_aes_ocb_seal,ocb_openandsiv_init: the analysis fails.Proofs
sorry,native_decide,bv_decide, axioms or resource options.BlocksResiduetakes about a minute to build: each large-stack analysis is 20–30 s in the kernel, even withmaterialize_code. It stays within the default heartbeats, andcheck_lean_speed.pypasses.Checks
lake build(all modules),Emit.leanandEmit.lean --check: pass.--base origin/mainwhere it applies): pass.check_lean_public_imports.pyon the changed modules: pass.cargo fmt --checkandcargo clippy --all-targets -- -D warnings: pass.cargo testwith Wycheproof, with every CPU feature and withVG_CPU_FEATURES=none: pass.Speed
Two scoped Benchmarks runs, each x86-64 against the merge base, in every configuration that chooses among AES's implementations, one interleaved run:
🤖 Generated with Claude Code
https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa