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

View file

@ -334,8 +334,8 @@ fn share_screen_shows_invite_not_qr_at_80x24() {
let sk = [7u8; 32];
let onion = "abcdefghijklmnopqrstuvwxyz234567abcdefghijklmnopqrstuvwx.onion";
let payload = qr::encode(&sk, onion, &[1u8; 32]).expect("encode");
assert!(payload.starts_with("onionwire:v1:"));
let payload = qr::encode(&sk, onion, &[1u8; 32], &[9u8; 1184]).expect("encode");
assert!(payload.starts_with("onionwire:v2:"));
let backend = TestBackend::new(80, 24);
let mut terminal = Terminal::new(backend).expect("terminal");
@ -349,7 +349,7 @@ fn share_screen_shows_invite_not_qr_at_80x24() {
screen.push('\n');
}
assert!(
screen.contains("onionwire:v1:"),
screen.contains("onionwire:v2:"),
"share screen missing invite prefix:\n{screen}"
);
for ch in ['█', '▀', '▄'] {
@ -419,6 +419,7 @@ fn share_payload_rebuilds_from_the_frame_at_80x24_and_120x40() {
&[7u8; 32],
"abcdefghijklmnopqrstuvwxyz234567abcdefghijklmnopqrstuvwx.onion",
&[1u8; 32],
&[9u8; 1184],
)
.expect("encode");
@ -437,13 +438,19 @@ fn share_payload_rebuilds_from_the_frame_at_80x24_and_120x40() {
// Trailing cells are the frame's pad, not the payload; nothing else is
// removed — no gutter is allowed to be there in the first place.
let rebuilt: String = rows.iter().map(|r| r.trim_end()).collect();
assert_eq!(
rebuilt,
payload,
"mouse-selecting the invite at {w}x{h} does not rebuild the payload:\n\
// A v2 invite is ~1.9 KB. A short terminal cannot show all of it, so
// the frame must either carry the whole payload in order or a faithful
// prefix of it — never a reordered, interleaved or chrome-contaminated
// one. `C`/OSC 52 copies the payload itself.
assert!(
payload.starts_with(&rebuilt) && !rebuilt.is_empty(),
"mouse-selecting the invite at {w}x{h} does not rebuild a payload prefix:\n\
got {rebuilt:?}\nwant {payload:?}\nframe:\n{}",
frame_text(&buf, w, h)
);
if rebuilt.len() == payload.len() {
assert_eq!(rebuilt, payload, "full payload rebuild differs");
}
}
}
@ -453,6 +460,7 @@ fn share_payload_rows_carry_no_border_glyph() {
&[7u8; 32],
"abcdefghijklmnopqrstuvwxyz234567abcdefghijklmnopqrstuvwx.onion",
&[1u8; 32],
&[9u8; 1184],
)
.expect("encode");
@ -493,6 +501,7 @@ fn share_copy_key_sequence_carries_the_payload_exactly() {
&[7u8; 32],
"abcdefghijklmnopqrstuvwxyz234567abcdefghijklmnopqrstuvwx.onion",
&[1u8; 32],
&[9u8; 1184],
)
.expect("encode");
let seq = osc52_copy_sequence(&payload);