Skip to content

Spec: ML-DSA prepared keys for repeated signing and verification - #4366

Merged
reaperhulk merged 2 commits into
mainfrom
claude/wonderful-planck-ihi993
Nov 6, 2026
Merged

reaperhulk merged 2 commits into
mainfrom
claude/wonderful-planck-ihi993

Conversation

@reaperhulk

@reaperhulk reaperhulk commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Trusted specification change (Spec/ only; one new file, lean/VerifiedGarbage/Spec/MlDsa/PreparedKey.lean). This takes over the specification of #3806. The Rust API it is shaped for is an explicit prepared-key type, rather than #3819's cache hidden in the key types.

ML-DSA signing (FIPS 204 Algorithm 7, lines 1–5) and verification (Algorithm 8, lines 1–9) decode the key and transform its polynomials on every call. This specifies four functions, so a key that signs or verifies a stream of messages does that work once:

  • vg_mldsa{44,65,87}_prepare_signing_key and vg_mldsa{44,65,87}_prepare_verifying_key copy the encoded key and append the key polynomials in NTT form, as canonical u32 coefficients:

    • a private key gets NTT(s₁), NTT(s₂) and NTT(t₀);
    • a public key gets NTT(t₁ · 2^d).

    Preparation is constant time and adds no key validation.

  • vg_mldsa{44,65,87}_sign_message_prepared and vg_mldsa{44,65,87}_verify_message_prepared take a prepared key in place of the encoded key. Being prepared is a precondition (PreparedSecretKey, PreparedPublicKey). Otherwise they are signMessageContract and verifyMessageCachedContract of the encoded prefix:

    • the same results and failures;
    • the same permitted leakage (signMessageLeak for signing; the inputs for verification);
    • for verification, the same tr = H(pk, 64) precondition.

What changed from #3806:

  • Only the functions the Rust code will call have specs, following ML-DSA: no specs for its internal functions #3914. The shared kernels with an optional cache slice (*_with_cache) and the μ entries with a prepared key (*_sign_prepared, *_verify_prepared) become internal functions. Their contracts move to untrusted Proof/ in the implementation PR.
  • PolyIs moved out of Spec/ in ML-DSA: no specs for its internal functions #3914, so the spec now states a prepared key's polynomials directly, as PolyStored: coefficient i is the little-endian u32 at p + 4i, equal to its representative in [0, q). The implementation PR proves this equivalent to Proof/'s PolyIs.
  • The intended Rust API is SigningKey*::prepare(self) -> PreparedSigningKey* and VerifyingKey*::prepare(self) -> PreparedVerifyingKey*, with the usual sign, sign_deterministic and verify:
    • the prepared bytes are stored inline, with no allocation and no lazy or shared mutable state;
    • a prepared key is immutable, so threads can share one;
    • a prepared private key is wiped when dropped;
    • only callers who keep a key pay the preparation cost and memory: 5–11 KiB for a public key, 15–28 KiB for a private key.

Nothing here changes existing key formats or contracts, adds ISA semantics, or caches the expanded matrix Â.

Validation: lake build +VerifiedGarbage.Spec.MlDsa.PreparedKey passes on main d3d83849a. CI's static checks and Lean build pass.

The implementation (AArch64 proofs, registrations, generated code, Rust API, tests, benchmarks) will be a separate PR stacked on this one.

🤖 Generated with Claude Code

https://claude.ai/code/session_015ajQWy42drMfWKyQXeWwK8

@reaperhulk reaperhulk changed the title Spec: ML-DSA prepared keys for batch signing and verification Spec: ML-DSA prepared keys for repeated signing and verification Nov 6, 2026
@reaperhulk
reaperhulk marked this pull request as ready for review November 6, 2026 21:28
@reaperhulk
reaperhulk added this pull request to stack #4378 November 6, 2026 21:31
@reaperhulk
reaperhulk enabled stacked auto-merge November 6, 2026 21:33
vg_mldsa*_prepare_signing_key and vg_mldsa*_prepare_verifying_key copy an
encoded key and append the NTTs of its key polynomials (NTT(s1), NTT(s2),
NTT(t0) for a private key; NTT(t1 * 2^d) for a public key), stored as
canonical u32 coefficients (PolyStored). vg_mldsa*_sign_message_prepared
and vg_mldsa*_verify_message_prepared take such a prepared key in place of
the encoded key, with the results, failures and permitted leakage of
vg_mldsa*_sign_message and vg_mldsa*_verify_message_cached. A batch API
prepares a key once and signs or verifies many messages with it.

Adapted from the specification of #3806, with only the
functions the Rust code will call.

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWy42drMfWKyQXeWwK8
@reaperhulk
reaperhulk force-pushed the claude/wonderful-planck-ihi993 branch from d16a214 to 5515dd9 Compare November 6, 2026 21:40
@reaperhulk
reaperhulk added this pull request to the merge queue Nov 6, 2026
Merged via the queue into main with commit 716adfd Nov 6, 2026
17 checks passed
@reaperhulk
reaperhulk deleted the claude/wonderful-planck-ihi993 branch November 6, 2026 22:24
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