Skip to content

Miller–Rabin x86-64 IFMA: 1024- and 1536-bit candidates (RSA-2048/3072 keygen, DSA-1024) - #4513

Merged
alex merged 25 commits into
mainfrom
claude/perf-4141-mr-ifma
Nov 7, 2026
Merged

alex merged 25 commits into
mainfrom
claude/perf-4141-mr-ifma

Conversation

@alex

@alex alex commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Part of #4141. Follow-up to #4450.

What was slow

#4450's vg_miller_rabin_round_ifma ran the IFMA round only for candidates of 32, 48 and 64 words. RSA-2048 and RSA-3072 key generation test 1024- and 1536-bit primes, and DSA-1024 a 1024-bit p, so on IFMA CPUs they still ran the ADX round.

What changed

  • Two one-lane layouts in Impl/Rsa/X86_64/PubIfma.lean: pay1024 = ⟨5, 16, 20, 4, 1⟩ (16 words, 20 limbs) and pay1536 = ⟨8, 24, 32, 4, 1⟩ (24 words, 32 limbs). Both have S = L, the radix the round's proofs use. The round's code now dispatches on 16, 24, 32, 48 and 64 words, and every other size still falls back to the ADX round.
  • The shared multiplication (Proof/Bignum/X86_64/Ifma): the new layouts join AmmOk. Both have nl·R ≤ 10, so ammMul takes its look-ahead for them, and they also join UOk. Each layout's per-step symbolic checks are added (checkStep, checkStepU, checkZerosU, checkStartU), checked by the kernel like every existing layout's. The case splits on AmmOk are widened.
  • The round's proofs use their own predicate, MrOk (the five one-lane layouts), instead of PubOk. RSA's public operation and FFDH, which use PubOk, are unchanged. Three shared lemmas now take only what they use:
    • mod_ofN (mod_of stays as a wrapper).
    • OutN.one' (OutN.one stays as a wrapper).
    • ld52_ok, which now takes AmmOk; its three callers pass hl.amm.
  • Generated code. Only vg_miller_rabin_round_ifma changes, so the round's callers keep calling it. No new variant is added, so the dispatchers and README tables are unchanged.

Correctness, Keeps and the frame, and constant time (by taint on each layout's body, with RelCT.frame) are proven as in #4450. The MCDT prologue and ctlOk are as before, and ci/check_mcdt.py passes. No contract changed.

No TCB or Spec changes.

Numbers

One round, natively, same inputs (Intel Xeon @ 2.30 GHz with AVX512_IFMA):

candidate ADX IFMA
1024 bits 0.349 ms 0.256 ms
1536 bits 1.065 ms 0.800 ms

cargo bench on the same machine, main / this PR, with the benchmarks' fixed tapes:

benchmark main this PR change
rsa_keygen_generate/256 (RSA-2048) 61.0 ms 51.6 ms −15%
rsa_keygen_generate/384 (RSA-3072) 161.6 ms 128.6 ms −20%
rsa_keygen_generate/512 356.5 ms 353.4 ms ≈ (already IFMA)
dsa_generate_parameters/1024 53.6 ms 47.8 ms −11%
dsa_generate_parameters/2048 264.4 ms 254.0 ms ≈ (already IFMA)
dsa_generate_parameters/3072 1.69 s 1.69 s ≈ (already IFMA)
ffdh_parameters_g2/64 80.9 ms 75.8 ms ≈ (512-bit p, no IFMA layout)

Benchmarks workflow: run 6540 (x86_64, module miller_rabin, against main, with OpenSSL). Its runner was an AMD EPYC 7763 with no AVX-512, so it chose the ADX round on both sides and measures only the code CPUs without IFMA run. Every benchmark is within 0.2% of main (RSA keygen/256 79.62 → 79.65 ms, /384 207.56 → 207.85 ms, DSA-1024 74.10 → 74.23 ms). The IFMA numbers above are from the local Xeon.

Checks

  • Static checks: every step of the Static checks job passes, as does check_lean_public_imports.py on the changed modules.
  • Lean: the full lake build and Emit.lean pass.
  • Native test: before proving, the printer's text was assembled and checked natively against a Python Miller–Rabin: 200 random and structured candidates of 16 and 24 words, and 60 across all five sizes. Every verdict matched, and nothing outside the table arrays was written.
  • Rust: cargo test --features cpu-features-env passes, unrestricted and under VG_CPU_FEATURES=avx,avx2,bmi2,adx. There are no Rust changes.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TKUFHEiNkt2jkCEfLQ6B2u

claude added 25 commits November 7, 2026 11:13
…ndow math (WIP, unproven)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHEiNkt2jkCEfLQ6B2u
…ed MXCSR save; proof skeleton (WIP, contains sorry)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHEiNkt2jkCEfLQ6B2u
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHEiNkt2jkCEfLQ6B2u
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHEiNkt2jkCEfLQ6B2u
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHEiNkt2jkCEfLQ6B2u
…tlOk_of_noLoad

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHEiNkt2jkCEfLQ6B2u
…ather than never loaded

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHEiNkt2jkCEfLQ6B2u
…und proofs)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHEiNkt2jkCEfLQ6B2u
… (ctlC/ctlOk) rather than never loaded

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHEiNkt2jkCEfLQ6B2u
…he round; regenerate the crates

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHEiNkt2jkCEfLQ6B2u
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHEiNkt2jkCEfLQ6B2u
…A and FFDH parameter generation

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHEiNkt2jkCEfLQ6B2u
… x86-64 takes

On aarch64, x86 and powerpc64 every implementation runs, so the
skipped iteration's continue was never reached there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHEiNkt2jkCEfLQ6B2u
…n with the IFMA Miller–Rabin variant

#4428's dispatchers, merged from main, now rank the _ifma instances.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHEiNkt2jkCEfLQ6B2u
# Conflicts:
#	crates/verified-garbage-asm-x86_64/src/dispatch/ffdh.rs
#	src/ffdh/arithmetic.rs
#	src/ffdh/domain.rs
#	src/ffdh/generation.rs
#	src/ffdh/precomputed.rs
…to come)

pay1024 and pay1536, one-lane layouts of 16 and 24 words, join AmmOk and
UOk (the look-ahead, nl·R ≤ 10) with their kernel checks; the round's own
MrOk lists its five layouts; code dispatches on 16 and 24 words first.
mod_ofN, OutN.one' and ld52_ok take only what they use, so that the round's
proofs reach the new layouts without changing PubOk.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHEiNkt2jkCEfLQ6B2u
…d 1536-bit candidates

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHEiNkt2jkCEfLQ6B2u
@github-actions github-actions Bot added the untrusted-only This changes exclusively implementations and proofs, and thus is entirely formally verified. label Nov 7, 2026
@alex
alex enabled auto-merge November 7, 2026 18:08
@alex
alex added this pull request to the merge queue Nov 7, 2026
Merged via the queue into main with commit 76ed90e Nov 7, 2026
35 checks passed
@alex
alex deleted the claude/perf-4141-mr-ifma branch November 7, 2026 18: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