Files
arcanum/docs/02_signatures.md
T
mnovak c7294612ae docs: v0.2.0 design, hybrid signatures ML-DSA-65 + Ed25519 per RFC 10073
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.
2026-11-25 11:10:31 +01:00

154 lines
11 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 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<R: CryptoRng + ?Sized>(rng: &mut R) -> Self;
pub fn from_bytes(&[u8]) -> Result<Self, Error>; pub fn to_bytes(&self) -> Zeroizing<[u8; 64]>;
pub fn verifying_key(&self) -> &VerifyingKey;
pub fn sign<R: CryptoRng + ?Sized>(&self, msg: &[u8], ctx: &AppContext, rng: &mut R) -> Result<Signature, Error>;
}
impl VerifyingKey { pub fn verify(&self, msg: &[u8], ctx: &AppContext, sig: &Signature) -> Result<(), Error>; }
pub fn bind_kem_key<R>(sk: &SigningKey, id: &[u8], kem: &xwing::PublicKey, valid: (u64, u64), rng: &mut R) -> Result<Signature, Error>;
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/` 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, and checks both halves before answering, so timing does not
tell which component failed (RFC 10073 §3.2).
## 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) |
## 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 is not known yet; test 3 will say. If it does, the
vector, the decision and the reason go here.
## 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.
2. Validity windows on key bindings: the default the engine should use (proposal: 30 days, renewed by the
control service).