ML-DSA-65 keeps large vectors on the stack, and a thread that is too small
aborts the process; that is not an Error a caller can handle. Measured
here with tests/sig_stack.rs (Windows x86-64, a thread per run):
release: 128 KiB overflows, 256/512/1024 KiB pass
debug (deps at opt-level 2): 128 and 256 KiB overflow, 512/1024 KiB pass
SigningKey's docs now say so and advise at least 512 KiB for threads that
sign. generate_and_sign_fit_in_256_kib_of_stack pins the release figure
(ignored in debug builds); the four on_a_<n>_kib_stack measurements are
ignored and run by hand, one at a time.
The design doc, VerifyingKey::verify and Error::InvalidSignature claimed
that both halves are always checked so timing does not tell which failed.
Not so: a malformed ML-DSA half is refused at decode without verification,
and verify_strict returns early on a bad R (QA measured 59/187/217 us
against 225 us). The docs now say the error does not name the half, the
timing may, and that is fine because verification uses only public data
(RFC 10073 3.3 allows failing early). The `&` and its comment, which
bought nothing (both booleans were already computed), become a plain `&&`.
No behaviour change.
A label is one fixed string per purpose; taking any runtime bytes let a
consumer derive it from a peer name, a file name or a message field, and
two purposes could then collide. AppContext::new now takes
&'static [u8] and is a const fn, so contexts are built as consts and a bad
label fails the consumer's build; there is no runtime constructor (the
simplest API: one constructor, no escape hatch until a need appears).
Tests: a const OK and a const EMPTY context; sig_hygiene refuses a
consumer that passes a runtime Vec (E0597/E0716); the one test that needs
runtime labels (flipping label bytes) leaks them on purpose. The random
labels in sig_malformed and fuzz mode 5's AppContext part are dropped (the
raw-ctx part of mode 5 stays). A doctest shows the const pattern, and
docs/02_signatures.md says so.
With t1 = 0 (Wycheproof's ZeroPublicKey), ML-DSA verification only checks
c~ = H(mu || w1(A·z)), which anyone can satisfy with s1 = s2 = t0 = 0: such
a composite key is silently no stronger than its Ed25519 half.
VerifyingKey::from_bytes now refuses it as InvalidVerifyingKey, like a
small-order Ed25519 half. Invisible to honest keys (t1 = 0 has negligible
probability); rho may be anything.
sig_malformed::an_ml_dsa_key_with_zero_t1_is_refused, from QA's qa_s07
inverted: the key is refused, one non-zero t1 byte anywhere makes it parse,
and with the component crate alone a secret-free expanded key signs for it.
Removing the check makes the test fail.
arcanum::sign, as docs/02_signatures.md sets out. M' = Prefix || Label ||
u8(len ctx) || ctx || SHA-512(M), built on the stack. The ML-DSA-65 half is
ExpandedSigningKey::sign_randomized(M', ctx = Label, rng), hedged; the
Ed25519 half is pure Ed25519 over M' (try_sign), checked with verify_strict.
Verification computes both halves before answering, and returns one
InvalidSignature whichever failed. ml-dsa's Signer/Verifier traits,
sign_deterministic and sign_mu_deterministic are never called.
- SigningKey: two 32-byte seeds (RFC 10073's private key format), the
expanded ML-DSA key boxed; ZeroizeOnDrop, not Clone, Debug redacted.
- VerifyingKey: 1984 bytes; refuses an Ed25519 half that is not a point,
not its canonical encoding, or of small order (InvalidVerifyingKey).
- AppContext: only "domi/arcanum/v2/sig/app/" + a 1..=231-byte label.
- bind_kem_key / verify_binding: an X-Wing public key bound to a key id and
an inclusive validity window under "domi/arcanum/v2/sig/kem-key"; the
message is hashed field by field; window and id are checked first, then
the signature, then now (InvalidValidity, TooLong, InvalidSignature,
OutsideValidity).
- sign_composite_raw / verify_composite_raw: the bare RFC ctx, hazmat only.
They still take an RNG (the ML-DSA half stays hedged), not the
deterministic variant the doc mentions.
- Error gains TooLong, InvalidVerifyingKey, InvalidSignature,
SigningFailed, InvalidValidity, OutsideValidity; Input gains SigningKey,
VerifyingKey, Signature, Context, KeyId.
Also fixes tests/kat_mldsa65.rs, which passed a &[&Vec<u8>] to
sign_internal and did not compile.
cargo test (debug): 121 passed, 0 failed (82 from v0.1.0, golden_v1
unchanged). clippy --all-targets --all-features -D warnings: clean.