Skip to content

PPC64LE FFDH parameter candidates: trial division only, p's before q's - #4660

Merged
alex merged 1 commit into
mainfrom
claude/ppc64le-ffdh-params
Nov 8, 2026
Merged

alex merged 1 commit into
mainfrom
claude/ppc64le-ffdh-params

Conversation

@alex

@alex alex commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Finding 3 of the PPC64LE audit: FFDH parameter generation on ppc64le is 92× OpenSSL with g = 5 and 13× with g = 2.

What it changes

vg_ffdh_parameter_candidate_sieved (Impl/Ffdh/PPC64LE/ParameterCandidate.lean) ran, on every candidate that passed the generator's congruence:

  1. a bit-serial remainder (smallMod, about 10 instructions per bit) by each of the 53 odd primes below 256, on p and again on q, with no early exit;
  2. RSA's trial division of p and then of q, which does stop at the first divisor.

The first 53 entries of RSA's table are exactly those 53 primes, so step 1 rejected nothing that step 2 doesn't. This PR:

  • drops both sieves;
  • makes and divides q only once p's trial division has passed.

At 512 bits each sieve cost about 270k instructions, which is most of the per-candidate cost. That explains why g = 5, whose congruence passes 2/5 of odd candidates against g = 2's 1/12, was 6× slower.

Proof

  • MainShape.trial_sieve: trial division by at least 53 entries clears the sieve.
  • trial_shape_iff: the congruence, q's parity and the two trial divisions pass exactly when Spec.Ffdh.sievedParameterCandidate's shape checks do.
  • main_ok and main_ct follow the new control flow. q's checks are now a branch (mainQ), and its condition (pOk) is a function of the public candidate.

No TCB or spec change. No Rust change: only the generated vg_ffdh_parameter_candidate_sieved changes.

Checks

  • lake build: everything.
  • Emit.lean: in full, only this function's files change.
  • check_lean_public_imports.py on the edited modules.
  • The Static checks steps.

ppc64le correctness is tested by CI's ppc64le jobs.

Benchmark

Benchmarks run 42509875481: powerpc64, modules=ffdh, groups=ffdh_parameters_g(2|5), base 413d7b9.

Benchmark Base Head Change
ffdh_parameters_g2/64 1089.68 ms 210.98 ms 80.6% faster
ffdh_parameters_g5/64 6425.91 ms 453.63 ms 92.9% faster

The audit's OpenSSL times were 80 ms (g = 2) and 70 ms (g = 5). Stacked follow-ups:

  • a cheap screen of the congruence in place of smallMod;
  • testing p and q together at each prime.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TKUFHGTYqNsecxgCdT9ZaD

vg_ffdh_parameter_candidate_sieved no longer runs the bit-serial sieve of
the 53 odd primes below 256 on p and on q before RSA's trial division:
the table's first 53 entries are those primes, so trial division, which
stops at the first divisor, already rejects what the sieve did
(trial_shape_iff). q is made and divided only once p's trial division
passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHGTYqNsecxgCdT9ZaD
@github-actions github-actions Bot added the untrusted-only This changes exclusively implementations and proofs, and thus is entirely formally verified. label Nov 8, 2026
@alex
alex added this pull request to the merge queue Nov 8, 2026
Merged via the queue into main with commit 418d0fe Nov 8, 2026
24 checks passed
@alex
alex deleted the claude/ppc64le-ffdh-params branch November 8, 2026 20:03
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