17 KiB
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 exactly as drafted | draft-connolly-cfrg-xwing-kem-11, FIPS 203, RFC 7748 |
exchange |
A mutual exchange: each peer encapsulates to the other's public key; both get a Session bound to both secrets, 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, hmac 0.13.0, sha2 0.11.1 |
key schedule | |
| ChaCha20-Poly1305 | chacha20poly1305 (RustCrypto) |
0.11.0 | sealing |
| Zeroisation | zeroize |
1.9.2 | every secret type is ZeroizeOnDrop |
Exact versions are pinned by Cargo.lock, which is committed. ml-kem and x25519-dalek are
pinned with = in Cargo.toml as well, so an upgrade is a deliberate edit that re-runs the KATs.
The hybrid KEM: X-Wing, draft -11 (decision D-QA-1)
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 CFRG-adopted. 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). Source: Appendix G of https://www.ietf.org/archive/id/draft-connolly-cfrg-xwing-kem-11.txt.
- Appendix C has three vectors and still carries the note "TODO: replace with test vectors that
re-use ML-KEM, X25519 values", so later drafts may change the vectors. Arcanum pins the vector
file by sha256 together with the draft number (
tests/vectors/SOURCES.md); a changed file fails the KAT, and moving to a new draft is a deliberate decision. - RustCrypto's
x-wing0.1.1 (2026-10-01) describes itself as draft 06; its vectors are the same three as draft -11 (identical after removing whitespace).
Decision D-QA-1 (recommended by QA, adopted). Mark's spec asks for a combiner that hashes both
shared secrets, both ciphertexts and both public keys, "X-Wing-style … use it if it fits". X-Wing's
combiner hashes ss_M, ss_X, ct_X and pk_X and deliberately leaves ct_M and pk_M to
ML-KEM's own binding (draft -11 §5.3). So:
- The KEM is X-Wing, unmodified, so the draft's vectors pass byte for byte:
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 || "\.//^\") - Both public keys and both ciphertexts are bound in Arcanum's own key schedule, where the
domi/arcanum/v1/...labels live (below). That meets the spec in full, and the spec's own "use it if it fits" condition holds.
Arcanum composes X-Wing from ml-kem, x25519-dalek, sha3 and shake rather than calling the
x-wing crate, because mandatory test 3 needs the combiner as a separate function and because
Arcanum wants typed errors for every malformed input. The composition is about twenty lines of
glue between vetted primitives. It is pinned by the draft's three vectors and by a differential
test against RustCrypto x-wing (a 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 (was_contributory() == false, a constant-time check in x25519-dalek).
An honest key or ciphertext is never such a point, so this changes no honest exchange and no
official vector; it removes the case where the classical half silently contributes a known value
(QA A-16, A-17). 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, and the NIST ACVP encapsulationKeyCheck vectors check that.
X25519 clamping. Five bits of the 32-byte X25519 ephemeral scalar (bits 0–2 of the first byte,
bits 6–7 of the last) are clamped by RFC 7748, so changing only those bits of eseed[32:64] does
not change the exchange. That is the standard's behaviour, not a binding gap; the byte-flip test
flips bit 4 of each byte.
Is ml-kem stable enough?
ml-kem0.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 depends onrand_core0.10 (read from itsCargo.toml).- It is still 0.x, so a minor bump may break the API. Its 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.
- Correction to a QA fact (F10): in 0.3.4,
EncapsulationKey::encapsulate_deterministicis public whether or not thehazmatfeature is on;hazmatonly un-hides it in the docs (#[cfg_attr(not(feature = "hazmat"), doc(hidden))],src/encapsulation_key.rs). Soml-kem's feature gives no protection; Arcanum's ownhazmatfeature (below) is what gates the deterministic paths for Domi code. - 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 pinned; an upgrade re-runs the KATs.
x25519-dalek
x25519-dalek 3.0.0 (2026-07-06), the newest stable release, on curve25519-dalek 5.0.0, with
SharedSecret::was_contributory(). Source: https://crates.io/api/v1/crates/x25519-dalek and the
crate source. Used with static_secrets and zeroize.
The exchange is mutual (decision on QA A-15)
A PSK from a single encapsulation authenticates only the receiver: anyone who knows the responder's public key can encapsulate to it. Today WireGuard's static X25519 keys authenticate the peers, but a quantum attacker can recover those from the public keys, and then a one-way PSK is the only thing left — and the attacker could impersonate the initiator and choose it.
Chosen: both directions. The initiator encapsulates to the responder (ct_IR), the responder
encapsulates back to the initiator (ct_RI), and the session is derived from both secrets and the
whole transcript. Whoever lacks either secret key cannot compute the PSK. This is the design
Rosenpass uses for the same reason. API:
let init = exchange::initiate(&my_sk, &peer_pk, context, rng)?; // send init.ciphertext()
let (ct_ri, session) = exchange::respond(&my_sk, &peer_pk, &ct_ir, context, rng)?; // send ct_ri
let session = init.finish(&ct_ri)?;
What Day 3 must still do (recorded here and in THREAT_MODEL.md):
- Authenticate the public keys. Mutual KEM authentication is only as good as each side's copy of the other's hybrid public key. Via distributes them signed with Tessera. If Tessera's signatures are classical (Ed25519), a quantum attacker who can forge them can substitute keys. That is the gap ML-DSA closes later.
- Forward secrecy against key theft. With static key pairs, someone who later steals both secret keys and has recorded the exchanges can recompute every PSK. Day 3 should add an ephemeral key pair per exchange (Rosenpass does), or rotate the key pairs.
- One exchange per epoch, every 120 s (below).
- Replay and rollback protection (QA A-13). Arcanum is pure and keeps no epoch state, so
refusing an old epoch or an old exchange is the caller's job. Arcanum does not wrap epochs: the
caller passes a
u64, andepoch_atis a division (QA A-12 becomes a Day 3 test).
Key schedule (labels domi/arcanum/v1/...)
exchange: th = SHA-256("domi/arcanum/v1/transcript/exchange"
|| pk_I (1216) || pk_R (1216) || ct_IR (1120) || ct_RI (1120)
|| u64be(len ctx) || ctx)
prk = HKDF-Extract(salt = "domi/arcanum/v1/extract", ikm = ss_IR || ss_RI || th)
psk(epoch) = HKDF-Expand(prk, "domi/arcanum/v1/wireguard-psk" || u64be(epoch), 32)
seal: th = SHA-256("domi/arcanum/v1/transcript/seal" || pk (1216) || ct (1120)
|| u64be(len aad) || aad)
prk = HKDF-Extract(salt = "domi/arcanum/v1/extract", ikm = ss || th)
key = HKDF-Expand(prk, "domi/arcanum/v1/seal/key", 32)
nonce = HKDF-Expand(prk, "domi/arcanum/v1/seal/nonce", 12)
pk_*are whole hybrid public keys (pk_M || pk_X) andct_*whole ciphertexts (ct_M || ct_X), so both public keys and both ciphertexts of each direction are hashed.- Roles are bound by position (initiator first), so a reflected exchange gives a different PSK (QA A-14).
- Every field before the context is fixed-width and the context is length-prefixed, so the encoding is injective (QA A-08). Labels are unique, versioned and prefix-free (QA A-07, a unit test). The epoch is a full 64-bit big-endian value (QA A-11).
ctxis the caller's binding (for Via: both Tessera device ids, the protocol name, the version).- A v2 changes the labels and never reuses these. The v1 outputs are frozen by golden vectors
(
tests/golden_v1.rs, QA A-10, A-38), so a "harmless" relabel fails loudly instead of making every stored Custos blob unopenable.
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), andREJECT_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. The Go port (cunicu.li/go-rosenpass) uses the same 120 s / +10 s / 3 min. - Arcanum takes no clock. It exports
RECOMMENDED_EPOCH_SECONDS = 120and a pure helperepoch_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. Deriving several epochs from one session is a fallback when an exchange fails.
Sealing
sealed = 0x01 || ct (1120 B) || ChaCha20-Poly1305 ciphertext || tag (16 B), AEAD associated
data = the version byte, key and nonce from the schedule above. Each seal uses a fresh
encapsulation, so a key and nonce are never used twice. Overhead is 1137 bytes. Anyone who knows
the recipient's public key can seal: there is no sender authentication, and ChaCha20-Poly1305 is
not key-committing, so Custos must not read a successful open as proof of who sealed it
(QA A-27). The output buffer is allocated once at its final size, so no buffer that held
plaintext is reallocated and freed unwiped (QA A-29). This is a documented construction, not HPKE
(RFC 9180).
Shape of the API
#![no_std]withalloc,#![forbid(unsafe_code)], no I/O, no clock, no OS RNG in the normal dependency graph (checked bytests/feature_hygiene.rs).- Randomness is a parameter:
&mut R where R: rand_core::CryptoRng(rand_core 0.10). - The
hazmatfeature exposes the deterministic entry points (SecretKey::from_seed,PublicKey::encapsulate_derand,exchange::{initiate,respond}_derand,seal::seal_derand) used by the known-answer tests. It is off by default. The tests turn it on through a self-dev-dependency, which never reaches a normal build;tests/feature_hygiene.rsasserts that neitherarcanum/hazmatnorml-kem/hazmatis in the normal-edge feature graph, and proves the check can see the feature when it is on (QA A-34, A-35). Via and via-core must run the same check. - Every secret type (
SecretKey,SharedSecret,Session,Initiation,WireGuardPsk) is zeroised on drop, is notCopy, has noPartialEq, and prints as[redacted]inDebug. - Every parser returns
Result<_, arcanum::Error>; errors carry only lengths and variants.
Tests (written first)
| # | Mandatory test | File |
|---|---|---|
| 1 | KATs: ML-KEM-768 (NIST ACVP), X25519 (RFC 7748), X-Wing (draft -11) + differential vs x-wing |
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)] |
Also: tests/golden_v1.rs (frozen v1 outputs), tests/feature_hygiene.rs (no hazmat, no OS RNG
in the release graph). Vector provenance is in tests/vectors/SOURCES.md. QA's attack plan
(F:\Akce\Via\qa\01_arcanum_attacks.md) is mapped case by case in the PR's self-review.
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 pinned; cargo audit |
| Reusing one session for many epochs | No forward secrecy between epochs | Documented; Day 3 runs a fresh exchange per epoch |
| Substituted public key (MITM) | Attacker learns the PSK | Mutual exchange; Via must authenticate both hybrid public keys (Tessera); PQ signatures later. See THREAT_MODEL.md |
| Static key theft later | Recorded exchanges recomputable | Day 3 adds ephemeral keys or rotates key pairs |
| Deterministic API reaching production | Predictable PSKs | hazmat off by default; feature-graph test; consumers repeat it |
| 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 | Draft number and vector sha256 pinned; labels versioned |
| A relabel or re-encoding | Stored sealed blobs unopenable; peers disagree | Golden v1 vectors |
Gaps (known, not hidden)
- Not audited, and neither are
ml-kemnor thex-wingreference. - No post-quantum authentication of public keys. The mutual exchange authenticates whoever holds the secret keys matching the public keys each side was given; getting the right public keys is the caller's job, and ML-DSA is out of scope.
- No forward secrecy against later theft of static secret keys within Arcanum itself.
- Side channels are inherited from the crates; Arcanum adds no constant-time analysis of its own (QA A-32, a dudect run, is not done).
- Zeroisation residuals: HKDF/HMAC and SHA-3 internal states are wiped only as far as those
crates'
zeroizefeatures go; values moved by the compiler may leave copies on the stack;PublicKeycopies are not secret. QA A-29's allocator probe is not built. - 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.
- FIPS 203 itself was not read from the NIST PDF; the ML-KEM facts rest on the ACVP vectors,
the draft's references and the
ml-kemsource. - Fuzzing ran on Windows MSVC with libFuzzer for the time recorded in the PR, not continuously.