Skip to content

AES-GCM x86-64: the out-of-place VAES encryption batch is the in-place one - #4391

Merged
reaperhulk merged 1 commit into
claude/gcm-dec-store-mode-zfrom
claude/gcm-enc-store-mode
Nov 7, 2026
Merged

reaperhulk merged 1 commit into
claude/gcm-dec-store-mode-zfrom
claude/gcm-enc-store-mode

Conversation

@reaperhulk

Copy link
Copy Markdown
Member

Stacked on pyca/verified-garbage#4390 (review only the commit after it). This is the encryption counterpart of pyca/verified-garbage#4388. The 256-bit out-of-place encryption loop (StitchTo) had its own copy of the batch: xorDataKTo and batchTo, with their own 220 lines of proof. It now uses Stitch.batch and its proof.

Code. Stitch.batch takes a second mode, ld (default false). It reads each pair of data blocks at rdx + r8 + 32 j instead of at rdx + 32 j (Stitch.srcK). Out-of-place encryption reads the plaintext there and writes the ciphertext at rdx, where the GHASH loads read it back, as in place. Stitch.first and Stitch.body pass ld on. StitchTo.firstTo and bodyTo are now Stitch.first true and Stitch.body true, and StitchTo.xorDataKTo and batchTo are gone. The emitted code is unchanged (Emit.lean --check).

Proofs.

  • Stitch/Aes.lean:
    • xor1M_ok and xorDataKM_ok take the load mode: they read at oA s ld, which is rdx, or rdx + r8.
    • batchM_ok takes the code's two modes, st (store at rdx + r8) and ld, with st = ix && !ld and ld → ix, where ix says whether the output is the data or the buffer at r10. rdx points at the data, or, when ld, at the output.
    • The distance in r8 is now a hypothesis of batchM_ok, and a field of the loops' invariants (DInvM.r8, StitchFrom.ReadyFrom.r8), instead of a field of AInvM, because its sign depends on the mode.
  • StitchTo/Aes.lean: batchTo_ok is batchM_ok with ld, through AInvTo.toM and AInvM.toTo. Its statement is unchanged, so StitchTo/Loop.lean, StitchR/OnePass.lean and StitchR/RemETo.lean are unchanged.
  • StitchTo/Base.lean: xor1KTo_ok and xorDataKTo_ok are removed.

Net, the proofs lose 177 lines.

Not yet shared, for follow-ups: the out-of-place loop's body, first group and final group (StitchTo.bodyTo_ok, firstTo_ok and finalTo_ok). They reuse the in-place GHASH lemmas through the in-place view StitchZTo.dst, but are still separate from Stitch.body_ok and its neighbours. The same applies to the 512-bit out-of-place encryption loops (StitchZTo, StitchZHTo).

Trust. No Spec/ or TCB/ changes, and no change to the emitted code, so there are no Rust, test or benchmark changes.


Generated by Claude Code

… (WIP)

Stitch.batch takes the load mode (ld: the data read at rdx + r8);
StitchTo's batch, its XOR and their proofs are replaced by
Stitch.batchM_ok. The distance in r8 moves from AInvM to the loops'
invariants.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWvqXkQxFyWZxghqxBG
@github-actions github-actions Bot added the untrusted-only This changes exclusively implementations and proofs, and thus is entirely formally verified. label Nov 7, 2026
@reaperhulk
reaperhulk added this pull request to stack #4395 November 7, 2026 07:54
@reaperhulk
reaperhulk added this pull request to the merge queue Nov 7, 2026
Merged via the queue into main with commit 264add2 Nov 7, 2026
14 checks passed
@reaperhulk
reaperhulk deleted the claude/gcm-enc-store-mode branch November 7, 2026 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

untrusted-only This changes exclusively implementations and proofs, and thus is entirely formally verified.

Development

Successfully merging this pull request may close these issues.

2 participants