Skip to content

DSA parameter search over a refillable tape on AArch64 - #4297

Merged
reaperhulk merged 16 commits into
mainfrom
claude/unify-random-bytes-crypto-xqmg0z-dsa-aarch64
Nov 6, 2026
Merged

reaperhulk merged 16 commits into
mainfrom
claude/unify-random-bytes-crypto-xqmg0z-dsa-aarch64

Conversation

@reaperhulk

@reaperhulk reaperhulk commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Moves AArch64's DSA parameter generation onto the refill protocol (Spec/Dsa/ParameterSearch.lean, Spec/Entropy.lean) and deletes its old three-tape function and controller. AArch64 is the last architecture: with #4293, #4295 and #4296, no target calls generateParametersApi any more, and a follow-up removes it. This is an implementation PR: nothing in TCB/ or Spec/ changes.

Lean

AArch64's generation was laid out like x86-64's old one, so this follows #4234: a new refill controller wraps the existing seed-attempt pieces. The q and p searches and their constant-time proofs are reused as they are.

Code

  • Impl/Dsa/AArch64/Generation/Refill.lean adds vg_dsa_parameter_search(out, out_len, used, rand, rand_len, scratch, scratch_len, state):
    • arguments in x0–x7, a 768-byte stack, and dispatch on state[1];
    • a 480-byte frame, with four controller words above the saved registers: the used and state pointers, the seeds left, and the current seed's start;
    • it runs seeds while they are rejected and stops with status 1 (parameters), 3 (no seeds left), or 0 (the tape is too short for the next seed, or a seed ran out of tape). Running out returns 3 instead once the seed's budget 32769·L is spent; otherwise the request is min(2·max(avail, 256·L), 32769·L);
    • each seed's generator reads its h candidates from a window of rand, at most 128·pLen octets;
    • it loads the state and used pointers once at the end, so the stores have public addresses.
  • The generator stage now returns code + 4·octets read, where code is 1 found, 2 invalid domain, 3 none. This changes the untrusted internal contract Proof/Dsa/GeneratorStageContract.lean, which only AArch64 uses. The controller needs the count to know how much was consumed, and needs to tell no generator from an invalid domain.
  • Variants are registered in Generic/MdHash/MdHash/MillerRabin/AArch64/Dsa.lean against parameterSearchApi: the baseline, _sha1_sha2, _sha256_sha2 and _sha1_sha2_sha256_sha2.
  • vg_dsa_parameter_search_init(state, p_len) (Impl/Dsa/AArch64/ParameterSearch.lean, registered in the new Artifacts/Dsa/AArch64.lean) writes [4096, L, 32769·L, 512·L] and returns 1, or writes zeros and returns 0.

Proofs (Proof/Dsa/AArch64/Generation/)

  • New:
    • correctness: RefillOutcome, RefillAttempt, RefillABI, RefillEntry, RefillLoop, RefillFinish, RefillCorrect;
    • constant time: RefillCTAttempt, RefillCTLoop, RefillCTFinish, RefillCT;
    • RefillVerified, and Proof/Dsa/AArch64/ParameterSearchInit.lean.
  • They use the shared refillAttempt, search_* and requested_requests from Proof/Dsa/Generation/.
  • The generator proofs were updated for the new return value: Finish, Body, Correct, ABI, CT and the search plan.
  • 32 old-controller modules that became unreachable are deleted: ABI*, Correct, ConstantTime, BackendVerified, Satisfiable, Generate/GenerateCT, Parameter*, the old Entry* chain, Public*CT, SeedAttempt, SeedPrimeFinish, TapeCheck and others. So are the old Generate.lean, seedAttempt, parameterSearch and generatorCall*.

Rust

  • src/dsa/parameters/search.rs now covers AArch64: an exhaustive match over the SHA-1/SHA-256 backends.
  • search/tests.rs checks the dispatch table against the emitted feature sets and runs every variant the CPU supports.
  • AArch64's select and its three-tape test are removed from parameters.rs.

Size

added removed
Lean (81 files) 4,584 3,108
Generated crate 6,232 4,370
Rust 123 124

Checks

  • Lean: the full lake build passes. Emit.lean --check passes with the standard axiom audit. No sorry, native_decide, bv_decide or maxHeartbeats.
  • Static checks: every step passes, including check_variants. check_lean_public_imports --base origin/main passes too.
  • Lints: cargo fmt and clippy -D warnings pass on x86-64 and on aarch64-unknown-linux-gnu.
  • Tests: the DSA parameter tests pass on aarch64-unknown-linux-gnu under qemu, with the detected features and with VG_CPU_FEATURES=none, and on x86-64.

Benchmark

Run: https://github.com/pyca/verified-garbage/actions/runs/42145796502 (arches: aarch64, modules: dsa, base main).

Benchmark Base Head Change Base (none) Head (none) Change
dsa_generate_parameters/1024 193.98 ms 191.90 ms 1.1% faster 195.04 ms 193.09 ms 1.0% faster
dsa_generate_parameters/2048 262.70 ms 256.15 ms 2.5% faster 262.91 ms 256.27 ms 2.5% faster
dsa_generate_parameters/3072 2650.60 ms 2809.01 ms 6.0% slower 2651.92 ms 2810.08 ms 6.0% slower

These differences are not noise. The benchmark feeds a fixed tape (fixed_tape in bench/benches/primitives/main.rs). The base splits it into three tapes: seeds, h values, then witnesses. The refill search instead reads seeds, witnesses and h windows from one tape in order. So the same stream yields different seeds and witnesses, and the search does a different amount of work. The same shift appears on every architecture (#4293, #4295, #4296): about 1% less at 1024 bits, 2.5–3.5% less at 2048, and 4–6% more at 3072. It measures which candidates this one tape yields, not how fast the code runs. The other DSA benchmarks run code this PR does not change. They move only by noise, the largest being single runs of sub-microsecond key-construction timings.

This conflicts with #4293, #4295 and #4296 only in the cfgs of src/dsa/parameters*.rs. I'll rebase it as they merge.

🤖 Generated with Claude Code

https://claude.ai/code/session_015ajQWxFgLnhRDJS1FKU7Ub

claude added 14 commits November 6, 2026 00:14
… and one seed over the refill window (WIP)

The generator stage returns its end (1, 2 for an invalid domain, 3
without a generator) and the octets of the candidates it read; the
refill controller's seed attempt runs it over the window of the tape.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWxFgLnhRDJS1FKU7Ub
… entry (WIP)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWxFgLnhRDJS1FKU7Ub
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWxFgLnhRDJS1FKU7Ub
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWxFgLnhRDJS1FKU7Ub
… and start, the h tape reset per seed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWxFgLnhRDJS1FKU7Ub
…tant time

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWxFgLnhRDJS1FKU7Ub
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWxFgLnhRDJS1FKU7Ub
…r and proofs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWxFgLnhRDJS1FKU7Ub
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWxFgLnhRDJS1FKU7Ub
AArch64 joins x86-64 on the shared entropy::serve path, matching the
SHA-1 and SHA-256 backends exhaustively over the four emitted variants.
The three-tape path's AArch64 select and its test are gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWxFgLnhRDJS1FKU7Ub
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWxFgLnhRDJS1FKU7Ub
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWxFgLnhRDJS1FKU7Ub
@reaperhulk
reaperhulk added this pull request to the merge queue Nov 6, 2026
Merged via the queue into main with commit 6dc8acc Nov 6, 2026
34 checks passed
@reaperhulk
reaperhulk deleted the claude/unify-random-bytes-crypto-xqmg0z-dsa-aarch64 branch November 6, 2026 08:22
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