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

@ -229,7 +229,7 @@ fn dump_spec_frames() {
fn sample_invite() -> String {
let sk = [7u8; 32];
qr::encode(&sk, ONION, &[1u8; 32]).expect("encode")
qr::encode(&sk, ONION, &[1u8; 32], &[9u8; 1184]).expect("encode")
}
fn invite_line_ok(line: &str) -> bool {
@ -240,7 +240,17 @@ fn invite_line_ok(line: &str) -> bool {
|| t.starts_with("o=")
|| t.starts_with("spk=")
|| t.starts_with("sig=")
|| t.starts_with("kem=")
|| t.chars().all(|c| c.is_ascii_hexdigit())
// Continuation chunks of the long base64url `kem=` field (1579 chars,
// so it must be split even though there is no internal delimiter).
|| {
let body = t.trim_end_matches(':');
!body.is_empty()
&& body
.chars()
.all(|c| c.is_ascii_alphanumeric() || matches!(c, '-' | '_'))
}
}
#[test]
@ -286,11 +296,12 @@ fn wrap_invite_breaks_on_field_boundaries() {
);
}
assert!(
wrapped.contains("onionwire:v1:"),
wrapped.contains("onionwire:v2:"),
"lost invite prefix:\n{wrapped}"
);
assert!(wrapped.contains("k="), "lost k= field:\n{wrapped}");
assert!(wrapped.contains("spk="), "lost spk= field:\n{wrapped}");
assert!(wrapped.contains("kem="), "lost kem= field:\n{wrapped}");
let joined: String = wrapped.lines().map(str::trim).collect();
assert_eq!(
joined, invite,
@ -306,7 +317,7 @@ fn draw_share_invite_does_not_wrap_mid_token() {
terminal.draw(|f| draw_share(f, &invite)).expect("draw");
let screen = screen_from(terminal.backend().buffer(), 80, 24);
assert!(
screen.contains("onionwire:v1:"),
screen.contains("onionwire:v2:"),
"missing prefix:\n{screen}"
);
for raw in screen.lines() {
@ -317,7 +328,15 @@ fn draw_share_invite_does_not_wrap_mid_token() {
|| inner.starts_with("o=")
|| inner.starts_with("spk=")
|| inner.starts_with("sig=")
|| inner.starts_with("kem=")
|| inner.chars().all(|c| c.is_ascii_hexdigit())
|| {
let body = inner.trim_end_matches(':');
!body.is_empty()
&& body
.chars()
.all(|c| c.is_ascii_alphanumeric() || matches!(c, '-' | '_'))
}
{
assert!(
invite_line_ok(inner),
@ -782,6 +801,7 @@ async fn renders_a_queued_row_from_a_real_outbox_send() {
_pinned_id: &'a [u8],
_prekey: &'a [u8],
_plaintext: &'a [u8],
_remote_kem: Option<&'a [u8]>,
) -> BoxFut<'a, Result<(), String>> {
Box::pin(async { Err("connect dead.onion:80: timed out".to_string()) })
}