Skip to content

ARM: vg_chacha20_poly1305_open_to sharing open's body, and decrypt on ARM - #4443

Closed
reaperhulk wants to merge 1 commit into
mainfrom
claude/determined-gates-p7sa7b-arm-open-to
Closed

reaperhulk wants to merge 1 commit into
mainfrom
claude/determined-gates-p7sa7b-arm-open-to

Conversation

@reaperhulk

Copy link
Copy Markdown
Member

This is ARM's out-of-place ChaCha20-Poly1305 decryption without a copy. It is the counterpart of #4384 (RISC-V) and #4427 (PPC64LE). It builds on ARM's src/dst vg_chacha20_xor (#4436). No change to TCB/ or Spec/.

Design: one body for open and open_to

  • Shared body. It reads the source at r10 and writes the destination it keeps in r6.
    • crypt passes the destination to vg_chacha20_xor (mov r5, r6), and zeroData zeroes from r6.
    • The body reads the received tag through r4. As a result it reads no stack argument, and seal passes the tag to finalize with mov r1, r4.
  • Entries. On ARM no register is free until the callee-saved ones are saved, so each entry is a short prologue: prologue w t dst = entry w ++ save ++ moves t ++ [dst]. One definition generates the saves for both. The shared code starts at initState:
    • seal = inPlace; sealBody
    • open = inPlace; openBody, where inPlace ends with mov r6, r10
    • openTo = toEntry; openBody, where toEntry ends with ldr r6, [sp, #8]
  • Frames.
    • open_to is withStackScratchWiped 664 5 158, and its stack is 672. Its five stack arguments are src, len, dst, dst_len and tag.
    • seal and open keep 656 3 158, and their stack stays 664. seal_gather reuses seal's code unchanged.

Proofs

  • Body. Stages.lean proves the body from the state the prologue leaves.
    • APre takes membership facts, inout (in place, or open only with disjoint buffers), and o_* disjointness.
    • Inv.frame is over the context, the destination and the stack below.
    • EntryOk, Entered and prologueA_ok connect the body to the function's entry, and APre.ofIn/APre.ofTo derive its precondition.
    • crypt_ok uses the kernel's xor_call_to.
  • Constant time.
    • The prologue is checked by taint, with the stack arguments public.
    • openBody_ct is proven once and used by open_ct and openTo_ct; sealBody_ct likewise.
    • vg_chacha20_xor's secret stores through the destination make the analysis forget the public slots. So crypt and compare are two taint runs, with r4/r6 re-established from the invariant between them.
  • open_to. openTo_verified, against the shared openToScratchContract Arm.abi 79 8, and openTo_framed.
  • Framework. Verified.stackScratchWipedPre is new in Proof/Framework/Arm/StackScratchWipe.lean: its hpostOut may assume the precondition (dst_len = len). Verified.stackScratchWiped is now its corollary, and its signature is unchanged.

Rust

ChaCha20Poly1305::decrypt is now enabled on ARM, alongside RISC-V and PPC64LE, with its unit test decrypt_out_of_place, the Wycheproof out-of-place check and the chacha20poly1305-decrypt-out-of-place benchmark group.

Checks

Run before the rebase onto main, which conflicted only in the Rust cfgs (merged with PPC64LE's):

  • Full lake build, Emit.lean and Emit.lean --check pass. The emitter changed only the ARM crate's chacha20poly1305.
  • Every step of the Static checks job passes, and so does check_lean_public_imports.py.
  • Under qemu, cargo test chacha passes on armv7-unknown-linux-gnueabihf and thumbv7neon-unknown-linux-gnueabihf, with Wycheproof, including decrypt_out_of_place and the out-of-place Wycheproof check.
  • cargo fmt --check passes for the library and the bench crate, after the rebase too. Host clippy and armv7 clippy (--lib and --all-targets) pass.

Benchmarks: not run. seal/open change by a few register moves, and the stack loads of the tag become a register. A scoped manual Benchmarks run (ChaCha20-Poly1305 on ARM, including the new out-of-place group) should go with this PR; I have not triggered one.


Generated by Claude Code

… 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
@reaperhulk
reaperhulk force-pushed the claude/determined-gates-p7sa7b-arm-open-to branch from 266c6ed to d1c4123 Compare November 7, 2026 16:24

Copy link
Copy Markdown
Member Author

Closing: this ARM change is now part of #4466, which carries x86 and ARM open_to together. Its commit is unchanged apart from the Rust cfgs, which now name both arm and x86.


Generated by Claude Code

@reaperhulk reaperhulk closed this Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants