ratchet: hybrid ML-KEM steps (KDF_RK v2, 2312-byte header, state v2)

Every ratchet keypair is {x25519, ml-kem-768}. On a rotation the stepper
encapsulates to the receiver's current ratchet KEM key; both the X25519 DH
and the ML-KEM secret feed KDF_RK under the new onionwire-ratchet-v2-kdfrk
domain, so a later X25519 break does not open a chain established by a
hybrid step.

Epoch 0 stays classical by construction: the bootstrap root must be a pure
function of the two long-lived prekeys for both-send-first convergence, and
a per-session ss_kem differs for every one-shot Noise dial. The first
rotation (including the bootstrap tie-break rotation) is hybrid, so the
residual HNDL window is exactly the epoch-0 chain. docs/THREAT_MODEL.md
states that window; no full PQ forward secrecy is claimed.

Header 0x02 adds kem_pub[1184] || kem_ct[1088] to the 40-byte classical
header and is used on every frame of a hybrid chain, so a lost first frame
is harmless. A step with no KEM section is rejected (hybrid step required)
and a hybrid step at a classical friend is rejected (unexpected hybrid
step): no classical fallback.

State moves to blob v0.2: fixed 211-byte prefix plus flagged KEM fields.
A v1 blob is dropped and re-bootstrapped (hard cut, like F8); a corrupt v2
or a newer version is an error, not a silent reset.

Tests: hybrid root agreement on both sides, both-send-first convergence
with hybrid keys, no-downgrade, tampered kem_pub/kem_ct fail closed,
MAX_SKIP on a hybrid chain, classical friends still step classically,
state freeze at v0.2 and the node-level hard cut.
This commit is contained in:
rust-dev 2026-10-20 12:54:30 -04:00 • committed by agent
commit b22abd7b2b
No known key found for this signature in database
7 changed files with 1198 additions and 168 deletions

View file

@ -317,11 +317,14 @@ session carries. Wire format: [docs/PROTOCOL.md](docs/PROTOCOL.md).
removes the data dir.
- There is no `/reset`. State drops when the friend's prekey or ML-KEM key
changes (you `F3`-paste a refreshed invite).
- **The ratchet is not post-quantum.** The hybrid prelude protects the one-shot
Noise transport. The chat bootstrap epoch is still derived from the two
long-lived X25519 prekeys, so a future quantum adversary holding a recorded
`rat ` chain and both prekeys can reconstruct epoch 0. PQ ratchet steps are a
separate follow-up; see [docs/THREAT_MODEL.md](docs/THREAT_MODEL.md).
- **Ratchet steps are hybrid; epoch 0 is not.** Every rotation after the
bootstrap mixes an ML-KEM-768 secret into the chain KDF, so a later X25519
break does not open a hybrid chain. The bootstrap epoch is still derived only
from the two X25519 prekeys — a per-session KEM secret cannot be folded in
without breaking both-send-first convergence — so messages sent before the
first rotation stay X25519-only at the ratchet layer, and classical (v1)
friends have no PQ layer at all. No full post-quantum forward secrecy is
claimed; see [docs/THREAT_MODEL.md](docs/THREAT_MODEL.md).
- An inbound `rat ` frame that does not authenticate is logged as
`rat dropped (<reason>)` on stderr and dropped. There is no in-app desync banner.