Repository navigation
Arm: vg_aes_gcm_open_to in one pass, sharing open's body - #4561
Merged
Merged
Conversation
vg_aes_gcm_open_to on Arm (A32 and Thumb) used to copy the ciphertext from src to dst and call vg_aes_gcm_open on dst in place. It now reads the ciphertext from src, hashes it, and decrypts it straight into dst, and zeroes the len bytes at dst if the tag is wrong, as the contract (openToPost) requires. The spec, the TCB and the Rust code are unchanged. The code is shared, not duplicated: * Impl/Aes/Arm/Ctr32.lean: ctr32Gen to; vg_aes_ctr32 is ctr32Gen false (its code is unchanged) and the new internal vg_aes_ctr32_to is ctr32Gen true, which keeps the destination pointer in a scratch slot and stores the XOR through it. Its proofs (Proof/Aes/Arm/Group.lean, Ctr32.lean) are generic over the mode. * Impl/AesGcm/Arm.lean: open and open_to are one body, openG to, which differs only in the stack offsets, the decryption step (oneCryptG: crypt in place, or cryptTo from src to dst through vg_aes_ctr32_to) and the end (openEnd: open_to's wipe of dst when the result is 0). vg_aes_gcm_open's emitted code is unchanged. The whole-block and tail steps of crypt are generic (cryptWholeG, cryptTailG), as are their proofs (CryptOk.lean, CTCrypt.lean) and the body's correctness and constant-time proofs (Open.lean openBody_wp, CTOpen.lean openBody_rel). * Proof/AesGcm/Arm/OpenTo.lean replaces the copy-based OpenTo/ proofs: the contract, the wipe, constant time (branches only on public lengths and on whether the tag is right, which openToLeak makes public), and the frame that puts the working space on the stack (2608 bytes: 8 words of copied stack arguments; 2620 bytes of stack in all, from 2648). onePre (Contract.lean) now lets the data be read-only, as open_to's source is, with its disjointness from the other buffers required only when it is written. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWykBrvUW5UtsP5uhDu
The tail of open_to no longer copies the last bytes of src to dst and XORs them in place: the byte-XOR loop is generic (xorLoopG), reading the text through r4 out of place and writing it to dst, with one proof for both modes. xorLoop is xorLoopG false, whose code is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWykBrvUW5UtsP5uhDu
Only vg_aes_gcm_open_to changes, and the new internal vg_aes_ctr32_to is added; vg_aes_gcm_open and vg_aes_ctr32 are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWykBrvUW5UtsP5uhDu
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Nov 7, 2026
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.
On Arm (A32 and Thumb, one crate),
vg_aes_gcm_open_toused to copy the ciphertext fromsrctodstand callvg_aes_gcm_openondstin place. Now it reads the ciphertext fromsrc, hashes it, and decrypts it straight intodstin one pass, on every path including the last partial block. If the tag is wrong it zeroes thelenbytes atdst, asopenToPostrequires.No
Spec/orTCB/change, and no Rust change.Sharing, not duplicating
Each piece is one definition and one proof, generic over the mode (
to : Bool). The in-place instance's code is unchanged:Impl/Aes/Arm/Ctr32.lean:ctr32Gen to.vg_aes_ctr32isctr32Gen false, byte-identical to before.vg_aes_ctr32_toisctr32Gen true. It keeps the destination pointer in scratch slot 48, loading it before each group's XOR and storing it back advanced after, on either branch, so it stays public. The XOR loads fromr10and stores throughkp.Proof/Aes/Arm/Group.leanandCtr32.leanare generic, both functional and constant-time.Impl/AesGcm/Arm.lean:openandopen_toare one body,openG to. It differs only in:tagOff,tagLenOff,workOff);oneCryptG:cryptin place, orcryptTofromsrctodstthroughvg_aes_ctr32_to;openEnd:open_tozeroesdstwhen the result is 0.crypt's whole-block and tail steps are generic (cryptWholeG,cryptTailG).xorLoopG to.xorLoopisxorLoopG falseand keeps its code, so its other users (CCM, OCB, GCM-SIV, SIV) are unchanged. Out of place it reads the text throughr4and writesdst.CryptOk.lean,CTCrypt.lean,Loops.lean,Open.lean(openBody_wp) andCTOpen.lean(openBody_rel).Proof/AesGcm/Arm/OpenTo.leanreplaces the copy-basedOpenTo/proofs andImpl/AesGcm/Arm/OpenTo.lean. It has:openToLeakmakes public;Generated code
vg_aes_gcm_open_tochanges, andvg_aes_ctr32_tois added.vg_aes_gcm_open,vg_aes_ctr32and every other crate are byte-identical.The two counter-mode instances, deduplicated in a follow-up PR
vg_aes_ctr32andvg_aes_ctr32_toare one definition with one proof, but the binary carries both. On Arm,vg_aes_ctr32is internal, and GCM, CCM, GCM-SIV, SIV and CMAC call it.A separate follow-up PR will drop the in-place instance:
vg_aes_ctr32_towithdst = src, which needs its contract widened to "src = dstor disjoint".Changes to shared Arm proof files
onePre(Proof/AesGcm/Arm/Contract.lean) now lets the data be read-only, asopen_to's source is. The data must be disjoint from the other buffers only when it is written; seal and open in place still prove with it.Callee.leanadds the 12-byte-push call ofvg_aes_ctr32_to.Compare.leanandCTVerify.leantake the received-tag offset as a parameter.Checks run
lake build --log-level=warning(all 28614 jobs) andlake env lean --run Emit.lean --check, after rebasing ontomainand restoring its cache.Static checks, withcheck_lean_single_importer.py --base origin/main.ci/check_lean_public_imports.py --base origin/main -mon the changed modules.cargo fmt --check, andcargo clippy --all-targets -- -D warningson the host,armv7-unknown-linux-gnueabihfandthumbv7neon-unknown-linux-gnueabihf.qemu-armon both Arm targets: pass.Benchmark
Scoped run: https://github.com/pyca/verified-garbage/actions/runs/42422486721 (arm,
VG_CPU_FEATURES=-,aes_gcm,aes-128-gcm-decrypt-out-of-place, againstmain4f412a1).Each cell is the median over the run's 8 interleaved copies of each side's median time. The spread is (max − min) / median across those copies.
Every size is about 0.3% faster, beyond the copy-to-copy spread. The copy of the ciphertext is gone, and the decryption itself (bitsliced AES, then GHASH) dominates the time.
🤖 Generated with Claude Code
https://claude.ai/code/session_015ajQWykBrvUW5UtsP5uhDu