Repository navigation
AES-XTS out of place: AesXts::encrypt and decrypt (breaking: in-place ones become _in_place) - #4283
Merged
Conversation
reaperhulk
enabled stacked auto-merge
November 5, 2026 20:56
github-merge-queue
Bot
removed this pull request from the merge queue due to invalid changes in the merge commit
Nov 5, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to invalid changes in the merge commit
Nov 5, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to invalid changes in the merge commit
Nov 5, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to invalid changes in the merge commit
Nov 5, 2026
…me _in_place) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWwoHb4ZQEEHLgZCj5J
reaperhulk
force-pushed
the
claude/out-of-place-impl
branch
from
November 6, 2026 08:13
a7a544d to
3193167
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 #4282 (the contracts). Implements
vg_aes_xts_encrypt_unit_toandvg_aes_xts_decrypt_unit_toon x86-64, proven againstSpec/Xts/OutOfPlace.lean, and givesAesXtsout-of-placeencryptanddecrypt. No changes toTCB/orSpec/.Breaking change:
AesXts's in-placeencryptanddecryptare renamedencrypt_in_placeanddecrypt_in_place, and the plain names now write to a separate output. This matchesAesGcmandChaCha20Poly1305, whoseencryptis out of place andencrypt_in_placein place.What changes
src/cipher/aes/xts.rs).AesXts::encrypt(&self, i, src, dst)anddecryptread the data unit fromsrcand write the result todst;encrypt_in_place(&self, i, buffer)anddecrypt_in_placeare the formerencryptanddecrypt, unchanged but for their names. A newXtsError::InvalidOutputLength(the variant name AES-GCM and ChaCha20-Poly1305 use) is returned whendst.len() != src.len(); the existing length limits also apply. On x86-64 the backend is chosen by an exhaustive match over the existingImplenum, covering all ten functions. On the other architectures the Rust code copiessrctodstand calls the in-place function. There is no new assembly there.Impl/AesXts/X86_64UnitTo.lean,Proof/AesXts/X86_64/UnitTo/). These are the in-place data-unit functions, except that the whole blocks go through an internal out-of-place whole-block function,vg_aes_xts_{en,de}crypt_to(contractTo.xtsToX86_64). The ciphertext-stealing tail is then done indst.XtsImplgains a fieldto : To.ToImpl, so every variant must supply one, and the data-unit functions call it throughUnitImpl.of._aesni_pclmuland_vaes_vpclmul) get new code (Impl/AesXts/X86_64VaesTo.lean,Proof/AesXts/X86_64/VaesTo/). Each block is loaded once fromsrc([r11 + rcx + d], withrcx = src - dst) and stored once todst; nothing is copied. The proofs are the in-place ones adapted to that addressing._aesniand_vaesvariants copysrctodstand call their in-place functions (To.ToImpl.ofCopy,Impl/AesXts/X86_64To.lean). They are verified but no faster.src - dstis kept in a slot of the scratch buffer between entry and the loops. The taint analysis starts from the writable regions' lengths and the scratch buffer's base (VaesTo.τ₀,agree), so it can see that the slot holds a public value.Tests
aes_xts_test.json: every vector out of place, withsrcanddstat offsets(0,0), (1,3), (7,0), (0,15), (9,9), encrypt then decrypt.InvalidOutputLengthand the too-short and too-long cases.VG_CPU_FEATURESunset,none,aes,ssse3,aes,avx,pclmulqdq,ssse3,aes,avx,avx2,ssse3,vaesandaes,avx,avx2,pclmulqdq,ssse3,vaes,vpclmulqdq.Benchmarks
New group
aes-xts-{bits}-out-of-placeinbench/benches/primitives/aes_xts.rs, next to the existing in-place group (which copies, then encrypts in place) and OpenSSL's. Sizes are the usual set plus 1 MiB.Benchmarks run 42095769221 (x86-64,
aes_xts, everyVG_CPU_FEATURESconfiguration; AMD EPYC 9V45, Zen 5, with OpenSSL 3.5.5), XTS-AES-256 (64-byte key). It ran on the commit before the rename, which changes no code a benchmark runs. aws-lc-rs has no XTS, so it has no column.Default configuration (
_vaes_vpclmul):VG_CPU_FEATURES=aes,avx,pclmulqdq,ssse3(_aesni_pclmul): 1 MiB 249.73 → 220.03 µs, 16 KiB 3.80 → 3.62 µs.Out of place saves the copy: about 16% at 1 MiB here, less below. On this CPU OpenSSL is faster from 16 KiB up (2× at 1 MiB), which this PR does not change: that gap is in the XTS loop itself, not the copy (#4291 closes it with AVX-512).
Locally (Intel Xeon @ 2.30GHz with VAES, a different OpenSSL), the same benchmark gave 1 MiB: copy + in-place 105 µs, out-of-place 73.7 µs, OpenSSL 150 µs.
Not covered
🤖 Generated with Claude Code
https://claude.ai/code/session_015ajQWwoHb4ZQEEHLgZCj5J