Skip to content

ML-DSA x86: verified prepared keys - #4393

Merged
reaperhulk merged 10 commits into
mainfrom
claude/mldsa-prepared-x86
Nov 7, 2026
Merged

reaperhulk merged 10 commits into
mainfrom
claude/mldsa-prepared-x86

Conversation

@reaperhulk

@reaperhulk reaperhulk commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Verified ML-DSA prepared keys for 32-bit x86 (crates/verified-garbage-asm-x86), following AArch64, x86-64 and RISC-V: SigningKey{44,65,87}::prepare() and VerifyingKey*::prepare() now use verified prepared functions on x86 too, rather than keeping the encoded key.

No changes to TCB/ or Spec/. This is an implementation PR: Impl/ + Proof/ + registrations + regenerated crate + Rust.

What's new on x86

  • vg_mldsa{44,65,87}_prepare_signing_key / _prepare_verifying_key (Impl/MlDsa/X86/PreparedKey.lean, Proof/MlDsa/X86/PreparedKey.lean, stack 96).
    • They copy the key, then write after it, as u32 coefficients, the NTTs signing and verification compute from it: ŝ₁, ŝ₂, t̂₀ for a private key; t̂₁ for a public key.
  • vg_mldsa*_sign_message_prepared / _verify_message_prepared.
    • The message-level proofs are now generic over the key argument (KeyArg: its length and precondition); the ordinary functions are the plain key's instance, by rfl.
  • Code shared between the ordinary and prepared paths, as internal functions with no Api:
    • vg_mldsa*_sign_core, called by vg_mldsa*_sign and by vg_mldsa*_sign_prepared; a word of scratch tells it whether to decode the key and compute the NTTs, or take them from the prepared key.
    • vg_mldsa*_verify_core, which takes t̂₁ as an argument: vg_mldsa*_verify computes it in scratch, and vg_mldsa*_verify_prepared passes the prepared key's.
  • src/mldsa_common.rs: target_arch = "x86" joins each prepared-key cfg.
    • x86 has only the Scalar backend, so its prepares take AArch64 and RISC-V's path, with no dispatch.
    • The Backend matches stay exhaustive: the Sha3/Avx2/Avx512 arms keep their own cfgs.

Constant time is proven with taint_decide throughout. There is no sorry, native_decide or maxHeartbeats.

Testing

  • lake build (full) and Emit.lean: only crates/verified-garbage-asm-x86 changes.
  • All Static checks, and check_lean_public_imports.py on the edited modules.
  • i686-unknown-linux-gnu: cargo test, and VG_CPU_FEATURES=none cargo test --features cpu-features-env, with Wycheproof. All pass, with x86 line coverage 21573/21573 (100%).
    • The ML-DSA tests were rerun after the rebase.
  • Clippy (-D warnings) and fmt, for i686, x86-64 and AArch64, with each feature set.

Benchmarks

https://github.com/pyca/verified-garbage/actions/runs/42331360693 measures x86 with modules=mldsa_common against main (9ff6f96, before the rebase; the x86 code is unchanged by it).

It is scoped to x86 ML-DSA because no other code changes:

  • the crate's other functions are unchanged;
  • on the other architectures, mldsa_common.rs compiles to the same code.

The work moves into prepare, and the prepared operations get faster by about what it costs:

ML-DSA-44 ML-DSA-65 ML-DSA-87
prepare/verifying (base → head) 31 ns → 14.29 µs 40 ns → 21.53 µs 53 ns → 28.76 µs
verify_prepared (base → head) 258.65 → 244.94 µs (−5.3%) 444.51 → 423.58 µs (−4.7%) 779.55 → 750.77 µs (−3.7%)
verify (ordinary, head) 258.43 µs 444.35 µs 778.35 µs
prepare/signing (base → head) +14.6% +12.4% +9.6%
sign_deterministic_prepared (base → head) −5.9% −4.8% −2.4%
sign_deterministic (ordinary, base → head) −0.5% +0.1% −1.2%
  • prepare/verifying: before this PR, preparing a verifying key on x86 only copied the key. It now computes the k polynomials t̂₁. That is the run's red check: the workflow's 35% threshold, on 3 benchmarks.
  • prepare/signing: now also computes ŝ₁, ŝ₂ and t̂₀.
  • Ordinary operations: sign, verify, _mu and keygen are unchanged within noise. Randomized sign moves by ±5% in both directions across parameter sets; the deterministic signature does not.

🤖 Generated with Claude Code

https://claude.ai/code/session_015ajQWwDf2TWyuN7bZSQDiU

Copy link
Copy Markdown
Member Author

Compare with base (x86) is red on its 35% threshold, on mldsa{44,65,87}_prepare/verifying only. That slowdown is this PR's intended change, so I am not re-running it.

  • Before, preparing a verifying key on x86 only kept the key (31–53 ns).
  • Now it computes t̂₁ once (14–29 µs), and verify_prepared is faster by about that much (−3.7% to −5.3%).
  • Ordinary sign and verify show no regression.

The numbers are in the description.


Generated by Claude Code

@reaperhulk
reaperhulk force-pushed the claude/mldsa-prepared-x86 branch from 3aacf86 to 776c6a1 Compare November 7, 2026 03:49
@reaperhulk
reaperhulk added this pull request to the merge queue Nov 7, 2026
Merged via the queue into main with commit 3970f78 Nov 7, 2026
36 checks passed
@reaperhulk
reaperhulk deleted the claude/mldsa-prepared-x86 branch November 7, 2026 08:44
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