Skip to content

FFDH parameter generation on AArch64: the generator's congruence by a digit sum and a reciprocal - #5124

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

alex merged 3 commits into
mainfrom
claude/aarch64-ffdh-congruence

Conversation

@alex

@alex alex commented Nov 15, 2026

Copy link
Copy Markdown
Member

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:
    • one pass over p's words sums their 32-bit halves into S, which is congruent to p modulo 2³² − 1, and so modulo 3 and 5;
    • T = 105·(p mod 8) + 16·S is then congruent to p modulo 120;
    • T mod e, for e = 24 or 10, is T − e·⌊T·m / 2⁶⁴⌋ with m = ⌈2⁶⁴ / e⌉ (umulh, mul), exact for T < 2⁶¹, which the working space's bound on the word count gives.
  • The remainder is exact, as PPC64LE's is, so residue_ok's statement is unchanged and nothing outside ShapeOk.lean changed. (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.)
  • The model has no division instruction and none was added: umulh and mul were there.
  • Constant time: the existing residue_ct passes unchanged; the modulus and its reciprocal are selected by csel, as before.
  • The regenerated crate changes vg_ffdh_parameter_candidate_sieved alone.

No change to Spec/ or TCB/.

Measurement

Benchmarks run 43742228821, against main at 76b006d (with #5119), on the Neoverse N2 runner (512-bit parameters from a fixed tape):

Benchmark Base Head Change
ffdh_parameters_g2/64 104.12 ms 59.87 ms 42.5% faster
ffdh_parameters_g5/64 213.76 ms 150.24 ms 29.7% faster

With #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 of tests/cavp pass, safe_prime_parameter_generation among them (512 bits, both generators), and the sixteen FFDH unit tests, with published_candidates_and_tape_consumption and rejected_candidates_are_consumed. That is emulation; CI is the first run on an ARM64 CPU. No test was added.


Generated by Claude Code

…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
@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 7378b4f Nov 15, 2026
24 checks passed
@alex
alex deleted the claude/aarch64-ffdh-congruence branch November 15, 2026 17:52
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