Skip to content

AES-XTS: a variant with AVX-512 VAES, sixteen blocks at a time - #4291

Merged
reaperhulk merged 1 commit into
claude/out-of-place-implfrom
claude/xts-avx512
Nov 6, 2026
Merged

reaperhulk merged 1 commit into
claude/out-of-place-implfrom
claude/xts-avx512

Conversation

@reaperhulk

@reaperhulk reaperhulk commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

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 to TCB/ or Spec/: 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 of zmm0–zmm3 and their tweaks are in zmm4–zmm7, with each round key broadcast into zmm8. The next group's tweaks are the last eight's times α⁸ (a byte shift of each lane, and the byte shifted out times 0x87, 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, as VaesBlocks.aesDec does on two. Encryption uses the existing VaesZ.aesZ.
  • Proof/AesXts/X86_64/VaesZ/: correctness of the four functions (in place against modeX86_64 (xtsMode _), out of place against To.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 features aes avx avx2 vaes vpclmulqdq avx512f avx512bw.
  • src/cipher/aes/xts.rs: Impl::VaesVpclmulAvx512, chosen over VaesVpclmul on a CPU with its features. It's in every exhaustive match, and select_features tests it both ways.
  • ci/rust_matrix.toml: aes_xts is added to the native runner's aes,avx,avx2,pclmulqdq,ssse3,vaes,vpclmulqdq line (the 256-bit one-pass variant, which an AVX-512 runner no longer chooses by default) and to icx'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_FEATURES unset (the new variant, on an AVX512BW machine), aes,avx,avx2,pclmulqdq,ssse3,vaes,vpclmulqdq, aes,avx,avx2,ssse3,vaes, aes,avx,pclmulqdq,ssse3, aes,ssse3 and none. 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:

size in place (copy first), before → after out of place, before → after OpenSSL (out of place)
64 B 185 → 172 ns 185 → 174 ns 394 ns
1 KiB 264 → 225 ns 247 → 223 ns 445 ns
16 KiB 1.33 → 1.16 µs 1.31 → 1.10 µs 1.33 µs
1 MiB 100.92 → 87.40 µs 75.63 → 62.12 µs 62.07 µs

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

@reaperhulk
reaperhulk added this pull request to stack #4288 November 5, 2026 20:53
@reaperhulk
reaperhulk enabled stacked auto-merge November 5, 2026 20:56
@reaperhulk
reaperhulk added this pull request to the merge queue Nov 5, 2026
@github-merge-queue
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
@reaperhulk
reaperhulk added this pull request to the merge queue Nov 5, 2026
@github-merge-queue
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
@reaperhulk
reaperhulk added this pull request to the merge queue Nov 5, 2026
@github-merge-queue
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
reaperhulk added this pull request to the merge queue Nov 6, 2026
Merged via the queue into main with commit bc21f57 Nov 6, 2026
35 checks passed
@reaperhulk
reaperhulk deleted the claude/xts-avx512 branch November 6, 2026 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants