Skip to content

ARM: vg_chacha20_xor from a source to a destination - #4436

Merged
reaperhulk merged 1 commit into
mainfrom
claude/determined-gates-p7sa7b-arm-xor
Nov 7, 2026
Merged

reaperhulk merged 1 commit into
mainfrom
claude/determined-gates-p7sa7b-arm-xor

Conversation

@reaperhulk

Copy link
Copy Markdown
Member

This is the ARM counterpart of #4381 (RISC-V) and #4424 (PPC64LE). It generalizes the ChaCha20 XOR kernel to read from src and write to dst. dst is either src itself or a buffer disjoint from it. This is the groundwork for ARM's vg_chacha20_poly1305_open_to, which will share open's body, in a follow-up PR. No change to TCB/ or Spec/.

Code

  • dst argument. The new signature is vg_chacha20_xor(state = r0, src = r1, len = r2, buf = r3, dst = r5). AAPCS passes only four arguments in registers, and this function is internal, so dst comes in r5.
    • vg_chacha20_apply already keeps the data in r5, so its code is unchanged.
    • seal and open add one mov r5, r10 before the call (crypt).
  • Kernel. The kernel keeps dst in r7, and saves r7 with r4–r6 and lr in buf[256, 276). No stack is used, as before.
  • Byte loop. The loop (xorTo) loads each source byte before it stores the destination's. xorLoop, which works in place, stays for apply's bytes of a buffered block.
  • Generated code. The emitter changed only the ARM crate's vg_chacha20_xor and chacha20poly1305.

Proofs

  • Proof/ChaCha20/Arm/Xor.lean states the contract over the source and the destination:
    • XPre.alias requires that dst = src or that the two regions are disjoint.
    • Dst says the destination's bytes done so far are correct, and Src says the source after them is intact.
    • src_step carries Src through each step.
  • Call lemmas. xor_call_to covers calls from source to destination, and xor_call covers in-place calls. The callers use them: Stream's Apply/ApplyCT/Calls, and ChaCha20-Poly1305's Stages/Verified.

Checks

  • Full lake build passes, and so does the full Emit.lean. I ran both on the commit before rebasing onto current main; none of the files main changed since touch ARM or ChaCha20 Lean.
  • check_lean_public_imports.py and every step of the Static checks job pass.
  • Under qemu, cargo test passes for the ChaCha20 and ChaCha20-Poly1305 tests, including Wycheproof, on armv7-unknown-linux-gnueabihf and on thumbv7neon-unknown-linux-gnueabihf (T32).

Benchmarks: not run. seal/open gain one mov, and the kernel saves and restores one more register and advances one more pointer per byte. A scoped manual Benchmarks run (ChaCha20 and ChaCha20-Poly1305 on ARM) should go with this PR; I have not triggered one.


Generated by Claude Code

vg_chacha20_xor(state, src, len, buf, dst) now writes src XORed with the
keystream to dst, which is src itself or a buffer apart from it. dst
comes in r5 (AAPCS passes four arguments in registers): vg_chacha20_apply
keeps the data there already, and seal and open set it to the data. The
kernel keeps dst in r7, saved with r4-r6 and lr in buf[256, 276).

The proof states the contract over src and dst (Dst: the destination's
bytes done; Src: the source after them intact), with xor_call_to and the
in-place xor_call for the callers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWwrECv53ESEcwjcHaU
@github-actions github-actions Bot added the untrusted-only This changes exclusively implementations and proofs, and thus is entirely formally verified. label Nov 7, 2026
@reaperhulk
reaperhulk added this pull request to the merge queue Nov 7, 2026
Merged via the queue into main with commit debbce9 Nov 7, 2026
15 checks passed
@reaperhulk
reaperhulk deleted the claude/determined-gates-p7sa7b-arm-xor branch November 7, 2026 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

untrusted-only This changes exclusively implementations and proofs, and thus is entirely formally verified.

Development

Successfully merging this pull request may close these issues.

2 participants