194 lines
11 KiB
Markdown
194 lines
11 KiB
Markdown
# 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: <https://datatracker.ietf.org/doc/draft-connolly-cfrg-xwing-kem/>.
|
|
- 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 <https://www.ietf.org/archive/id/draft-connolly-cfrg-xwing-kem-11.txt>.
|
|
- 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: <https://crates.io/api/v1/crates/ml-kem>.
|
|
- 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:
|
|
<https://github.com/RustCrypto/KEMs/blob/master/ml-kem/README.md>.
|
|
- 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:
|
|
<https://crates.io/api/v1/crates/x25519-dalek>. 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: <https://github.com/rosenpass/rosenpass/blob/main/rosenpass/src/protocol/constants.rs>,
|
|
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.
|