Repository navigation
Spec: out-of-place AES-GCM decryption (vg_aes_gcm_open_to) - #4292
Merged
Merged
Conversation
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
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.
Trust change:
Spec/only. No changes toTCB/, no implementations. This is the spec half of out-of-place AES-GCM decryption. It follows the out-of-place encryption already onmain(vg_aes_gcm_seal_gather,Spec/Gcm/OutOfPlace.lean) and the XTS stack (#4282 spec, #4283 implementation). The implementation, the RustAesGcm::decrypt(out of place, next todecrypt_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) -> u32isvg_aes_gcm_open(openContract), except that it reads the ciphertext fromsrcand writes the plaintext todst:openToSig):openSigwithdatasplit intosrc(read-only,len) anddst(writable,dst_len), the layout of XTS'saesUnitToSig. Like every writable slice,dstoverlaps no other buffer (Sig.contract), so it never overlapssrc. Callers that decrypt in place keep usingvg_aes_gcm_open.openToPre):roundsis 10, 12 or 14, anddst_len = len.openToPost): uses the sameopenResultasopenPost, on the bytes atsrc. If it issome pt, the function returns 1 anddstholdspt. Otherwise it returns 0 anddstis all zeros.openToLeak):openLeakonsrc, which is only whether the tag is right.On a wrong tag,
vg_aes_gcm_openleaves its buffer unchanged. Here the output is written with zeros instead. That lets an implementation decrypt intodstin the same pass that hashessrc, and wipedstif 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 toopenToPost, 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:vg_aes_gcm_open_toSpec/Gcm/OutOfPlace.leanKeyRounds(via the post)vg_aes_gcm_open_to_precomputedSpec/Gcm/OutOfPlace.leanPowersReprvg_aes_gcm_open_to_preparedSpec/Gcm/Prepared.leanPreparedPowersReprvg_aes_gcm_open_to_prepared16Spec/Gcm/Prepared16.leanPreparedPowers16ReprEach one has the postcondition
openToPostand the leakopenToLeak.Checks
All of the
Static checksjob'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