Skip to content

ML-DSA x86-64: prepared keys - #4382

Merged
reaperhulk merged 2 commits into
mainfrom
claude/mldsa-prepared-x86_64
Nov 6, 2026
Merged

reaperhulk merged 2 commits into
mainfrom
claude/mldsa-prepared-x86_64

Conversation

@reaperhulk

@reaperhulk reaperhulk commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Follows #4375 (the AArch64 implementation, merged). Implements the prepared-key spec of #4366 on x86-64 for every arithmetic variant (baseline, _avx2, _avx512).

What changes

  • Shared kernels. The x86-64 sign and verify kernels become internal functions, vg_mldsa*_sign_with_cache{sfx} and vg_mldsa*_verify_with_cache{sfx}, taking a flag (r9 / r8, saved in scratch across the calls of ExpandA). With the flag set the key is a prepared key: signing copies ŝ₁ ‖ ŝ₂ ‖ t̂₀ from it instead of decoding and transforming (decodeOrCopy), and verification copies each NTT(t₁[r]·2ᵈ) instead of unpacking and transforming it (keyRow). The ordinary vg_mldsa*_sign / vg_mldsa*_verify are now mov r9/r8, 0; call kernel (stack 40); sign_message / verify_message_cached pass flag 0, and the new sign_message_prepared / verify_message_prepared the same code with flag 1. Their proofs are generalized over the flag (a cumulative memory frame in the kernels' invariants shows the cached polynomials are unchanged when copied).
  • Preparation. vg_mldsa{44,65,87}_prepare_signing_key / _prepare_verifying_key (Impl/MlDsa/X86_64/PreparedKey.lean): for each key polynomial, the existing bit_unpack / unpack_t1 into its slot, then vg_mldsa_ntt in place with the first KiB of prepared as working space; the encoded key is copied last, over that space. One generic proof (Proof/MlDsa/X86_64/PreparedKey/Prepare.lean) covers both, correctness and constant time (only the pointers leak), against preparePublicKeyContract / prepareSecretKeyContract at stack 32.
  • Satisfiability of the prepared message contracts' preconditions (PreparedKey/Sat.lean) is shown with a key that the verified preparation itself writes, so no assumption is added.
  • Registrations: a new generic file Generic/MlDsaArith/X86_64/MlDsaPreparedKey.lean; the prepared message functions are added to the existing generic sign-message / verify-message files. The AVX-512 arithmetic variant differs from AVX2 only in two samplers the preparation never calls, so its prepare functions declare the AVX2 features (ArithImpl.prepareFeatures, defaulting to features), as the emitter requires the exact set.
  • Rust (src/mldsa_common.rs): PreparedSigningKey / PreparedVerifyingKey hold and use the prepared key on x86-64 as on AArch64, matching exhaustively on Backend; the new functions' features are in backend()'s required lists. AArch64 is unchanged.

Trusted code

No changes to TCB/ or Spec/.

Testing

  • Full lake build and Emit.lean (all audits pass; --check clean after restacking onto main); only the x86-64 crate changes.
  • The existing prepared-key tests (tests/acvp/mldsa.rs prepared, tests/wycheproof/mldsa.rs sign_seed_prepared / verify_prepared) and the rest of the ML-DSA tests pass locally with VG_CPU_FEATURES=none, avx,avx2, avx,avx2,avx512f,avx512vl and unrestricted (on an AVX-512 CPU). Full cargo test passes in none / avx,avx2 / unrestricted; ML-DSA's Rust lines are fully covered.
  • Static checks, check_lean_public_imports.py on the edited modules, fmt, clippy, algorithms_table.py --check.

Benchmarks

Scoped run (x86-64, mldsa44 mldsa65 mldsa87, against the base): https://github.com/pyca/verified-garbage/actions/runs/42308361531 (code identical to this head; it was measured before the restack onto main). Its jobs exit 1 only on the gate's alarm for prepare/verifying, which did nothing on x86-64 before; the prepared groups are 4–13% faster and the ordinary ones within noise: details in the comment below.

🤖 Generated with Claude Code

https://claude.ai/code/session_015ajQWv8vyagFtvNRScZ3FE

reaperhulk commented Nov 6, 2026 •

Copy link
Copy Markdown
Member Author

Benchmark run 42308361531 (x86-64, mldsa44 mldsa65 mldsa87, base a4b74f24): both "Compare with base" jobs exit 1 only on the gate's >35% alarm for mldsa*_prepare/verifying. That is the intended change, not a regression: on the base, VerifyingKey::prepare on x86-64 only moved the key (6–27 ns); it now writes the prepared key (NTT(t₁·2ᵈ) for each row). I have not re-run it, since a re-run cannot change that.

default features (AVX-512) VG_CPU_FEATURES=none
verify_prepared vs base 6.6% / 5.5% / 8.1% faster 9.7% / 5.7% / 4.5% faster
sign_prepared vs base 7.6% / 6.8% / 10.7% faster 3.4% / 0.6% / 12.6% faster
sign_deterministic_prepared vs base 5.7% / 4.7% / 9.2% faster 6.7% / 3.6% / 12.2% faster
prepare/verifying (new work) 1.53 / 2.28 / 3.14 µs 2.75 / 4.12 / 5.50 µs
prepare/signing (keygen + preparation) +6.1 / +8.4 / +10.8 µs +8.9 / +12.8 / +17.7 µs

(44 / 65 / 87.) The ordinary sign, sign_mu, verify, verify_mu and keygen, whose entries now add a call into the shared kernel, stay within ±3% in both configurations, except one mldsa65_sign at 5.5% slower (default features) whose deterministic and _mu counterparts are within 3%; rejection sampling makes signing the noisiest group. From these numbers, preparing a key pays for itself after roughly one to three signatures or verifications, depending on the parameter set and configuration.


Generated by Claude Code

Base automatically changed from claude/wonderful-planck-ihi993-prepared to main November 6, 2026 23:05
Verified x86-64 prepare_signing_key / prepare_verifying_key for every
arithmetic variant, the sign and verify kernels taking a cache flag
(sign_message_prepared, verify_message_prepared), their registrations,
and the Rust wiring. The generated crate is not yet regenerated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWv8vyagFtvNRScZ3FE
The AVX-512 prepare functions call only the AVX2 arithmetic (NTT and
unpacking), so they declare its features (`ArithImpl.prepareFeatures`).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWv8vyagFtvNRScZ3FE
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

This pull request has conflicts with main, found after 9ff6f96 landed on main: rebase it to resolve them. Before rebasing, see CLAUDE.md on checking how much Lean main changed, and on restacking a stacked pull request.

Posted by .github/workflows/conflicts.yml, once per push to a conflicting pull request.

@reaperhulk
reaperhulk force-pushed the claude/mldsa-prepared-x86_64 branch from 7a7bb52 to bb698bf Compare November 6, 2026 23:10
@reaperhulk
reaperhulk enabled auto-merge November 6, 2026 23:11
@reaperhulk
reaperhulk added this pull request to the merge queue Nov 6, 2026
Merged via the queue into main with commit f63cc42 Nov 6, 2026
36 checks passed
@reaperhulk
reaperhulk deleted the claude/mldsa-prepared-x86_64 branch November 6, 2026 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants