Repository navigation
AES-CTR x86-64: eight blocks at a time in SSE2 registers in the baseline vg_aes_ctr32 - #4410
Merged
Merged
Conversation
…ine vg_aes_ctr32 WIP: proofs; crates not yet regenerated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFAHEwRUgwg8TfgQXC
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFyzdwwyDWb9QSQqR1
alex
enabled auto-merge
November 7, 2026 09:16
6 tasks done
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.
Part of #4141 (findings: "Baseline AES at
none: AES-GCM is 1.1–1.9× aws-lc's constant-time code. AES-CTR is 1.45× at 16 KiB").What was slow, and why
Without AES-NI, x86-64's
vg_aes_ctr32(which AES-CTR, -GCM, -CCM, -GCM-SIV, -SIV and CMAC all call) bitsliced four blocks into eight 64-bit general-purpose registers (BearSSL'saes_ct64). With only two free temporaries, the S-box spilled heavily, and every layer handled four blocks per instruction. aws-lc'saes_nohwdoes eight blocks in SSE2 registers.What changed
The baseline
vg_aes_ctr32now runs groups of eight blocks inxmm0 … xmm7, with the samect64layout in each quadword: quadword 0 holds blocks 0–3, quadword 1 blocks 4–7. Everything is SSE2, the x86-64 baseline. The other x86-64 implementations (AES-NI, VAES) are unchanged.Circuit.sbox, allocated by the DES circuits' SSE allocator (BitsliceAllocX) toxmm0 … xmm14, with spills to scratch.psrlw/psllwand blends with two masks kept in scratch.pshufd 0xb1.punpcklqdq).No TCB or Spec changes. Proofs (no
sorry, no new axioms):Proof/Framework/X86_64/StraightX.lean: the quadword-lane evaluator gainspsrlw/psllw(a quadword shift masked to its words) andpshufd 0xb1(a rotation of each quadword by 32), each with its per-quadword lemma from the TCB semantics.LinearX.leanisLinear.lean's lane-domain check, for SSE registers.Proof/Aes/X86_64/Sse/Layers.lean: each layer is checked per quadword against the existing target-independent bit specs (sboxT,toBsG,srG,mcG, …), soBitsliced.lean'sbs_*lemmas apply unchanged.Proof/Aes/X86_64/Sse/Group.lean:encrypt8_ok;Group.lean'sctr_inRelfor groups2gand2g + 1;sseGroup_ok, which keepsGroup.lean's loop invariantGInvfromgtog + 2;Proof/Aes/X86_64/Ctr32.lean: the whole-function proof, now with the mask setup and the mixed loop. The constant-time proof is the sametaint_decideover the new code.Numbers
Benchmarks workflow (x86_64 runner,
VG_CPU_FEATURES=none, base5e5cbf56): https://github.com/pyca/verified-garbage/actions/runs/42358850299aes-ctr-128/64aes-ctr-128/1024aes-ctr-128/16384aes-128-gcm-encrypt/64aes-128-gcm-encrypt/1024aes-128-gcm-encrypt/16384aes-128-gcm-encrypt/1048576That run's OpenSSL and aws-lc-rs columns weren't feature-masked (they ran with AES-NI, about 1.5 µs at 16 KiB), so they aren't a like-for-like comparison.
This machine (Intel Xeon @ 2.30GHz;
ci/bench_compare.py --openssl --openssl-with-features, withVG_CPU_FEATURES=noneandOPENSSL_ia32capasbench/gcm_siv_features.py scalar), where the gain is larger:aes-ctr-128/64aes-ctr-128/1024aes-ctr-128/16384aes-128-gcm-encrypt/64aes-128-gcm-encrypt/1024aes-128-gcm-encrypt/16384aes-128-gcm-encrypt/1048576Most of GCM's remaining time at
noneis GHASH without PCLMULQDQ (about 42 µs of the 85 µs at 16 KiB here), which this PR doesn't touch.Checks
lake build(all modules) andEmit.lean: onlyvg_aes_ctr32changes in the generated code.Static checksstep, andcheck_lean_public_imports.pyon the edited modules.cargo testwith Wycheproof, at the default features and atVG_CPU_FEATURES=nonewithcpu-features-env.🤖 Generated with Claude Code
https://claude.ai/code/session_01TKUFHFAHEwRUgwg8TfgQXC