Repository navigation
AArch64 AES-GCM: one-pass out-of-place decryption for vg_aes_gcm_open_to_with_powers (interleaved variant) - #4563
Merged
Merged
Conversation
…place Impl.Gcm.AArch64.Stitch.decBody, decLoop and dec take a store mode: over the ciphertext (x9, the code of before), or to a destination at x15, advanced with it. The proofs of the loop (KPreM, LInv, DPostT) are generic over the mode; dec_ok, the in-place case, keeps its statement. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWvMpP5uQgBBji1Ngb6
…open_split_with_powers' code Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWvMpP5uQgBBji1Ngb6
…ny output Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWvMpP5uQgBBji1Ngb6
…ace; MidS over the ciphertext Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWvMpP5uQgBBji1Ngb6
…e entry for up to five stack arguments
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWvMpP5uQgBBji1Ngb6
…verlap the key context The text only read by the loop, out of place, is a read-only buffer the contract lets overlap the key context; nothing needed it apart, but for the bound on its length, which the output's disjointness gives. OpenIn.of_regs over any registers the entry state does not hold. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWvMpP5uQgBBji1Ngb6
openRestWithG_rel (any ciphertext, as openRestWithG_wp), the entry's CT lemma for work at [sp + 40]. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWvMpP5uQgBBji1Ngb6
Constant time (openSp_ctN): the entry and the pointer to src, loaded from the stack, are public; the rest is open's path for TLS records out of place. Framed with its working space on the stack (openSp_framed). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWvMpP5uQgBBji1Ngb6
…l), its call's proof Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWvMpP5uQgBBji1Ngb6
…ied.entryBranch), registered for the interleaved variant Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWvMpP5uQgBBji1Ngb6
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWvMpP5uQgBBji1Ngb6
…l functions Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWvMpP5uQgBBji1Ngb6
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.
What changed
On AArch64,
vg_aes_gcm_open_to_with_powers_aes_sha3(the variant with the interleaved CTR+GHASH loop) no longer copiessrctodstbefore decrypting in place, for TLS-shaped records. It now reads the ciphertext fromsrc, hashes it, and writes the plaintext straight todst. If the tag is wrong,dstis still zeroed.vg_aes_gcm_open_split_with_powers(Impl/AesGcm/AArch64/Stitch.lean,openSplitWithPw). It isopen_with_powers' path for TLS records (openFastS), out of place.(ctx, rounds, nonce, nonce_len, aad, aad_len, dst, len, tag, tag_len, pw, src, src_len).withStackArgScratch 2608 5).Proof/AesGcm/AArch64/OpenSplit/Contract.lean; only verified code calls it, so there is noApi.VerifiedinOpenSplit/Run.lean(what it computes) andOpenSplit/Verified.lean(constant time, and the stack-scratch framing).vg_aes_gcm_open_to_with_powersfor the interleaved variant is nowOpenTo.openToSel.x10 = (aad_len >> 4) | ((len - 768) >> 63) | (nonce_len ^ 12).Code.iteColdchooses between two paths:openToSplit: a 48-byte frame that calls the new function, then zeroesdstif it returns 0.openTo 3copy path, used otherwise.Verified.entryBranch(Proof/AesGcm/AArch64/OpenTo/Split.lean), againstopenToWithPowersRoundsContractwith 2656 bytes of stack. Before this change it used 2624 bytes; the extra 32 come from the new frame plus the callee's working space.Generic/AesGcm/AArch64/AesGcm.leanusesopenToSelwhenv.stitch, and leaves every other variant unchanged.gcm.s, onlyvg_aes_gcm_open_to_with_powers_aes_sha3changed. The new internal functioninternal/vg_aes_gcm_open_split_with_powers_aes_sha3was added.vg_aes_gcm_open's emitted code is byte-identical.How the code is shared, not duplicated
Impl/Gcm/AArch64/Stitch.lean):decBody,decLoopanddectake a store modeto.to = falsestores over the text (the in-place code, emitted unchanged).to = truestores tox15and advances it.Proof/Gcm/AArch64/Stitch/{Spec,Base,Steps,Loop,Ok,Final}) are stated once, overKPreM s₀ toandDPostT. The in-placedec_okis an instance ofdecM_ok.openRunWithStakes the same mode throughdecPart.decPartfirst copies only the tail after the loop's whole batches todst(tailTo).dec truefromsrctodst. The rest ofopenruns ondstunchanged.Stitch/Pre,Open,OpenB,OpenW,OpenCT,ShortOpenCT) are generic over the mode. The in-place lemmas (openRunWithS_postX,dec_ok, …) are instances of the generic ones (openRunWithS_postXT,decM_ok).openEntryW_okhandlesworkat stack argument 5.OpenPostG,oiteWithG_ok,openRestWithG_wpandopenRestWithG_relhandle any ciphertext.OpenIn.of_regsworks over any registers the entry does not hold.entry_relandentryStash_relalso acceptworkat[sp + 40].KPreMno longer hasd_k(text disjoint from the key context). The out-of-place source is a read-only buffer, which the contract lets overlap the key context, and nothing neededd_kexcept a length bound that the output's disjointness also gives.openToSplit's wipe and return,Split.lean) followsOpenTo/Fn.lean's. It reuses its generic lemmas (head_ok,copyStep_ok,wipeLoop_wp,bytesAt_zeros,WArgs). The frame and stack offsets (48/2608/2656 against 32/2592/2624) are restated inSLay,SCalledandSDone.Trust
No changes to
Spec/orTCB/.Constant time holds as before. The new code branches only on public lengths (
nonce_len,aad_len,len) and on whether the tag is right. The new taint checks usetaint_decide(pwRestDecTo_relfordec true, and the wrapper's entry, wipe and return).There are no
sorry,native_decide,bv_decideor resource options. The one newdecide +kernelis institchOpenSplit_keepsV, a vector-register keep check that mirrors the existingstitchOpenWithS_keepsV. It is not a constant-time proof.Not done (left for follow-ups)
These paths still copy
srctodstand decrypt in place (openTo):vg_aes_gcm_open_to,_aesvg_aes_gcm_open_to, and_aesvg_aes_gcm_open_to_with_powers. They decrypt withvg_aes_ctr32, which works only in place.vg_aes_ctr32_to, as RISC-V AES-GCM: open_to decrypts from src to dst in one pass #4555 (RISC-V) and Arm: vg_aes_gcm_open_to in one pass, sharing open's body #4561 (Arm) did._aes_sha3vg_aes_gcm_open_to_with_powersoutside the one-pass condition. That is, a nonce other than 12 bytes, 16 or more bytes of AAD, or fewer than 768 bytes.open_with_powersuses its short path (openShortF) oropenFastP, and for other nonce/AAD lengths it usesopenRest. None of these is generic over the output yet.openTocopy wrapper.dec falseinopen_with_powersanddec truein the new internal function. The source and proof exist once. A follow-up will try one emitted instance, measured by oneaes-128-gcm-decryptrun, and keep it only if no size gets slower.Checks run
lake build --log-level=warning, after rebasing ontomain(f5b36e1), on main's restored CI cache.lake env lean --run Emit.lean, thenlake env lean --run Emit.lean --check.Static checksjob, with--base origin/mainfor the single-importer check.ci/check_lean_public_imports.py --base origin/main -m <changed modules>.cargo fmt --check, andcargo clippy --all-targets -- -D warningson the host and foraarch64-unknown-linux-gnu.qemu-aarch64 -cpu max, with Wycheproof (WYCHEPROOF_ROOT), withVG_CPU_FEATURESunset and set tonone.backends_agreeandprepared_boundaries: out-of-placedecryptat 768–10000 bytes, a 12-byte nonce, short AAD, and a wrong tag that must zero the output.Benchmark
Scoped run, as the task asked: https://github.com/pyca/verified-garbage/actions/runs/42423188866 (
arches=aarch64,cpu_features='-',modules=aes_gcm,groups='aes-128-gcm-decrypt-out-of-place').The runner was a Neoverse N2 (
CPU part 0xd49) with SHA3, so this run measured the_aes_sha3variant, the one this PR changes.aes-128-gcm-decrypt-out-of-place/64aes-128-gcm-decrypt-out-of-place/128aes-128-gcm-decrypt-out-of-place/192aes-128-gcm-decrypt-out-of-place/384aes-128-gcm-decrypt-out-of-place/1024aes-128-gcm-decrypt-out-of-place/16384aes-128-gcm-decrypt-out-of-place/1048576aes-128-gcm-decrypt-out-of-place/64aes-128-gcm-decrypt-out-of-place/128aes-128-gcm-decrypt-out-of-place/192aes-128-gcm-decrypt-out-of-place/384aes-128-gcm-decrypt-out-of-place/1024aes-128-gcm-decrypt-out-of-place/16384aes-128-gcm-decrypt-out-of-place/1048576What this shows:
So on this core, removing the copy did not pay for itself. The likely costs are the out-of-place loop's extra output pointer, and the call and frame of
openToSplit. The copy it replaces was cheap on N2. I have not rerun the benchmark.https://claude.ai/code/session_015ajQWvMpP5uQgBBji1Ngb6
Generated by Claude Code