From ed9b8a3b17a6a9e3097a005d182d9a714df430e1 Mon Sep 17 00:00:00 2001 From: mnovak Date: Wed, 25 Nov 2026 07:23:10 +0100 Subject: [PATCH] docs: Day 1 analysis (X-Wing draft -11, key schedule, PSK rotation) and threat model --- docs/01_arcanum.md | 193 +++++++++++++++++++++++++++++++++++++++++++ docs/THREAT_MODEL.md | 55 ++++++++++++ 2 files changed, 248 insertions(+) create mode 100644 docs/01_arcanum.md create mode 100644 docs/THREAT_MODEL.md diff --git a/docs/01_arcanum.md b/docs/01_arcanum.md new file mode 100644 index 0000000..3833fce --- /dev/null +++ b/docs/01_arcanum.md @@ -0,0 +1,193 @@ +# Day 1 — Arcanum + +Status: v0.1.0 candidate, **not audited**. Nothing here is called secure before an external audit. + +## Why + +Every Domi product that moves data between devices (Via first, then Canalis, Custos sealing and +Tabellarius) needs a key exchange that survives a future quantum computer. Traffic recorded today +can be decrypted later ("harvest now, decrypt later"), so the protection has to be in place before +such a computer exists. Arcanum is the one small, reviewable crate that provides it, so the +ecosystem audits one piece of code instead of five. + +## What + +| Piece | What it does | Standard | +|:--|:--|:--| +| `xwing` | Hybrid KEM: ML-KEM-768 + X25519, X-Wing combiner | draft-connolly-cfrg-xwing-kem-11, FIPS 203, RFC 7748 | +| `exchange` | One exchange: the initiator encapsulates to the responder's public key; both get a `Session` bound to the full transcript and a caller context | HKDF (RFC 5869) with SHA-256 | +| `Session::wireguard_psk(epoch)` | The 32-byte WireGuard pre-shared key for one rotation epoch | HKDF-Expand | +| `seal` / `open` | One-shot sealed box to a recipient's hybrid public key | X-Wing + HKDF + ChaCha20-Poly1305 (RFC 8439) | + +Not in scope for Day 1: networking, WireGuard itself, signatures (ML-DSA comes later), migrating +other Domi apps. + +## How + +### Primitives (all from vetted crates, none written here) + +| Primitive | Crate | Version locked | Notes | +|:--|:--|:--|:--| +| ML-KEM-768 | `ml-kem` (RustCrypto) | 0.3.4 | FIPS 203 final. README: "never been independently audited". | +| X25519 | `x25519-dalek` | 3.0.0 | with `curve25519-dalek` 5.0.0 | +| SHA3-256 | `sha3` (RustCrypto) | 0.12.0 | X-Wing combiner | +| SHAKE256 | `shake` (RustCrypto) | 0.1.0 | X-Wing key expansion | +| HKDF-SHA-256 | `hkdf` 0.13.0, `sha2` 0.11 | | key schedule | +| ChaCha20-Poly1305 | `chacha20poly1305` (RustCrypto) | 0.11.0 | sealing | +| Zeroisation | `zeroize` | 1.x | every secret type is `ZeroizeOnDrop` | + +Exact versions are pinned by `Cargo.lock`, which is committed. + +### The hybrid KEM: X-Wing, draft -11 + +The roadmap asks for an X-Wing-style combiner and for the current draft to be checked. Facts +checked on 2026-11-25: + +- The current draft is **draft-connolly-cfrg-xwing-kem-11**, dated 2026-09-23, an individual + Internet-Draft (intended status Informational), not an RFC and not yet a CFRG-adopted document. + Source: . +- Its change log lists only editorial changes since -06 (ASN.1 module, SHAKE output length stated + in bits, implementation list, PEM header). The algorithm and the test vectors are the same as in + -06. Source: Appendix G of . +- RustCrypto's `x-wing` crate 0.1.1 (2026-10-01) describes itself as draft 06. Because the + algorithm did not change, its vectors are the -11 vectors; three were compared by hand against + Appendix C of -11 (seed and `ss` of vectors 1 and 2, `ss` of vector 3) and match. + +**Chosen: X-Wing as specified in draft -11**, with sizes public key 1216 B, secret key 32 B (a +seed), ciphertext 1120 B, shared secret 32 B: + +``` +expand(sk) = SHAKE256(sk, 96 bytes) -> d = [0:32], z = [32:64], sk_X = [64:96] +(pk_M, dk_M) = ML-KEM-768.KeyGen_internal(d, z); pk_X = X25519(sk_X, 9) +Encaps(pk, eseed) : (ct_M, ss_M) = ML-KEM-768.Encaps_internal(pk_M, eseed[0:32]) + ek_X = eseed[32:64]; ct_X = X25519(ek_X, 9); ss_X = X25519(ek_X, pk_X) +Combiner = SHA3-256(ss_M || ss_X || ct_X || pk_X || "\.//^\") +``` + +Arcanum composes X-Wing itself from `ml-kem`, `x25519-dalek`, `sha3` and `shake` rather than +calling the `x-wing` crate in production. The reasons, in order: + +1. Mandatory test 3 must replace a component secret by zeros and see the output change. That needs + the combiner as a separate function, which the `x-wing` crate does not expose. +2. Arcanum must reject malformed input with typed errors (test 5). Owning the parsing makes that + explicit. +3. The composition is twenty lines of glue between vetted primitives, not a primitive. It is pinned + by the three official X-Wing vectors **and** by a differential test against the `x-wing` crate + (dev-dependency only) over random seeds and random ciphertexts. + +**Stricter than the draft, on purpose.** Arcanum rejects an X25519 public key or ciphertext part +that is a low-order point (the X25519 result is all zeros, `was_contributory() == false`). An honest +key or ciphertext can never be such a point (it is a clamped scalar times the base point), so this +changes no honest exchange and no official vector. It removes the case where the classical half +silently contributes a known value. RustCrypto ships the same option as +`DecapsulationKeyRejectNonContrib`. + +**ML-KEM key check.** The draft requires the FIPS 203 §7.2 encapsulation key check. `ml-kem`'s +`EncapsulationKey::new` performs it; Arcanum maps its failure to `Error::InvalidPublicKey`. + +### Is `ml-kem` stable enough? + +- `ml-kem` 0.3.4 (2026-10-31) is the newest release; the 0.3 line has been out since 2026-04-28 + (0.3.0, 0.3.2, 0.3.3, 0.3.4). Source: . +- It is still 0.x, so a minor bump may break the API. The README says it implements FIPS 203 + (final) and that it **"has never been independently audited"**. Source: + . +- Judgement: stable enough for X-Wing in a household mesh where WireGuard's classical security + remains underneath (the PSK can only add security, see THREAT_MODEL.md), **not** stable enough to + be the only protection of anything. The version is locked, and an upgrade must re-run the KATs. + +### `x25519-dalek` + +`x25519-dalek` 3.0.0 (2026-07-06), the newest stable release, on `curve25519-dalek` 5.0.0. Source: +. Used with `static_secrets` and `zeroize`. + +### Key schedule (labels `domi/arcanum/v1/...`) + +The roadmap's decided combiner "hashes both shared secrets together with both ciphertexts and both +public keys". X-Wing's combiner hashes `ss_M`, `ss_X`, `ct_X` and `pk_X`, and leaves `ct_M` and +`pk_M` to ML-KEM's own binding. Arcanum adds the missing two in the key schedule, so the decided +property holds in full: + +``` +th = SHA-256("domi/arcanum/v1/transcript" || pk (1216 B) || ct (1120 B) || u32be(len ctx) || ctx) +prk = HKDF-Extract(salt = "domi/arcanum/v1/extract", ikm = ss_xwing || th) +psk(epoch) = HKDF-Expand(prk, "domi/arcanum/v1/wireguard-psk" || u64be(epoch), 32) +``` + +`pk` is the whole hybrid public key (`pk_M || pk_X`) and `ct` the whole ciphertext +(`ct_M || ct_X`), so both public keys and both ciphertexts are hashed. `ctx` is the caller's binding +(for Via: the two peers' Tessera device ids and the protocol name). Every label is versioned; a v2 +changes the labels, never reuses them. + +### WireGuard PSK and rotation + +- Rosenpass, the reference design, rotates every two minutes: `REKEY_AFTER_TIME_RESPONDER = 120 s`, + `REKEY_AFTER_TIME_INITIATOR = 130 s` (so the roles alternate), and `REJECT_AFTER_TIME = 180 s`. + Source: , + read 2026-11-25; the code comment cites WireGuard's own two-minute rekey. +- Arcanum takes no clock. It exports `RECOMMENDED_EPOCH_SECONDS = 120` and a pure helper + `epoch_at(unix_seconds) = unix_seconds / 120`; the caller passes the time. +- `Session::wireguard_psk(epoch)` is deterministic: both peers get the same PSK for the same epoch, + and successive epochs differ. **Forward secrecy between epochs needs a fresh exchange per epoch** + (as Rosenpass does). Deriving several epochs from one session is a fallback when an exchange + fails, and loses that property; Via's engine (Day 3) must run a new exchange each epoch. + +### Sealing + +``` +sealed = 0x01 || ct (1120 B) || ChaCha20-Poly1305(key, nonce, plaintext, aad = 0x01) +th, prk as above with ctx = the caller's associated data +key = HKDF-Expand(prk, "domi/arcanum/v1/seal/key", 32) +nonce = HKDF-Expand(prk, "domi/arcanum/v1/seal/nonce", 12) +``` + +Each seal uses a fresh encapsulation, so a key and nonce are never used twice. Overhead is 1137 +bytes. This is a plain documented construction, not HPKE (RFC 9180). + +### Shape of the API + +- `#![no_std]` with `alloc`, `#![forbid(unsafe_code)]`, no I/O, no clock. +- Randomness is a parameter: `&mut impl rand_core::CryptoRng` (rand_core 0.10), with `_derand` + variants that take the exact bytes (used by the known-answer tests). +- Every secret type (`SecretKey`, `SharedSecret`, `Session`, `WireGuardPsk`) is zeroised on drop and + prints as `[redacted]` in `Debug`. +- Every parser returns `Result<_, arcanum::Error>`; nothing panics on input. + +## Tests (written first) + +| # | Mandatory test | File | +|:--|:--|:--| +| 1 | KATs: ML-KEM-768 (NIST ACVP), X25519 (RFC 7748), X-Wing (draft -11) | `tests/kat_mlkem768.rs`, `tests/kat_x25519.rs`, `tests/kat_xwing.rs` | +| 2 | Both sides derive the same secret; any changed input byte changes it | `tests/exchange.rs` | +| 3 | A zeroed component secret changes the output (both halves bound) | `src/binding_tests.rs`, `tests/binding.rs` | +| 4 | PSK epochs differ and are reproducible | `tests/psk_epochs.rs` | +| 5 | Malformed input gives typed errors, never a panic; fuzz target | `tests/malformed.rs`, `fuzz/fuzz_targets/untrusted_input.rs` | +| 6 | `cargo deny`, `cargo audit` clean; no unsafe | `deny.toml`, `tests/no_unsafe.rs`, `#![forbid(unsafe_code)]` | + +Vector provenance is in `tests/vectors/SOURCES.md`. + +## Risks + +| Risk | Consequence | Mitigation | +|:--|:--|:--| +| A bug in our X-Wing glue | Peers agree on a weak secret, or interoperate with nobody | Official vectors + differential test vs RustCrypto `x-wing` | +| `ml-kem` or `x25519-dalek` bug, side channel | Weaker PQ or classical half | Hybrid: either half suffices; versions locked; `cargo audit` | +| Reusing one session for many epochs | No forward secrecy between epochs | Documented; Day 3 runs a fresh exchange per epoch | +| Unauthenticated public key (MITM) | Attacker learns the PSK | WireGuard's static keys still authenticate; Via must sign the Arcanum public key with Tessera (Day 3). See THREAT_MODEL.md | +| Randomness misuse in `_derand` functions | Reused eseed leaks the secret | `_derand` documented as test-only hazmat; normal API takes an RNG | +| Secrets left in memory | Key recovery from a memory dump | `ZeroizeOnDrop` everywhere we own the bytes; residuals listed below | +| Draft changes before RFC | Interop break with other X-Wing users | Version recorded; labels versioned; vectors pinned | + +## Gaps (known, not hidden) + +- **Not audited**, and neither are `ml-kem` nor the `x-wing` reference. +- **No authentication** in Arcanum v1. Peer public keys must be authenticated by the caller. + Post-quantum authentication (ML-DSA) is out of scope. +- **Side channels** are inherited from the crates; Arcanum adds no constant-time analysis of its own. +- **Zeroisation residuals:** HKDF/HMAC and SHA-3 internal states hold secret-derived data and are + dropped without guaranteed wiping where the crates do not offer it; values moved by the compiler + may leave copies on the stack. `zeroize` cannot promise more than that. +- **Sealing is not HPKE**, and has no sender authentication. +- **X25519 RFC 7748 1,000,000-iteration vector** is not run (minutes in a debug build); the + 1- and 1,000-iteration vectors are. +- **Fuzzing** ran on Windows MSVC with libFuzzer for the time recorded in the PR, not continuously. diff --git a/docs/THREAT_MODEL.md b/docs/THREAT_MODEL.md new file mode 100644 index 0000000..060e1d0 --- /dev/null +++ b/docs/THREAT_MODEL.md @@ -0,0 +1,55 @@ +# Arcanum threat model + +Scope: the `arcanum` crate v0.1.0 — the X-Wing hybrid KEM, the key schedule, the WireGuard PSK +derivation and the sealing helper. **Not audited.** + +## Assets + +1. The responder's hybrid secret key (a 32-byte seed). +2. Each exchange's shared secret and the `Session` derived from it. +3. Each epoch's WireGuard pre-shared key. +4. The plaintext inside a sealed box. + +## Adversaries and what Arcanum protects against + +| Adversary | Can do | Protected? | Why | +|:--|:--|:--|:--| +| **Harvest now, decrypt later** | Records every control-channel message and WireGuard packet today; gets a large quantum computer later | **Yes**, the main goal | The PSK comes from X-Wing. Shor breaks X25519, but ML-KEM-768 is believed to resist quantum attack, and X-Wing's secret is secure if either half is. WireGuard mixes the PSK into its key schedule, so recorded traffic stays confidential. | +| Classical passive eavesdropper | Records traffic, no quantum computer | Yes | Both halves hold. | +| A future break of ML-KEM (cryptanalysis or an implementation bug) | Recovers `ss_M` | Yes, classically | X25519 still protects the secret (hybrid). | +| A break of X25519 | Recovers `ss_X` | Yes | ML-KEM still protects it. | +| Active attacker who modifies ciphertexts | Flips bytes in transit | Detected or harmless | Changed `ct_M` → ML-KEM implicit rejection gives an unrelated secret; changed `ct_X` → different `ss_X`; the transcript hash binds both. The peers' PSKs differ and WireGuard simply fails to handshake. Low-order X25519 values are rejected with a typed error. | +| Malformed or hostile input | Sends wrong lengths, invalid ML-KEM keys, random bytes | No panic, typed error | Tests 5 and the fuzz target. | +| Epoch confusion | Replays an old exchange for a new epoch | Harmless | The epoch number is in every PSK derivation; an attacker who cannot decapsulate cannot compute any epoch's PSK. | + +## What Arcanum does NOT protect against + +| Not protected | Why, and who has to handle it | +|:--|:--| +| **Endpoint compromise** | Malware on a device reads keys and plaintext from memory. Zeroisation narrows the window; it does not close it. Keys at rest belong in Custos or Tessera. | +| **Traffic analysis** | Who talks to whom, when and how much is visible on the wire. Padding and cover traffic are the Stealth transport's job (Day 7), and only partly. | +| **Man in the middle on the public key** | Arcanum v1 does not authenticate. An attacker who substitutes the responder's public key learns that exchange's PSK. In Via, WireGuard's static keys still authenticate the tunnel, so the attacker gets back to classical security, not to plaintext; Via must also sign the Arcanum public key with the device's Tessera key (Day 3). Post-quantum authentication (ML-DSA) is not in v1. | +| **A quantum attacker who is also active today** | Without post-quantum authentication, an active quantum attacker could impersonate a peer in real time. v1 targets the passive harvest-now threat. | +| **Bad randomness** | The caller supplies the RNG. A broken RNG breaks every scheme. The `_derand` functions are for known-answer tests; reusing their seeds is catastrophic. | +| **Side channels** | Timing and cache behaviour are those of `ml-kem`, `x25519-dalek`, `sha3` and `chacha20poly1305`. Arcanum adds only fixed-length, data-independent glue, but has not been measured. | +| **Reusing one session for many epochs** | Supported, but a leaked session reveals every epoch's PSK derived from it. Forward secrecy needs one exchange per epoch. | +| **Denial of service** | An attacker on the path can always drop packets. | +| **Legacy peers** | Classic WireGuard peers (routers, third-party clients) get no Arcanum PSK and are labelled "not post-quantum" by Via. | + +## Trust assumptions + +- ML-KEM-768 is IND-CCA2 secure against quantum adversaries (FIPS 203). +- X25519 is a secure Diffie–Hellman group against classical adversaries (RFC 7748). +- SHA3-256, SHAKE256 and HKDF-SHA-256 behave as their standards say; X-Wing's security argument + (draft-connolly-cfrg-xwing-kem-11) holds. +- The vetted crates implement those standards correctly; the known-answer tests check the parts + Arcanum uses, not everything. +- The caller authenticates the responder's public key and supplies a cryptographically secure RNG. + +## Blast radius if Arcanum is wrong + +Via uses Arcanum only as the WireGuard PSK. A total failure of Arcanum (for example, both peers +derive a predictable PSK) reduces a Via tunnel to plain WireGuard: still authenticated and encrypted +classically, but open to harvest-now-decrypt-later. It never reduces it below WireGuard. Sealing +(Custos, Tabellarius) is different: there Arcanum is the only layer, which is why those migrations +wait for the audit.