Repository navigation
GCM x86-64: baseline vg_aes_gcm_prepare by calls of vg_ghash - #4538
Merged
Merged
Conversation
The baseline vg_aes_gcm_prepare, writing the 48 prepared powers of a key context, for the implementations of vg_ghash with no prepare of their own (today the baseline vg_ghash). It calls vg_ghash 47 times on one zero block: each power is first stored in its slot as vg_ghash's accumulator, then turned in place into its prepared power with vg_ghash's own hInv. The slot pointer (rsi) and the scratch buffer (r8, 312 bytes on the stack, zeroed on return) are registers vg_ghash never writes, so they stay public through the calls and constant time is one taint_decide. Registered generic over vg_ghash's implementations (Generic/Ghash/X86_64/Prepare.lean); vg_ghash_pclmul and vg_ghash_vpclmul have none, as vg_aes_gcm_prepare_pclmul and vg_aes_gcm_prepare_vpclmul compute the powers themselves. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFuGsz7F32Tm9DLkuP
Dispatch.lean ranked `_vpclmul` but had no entry for a bare `_pclmul_avx`, which it read as its parts and put first. Every CPU with VPCLMULQDQ and AVX2 also has AVX and PCLMULQDQ, so vg_aes_gcm_prepare_auto never chose the 256-bit `_vpclmul` code. The order is now `_vpclmul_avx512`, `_vpclmul`, `_pclmul_avx`, then the baseline; no other dispatcher changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFuGsz7F32Tm9DLkuP
Member
Author
|
This is expected for this PR. With a baseline Pushed Generated by Claude Code |
alex
marked this pull request as ready for review
November 7, 2026 22:21
alex
pushed a commit
that referenced
this pull request
Nov 7, 2026
With #4538's baseline vg_aes_gcm_prepare on main, the dispatcher also tries vg_aes_gcm_prepare_pclmul, after _pclmul_avx and before the baseline. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHHDjuK1puxAcLZKKff
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 is step (2a) of the GCM single-family plan: an x86-64
vg_aes_gcm_preparethat needs no CPU feature. It writes all 48 prepared powers (PreparedPowersRepr). With it,vg_aes_gcm_prepare_autohas a baseline to fall back to.Code
Impl/Gcm/X86_64/PrepareCall.lean:vg_ghash47 times, each on one zero block:Y := Y • H.Hⁿis first stored in its own slot of the context, asvg_ghash's big-endian accumulator. Stepncopies it to the next power's slot, then turns it in place intopreparedPower(Hⁿ), as a little-endian 128-bit word, with the baselinevg_ghash's ownhInv. It then callsvg_ghashon the next slot.rsiholds the current slot andr8holds the 312-byte scratch buffer. Neithervg_ghashnorvg_ghash_pclmulever writes these two registers.vg_ghash's working space, a copy ofH, the zero block and the savedr12–r14. It sits in a stack frame that is zeroed on return (withStackScratchWiped, 328 bytes of stack).Proof
Proof/Gcm/X86_64/PrepareCall.leanproves it againstSpec.Gcm.prepareContract.St nis what holds before stepn:Hⁿis in its slot atrsi, the prepared powers belownare in theirs, and the scratch buffer holds its contents.setup_okestablishesSt 1.step_oktakesSt ntoSt (n+1), using:copy_ok;pp_ok, built onhInv_ok;add_ok;mulH_ok/call_ok, which useWP.callwith thevg_ghashcontract.pairs_okcomposes the 23 pairs by induction.final_okhandlesH⁴⁸and restores the registers.taint_decide(about 0.2 s), withctx,scratchandrsppublic.rsiorr8, so the slot and buffer addresses stay public through every call.vg_ghashrestoresrbx,rbpandr12–r15from memory, so a taint analysis can't keep those public after a call.Verified.stackScratchWipedadds the stack frame.postOut_localshows thatpreparePostreads only the context.Registration
The code is registered generic over
vg_ghash's implementations inGeneric/Ghash/X86_64/Prepare.lean, as CLAUDE.md requires of a caller of a function with variants.Gh.ofNamegives the instance for the baselinevg_ghashonly.vg_ghash_pclmulandvg_ghash_vpclmulget none, because their suffixes are taken by prepares that compute the powers themselves:vg_aes_gcm_prepare_pclmul(GCM: 48 prepared powers on SSE registers (vg_aes_gcm_prepare_pclmul) #4521) andvg_aes_gcm_prepare_vpclmul(GCM: 48 prepared powers on 256-bit registers (vg_aes_gcm_prepare_vpclmul) #4518).Ghcarries the per-instance checks that evaluate code: constant time, MXCSR, stack-pointer safety, depth, and that the callee keepsrsi/r8.vg_aes_gcm_prepare.vg_aes_gcm_prepare_autonow falls back to it.Dispatch order
Dispatch.leannow ranks the bare_pclmul_avxsuffix right after_vpclmul._pclmul_avxand read it as its parts, which put it first invg_aes_gcm_prepare_auto._vpclmulwas never chosen._vpclmul_avx512,_vpclmul,_pclmul_avx, then the baseline. No other dispatcher changes.Scope
vg_aes_gcm_prepare_autoyet.Checks
On the merge of
main(daf7be3):Emit.lean, whose audits pass (standard axioms only), with no generated file left to update.Static checksstep, withcheck_lean_single_importer.py --base origin/main.check_lean_public_imports.pyon the three new modules.cargo fmt --checkandcargo clippy --all-targets -D warningson x86-64.🤖 Generated with Claude Code
https://claude.ai/code/session_01TKUFHFuGsz7F32Tm9DLkuP