Skip to content

Spec: out-of-place AES-GCM decryption (vg_aes_gcm_open_to) - #4292

Merged
reaperhulk merged 1 commit into
mainfrom
claude/happy-goodall-uzpm6i
Nov 6, 2026
Merged

reaperhulk merged 1 commit into
mainfrom
claude/happy-goodall-uzpm6i

Conversation

@reaperhulk

Copy link
Copy Markdown
Member

Trust change: Spec/ only. No changes to TCB/, no implementations. This is the spec half of out-of-place AES-GCM decryption. It follows the out-of-place encryption already on main (vg_aes_gcm_seal_gather, Spec/Gcm/OutOfPlace.lean) and the XTS stack (#4282 spec, #4283 implementation). The implementation, the Rust AesGcm::decrypt (out of place, next to decrypt_in_place) and its tests and benchmark come in a stacked PR once this one is reviewed. Existing contracts are unchanged.

What it adds

vg_aes_gcm_open_to(ctx, rounds, nonce, nonce_len, aad, aad_len, src, len, dst, dst_len, tag, tag_len) -> u32 is vg_aes_gcm_open (openContract), except that it reads the ciphertext from src and writes the plaintext to dst:

  • Signature (openToSig): openSig with data split into src (read-only, len) and dst (writable, dst_len), the layout of XTS's aesUnitToSig. Like every writable slice, dst overlaps no other buffer (Sig.contract), so it never overlaps src. Callers that decrypt in place keep using vg_aes_gcm_open.
  • Precondition (openToPre): rounds is 10, 12 or 14, and dst_len = len.
  • Postcondition (openToPost): uses the same openResult as openPost, on the bytes at src. If it is some pt, the function returns 1 and dst holds pt. Otherwise it returns 0 and dst is all zeros.
  • Leak (openToLeak): openLeak on src, which is only whether the tag is right.

On a wrong tag, vg_aes_gcm_open leaves its buffer unchanged. Here the output is written with zeros instead. That lets an implementation decrypt into dst in the same pass that hashes src, and wipe dst if the tag fails. A two-pass implementation (verify first, then decrypt) only needs to add the wipe. If the output should instead stay unchanged on failure, that is a one-line change to openToPost, but it would rule out the one-pass design.

The key-context forms are the same contract with each existing context format, as for seal_gather:

function file context precondition
vg_aes_gcm_open_to Spec/Gcm/OutOfPlace.lean KeyRounds (via the post)
vg_aes_gcm_open_to_precomputed Spec/Gcm/OutOfPlace.lean PowersRepr
vg_aes_gcm_open_to_prepared Spec/Gcm/Prepared.lean PreparedPowersRepr
vg_aes_gcm_open_to_prepared16 Spec/Gcm/Prepared16.lean PreparedPowers16Repr

Each one has the postcondition openToPost and the leak openToLeak.

Checks

All of the Static checks job's steps pass locally. I did not build the Lean locally (no toolchain in this environment), so CI's build is the first compile of these definitions.


Generated by Claude Code

Adds vg_aes_gcm_open_to and its _precomputed, _prepared and _prepared16
counterparts: vg_aes_gcm_open that reads the ciphertext from src and
writes the plaintext to dst, writing zeros to dst if the tag is wrong.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWvqXkQxFyWZxghqxBG
@reaperhulk
reaperhulk added this pull request to the merge queue Nov 5, 2026
Merged via the queue into main with commit a8b276d Nov 6, 2026
16 checks passed
@reaperhulk
reaperhulk deleted the claude/happy-goodall-uzpm6i branch November 6, 2026 03:38
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