Repository navigation
FFDH parameter generation on x86-64: sieve p's first 64 primes before q's sieve - #4525
Merged
Merged
Conversation
… sieve p is now divided by only the first 16 words of RSA's table (64 primes) before q's whole sieve, and by the rest of the table after q passes. Most candidates that pass the screen have a small factor among those 64 primes, and a q with a small factor is now rejected before p's whole sieve. - `sieveFirst`/`earlyCheck`: oddness, then the sieve with a fixed count of `firstWords` words, stopping at the first divisor as the whole sieve does. - `sieveP`: p's whole sieve, after q's (`sieveQ`), before the witnesses. - `earlyOk_of_sieved`: the early check rejects only what p's whole sieve rejects, so the order of the checks does not change the result (`candidate_result`). - Timing: `sieveFirst_ct`/`earlyCheck_ct` (the sieve's relational proof, now over any count of words) and `sieveP_ct`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGjpPevDhRbNs9mJKT
alex
enabled auto-merge
November 7, 2026 19:13
This was referenced Nov 7, 2026
This was referenced Nov 15, 2026
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.
Part of #4141, following #4507.
What was slow
After #4507, for g = 2 about 27% of the search's time went to candidates whose q has a small factor. Each of those still paid for p's whole sieve first (~14 µs per such candidate), because p was sieved in full before q.
The change (x86-64
Impl+Proofonly; no spec or TCB change)The trial checks now run in this order:
earlyCheck,sieveFirst): oddness, then the first 16 words of RSA's table (64 primes). It stops at the first divisor, as the whole sieve does. Most candidates that pass the screen and are rejected by trial division have a factor among these 64 primes.sieveQ), as before.sieveP): p's whole sieve, once q has passed, before the Miller–Rabin witnesses.The result is unchanged:
earlyOk_of_sievedproves that the early check rejects only candidates that p's whole sieve also rejects.candidate_resultstill equalsSpec.Ffdh.sievedParameterCandidate; only the order of the trial checks changes.Correctness:
sieveFirst_okandearlyCheck_ok/earlyCheck_state_okprove what the new checks compute.sieveP_okproves the reordered p sieve.Timing:
SieveAt,sieveWords,word_at) now takes the number of table words as a parameter.sieveFirst_ctreuses it for 16 words, with the setup taint-checked (inner_sievePrefixN_ct).earlyCheck_ctandsieveP_ctprove the timing of the new early check and the reordered p sieve.Measurements
Benchmarks workflow, x86-64, against
mainat ae39a25, with OpenSSL: https://github.com/pyca/verified-garbage/actions/runs/42406449406 (medians).ffdh_parameters_g2/64ffdh_parameters_g5/64OpenSSL's search has high variance; its means on that runner were 47.4 ms (g = 2) and 53.7 ms (g = 5). An earlier run, https://github.com/pyca/verified-garbage/actions/runs/42405025925, started before this PR existed and so had no base to compare with.
Local runs on seven tapes (the bench tape and seeds 1000–1005), sums of the best of 3. I alternated the two builds, two runs each (Intel Xeon). OpenSSL's figure is 7 × its mean over 300 runs on the same machine:
What remains
I profiled candidates whose p fails its first Miller–Rabin round: about 90 µs each natively.
Checks
lake build(all), andEmit.lean: only the x86-64ffdhfiles change.Static checks, andcheck_lean_public_imports.pyon the edited modules.cargo test --release ffdh, also withVG_CPU_FEATURES=none --features cpu-features-env.🤖 Generated with Claude Code
https://claude.ai/code/session_01TKUFHGjpPevDhRbNs9mJKT