Repository navigation
AES-XTS: a variant with AVX-512 VAES, sixteen blocks at a time - #4291
Merged
Merged
Conversation
reaperhulk
enabled stacked auto-merge
November 5, 2026 20:56
github-merge-queue
Bot
removed this pull request from the merge queue because the pull requests in the stack were not ordered correctly in the queue
Nov 5, 2026
github-merge-queue
Bot
removed this pull request from the merge queue because the pull requests in the stack were not ordered correctly in the queue
Nov 5, 2026
github-merge-queue
Bot
removed this pull request from the merge queue because the pull requests in the stack were not ordered correctly in the queue
Nov 5, 2026
vg_aes_xts_{en,de}crypt_vaes_vpclmul_avx512 and their out-of-place
counterparts: the one-pass functions with a loop over sixteen blocks, four
to a 512-bit register, before their eight-block loop, as OpenSSL's
AVX-512 XTS does. The tweaks of the next group are computed from the last
eight with byte shifts and a carry-less multiply by 0x87 in each lane.
The loop starts from the tweaks the eight-block loop keeps in the scratch
buffer and leaves the next eight's there, so the eight-block loop and the
blocks left go on unchanged; their lemmas now start from any block.
The decryption rounds on 512-bit registers are new
(Impl/Aes/X86_64/VaesZDec.lean, Proof/Aes/X86_64/VaesZ/Dec.lean), as the
256-bit ones. The variant needs AVX-512F and AVX512BW as well as the
256-bit one-pass variant's features; a CPU with them chooses it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWwoHb4ZQEEHLgZCj5J
reaperhulk
force-pushed
the
claude/xts-avx512
branch
from
November 6, 2026 08:13
5f3cfe0 to
d63fec6
Compare
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 #4283 (and #4282). A new x86-64 CPU-feature variant of XTS,
_vaes_vpclmul_avx512, in place and out of place, proven against the same contracts as the other variants. No changes toTCB/orSpec/: every instruction it uses is already in the ISA model.Why
On the Zen 5 runner of the earlier benchmark run, OpenSSL 3.5's XTS took 38.96 µs at 1 MiB to our 78.12 µs (out of place). OpenSSL uses Intel's AVX-512 XTS (
aesni-xts-avx512.pl, from ISA-L): sixteen blocks per iteration, four to a 512-bit register. Ours did eight, in 256-bit registers.What changes
Impl/AesXts/X86_64VaesZ.lean: the one-pass functions with a loop over sixteen blocks (loop16) before their eight-block loop. The blocks are four to each ofzmm0–zmm3and their tweaks are inzmm4–zmm7, with each round key broadcast intozmm8. The next group's tweaks are the last eight's times α⁸ (a byte shift of each lane, and the byte shifted out times0x87, carry-less), then those times α⁸, as OpenSSL computes them. The loop starts from the tweaks the eight-block loop keeps in the scratch buffer and leaves the next eight's there, so the eight-block loop and the blocks left go on unchanged.Impl/Aes/X86_64/VaesZDec.lean,Proof/Aes/X86_64/VaesZ/Dec.lean: AES's inverse cipher on the four lanes of 512-bit registers, asVaesBlocks.aesDecdoes on two. Encryption uses the existingVaesZ.aesZ.Proof/AesXts/X86_64/VaesZ/: correctness of the four functions (in place againstmodeX86_64 (xtsMode _), out of place againstTo.xtsToX86_64). Constant time is by the taint analysis, as for the other one-pass functions.Vaes/Body.lean,VaesTo/Crypt.lean: the eight-block loop's lemmas now start from any block, not only block 0, so the sixteen-block loop can run first.Variant.lean,Variants/AesXts/X86_64/VaesVpclmulAvx512.lean: the variant, with featuresaes avx avx2 vaes vpclmulqdq avx512f avx512bw.src/cipher/aes/xts.rs:Impl::VaesVpclmulAvx512, chosen overVaesVpclmulon a CPU with its features. It's in every exhaustive match, andselect_featurestests it both ways.ci/rust_matrix.toml:aes_xtsis added to the native runner'saes,avx,avx2,pclmulqdq,ssse3,vaes,vpclmulqdqline (the 256-bit one-pass variant, which an AVX-512 runner no longer chooses by default) and toicx's default line (the new variant, under SDE).README.md: the regenerated XTS row.Tests
The Wycheproof and NIST CAVP XTS vectors pass, in place and out of place. They ran with
VG_CPU_FEATURESunset (the new variant, on an AVX512BW machine),aes,avx,avx2,pclmulqdq,ssse3,vaes,vpclmulqdq,aes,avx,avx2,ssse3,vaes,aes,avx,pclmulqdq,ssse3,aes,ssse3andnone. The NIST vectors' 512-byte data units run the sixteen-block loop.Benchmarks
Benchmarks run 42107301891 (x86-64,
aes_xts, default configuration, against #4283's head, with OpenSSL 3.5.5) ran on an Intel Xeon 6975P-C (Granite Rapids, AVX-512 and VAES). XTS-AES-256:Out of place, which is what OpenSSL's benchmark measures, we're now level with OpenSSL at 1 MiB and faster below. AES-128 and AES-192 are in the run's summary.
The first run (42104254704) landed on an AMD EPYC 7763 (Zen 3), which has no AVX-512, so both sides ran the same 256-bit code. Zen 5, where OpenSSL was 2× faster before, hasn't been measured with this change.
Locally, on an Intel Xeon @ 2.30GHz with AVX-512, the out-of-place 1 MiB time went from 82.2 to 71.5 µs.
🤖 Generated with Claude Code
https://claude.ai/code/session_015ajQWwoHb4ZQEEHLgZCj5J