Skip to content

FFDH parameter generation on AArch64: p's first table words, then q's sieve, then the rest of p's - #5133

Merged
alex merged 4 commits into
mainfrom
claude/aarch64-ffdh-sieve-order
Nov 15, 2026
Merged

alex merged 4 commits into
mainfrom
claude/aarch64-ffdh-sieve-order

Conversation

@alex

@alex alex commented Nov 15, 2026

Copy link
Copy Markdown
Member

FFDH parameter generation on AArch64 with g = 5 is another 1.9 times as fast. This is the third step on finding 3 of the ARM64 audit, after #5119 and #5124. x86-64 did this step in #4525 and PPC64LE in #4684.

Cause

After the generator's congruence, a candidate ran p's whole trial division before anything was asked of q = (p − 1)/2. Most candidates fail on a small factor of p, of q, or on q being even, and each of those is cheaper to find first.

Change

  • Impl/Ffdh/AArch64/ParameterCandidate.lean: after the congruence, p is divided by the table's first four words (sixteen entries) only (mainP); then q is rejected at once if it is even; then q's sieve runs; and only then is p loaded again and divided by the whole table (mainQ). sieve takes its count of words.
  • The test of q's parity before its sieve is not in x86-64's or PPC64LE's code. With g = 5 half the candidates that reach it have an even q.
  • Four first words is what the other two targets use. A model of the search on the benchmarks' two tapes puts it within 1% of the best count on both.
  • The result is the spec's: both sides of the benchmark produce the same p and draw the same number of octets from the same tape.
  • Main.lean, CTMain.lean: main_ok and main_ct run the same stage lemmas (Stg, stgA_ok … stgTests_ok, check_ct), which replace the per-stage predicates. Sieve.lean and CTPieces.lean are generalised over the count; ShapeOk.lean gains the partial flags.
  • The regenerated crate changes vg_ffdh_parameter_candidate_sieved alone: 5,237 instructions rather than 4,930.

No change to Spec/ or TCB/.

Estimated before it was proven

The search was modelled on the benchmarks' two fixed tapes (the model finds the primes the code finds), and the cost of a table word taken from #5119's measurement: 104.6 ns. It predicted 47% for g = 5 and 13% for g = 2.

Measurement

Benchmarks run 43753876055, against main at daa7fe6, on the Neoverse N2 runner (512-bit parameters from a fixed tape):

Benchmark Base Head Change
ffdh_parameters_g2/64 59.88 ms 52.35 ms 12.6% faster
ffdh_parameters_g5/64 150.28 ms 79.22 ms 47.3% faster

Since the audit that is 199 → 52 ms for g = 2 and 878 → 79 ms for g = 5. OpenSSL took 47–52 ms and 43–67 ms there (its own draws, so the comparison is approximate): g = 2 is level with it, and g = 5 is 1.2–1.8×, from 13–21×.

What is left

One reduction per product of four table entries (#4534, #4705) is estimated at about 13 ms more for g = 5 and 5 ms for g = 2. Not planned unless someone wants it.

Tests

Under qemu-aarch64: the eight FFDH tests of tests/cavp and the sixteen FFDH unit tests pass, safe_prime_parameter_generation and published_candidates_and_tape_consumption among them. That is emulation; CI is the first run on an ARM64 CPU. No test was added.


Generated by Claude Code

…'s whole sieve

The sieve takes its count (sieve first); Sieve.lean and CTPieces.lean build.
Main.lean, CTMain.lean and Generation/Search/Verified.lean do not yet.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHFQ9fhoiRgxoBRku5u
…e's checks

Main.lean builds (the stages stgA_ok to stgTests_ok). CTMain.lean and
Generation/Search/Verified.lean do not yet.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHFQ9fhoiRgxoBRku5u
…e new order

The candidate's proofs build; the full build, the emitter and the generated
crate are not yet run.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHFQ9fhoiRgxoBRku5u
…al division

A candidate that passes the generator's congruence had p divided by RSA's
whole table before q was looked at. Now p is divided by the table's first
four words (16 entries) alone; then q = (p - 1) / 2 is rejected at once if
it is even, and divided by the table; and only then is p loaded again and
divided by the whole table, as PPC64LE's candidate does. The flag is looked
at after each of the five checks. The result is the specification's
(Spec.Ffdh.sievedParameterCandidate): the same p, the same octets drawn.

The sieve takes its count of the table's words (sieve first), and main_ok
and main_ct run the same stages (Stg, stgA_ok to stgTests_ok).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHFQ9fhoiRgxoBRku5u
@github-actions github-actions Bot added the untrusted-only This changes exclusively implementations and proofs, and thus is entirely formally verified. label Nov 15, 2026
@alex
alex enabled auto-merge November 15, 2026 19:46
@alex
alex added this pull request to the merge queue Nov 15, 2026
Merged via the queue into main with commit 0eb9fc1 Nov 15, 2026
24 checks passed
@alex
alex deleted the claude/aarch64-ffdh-sieve-order branch November 15, 2026 19:58
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