Repository navigation
RISC-V AES-GCM: open_to decrypts from src to dst in one pass - #4555
Merged
Merged
Conversation
vg_aes_gcm_open_to on RISC-V no longer copies src to dst and decrypts there in place by a call of vg_aes_gcm_open: it is vg_aes_gcm_open's body out of place (openWith true). It hashes the ciphertext at src and, if the tag is right, decrypts it from src straight to dst; if the tag or its length is wrong it zeroes dst and returns 0. One body and one proof serve both: AES's counter mode (ctr32With o, the new internal vg_aes_ctr32_to out of place, vg_aes_ctr32 in place), GCM's crypt (cryptWith o, xorLoopWith o) and open's body (openWith o) are proved once, generic in o, with the in-place functions their instances. vg_aes_gcm_open's and vg_aes_gcm_seal's emitted code is unchanged. No Spec/ or TCB/ change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWua1KdmeJmEbr5Ydzz
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.
vg_aes_gcm_open_toon RISC-V no longer copiessrctodstand decrypts there in place (by a call ofvg_aes_gcm_open). It is nowvg_aes_gcm_open's body out of place (openWith true): it hashes the ciphertext atsrcand, if the tag is right, decrypts it fromsrcstraight todst, with no copy on any path. If the tag or its length is wrong, it zeroesdsta byte at a time (wipe) and returns 0 (openToPost). As on x86-64 (#4388, #4346, #4390); the proof follows ChaCha20-Poly1305 on RISC-V (#4384).One body, one proof
The in-place and out-of-place code share one body and one proof each, generic in
o : Bool. The in-place definitions are one-line instances (… := …With false), and the old in-place proofs were replaced rather than kept beside the new ones.Impl/Aes/RISCV64/Ctr32.lean):ctr32With o.vg_aes_ctr32iso = false. A new internal function,vg_aes_ctr32_to(o = true, source ina6), reads from the source and writes to the destination. Out of place, the source is held inraand our return address in a scratch slot, since every other register is in use. Doublewords are used only when both addresses are multiples of 8. Proved once:correctWith.Impl/AesGcm/RISCV64.lean):xorLoopWith o,cryptHeadWith/cryptWholeWith/cryptTailWith/cryptFillWith/cryptWith o. Out of place,s9holdsdst - src(stored by the entry atW + dstOand loaded once, after the tag comparison, bydeltaArg), and each destination address is computed from the source pointer. Proved once each (xorLoopWith_ok,crypt_ok, and the generic constant-time proofs inCTCrypt.lean), overAlias o S D n(S = Din place, disjoint out of place).openGoodWith oandopenWith o(«open» := openWith false,openTo := openWith true). Proved once:open_body/open_good,openGood_ct.The only paired items are what each emitted function needs on its own: a
taint_decidecheck per function (ctr32_ct/ctr32To_ct) and a call wrapper per callee contract (ctr_call/ctrTo_call).vg_aes_gcm_open's andvg_aes_gcm_seal's emitted code is byte-identical. In the generated crate,vg_aes_gcm_open_tochanges andinternal/vg_aes_ctr32_tois new. The rest of the diff inaes.rs/gcm.rsis only where the emitter places the shared internal modules (symbol paths).The contract and the frame
Proof/AesGcm/RISCV64/OpenTo/Fn.lean:openToRISCV64, with the working space as a fifth stack argument, and its correctness (openTo_wp, includingwipe_ok).OpenTo/CT.lean: constant time. It branches only on public lengths and on whether the tag is right (openToLeak).OpenTo/Verified.lean:VerifiedagainstSig.scratchContract … openToSig "work" .u64 320 … 2048 (some openToLeak), then inside the framewithStackScratchArgs 2608 4(Verified.stackScratchArgs), againstopenToRoundsContract RISCV64.abi 4656. This needs the locality lemmasopenToPre_local,openToPost_localandopenToLeak_local, which reuseProof/AesGcm/Scratch.lean'sopenResult_local.Artifacts/AesGcm/RISCV64.lean): stack 4672 → 4656.No
Spec/orTCB/changes. No shared files outside the RISC-V AES/AES-GCMImpl/andProof/files, the registration and the generatedcrates/verified-garbage-asm-riscv64/.Checks run
lake build --log-level=warning,lake env lean --run Emit.leanandEmit.lean --check, on the restored cache ofmainat c569192.Static checksjob (check_lean_single_importer.py --base origin/main).ci/check_lean_public_imports.py --base origin/main -m <changed modules>.cargo fmt --check;cargo clippy --all-targets -- -D warningson the host and onriscv64gc-unknown-linux-gnu.cargo test gcmforriscv64gc-unknown-linux-gnuunder qemu-riscv64, with Wycheproof (unit tests includingout_of_place, CAVPdecrypt_to, Wycheproof AES-GCM): all pass.Benchmark
Run 42420666804 (riscv64,
aes_gcm,aes-128-gcm-decrypt-out-of-place, base c569192). The table gives the median over the run's 8 base and 8 head copies of each copy's median time, in ns:Long inputs are about 4% faster (no copy pass). Inputs of a few blocks are 2–4% slower (a few hundred ns): the frame now copies four stack arguments, and the entry stores the distance to the destination and loads it back.
🤖 Generated with Claude Code
https://claude.ai/code/session_015ajQWua1KdmeJmEbr5Ydzz