v0.2.0: hybrid signatures ML-DSA-65 + Ed25519 (RFC 10073), docs first #2

Closed
mnovak wants to merge 0 commits from feature/signatures into main
Owner

v0.2.0: hybrid post-quantum signatures (docs first)

Mark's decision of 2026-11-25: add hybrid signatures (ML-DSA with Ed25519) to Arcanum before Day 3, so Day 3 can authenticate exchanged X-Wing public keys post-quantum, not only through Tessera's classical Ed25519.

This PR starts with the (D)TDD document, docs/02_signatures.md. The tests come next, then the code, on this branch. Not for merging until all three are in.

  • Construction: RFC 10073 (published 2026-11-06) id-MLDSA65-Ed25519-SHA512, byte for byte. No combiner of our own.
  • Crates: ml-dsa =0.1.2 (RustCrypto: pure Rust, forbid(unsafe_code), no_std, unaudited, three 2026 advisories all fixed before 0.1.0) and ed25519-dalek =3.0.0 (shares curve25519-dalek 5.0.0 with x25519-dalek). Both use rand_core 0.10. Facts checked against the local registry sources.
  • Parameter set: ML-DSA-65, NIST category 3, matching ML-KEM-768. Public key 1984 B, signature 3373 B, private key 64 B.
  • Tests planned: ACVP ML-DSA keyGen, sigGen and sigVer (the sigVer files after their 2026-07-31 correction); RFC 8032 and Wycheproof for Ed25519; the RFC 10073 Appendix E composite vectors; binding of both halves; every byte matters; malformed input and a 10-minute fuzz run; hazmat and zeroize hygiene; v0.1.0's golden vectors unchanged.

Research with sources: F:\Akce\Via esearch\ml-dsa-2026-11-25.md (outside the repository).

Critical self-review of the plan

  1. Major: ml-dsa is unaudited and 0.1.x. The hybrid only buys "either half holds". A bug in our glue could still break both, which is why the RFC vectors and an independent rebuild of M′ in the tests matter.
  2. Major: the crate's convenient traits are wrong for this. Signer and Verifier sign deterministically with an empty context, which is not RFC 10073. The plan calls the inherent methods and bans a direct ml-dsa dependency downstream. sign_internal is public in 0.1.2, the same pattern as ml-kem's encapsulate_deterministic.
  3. Minor: the composite is not SUF-CMA (RFC 10073 §9.2). Arcanum must never use a signature as an identifier, and the doc says so.
  4. Open: whether Tessera's identity moves to this key, or keeps Ed25519 and signs a separate Via key. Day 3 decides; Arcanum works either way.
## v0.2.0: hybrid post-quantum signatures (docs first) Mark's decision of 2026-11-25: add hybrid signatures (ML-DSA with Ed25519) to Arcanum **before Day 3**, so Day 3 can authenticate exchanged X-Wing public keys post-quantum, not only through Tessera's classical Ed25519. This PR starts with the (D)TDD document, `docs/02_signatures.md`. The tests come next, then the code, on this branch. **Not for merging until all three are in.** - **Construction:** RFC 10073 (published 2026-11-06) `id-MLDSA65-Ed25519-SHA512`, byte for byte. No combiner of our own. - **Crates:** `ml-dsa =0.1.2` (RustCrypto: pure Rust, `forbid(unsafe_code)`, `no_std`, unaudited, three 2026 advisories all fixed before 0.1.0) and `ed25519-dalek =3.0.0` (shares `curve25519-dalek 5.0.0` with `x25519-dalek`). Both use rand_core 0.10. Facts checked against the local registry sources. - **Parameter set:** ML-DSA-65, NIST category 3, matching ML-KEM-768. Public key 1984 B, signature 3373 B, private key 64 B. - **Tests planned:** ACVP ML-DSA keyGen, sigGen and sigVer (the sigVer files after their 2026-07-31 correction); RFC 8032 and Wycheproof for Ed25519; the RFC 10073 Appendix E composite vectors; binding of both halves; every byte matters; malformed input and a 10-minute fuzz run; hazmat and zeroize hygiene; v0.1.0's golden vectors unchanged. Research with sources: `F:\Akce\Via esearch\ml-dsa-2026-11-25.md` (outside the repository). ### Critical self-review of the plan 1. **Major: `ml-dsa` is unaudited and 0.1.x.** The hybrid only buys "either half holds". A bug in our glue could still break both, which is why the RFC vectors and an independent rebuild of M′ in the tests matter. 2. **Major: the crate's convenient traits are wrong for this.** `Signer` and `Verifier` sign deterministically with an empty context, which is not RFC 10073. The plan calls the inherent methods and bans a direct `ml-dsa` dependency downstream. `sign_internal` is public in 0.1.2, the same pattern as ml-kem's `encapsulate_deterministic`. 3. **Minor: the composite is not SUF-CMA** (RFC 10073 §9.2). Arcanum must never use a signature as an identifier, and the doc says so. 4. **Open: whether Tessera's identity moves to this key, or keeps Ed25519 and signs a separate Via key.** Day 3 decides; Arcanum works either way.
mnovak added 1 commit 2026-11-25 11:10:34 +01:00
Mark decided on 2026-11-25 to add post-quantum signatures before Day 3, so
exchanged X-Wing keys can be authenticated post-quantum. The construction is
RFC 10073 id-MLDSA65-Ed25519-SHA512, byte for byte, on ml-dsa =0.1.2 and
ed25519-dalek =3.0.0. Covers the crate choices and the API traps (the crate's
Signer/Verifier traits use an empty context and sign deterministically), the
Arcanum contexts, a key-binding helper, the eight mandatory tests with their
vector sources (ACVP after the 2026-07-31 sigVer correction, Wycheproof, the
RFC's Appendix E), risks and gaps. Tests and code follow.
mnovak added 6 commits 2026-11-25 14:14:14 +01:00
Official vectors for the signature tests, fetched 2026-11-25 at the commits
docs/02_signatures.md names: ACVP keyGen and sigGen at 2972def2, sigVer at
a7f283cd (after the ModifyZ correction), Wycheproof at 20b25694, the
composite-sigs repository at f0627ab, and RFC 8032 section 7.1.

Files under about 1 MB are kept whole. The larger ones are reduced to their
ML-DSA-65 groups and a few cases per group by make_subsets.py, which checks
each original's sha256 and drops only whole cases and groups; RFC 8032's
vectors are extracted from the RFC text by extract_rfc8032.py. SOURCES.md
records the URL, commit, git blob, original sha256 and the selection of
every file.
The mandatory tests of docs/02_signatures.md, against the API the doc sets
out (arcanum::sign). They do not compile yet: the module does not exist.

1 kat_mldsa65: ACVP keyGen, sigGen (deterministic and hedged groups, byte
  for byte, through sign_randomized/sign_mu_randomized fed the vector's
  rnd), sigVer on the corrected file; Wycheproof sign_seed and verify.
2 kat_ed25519: RFC 8032 section 7.1 and Wycheproof, with verify_strict.
3 sig_composite: the RFC 10073 vectors s and sWithContext verify, the RFC
  key derives the RFC public key, own signatures verify under an
  independent rebuild of M', ML-DSA hedged with ctx = Label.
4 sig_halves: either half swapped in from another signature, zeroed or
  cut, or the halves swapped, is refused; the ML-DSA half fails an
  empty-ctx verifier. Not SUF-CMA (RFC 10073 9.2) is pinned.
5 sig_every_byte: any flipped byte of message, ctx, public key or
  signature fails; contexts are prefix-free; key bindings and app
  messages never verify as each other; every binding field matters.
6 sig_malformed: wrong lengths, weak and non-canonical Ed25519 keys,
  0- and 256-byte contexts, a 65536-byte key id, random bytes.
7 sig_hygiene and feature_hygiene: compile-fail checks against a
  default-features consumer (hazmat raw interface, ml-dsa internals,
  non-crypto RNG, Clone), ZeroizeOnDrop, Debug; ml-dsa and ed25519-dalek
  in the normal graph with zeroize and without hazmat or defaults. The
  allocator probe covers the signing keys.
8 golden_v1.rs is untouched.

Adds ml-dsa =0.1.2 (alloc, rand_core, zeroize) and ed25519-dalek =3.0.0
(zeroize) with default features off, base64 for the tests, and bumps the
version to 0.2.0. The fuzz target follows with the code.
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.
fuzz/fuzz_targets/signatures.rs: raw bytes into VerifyingKey, Signature,
SigningKey and AppContext; and the input XORed into a valid verifying key,
signature, message, raw ctx, key-binding id/window/time, X-Wing key and
binding signature. Beyond "never panics" it asserts that only the exact
signed bytes verify.

Run on 5a52854 plus this target, Windows 10, nightly 1.102.0
(739adecd4 2026-11-24), libFuzzer + ASan (MSVC 14.44 asan runtime),
corpus and artifacts on D:, 12 seed inputs: 605 s, 38,609 executions,
63 exec/s, 0 crashes, 0 artifacts, coverage 3,549, 122 corpus units.
HANDOVER: the builder's counts (121 tests in debug and release, clippy,
fmt, the zeroize probe, deny, audit, a 605 s fuzz run with no crash), seven
mutation checks, the vector sources, and what is not verified.

docs/02_signatures.md: an "As built" section (the raw interface stays
hedged, the canonical Ed25519 key check, label lengths, the order of the
binding checks, crate features); the gap on verify_strict is answered (it
accepts both RFC 10073 vectors and agrees with all 151 Wycheproof
verdicts), and the subsets and stack copies are listed as gaps. The app
context prefix in the AppContext paragraph is corrected to
domi/arcanum/v2/sig/app/.

README: signatures in the summary, a usage sketch, the new fuzz target.
mnovak added 9 commits 2026-11-26 04:03:18 +01:00
Ported from QA's proof tests for PR #2 (qa_s03 to qa_s05):

- S-01, sig_halves: an Ed25519 half with a small-order R (the identity,
  s = H(R || A || M')·a from a throwaway key's own scalar) is accepted by
  plain verify and refused by verify_strict; Arcanum must refuse it.
- S-02, sig_every_byte: a forged window that also excludes now gives
  InvalidSignature, never OutsideValidity.
- S-03, sig_composite: generate draws exactly 64 bytes, and the two seeds
  are those bytes in order (RFC 10073 3.1, independent component keys).

Each mutation QA describes now fails (applied to src/sign.rs, reverted):
Q1 verify_strict -> verify fails the S-01 test; Q3 now checked before the
signature fails the S-02 test; Q4 the Ed25519 seed copied from the ML-DSA
seed fails the S-03 test. Adds curve25519-dalek =5.0.0 as a dev-dependency
(already in the lock) for the scalar arithmetic.
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.
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 legacy_compatibility, ed25519-dalek checks only the top bits of S, so
S + l is accepted: a second encoding of the Ed25519 half, and the
malleability promise of verify_strict is gone. Feature unification lets
any crate in the final binary turn it on. deny.toml now bans it for
ed25519-dalek and curve25519-dalek, and ed25519-dalek/hazmat with it
(cargo-deny 0.20 [[bans.features]]).

Checked: bans ok as committed; enabling legacy_compatibility on
ed25519-dalek in Cargo.toml fails `cargo deny --offline check bans` for
both crates, and enabling hazmat fails it for ed25519-dalek (reverted).
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.
The probe looked only for its 32-byte canary, i.e. the seeds; the key
material that actually signs is derived from them and never contains it,
so an unwiped copy of the expanded key went unseen (QA's mutation Q15).

The probe allocator now also watches up to four further 32-byte patterns,
held in atomics (dealloc must not allocate or lock). The test computes the
canary key's FIPS 204 expanded encoding with ml-dsa itself and watches K
(held raw inside ml-dsa's ExpandedSigningKey) and a 32-byte window of the
encoded s1; controls show an unwiped copy is seen and a Zeroizing one is
not; then building, signing, binding and dropping a canary SigningKey must
free no block holding either.

Q15 re-checked: a SigningKey field holding an unwiped Vec of
ml.to_expanded() fails the probe at the new assertion (reverted). The
ml-dsa rnd / rho'' / y stack residue is out of the probe's reach (stack,
not heap) and is recorded as a gap.
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 expanded ML-DSA-65 key is 34,992 bytes on the stack (QA measured;
  A_hat's rows are boxed inside ml-dsa), not 64 kB, and it is exactly the
  secret part. src/sign.rs and docs/02_signatures.md corrected.
- S-04: ml-dsa's signing loop leaves rnd, rho'' and y on the stack; a
  leaked y gives s1. Recorded in docs/02 and docs/THREAT_MODEL.md, with the
  key-construction stack copy.
- S-07: under open question 1, the recommendation for Day 3: a separate,
  freshly generated composite identity, never a wrapped Tessera Ed25519
  seed (RFC 10073 3.1); from_bytes cannot detect reuse (also on its docs).
- S-08: verify_binding does not tie id to vk and has no serial; both are
  the caller's, with the Day 3 replay rule (QA E-07); also on its docs.
- S-12: decoded on 2026-11-26, none of the 9 ML-DSA-65 "modified z" sigVer
  cases at a7f283cd reaches the z infinity-norm bound (max 524,077 <
  524,092), so no ACVP case could be added; only Wycheproof covers it.
- S-05, S-10, S-11 noted under "As built" and gaps.
What was fixed and how each of QA's mutations now fails, what is recorded
as a gap, the counts at 0b2480b (126 passed / 5 ignored in debug, 127 / 4
in release, clippy and fmt clean, the probe, cargo deny) and a 601 s fuzz
run with no crash, and the consumer advice added (legacy_compatibility
ban, const contexts, 512 KiB signing threads, the binding checks left to
the caller).
Author
Owner

Merged --no-ff into main as fc96614, from head 1e7e0bb. Tagged v0.2.0 (annotated, unsigned) and pushed; HEAD == origin/main.

  • QA (Via/qa/review-arcanum-pr2.md): 0 blockers, 0 majors, 12 minors.
    • Answered in 99db18a…1e7e0bb: S-01 to S-06 and S-09 to S-11.
    • Recorded as gaps in docs/02_signatures.md: S-07, S-08, S-12, and the S-04 stack residue inside ml-dsa.
  • Owner, fresh clone at 1e7e0bb: cargo test 126 passed / 0 failed / 5 ignored (debug) and 127 / 0 / 4 (release). clippy, fmt, cargo deny and the zeroize probe are clean.
  • Builder: fuzz signatures 601 s, 181,113 executions, 0 crashes; seven mutations, each seen to fail.
  • API change since d56ee10: AppContext::new is a const fn taking &'static [u8].
  • Not audited. Not verified: constant time, Linux, interop with a non-Rust implementation.

Closed by hand, since manual-merge detection is off in this repo.

Merged `--no-ff` into `main` as `fc96614`, from head `1e7e0bb`. Tagged **v0.2.0** (annotated, unsigned) and pushed; `HEAD` == `origin/main`. - **QA** (`Via/qa/review-arcanum-pr2.md`): 0 blockers, 0 majors, 12 minors. - Answered in `99db18a`…`1e7e0bb`: S-01 to S-06 and S-09 to S-11. - Recorded as gaps in `docs/02_signatures.md`: S-07, S-08, S-12, and the S-04 stack residue inside ml-dsa. - **Owner, fresh clone at `1e7e0bb`:** `cargo test` 126 passed / 0 failed / 5 ignored (debug) and 127 / 0 / 4 (release). clippy, fmt, `cargo deny` and the zeroize probe are clean. - **Builder:** fuzz `signatures` 601 s, 181,113 executions, 0 crashes; seven mutations, each seen to fail. - **API change since `d56ee10`:** `AppContext::new` is a `const fn` taking `&'static [u8]`. - **Not audited.** Not verified: constant time, Linux, interop with a non-Rust implementation. Closed by hand, since manual-merge detection is off in this repo.
mnovak closed this pull request 2026-11-26 04:07:12 +01:00

Pull request closed

Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mnovak/arcanum#2