# Arcanum v0.2.0: hybrid post-quantum signatures > (D)TDD document, written before the tests and the code. Mark decided on 2026-11-25: "Yes, before Day 3". > Research behind every fact here, with URLs and dates: `F:\Akce\Via\research\ml-dsa-2026-11-25.md`. > The crate facts below were also read from the local cargo registry (`ml-dsa-0.1.2`, `ed25519-dalek-3.0.0`). ## Why Arcanum v0.1.0 makes the key exchange post-quantum, but its threat model says that everything rests on each peer holding the **real** hybrid public key of the other. Today that key would be vouched for by Tessera's Ed25519 signatures, which a quantum attacker can forge, and then substitute keys. v0.2.0 adds a signature that stays secure while either ML-DSA or Ed25519 does, so Day 3 can authenticate exchanged X-Wing public keys, and signed plans, post-quantum. ## What - A **composite signature, ML-DSA-65 + Ed25519**, exactly RFC 10073 (November 2026) `id-MLDSA65-Ed25519-SHA512` (OID `1.3.6.1.5.5.7.6.48`). No combiner of our own. - **Key binding:** a helper that signs an X-Wing public key (and a key id and a validity) under a fixed Arcanum context, so Day 3 can check "this X-Wing key belongs to that device" with one call. - Same rules as v0.1.0: `#![no_std]`, `#![forbid(unsafe_code)]`, no I/O, no clock, randomness as a parameter, secrets zeroised on drop, typed errors, deterministic entry points only under `hazmat`. Out of scope: certificates and X.509 (we use the RFC's construction, not its ASN.1); SLH-DSA; HashML-DSA; changing v0.1.0's KEM, exchange or seal bytes (they stay frozen by `tests/golden_v1.rs`). ## How ### Primitives (vetted crates, none written here) | Crate | Version | Features | Why | |:--|:--|:--|:--| | `ml-dsa` (RustCrypto) | `=0.1.2` (2026-10-31) | `default-features = false`, `rand_core`, `zeroize`, `alloc` | FIPS 204; pure Rust, `forbid(unsafe_code)`, `no_std`; hedged signing with a context; same ecosystem as `ml-kem` (rand_core 0.10, signature 3, module-lattice 0.2.4, keccak 0.2) | | `ed25519-dalek` | `=3.0.0` (2026-07-06) | `default-features = false`, `zeroize` | RFC 8032; shares `curve25519-dalek 5.0.0` with `x25519-dalek`; `verify_strict` | | `sha2` | `0.11` (already a dependency) | — | PH = SHA-512 | Alternatives looked at and refused: `fips204` (no RustSec history, deterministic signing only behind a test feature), `libcrux-ml-dsa` (SIMD `unsafe`, four advisories in 2026), `aws-lc-rs` (needs std, empty context only), `pqcrypto-mldsa` (archived). **Parameter set: ML-DSA-65**, NIST category 3, matching ML-KEM-768 in X-Wing. It is RFC 10073's recommendation for the Ed25519 composite and RustCrypto's default. Cost: public key 1984 B, signature 3373 B, private key 64 B (two seeds). ML-DSA-44 (OpenSSH 10.6's choice, signature 2484 B) is the fallback if size ever matters more than a matched level; it would be a new label, never a silent switch. ### The construction (RFC 10073 §2.2, §3.2, §3.3, §4, §6) ``` Prefix = "CompositeAlgorithmSignatures2025" (32 ASCII bytes) Label = "COMPSIG-MLDSA65-Ed25519-SHA512" (ASCII, fixed) M' = Prefix || Label || u8(len(ctx)) || ctx || SHA-512(M) ctx: 0..=255 bytes Sign: mldsaSig = ML-DSA-65.Sign(mldsaSK, M', ctx = Label) hedged (fresh rnd from the caller's RNG) edSig = Ed25519.Sign(edSK, M') pure Ed25519, no Ed25519ctx sig = mldsaSig (3309 B) || edSig (64 B) Verify: split by fixed lengths (wrong length: invalid); rebuild M'; valid only if ML-DSA-65.Verify(mldsaPK, M', mldsaSig, ctx = Label) and Ed25519.verify_strict(edPK, M', edSig) Keys: public = mldsaPK (1952 B) || edPK (32 B) private = mldsaSeed (32 B) || edSeed (32 B), both generated fresh and never used outside the composite ``` Crate calls, chosen because the convenient traits are wrong for this: `ml-dsa`'s `Signer`/`Verifier` impls sign **deterministically** with an **empty** context, which is not RFC 10073. Arcanum calls the inherent `ExpandedSigningKey::sign_randomized(M', Label, rng)` and `VerifyingKey::verify_with_context(M', Label, sig)`, and builds the expanded key with `ExpandedSigningKey::from_seed`. `SigningKey::sign_internal` (public in 0.1.2, caller-chosen randomness) is never called outside `hazmat` tests, and via must ban a direct `ml-dsa` dependency the way it bans `ml-kem`. ### Arcanum's contexts The RFC's `ctx` is the application's domain separator. Arcanum fixes one per purpose, versioned like the KDF labels, so a signature made for one purpose never verifies for another: | Purpose | ctx | |:--|:--| | Binding an X-Wing public key to its owner | `domi/arcanum/v2/sig/kem-key` | | A caller's own messages (Day 3: plans) | `domi/arcanum/v2/sig/app/` + the caller's label (total ≤ 255 B) | The key-binding message is `u8(version=1) || u64be(not_before) || u64be(not_after) || u16be(len(id)) || id || xwing_pk (1216 B)`: fixed widths and one length prefix, so it is injective. Arcanum has no clock: the caller passes `now` to `verify_binding`. ### Shape of the API ```rust pub mod sign { pub struct SigningKey; // two 32-byte seeds; ZeroizeOnDrop; no Clone/Copy/PartialEq/Display; Debug redacted pub struct VerifyingKey; // 1984 bytes; from_bytes checks lengths and the Ed25519 point (not weak) pub struct Signature; // 3373 bytes impl SigningKey { pub fn generate(rng: &mut R) -> Self; pub fn from_bytes(&[u8]) -> Result; pub fn to_bytes(&self) -> Zeroizing<[u8; 64]>; pub fn verifying_key(&self) -> &VerifyingKey; pub fn sign(&self, msg: &[u8], ctx: &AppContext, rng: &mut R) -> Result; } impl VerifyingKey { pub fn verify(&self, msg: &[u8], ctx: &AppContext, sig: &Signature) -> Result<(), Error>; } pub fn bind_kem_key(sk: &SigningKey, id: &[u8], kem: &xwing::PublicKey, valid: (u64, u64), rng: &mut R) -> Result; pub fn verify_binding(vk: &VerifyingKey, id: &[u8], kem: &xwing::PublicKey, valid: (u64, u64), now: u64, sig: &Signature) -> Result<(), Error>; #[cfg(feature = "hazmat")] pub fn sign_composite_raw(...); // the bare RFC ctx, for the RFC's own vectors } ``` `AppContext` is a newtype that can only be built with the `domi/arcanum/v2/sig/app/` prefix, so a caller can never pass an empty or foreign context by accident. The bare RFC interface (any ctx, deterministic ML-DSA) exists only under `hazmat`, for the known-answer tests. Verification returns one error, `Error::InvalidSignature`, whichever half failed. **Correction (QA S-06):** the timing *does* tell which half failed: a malformed ML-DSA half is refused at decode without being verified, and `verify_strict` returns early on an undecodable or small-order R (QA measured 59 µs, 187 µs and 217 µs against 225 µs for a valid signature). That is harmless: verification handles only public data (the message, the public key, the signature), so its timing leaks nothing secret, and RFC 10073 §3.3 allows failing early. No dummy work is added. ## Tests (written first) | # | Mandatory test | Source of truth | |:--|:--|:--| | 1 | ML-DSA-65 KATs: keyGen, sigGen (deterministic groups, byte for byte), sigVer (accept and reject) | NIST ACVP-Server `gen-val/json-files/ML-DSA-*-FIPS204/`, keyGen/sigGen at `2972def2` (2026-07-20), **sigVer at `a7f283cd` (2026-07-31, the ModifyZ correction)**; sha256 pinned in `tests/vectors/SOURCES.md` | | 2 | Ed25519 KATs and edge cases, with `verify_strict` | RFC 8032 §7.1; Wycheproof `ed25519_test.json` | | 3 | The composite: verify the RFC's `s` and `sWithContext` for `id-MLDSA65-Ed25519-SHA512`; our own signatures verify under an independent rebuild of M′ in the test | RFC 10073 Appendix E (`lamps-wg/draft-composite-sigs` `testvectors.json` at `f0627ab`) | | 4 | Both halves are bound: a signature with either half replaced by a valid half from another signature, a zeroed half, or the halves swapped, is refused; an empty-ctx ML-DSA verifier refuses the ML-DSA half alone | constructed | | 5 | Every byte matters: flipping any byte of the message, ctx, public key or signature fails verification; contexts are prefix-free and a key-binding signature never verifies as an app message, or the other way round | constructed | | 6 | Malformed input (wrong lengths, a weak Ed25519 key, a 256-byte ctx) gives typed errors, never a panic; a fuzz target, 10 minutes | `cargo fuzz` | | 7 | Hygiene: `hazmat` and `ml-dsa`'s own randomness-taking internals are not reachable from a default-features consumer (compile-fail, like v0.1.0's A-33/A-34); the feature graph has no `hazmat`; secret types are ZeroizeOnDrop and freed wiped (the allocator probe) | v0.1.0's `feature_hygiene.rs`, `qa_consumer_api.rs`, `zeroize-probe` | | 8 | v0.1.0 is unchanged: `tests/golden_v1.rs` still passes | v0.1.0 | Also Wycheproof `mldsa_65_sign_seed_test.json` and `mldsa_65_verify_test.json` (`20b25694`, 2026-10-12). RustCrypto's own ACVP copies predate the sigVer correction, so Arcanum runs the current files itself. ## Risks | Risk | Consequence | Mitigation | |:--|:--|:--| | `ml-dsa` is unaudited and 0.1.x; three advisories in 2026 (a timing side channel, signature malleability, a `use_hint` bug), constant-time fixes in 0.1.2 | a forgery or a key leak in the PQ half | the hybrid: Ed25519 still holds; version pinned; ACVP + Wycheproof + RFC vectors; `cargo audit` in every run | | Using the crate's `Signer`/`Verifier` traits | signatures that are not RFC 10073 (empty ctx, deterministic) | never called; the RFC vectors fail if they are | | `zeroize` is opt-in in `ml-dsa` | secret keys left in memory | the feature is set, a hygiene test asserts it in the feature graph, the allocator probe covers signing | | The composite is **not SUF-CMA** and only weakly non-separable (RFC 10073 §9.2) | two valid signatures for one message; an Ed25519 half could be lifted out | Arcanum never uses a signature as an identifier; component keys never exist outside the composite; the Ed25519 half signs M′, which starts with the RFC Prefix (§9.4) | | Signing can fail (rejection sampling bound) | a panic in a release build | 0.1.2 returns an error from the hedged path; Arcanum surfaces it as `Error::SigningFailed`; the deterministic `sign_mu_deterministic` (documented to panic) is never called | | A 1984-byte key and a 3373-byte signature | larger control messages | fine over the control channel; noted for Day 5's QR import (classic keys only there) | ## As built (v0.2.0, `src/sign.rs`) Where the code differs from, or adds to, the design above (the code wins): - **The raw interface stays hedged.** `sign_composite_raw(sk, msg, ctx, rng)` and `verify_composite_raw(vk, msg, ctx, sig)` take any `ctx` of 0 to 255 bytes but still sign through `sign_randomized` with the caller's RNG; there is no deterministic ML-DSA path in Arcanum at all. A test that needs repeatable bytes passes a seeded RNG. Both are `hazmat` only. - **A stricter Ed25519 key check.** `ed25519-dalek`'s `VerifyingKey::from_bytes` accepts y >= p and a set sign bit on x = 0. Arcanum re-encodes the point and refuses any encoding that is not the canonical one, as well as small-order points (`Error::InvalidVerifyingKey`). Invisible to honest keys and to the RFC's vectors. - **And a weak ML-DSA key check** (QA S-05): an ML-DSA-65 half whose t1 is all zero is refused as `InvalidVerifyingKey`. With t1 = 0 a signature needs no secret (Wycheproof's `ZeroPublicKey`), so such a composite would silently be no stronger than Ed25519. ρ may be anything. - **App labels are 1 to 231 bytes** (`MAX_APP_LABEL_LEN` = 255 minus the 24-byte prefix); an empty label is `TooShort`, a longer one `TooLong`. **And `&'static`** (QA S-09): `AppContext::new` is a `const fn` taking `&'static [u8]`, so a label is written in the source, not derived from a peer name, file name or message field at run time (a consumer would have to leak memory on purpose to get around it). A consumer builds its contexts as `const`s, which also moves the length check to its compile time. There is no runtime constructor. - **Key bindings** are hashed field by field (no allocation); the window is inclusive at both ends; `verify_binding` checks, in this order, the window's shape and the id length (`InvalidValidity`, `TooLong`), the signature (`InvalidSignature`), then `now` (`OutsideValidity`), so `OutsideValidity` always means an authentic but expired binding. - `ml-dsa` gets `alloc` (its large vectors are boxed), `rand_core` and `zeroize`, default features off; `ed25519-dalek` gets only `zeroize` (not `fast`: no precomputed tables). ## Gaps - **Not audited**, like v0.1.0; the Day 7 audit pack covers both versions. - No constant-time measurement (dudect) of our own; inherited from the crates. - No HashML-DSA and no X.509: not needed. - The RFC's signing vectors are hedged, so the composite has no byte-exact signing KAT; byte-exact checks exist for the ML-DSA half (ACVP deterministic groups) and Ed25519. - ~~Whether `verify_strict` refuses any RFC 10073 vector~~: **it does not.** Test 3 (2026-11-25) verifies both the RFC's `s` (empty ctx) and `sWithContext` with `verify_strict`, through Arcanum and through the independent rebuild of M'. `verify_strict` also agrees with all 151 Wycheproof `ed25519_test.json` verdicts (test 2: no disagreement to list). - ACVP sigGen, sigVer and Wycheproof `mldsa_65_verify` run as subsets (`tests/vectors/SOURCES.md`): 18 of the sigGen cases, 15 sigVer cases, 70 of 210 Wycheproof verify cases. The full files' sha256 are pinned, so the subsets can be rechecked against them by rerunning `make_subsets.py`. - Stack copies: building a `SigningKey` moves the expanded ML-DSA key through the stack before it is boxed: **about 35 kB** (34,992 B, QA's measurement; `A_hat`'s rows are boxed inside `ml-dsa`), and those bytes are exactly the secret part (s1, s2, t0 and their NTT forms). The allocator probe sees only the heap. - **Stack residue inside `ml-dsa`** (QA S-04): every signature leaves `rnd`, ρ'' and the mask y on the stack, unwiped, in `try_raw_sign_mu`; with the public z, a leaked y gives c·s1 and so s1. Arcanum cannot reach it; it is in `docs/THREAT_MODEL.md`. The allocator probe now watches the expanded key's K and s1 bytes on the heap as well as the seed canary, but no heap probe can see the stack. - **Stack size** (QA S-11): building a key and signing need more than 128 KiB of stack in release (fit in 256 KiB) and more than 256 KiB in Arcanum's debug profile (fit in 512 KiB); a smaller thread aborts the process. Documented on `SigningKey`; pinned for release by `tests/sig_stack.rs`. - **ACVP never reaches the ‖z‖∞ bound** (QA S-12). The sigVer file at `a7f283cd` has 9 "modified signature - z" cases in its ML-DSA-65 non-preHash groups (3 kept in the subset); decoded with a script on 2026-11-26, the largest |z| coefficient among them is 524,077, below γ1 − β = 524,092, so all 9 decode and are refused only by the c̃ comparison. No ACVP case could be added for the bound; only Wycheproof's `InfinityNormViolation` cases (6 kept) test `ml-dsa`'s norm check at decode. Which of the 9 the ModifyZ correction changed was not checked (that needs the `2972def2` sigVer file). - **Key bindings have no serial and do not tie `id` to `vk`** (QA S-08). `verify_binding` checks that the holder of `vk` bound `kem` to `id` within the window; that `vk` is the right key for `id`, and that a newer binding has not replaced this one, are the caller's. For Day 3 (with the plan-replay rule, QA E-07): short windows, and keep only the binding with the newest `not_before` per `id` (no format change needed). - **Feature unification** (QA S-10): `ed25519-dalek/legacy_compatibility` in any crate of a consumer's binary would accept a non-reduced S (a second encoding of the Ed25519 half). Arcanum's `deny.toml` bans it (and `ed25519-dalek/hazmat`); consumers must ban it in theirs. ## Questions (none blocks the work) 1. Should Tessera's device identity itself move to this composite key, or should Tessera keep Ed25519 and this key be a separate Via identity signed by it? Day 3's `docs/03_engine.md` must decide; Arcanum works either way. **Recommendation (QA S-07):** the composite key is a **separate, freshly generated** identity (`SigningKey::generate`), optionally certified once by the old Ed25519 key. Never build it as `SigningKey::from_bytes(new_mldsa_seed || tessera_ed25519_seed)`: RFC 10073 §3.1 forbids reusing a component key, and with only weak non-separability (§9.2) any Tessera path that signs caller-influenced bytes beginning with the RFC Prefix would become a forgery oracle for the composite once ML-DSA falls. If the two keys ever coexist on one device, Tessera's Ed25519 signer should refuse messages that begin with `CompositeAlgorithmSignatures2025` (§9.4). `from_bytes` cannot detect reuse: any 64 bytes are a key. 2. Validity windows on key bindings: the default the engine should use (proposal: 30 days, renewed by the control service).