Repository navigation
AES-GCM x86-64: one-pass out-of-place decryption on the AVX-512 loop - #4390
Merged
reaperhulk merged 5 commits intoNov 7, 2026
Merged
Conversation
…(WIP) StitchZH.batch, dbody, dbody48 and bigDP take the store mode; the proofs of the batch, the GHASH states, the loop bodies and the 48-block loop are generic over it, the in-place lemmas their cases. StitchZH.decFromR is the out-of-place loop (its proof follows). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWvqXkQxFyWZxghqxBG
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWvqXkQxFyWZxghqxBG
The VaesVpclmulAvx512 variant names its out-of-place loop (StitchToName.decFromR, StitchZH.decFromR) for prepared key contexts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWvqXkQxFyWZxghqxBG
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWvqXkQxFyWZxghqxBG
The out-of-place loop's proof no longer imports the field algebra; the instances prove PowFinZ, as they do PowFinD. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWvqXkQxFyWZxghqxBG
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.
Stacked on pyca/verified-garbage#4388 (review only the commits after it). On x86-64,
vg_aes_gcm_open_to_prepared_vaes_vpclmul_avx512now decrypts fromsrctodstin one pass from 1024 bytes on, as pyca/verified-garbage#4346 did for the 256-bit variant. It uses the AVX-512 variant's own 512-bit loop, out of place.The 256-bit out-of-place loop was slower in this variant than a copy followed by the 512-bit loop in place, which is why #4346 left the variant alone. With its own loop out of place, out-of-place decryption here now runs about as fast as out-of-place encryption.
Code. As #4388 did for the 256-bit loop,
StitchZH.batch,dbody,dbody48andbigDPtake the store modeix(defaultfalse). Each register of four blocks (64 bytes) is stored back tordx + 64 j, or, out of place, tordx + r8 + 64 j(StitchZH.xorDataZM, usingStitch.dstK).StitchZH.decFromRisdecR's loops out of place: the setupsetupPFrom(StitchFrom.setupCFromin place ofsetupC), the round keys cached, the 48-block loop, the 16-block loop, and the stores. It takesStitchFrom.decR's arguments, for a multiple of 16 blocks. The in-place functions emit the same code as before. Of the exported functions, onlyvg_aes_gcm_open_to_prepared_vaes_vpclmul_avx512changes. It now calls two new internal functions:vg_aes_gcm_open_split_prepared_vaes_vpclmul_avx512andvg_aes_gcm_decrypt_blocks_to_prepared_vaes_vpclmul_avx512.Proofs. The AVX-512 counterparts of #4388's generic lemmas, with the in-place lemmas now their
falsecases:Cached/Aes.lean:xorDataZM_okandbatchM_ok(batch_ok).StitchZ/Aes.lean:AInvM, the invariant on four lanes, with its conversions to and fromAInv.StitchZ/Loop.lean:QG.keepM(QG.data),keepPM,DInvManddfinalM_ok(dfinal_ok).setupZ_runissetupZ_ok's execution, taken out so that the out-of-place setup can use it.StitchZ/Loop48.lean:QG48.keepM,AInvM.gpr2,AInvM.pow,keepWM,reloadM_ok,DInv3MandDInvM.of_eq.Cached/Loop.lean,Cached/Loop48.lean,Cached/RemD.leanandCached/Prepared.lean:dbodyM_ok,dbody48M_ok,loopD48M_ok,bigDRestM_ok,loopDRM_okandbigDPM_ok. The instruction checks the loops need, that they keep the cached keys, are now lemmas (dbody_keeps,dbody48_keeps) instead ofdecide +kernel.Cached/DecFrom.lean(new):setupFrom_okanddecFromR_ok : StitchFromOkM CtxMode.prepared decFromR, given the field factsPowFinZ, whichInstances.leanproves, as it doesPowFinD.Stitch.LPregainsd_p, which the 48-block loop's power tables need.Variants.
PieceFromRis now indexed by the loop's name (StitchToName.decFromR), andVaesVpclmulAvx512names its loop.GcmVariant.stitchFromRpicks each name's loop and proof. Forvg_aes_gcm_prepare16contexts, the 512-bit loop needs more powers than the context holds, so that variant'sopen_to_prepared16keeps the copy.Trust. No
Spec/orTCB/changes. The new functions are internal, and the exported function keeps its contract. The Rust unit testbackends_agreedecrypts out of place at 1024, 1300 and 3072 bytes on every backend the CPU runs. On AVX-512 runners, that reaches both loops (3072 bytes is 192 blocks, overbigMinP's 96).Benchmarks. The scoped run Benchmarks run 42316770570 (x86-64,
aes_gcm,aes-128-gcm-decrypt-out-of-place, against #4388's head) landed on a runner without AVX-512: its CPU flags lackavx512f. It measured the 256-bit code, which is unchanged, and found every size within 1.5%, so it says nothing about the AVX-512 loop. Rather than rerun it in the hope of an AVX-512 runner, I measured on an AVX-512 machine (VAES, VPCLMULQDQ, AVX-512F/BW/VL) withci/bench_compare.py --modules aes_gcm --groups aes-128-gcm-decrypt-out-of-place, base #4388's head, in two runs:That machine is a noisy VM: the copies of one binary differ by up to 20% at 16 KiB, and by more in the first run. So only the 1 MiB result is clear. At 1 MiB, out-of-place decryption now runs about as fast as out-of-place encryption (55 µs in the first run), instead of paying for the copy. At 16 KiB, the copy stays in cache and costs little, and I measured no gain. Below 1024 bytes both sides copy, and the differences (both ways, up to 20%) are within the noise. I kept the 1024-byte threshold shared with the 256-bit variant. A run on a quieter AVX-512 machine could set its own threshold. No benchmark slowed down by more than 35%.
Generated by Claude Code