Skip to content

FFDH parameter generation on AArch64: the sieve stops at the first divisor, and p is rejected before q's sieve - #5119

Merged
alex merged 3 commits into
mainfrom
claude/aarch64-ffdh-parameter-screening
Nov 15, 2026
Merged

alex merged 3 commits into
mainfrom
claude/aarch64-ffdh-parameter-screening

Conversation

@alex

@alex alex commented Nov 15, 2026

Copy link
Copy Markdown
Member

FFDH parameter generation on AArch64 is 4.1 times as fast with g = 5 and 1.9 times with g = 2. This is the first step on finding 3 of the ARM64 audit, where it was 13–21× and 4× OpenSSL. x86-64 did this step in #4507 and PPC64LE in #4660.

Cause

Every candidate that passed the generator's congruence (40% of them for g = 5, 8% for g = 2) ran the whole trial division on p, 512 table entries, and then the whole one on q, whatever either found. Most candidates have a small factor among the first entries.

Change

  • Impl/Ffdh/AArch64/ParameterCandidate.lean: after each table word, sieveStop zeroes the count of words left under the mask of a divisor found, which ends the loop. main checks the flag after p's sieve and rejects the candidate there; what follows is mainQ.
  • Every value here is public (the code already branches on the tape's contents), and 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.
  • Proof/Ffdh/AArch64/…/Sieve.lean: stopN, the number of words read, and anyPre_stopN: a divisor among the words read is one among all the entries. sieve_ok's statement is unchanged, so nothing after it changed.
  • CTPieces.lean, CTMain.lean: the sieve's relational proof is indexed by the word it stops at; one more stage and branch for the new check. Main.lean, ShapeOk.lean, Generation/Search/Verified.lean: the new reject branch.
  • The regenerated crate changes vg_ffdh_parameter_candidate_sieved alone.

No change to Spec/ or TCB/.

Measurement

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

Benchmark Base Head Change
ffdh_parameters_g2/64 198.97 ms 104.20 ms 47.6% faster
ffdh_parameters_g5/64 877.78 ms 213.86 ms 75.6% faster

In the audit OpenSSL took 43–67 ms for g = 5 and 47–52 ms for g = 2 (its own draws, so the comparison is approximate): this leaves about 3–5× and 2×.

What is left

AArch64 still lacks the other steps x86-64 and PPC64LE took, in order of expected gain:

  1. The generator's congruence (p mod 24 or 10) without the bit-serial reduction, which now runs on every candidate and is the largest cost left (FFDH parameter generation on x86-64: cheap pre-sieve screen of p and q #4401, PPC64LE FFDH parameter candidates: the generator's congruence from the digit sum #4677). In progress, stacked on this branch.
  2. p's first table words, then q's sieve, then the rest of p's (FFDH parameter generation on x86-64: sieve p's first 64 primes before q's sieve #4525, PPC64LE FFDH parameter candidates: q's trial division before p's whole #4684).
  3. One reduction per product of four table entries (FFDH parameter generation on x86-64: one reduction per table word's product #4534, PPC64LE FFDH parameter candidates: trial division by products of four entries #4705).

Tests

Under qemu-aarch64: the eight FFDH tests of tests/cavp pass, safe_prime_parameter_generation among them (it generates 512-bit parameters for both generators and exchanges keys with them), and the sixteen FFDH unit tests, with published_candidates_and_tape_consumption, rejected_candidates_are_consumed and composite_q_at_modulus_width_boundaries. That is emulation; CI is the first run on an ARM64 CPU. No test was added.


Generated by Claude Code

…st divisor

The implementation and the sieve's proof (Sieve.lean) build. CTPieces,
Main and CTMain do not build yet.

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

The candidate's proofs and the FFDH registration build. Not yet done: the
full build, the regenerated crate and the checks.

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

A candidate that passed the generator's congruence ran RSA's whole trial
division on p (512 or 1024 table entries) and then on q, whatever it
found, and only then looked at the result. Most candidates have a small
factor. The sieve now stops after the first word of the table (four
entries) with a divisor, and a p with one is rejected before q's sieve.

The result is the same (Spec.Ffdh.sievedParameterCandidate): a divisor
among the words read is one among all the entries, so the flag is the
whole division's.

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 added this pull request to the merge queue Nov 15, 2026
Merged via the queue into main with commit 76b006d Nov 15, 2026
24 checks passed
@alex
alex deleted the claude/aarch64-ffdh-parameter-screening branch November 15, 2026 17:14
alex pushed a commit that referenced this pull request Nov 15, 2026
…d crate

Builds in full, and the emitter's check passes, before restacking onto
main (step 1 merged as #5119).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHFQ9fhoiRgxoBRku5u
alex pushed a commit that referenced this pull request Nov 15, 2026
…d crate

Builds in full, and the emitter's check passes, before restacking onto
main (step 1 merged as #5119).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHFQ9fhoiRgxoBRku5u
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