Repository navigation
FFDH parameter generation on AArch64: the generator's congruence by a digit sum and a reciprocal - #5124
Merged
Conversation
…m of the halves The implementation and the congruence's proof (ShapeOk.lean) build. The modules after it, the full build and the regenerated crate are not done. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFQ9fhoiRgxoBRku5u
…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
… the sum of the words' halves p mod 24 (generator 2) or p mod 10 (generator 5) was RSA's bit-serial reduction, 64 steps a word, for every candidate. The sum S of the halves of 32 bits of p's words is congruent to p modulo 2^32 - 1, which 3 and 5 divide, so T = 105 (p mod 8) + 16 S is congruent to p modulo 120, and T mod 24 or T mod 10 is T less the modulus times the quotient by its reciprocal (umulh: the model has no division). The remainder, and so the flag, is the one the reduction gave. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFQ9fhoiRgxoBRku5u
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 is another 1.7 times as fast with g = 2 and 1.4 times with g = 5. This is the second step on finding 3 of the ARM64 audit, after #5119. PPC64LE did this step in #4677.
Cause
Every candidate is first tested against the generator's congruence (p mod 24 for g = 2, p mod 10 for g = 5), and that remainder was computed by RSA's bit-serial reduction: about 7,000 instructions for each candidate at 512 bits, whether or not it went on to the sieve.
Change
Impl/Ffdh/AArch64/ParameterCandidate.lean,residue:S, which is congruent to p modulo 2³² − 1, and so modulo 3 and 5;T = 105·(p mod 8) + 16·Sis then congruent to p modulo 120;T mod e, for e = 24 or 10, isT − e·⌊T·m / 2⁶⁴⌋withm = ⌈2⁶⁴ / e⌉(umulh,mul), exact forT < 2⁶¹, which the working space's bound on the word count gives.residue_ok's statement is unchanged and nothing outsideShapeOk.leanchanged. (x86-64's FFDH parameter generation on x86-64: cheap pre-sieve screen of p and q #4401 screens modulo 255 instead, which changes what the flag means.)umulhandmulwere there.residue_ctpasses unchanged; the modulus and its reciprocal are selected bycsel, as before.vg_ffdh_parameter_candidate_sievedalone.No change to
Spec/orTCB/.Measurement
Benchmarks run 43742228821, against
mainat 76b006d (with #5119), on the Neoverse N2 runner (512-bit parameters from a fixed tape):ffdh_parameters_g2/64ffdh_parameters_g5/64With #5119 that is 199 → 60 ms for g = 2 and 878 → 150 ms for g = 5 since the audit, where OpenSSL took 47–52 ms and 43–67 ms (its own draws, so the comparison is approximate): about 1.2× and 2–3.5× are left.
Both sides produce the same p and draw the same number of octets from the same tape.
What is left
For g = 5, where 40% of candidates reach the sieve: p's first table words, then q's sieve, then the rest of p's (#4525, #4684), and one reduction per product of four table entries (#4534, #4705). Not started.
Tests
Under
qemu-aarch64: the eight FFDH tests oftests/cavppass,safe_prime_parameter_generationamong them (512 bits, both generators), and the sixteen FFDH unit tests, withpublished_candidates_and_tape_consumptionandrejected_candidates_are_consumed. That is emulation; CI is the first run on an ARM64 CPU. No test was added.Generated by Claude Code