Repository navigation
FFDH parameter generation on AArch64: p's first table words, then q's sieve, then the rest of p's - #5133
Merged
Conversation
…'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
alex
enabled auto-merge
November 15, 2026 19:46
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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).sievetakes its count of words.Main.lean,CTMain.lean:main_okandmain_ctrun the same stage lemmas (Stg,stgA_ok…stgTests_ok,check_ct), which replace the per-stage predicates.Sieve.leanandCTPieces.leanare generalised over the count;ShapeOk.leangains the partial flags.vg_ffdh_parameter_candidate_sievedalone: 5,237 instructions rather than 4,930.No change to
Spec/orTCB/.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
mainat daa7fe6, on the Neoverse N2 runner (512-bit parameters from a fixed tape):ffdh_parameters_g2/64ffdh_parameters_g5/64Since 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 oftests/cavpand the sixteen FFDH unit tests pass,safe_prime_parameter_generationandpublished_candidates_and_tape_consumptionamong them. That is emulation; CI is the first run on an ARM64 CPU. No test was added.Generated by Claude Code