Repository navigation
x86 and ARM: vg_chacha20_poly1305_open_to sharing open's body, and decrypt on both - #4466
Merged
Merged
Conversation
github-merge-queue
Bot
removed this pull request from the merge queue due to a conflict with the base branch
Nov 7, 2026
|
This pull request has conflicts with Posted by |
Adds `vg_chacha20_poly1305_open_to` (and `_ssse3`) on x86, decrypting from `src` into `dst` without a copy. One body serves `open` (in place) and `open_to` (out of place): it reads the source at stack slot 4 and writes the destination held in slot 7, with the tag in slot 6 and the context in `eax`. Each entry moves the arguments there within its own (frame-copied, writable) argument slots: `seal` and `open` copy `data` into `work`'s slot (`inPlace`); `open_to` moves `tag` and `dst` into the slots of `dst` and `dst_len` (`toEntry`). `vg_chacha20_xor` is then called from `src` to `dst` (`XorImpl.call_to`), and a wrong tag zeroes the destination. Proofs: the body is proven from the state it is entered in (`APre`, now about the body's entry state, with `inout`: in place, or apart for `open`), once for both `open` and `open_to` (`openBody_correct`, `openBody_rel`); `Entered` relates it to the function's entry. `open_to` is generic over the `vg_chacha20_xor` variants like `seal`/`open`, and framed by the new `X86.Verified.stackScratchWipedPre`, whose `hpostOut` may assume the precondition (`dst_len = len`). Rust: `decrypt` (out of place) on x86, choosing `open_to` or `open_to_ssse3` by the backend, as `decrypt_in_place` does; its unit test, the Wycheproof out-of-place check and the benchmark now run on x86 too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWwrECv53ESEcwjcHaU
reaperhulk
force-pushed
the
claude/determined-gates-p7sa7b-x86-open-to
branch
from
November 7, 2026 16:23
c90ef7b to
9a153e9
Compare
reaperhulk
enabled auto-merge
November 7, 2026 16:26
… ARM Out-of-place ChaCha20-Poly1305 decryption on ARM with no copy. The decryption body exists once: it reads the source at r10 and writes the destination kept in r6 (crypt passes it to vg_chacha20_xor in r5, zeroData zeroes from it), and reads the received tag through r4, so it reads no stack argument. Each entry is a prologue (the callee-saved registers saved, the arguments moved) ending in one instruction: seal and open set r6 := r10 (in place), open_to loads dst from its stack arguments. open_to is withStackScratchWiped 664 5 158, stack 672; seal and open keep their frames. The body's correctness and constant-time proofs are shared by open and open_to (openBody_ct, sealBody_ct); openTo_verified bridges to the shared openToScratchContract, with Verified.stackScratchWipedPre, whose hpostOut may assume the precondition (stackScratchWiped is now its corollary). ChaCha20Poly1305::decrypt, its unit test, the Wycheproof out-of-place check and the benchmark group are enabled on ARM. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWwrECv53ESEcwjcHaU
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.
This PR adds out-of-place ChaCha20-Poly1305 decryption without a copy on x86 (32-bit) and ARM, in one PR. It is their counterpart of #4384 (RISC-V) and #4427 (PPC64LE), and builds on their src/dst
vg_chacha20_xor(#4447, #4436). The ARM part was #4443, which this replaces. Each architecture is one commit. No change toTCB/orSpec/.On both architectures,
openandopen_toshare one decryption body; only a short entry differs:seal = inPlace; sealBody,open = inPlace; openBody,openTo = toEntry; openBody.x86:
vg_chacha20_poly1305_open_toand_ssse3x86 has no spare callee-saved register for
dst, so the body keeps what it needs in the function's own copy of its stack arguments.withStackScratchWipedlays that copy out, and the contract already lets the function write it (writeArgs).work) ineax, the source andlenin slots 4 and 5, the tag in slot 6 ([esp+28]), and the destination in slot 7 ([esp+32]).inPlaceis three instructions: it loadsworkand copiesdatainto slot 7.toEntryis five: it loadsdst,tagandwork, then storestaganddstinto slots 6 and 7.cryptpassesdstto the kernel withmov esi, [esp+32], andzeroArgszeroes the destination from[esp+32].open_toiswithStackScratchWiped 748 9 176, with a stack of 780.seal/openkeep 740/772.openToApiis registered inGeneric/ChaCha20Xor/X86/ChaCha20Poly1305.leanwith the same suffix and features asseal/open. That emits it for SSE2 and SSSE3, and the dispatchervg_chacha20_poly1305_open_to_autochooses between them.APredescribes the body's entry state.inPlace_ok/toEntry_ok/Enteredconnect each entry to the body.openBody_correctandopenBody_relare proven once and used byopenandopen_to.espalone.openTo_verifiedis proven againstopenToScratchContract X86.abi 88 32.X86.Verified.stackScratchWipedPreis new: itshpostOutmay assume the precondition.stackScratchWipedwraps it, and its statement is unchanged.ARM:
vg_chacha20_poly1305_open_tor10and writes the destination held inr6.cryptpasses it to the kernel (mov r5, r6), andzeroDatazeroes from it.r4, so the body reads no stack argument.prologue w t dst = entry w ++ save ++ moves t ++ [dst], with one definition generating the saves.inPlaceends withmov r6, r10.toEntryends withldr r6, [sp, #8].open_toiswithStackScratchWiped 664 5 158, with a stack of 672.seal/openkeep656 3 158and 664, soseal_gatheris unchanged.APretakes membership facts,inoutand disjointness of the destination.openBody_ctandsealBody_ctare each proven once.vg_chacha20_xor's secret stores through the destination make the analysis forget the public slots. Socryptandcompareare two taint runs, withr4/r6re-established between them from the invariant.openTo_verifiedis proven againstopenToScratchContract Arm.abi 79 8.Verified.stackScratchWipedPreis new, withstackScratchWipedas its corollary.Rust
ChaCha20Poly1305::decryptis enabled on x86 and ARM, alongside RISC-V and PPC64LE, with its unit testdecrypt_out_of_place, the Wycheproof out-of-place check and the benchmark group.decryptcalls the generated dispatchervg_chacha20_poly1305_open_to_auto. On x86 the dispatcher picks SSSE3 or SSE2; elsewhere it is another name for the one implementation. CI's x86 jobs run both with SSSE3 and withVG_CPU_FEATURES=none.Generated code
crates/verified-garbage-asm-x86:chacha20poly1305and its dispatch file. These addopen_toandopen_to_ssse3.seal,seal_ssse3,openandopen_ssse3each gain two entry instructions and load the destination from[esp+32].crates/verified-garbage-asm-arm:chacha20poly1305and its dispatch file. These addopen_to.seal/openchange by a few register moves, and the tag's stack loads becomer4.Checks
lake build,Emit.leanandEmit.lean --checkpass, re-run after rebasing ontomainwith the dispatchers of Emit a dispatcher for every function's implementations #4428.check_lean_public_imports.py.cargo test --target i686-unknown-linux-gnu chachapasses with Wycheproof, both with the CPU's features and withVG_CPU_FEATURES=none. Clippy for i686 passes. Both were re-run after the last rebase.cargo test chachapassed under qemu onarmv7-unknown-linux-gnueabihfandthumbv7neon-unknown-linux-gnueabihf, includingdecrypt_out_of_placeand Wycheproof.decryptcalls, to the dispatcher.cargo fmt --checkpasses for the library and the bench crate, and host clippy passes, on the combined head.openssl-sysdoes not build for it here. CI's lint job covers it.Benchmarks: not run.
seal/openchange by a few instructions on both architectures. A scoped manual Benchmarks run should go with this PR (ChaCha20-Poly1305 on x86 and ARM, including the new out-of-place group). I have not triggered one.🤖 Generated with Claude Code
https://claude.ai/code/session_015ajQWwrECv53ESEcwjcHaU