Skip to content

DSA parameter search over a refillable tape on ARMv7 - #4296

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

reaperhulk merged 6 commits into
mainfrom
claude/unify-random-bytes-crypto-xqmg0z-dsa-arm

Conversation

@reaperhulk

@reaperhulk reaperhulk commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Moves ARMv7's DSA parameter generation onto the refill protocol (Spec/Dsa/ParameterSearch.lean, Spec/Entropy.lean), as #4234, #4293, #4295 and #4297 did for x86-64, PPC64LE, i686 and AArch64. ARMv7's old three-tape function and its _umaal variant are deleted.

ARMv7 is the last target, so this PR also deletes the Rust three-tape path, which no target builds any more. It is an implementation PR: there is no change to TCB/ or Spec/. Removing generateParametersApi from Spec/ is a separate PR.

Lean

The code and proofs are changed in place, following PPC64LE's design.

Impl/Dsa/Arm/Generation.lean

  • vg_dsa_parameter_search(out, out_len, used, rand, rand_len, scratch, scratch_len, state) follows AAPCS: the first four arguments in r0–r3, the rest on the stack. It keeps the 304-byte stack (a 128-byte frame plus 176 for callees) and takes the width from state[1].
  • vg_dsa_parameter_search_umaal, from Generic/MillerRabin/Arm/DsaParameters.lean, needs VG_DSA_PARAMETER_SEARCH_UMAAL_FEATURES.
  • Seeds are read at a cursor in rand. The generator search reads a window of at most 128·p_len, and a short window with no g asks for more entropy. The statuses and the request min(2·max(avail, 256·L), 32769·L) are x86-64's. used, state[0] and state[3] are written with their high halves zero.
  • ARMv7 has only eq/ne here, so unsigned comparisons go through a new less block (the carry of a subtraction), and 32-bit constants through cst (movw/movt).
  • The frame stays at 128 bytes:
    • fOutLen becomes fUsedP;
    • new words: fStP, fC, fHs, fHsLen;
    • the four result words reuse the p search's words, which are unused by the end.
  • vg_dsa_parameter_search_init(state, p_len) writes [4096, L, 32769·L, 512·L] and returns 1, or writes zeros and returns 0. It is registered in Artifacts/Dsa/Arm.lean.

Proofs (Proof/Dsa/Arm/Gen)

  • The seed is proven against the shared refillAttempt. The controller steps with search_zero/short/attemptNone/rejected/accepted and bounds its request with requested_requests, all from Proof/Dsa/Generation/.
  • The g search runs over the window. Each u64 is written as two 32-bit halves, combined with RsaKeyGen's Slots lemmas.
  • Init.lean reuses RsaKeyGen's Space, clear_ok, zeros_words and wordsAt_slots.
  • The old controller and its three-tape proofs are gone.

Rust

  • src/dsa/parameters/search.rs now covers ARMv7, with a Search type for the C ABI. It picks _umaal by the same rule as before: on operating systems that run only on A-profile cores, when the CPU has the features; everywhere else, the baseline. The module is now gated on all five of the parent's architectures.
  • search/tests.rs checks the dispatch table and select against the emitted feature sets, and runs each variant the CPU supports.
  • Every target now generates parameters through search::generate, so parameters.rs and tests.rs lose the three-tape path: tapes, Generate, ARMv7's select, the three-tape known-answer fills, and the empty-tape and exhausted-tape tests.

Size

added removed
Lean (23 files) 2,576 901
Generated crate 4,837 2,523
Rust 114 413

Checks

  • A full lake build passes, as does Emit.lean --check with the standard axiom audit. No sorry, native_decide, bv_decide or maxHeartbeats.
  • All the static checks pass, including check_variants, as does check_lean_public_imports --base origin/main.
  • cargo fmt passes, and clippy -D warnings passes on x86-64, i686, PPC64LE, AArch64, armv7-unknown-linux-gnueabihf and thumbv7neon-unknown-linux-gnueabihf.
  • The DSA tests pass on x86-64 and i686, and under qemu on ARMv7 and AArch64. On ARMv7 they also pass with VG_CPU_FEATURES=none.

Benchmark

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

Benchmark Base Head Change
dsa_generate_parameters/1024 706.32 ms 701.13 ms 0.7% faster
dsa_generate_parameters/2048 1131.36 ms 1110.13 ms 1.9% faster
dsa_generate_parameters/3072 11118.38 ms 11793.08 ms 6.1% 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, #4297): about 1% less at 1024 bits, 2–3% 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 and move by noise in both directions. The extremes are dsa_generate_key_q256/3072 at 24.5% faster and dsa_private_key_q160/2048 at 21.9% slower, the latter on sub-microsecond timings.

🤖 Generated with Claude Code

https://claude.ai/code/session_015ajQWxFgLnhRDJS1FKU7Ub

Replace ARMv7's three-tape vg_dsa_generate_parameters (and its _umaal
variant) in place with vg_dsa_parameter_search, proven against
parameterSearchContract, and add vg_dsa_parameter_search_init, proven
against parameterInitContract.

- Impl/Dsa/Arm/Generation.lean: the seeds, their witnesses and the
  generator's h window all come from rand at the cursor fC; the controller
  counts rejected seeds from state[0] and stops with parameters (1), no
  seeds left (3) or a tape that ran out (2); finish writes out, used,
  state[0] and state[3] (high halves zero) and asks for
  min(2 max(avail, 256 L), 32769 L) unless avail reached the budget.
  Unsigned comparisons are a subtraction's carry (less); init reuses the
  RSA prime search's clear block for unsupported widths.
- Proof/Dsa/Arm/Gen: the seed against refillAttempt, the controller with
  RefillSearch's search_* lemmas and requested_requests, the window search
  for g, the write-back of the u64 halves, and Init.lean.
- Registrations: parameterSearchApi in the generic MillerRabin caller
  (the baseline and _umaal rounds), parameterInitApi in Artifacts/Dsa/Arm.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWxFgLnhRDJS1FKU7Ub
lake env lean --run Emit.lean: vg_dsa_parameter_search,
vg_dsa_parameter_search_umaal (VG_DSA_PARAMETER_SEARCH_UMAAL_FEATURES) and
vg_dsa_parameter_search_init replace vg_dsa_generate_parameters and its
_umaal variant.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWxFgLnhRDJS1FKU7Ub
ARMv7 joins x86-64 on the shared entropy::serve path, choosing
vg_dsa_parameter_search_umaal by the same rule as before. The three-tape
path's ARMv7 select and its tests 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
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 6, 2026
With ARMv7, every target runs the refillable-tape search, so the Rust
three-tape path (tapes, Generate, its known-answer fills and empty-tape
tests) can no longer build anywhere: remove it, and gate the search
module on the parent's architectures.

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