transport: ML-KEM-768 hybrid prelude and onionwire:v2 invites
All checks were successful
ci / test (pull_request) Successful in 18m32s
android-ci / android (pull_request) Successful in 20m14s
ci / sdk (pull_request) Successful in 3m11s

Adds an ML-KEM-768 install key beside the ed25519 identity and x25519
prekey. A friend added from a v2 invite always gets a version-2 PQ
prelude before Noise msg 1, and both sides bind (ct, ss_kem) into the
Noise prologue (onionwire-v2 \0 ct \0 ss_kem). The row decides: a
kem_pk friend without a prelude is rejected with 'prelude required',
a prelude for a classical row with 'unexpected prelude'.

Invites are now onionwire:v2 with kem=<base64url pk>; decode still
accepts v1 (no kem) and yields a classical friend. F8 rotates the
KEM key with the prekey and hard-cuts stored ratchet state. The TUI
labels a legacy friend 'classical'.

Docs: PROTOCOL (keys, framing, prologues, no-downgrade, invite v2),
THREAT_MODEL (what PQ transport does and does not buy; epoch 0 stays
classical), README (invite size, F8, legacy caveat). SDK exposes pq on
InviteInfo/FriendInfo and gains a v2 decode round-trip test.
This commit is contained in:
agent 2026-10-20 11:15:46 -04:00
commit c741b660e4
No known key found for this signature in database
26 changed files with 1637 additions and 177 deletions

20
tests/kem.rs Normal file
View file

@ -0,0 +1,20 @@
//! ML-KEM-768 encaps/decaps through the byte encode/decode the invite and the
//! prelude actually use.
use onionwire::kem;
#[test]
fn kem_encaps_decaps_round_trip_through_encode_decode() {
let kp = kem::generate();
let pk = kem::encode_pk(&kp.pk).expect("encode pk");
let pk2 = kem::decode_pk(&pk).expect("decode pk");
assert_eq!(pk2.len(), kem::PK_LEN);
let (ct, ss_send) = kem::encapsulate(&pk2).expect("encapsulate");
let ct_bytes = kem::encode_ct(&ct).expect("encode ct");
let ct2 = kem::decode_ct(&ct_bytes).expect("decode ct");
let ss_recv = kem::decapsulate(&kp.seed[..], &ct2).expect("decapsulate");
assert_eq!(ss_send, ss_recv);
assert_eq!(ss_send.len(), kem::SS_LEN);
assert_eq!(ct2.len(), kem::CT_LEN);
}