Repository navigation
x86-64 AES-GCM: prepared AVX-512 out-of-place encryption hashes the last blocks in its loop - #1410
Merged
Merged
Conversation
…ast blocks in its loop vg_aes_gcm_encrypt_blocks_to_prepared_vaes_vpclmul_avx512 now runs one loop, StitchZHTo.encR, over all the blocks from 16 on: after the groups of 16 it encrypts the r < 16 blocks left from the plaintext into the output in the same pass, as StitchZH.encR does in place (StitchZH.remWith, reading at rdx + r8), instead of copying them to the output and calling vg_aes_gcm_encrypt_blocks there. Proofs: Cached/RemTo (remTo_ok, tailRTo_ok, encTailRGTo_ok; the in-place remainder's loop and keystream lemmas, on the in-place view dst s0), StitchZ/OkP's encRTo_ok and stitchToR_ok, and BlocksTo's `full` mode (BlocksTo/Full), in which the loop is given every block and nothing is left for the copy and the call. The cached 48-block out-of-place loop no longer needs a multiple of 16 blocks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FoYWDDEDFq1DFev5X7n2aq
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.
Follow-up to #1404 and part of #1228. This is the path
AesGcm::encrypttakes for long texts with a long-lived key (see the rustls analysis in #991).What changes
vg_aes_gcm_encrypt_blocks_to_prepared_vaes_vpclmul_avx512used to run the 512-bit out-of-place loop over16 ⌊n/16⌋blocks only. It then copied ther = n mod 16blocks left into the output and calledvg_aes_gcm_encrypt_blockson them there.Now one loop,
StitchZHTo.encR, takes every block from 16 on. After the groups of 16, it encrypts therremaining blocks from the plaintext into the output in the same pass. It reuses #1404's remainder code, reading atrdx + r8(StitchZH.remWith [add r8, rdx] .r8). Nothing is left for the copy or the call.Speed
Measured with
AesGcm::encrypton a reused key (so the prepared path runs), on a VAES/AVX-512 machine. Each value is the best of 7 runs; three alternating rounds against #1404's commit all agreed.seal, which #1404 already sped up)#1406, which is in the merge queue, adds these reused-key groups (
aes-128-gcm-encrypt-two-pieces-reused-key) to the Benchmarks check.Proofs
No changes to
TCB/orSpec/.Cached/RemTo.lean:remTo_okis the out-of-place remainder, followed bytailRTo_okandencTailRGTo_ok. It reuses x86-64 AES-GCM: prepared AVX-512 encryption hashes the last blocks in its loop #1404's loop lemma (remLoop_ok, whoseREnvkeeps the source and destination separate) and its keystream and hashing lemmas, applied to the in-place viewdst s₀. The plaintext stays apart from everything written, bySPreTo.s_o/s_p/s_c.StitchZ/OkP.lean:encRTo_okandstitchToR_okshow that the new loop meetsStitchToOkMfor any number of blocks from 16 on. The cached 48-block out-of-place loop (loop48To_ok,bigRestTo_ok,bigPTo_ok) no longer needs a multiple of 16.loopERTo_oklets the group loop stop with fewer than 32 blocks left.BlocksTogets x86-64 AES-GCM: prepared AVX-512 encryption hashes the last blocks in its loop #1404'sfullmode:takeAllTomakes the kept arguments those of an empty rest (src + 16n,dst + 16n, 0 blocks).BlocksTo/Full.lean,encrypt_wpandpart_rel/encrypt_ct.spreTo_ofandmid_of_postTonow take any block count.StitchToCodeandPieceTocarry the flag, which only the AVX-512 variant's prepared loop sets (StitchToName.fullR). Its taint check covers the new code.Only
vg_aes_gcm_encrypt_blocks_to_prepared_vaes_vpclmul_avx512changes insrc/asm/.Checks
These ran locally before restacking onto
main:lake build(full) andEmit.leanpass; the emitter's audits pass.ci/check_*scripts pass.cargo fmt --checkandclippy -D warningspass.cargo test --releasepasses with Wycheproof on AVX-512 hardware.The restack brought in no conflicts.
🤖 Generated with Claude Code
https://claude.ai/code/session_01FoYWDDEDFq1DFev5X7n2aq
Generated by Claude Code