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

@ -4,9 +4,13 @@ Lean Tor messenger: one Rust process (ratatui + Noise IK + sqlite + in-process A
No hosted server. Identity is an ed25519 public key; the onion is only a locator.
Current tagged release: **v0.14.0**. Linux TUI + Android SDK/APK. Two people add
each other with an `onionwire:v1:…` invite string (`F2` share / `F3` paste). There
is no invite QR graphic. Chat is Noise IK over your own v3 onion; every chat
message is ratcheted inside that session. Unreachable chat peers go to a **local
each other with an `onionwire:v2:…` invite string (`F2` share / `F3` paste;
~1.9 KB because it carries an ML-KEM-768 key). There is no invite QR graphic.
Chat is Noise IK over your own v3 onion; when the friend was added from a v2
invite the session is **hybrid** (ML-KEM-768 prelude mixed into the Noise
prologue). A friend from a legacy `onionwire:v1` invite stays classical and the
roster labels them `classical`. Every chat message is ratcheted inside that
session. Unreachable chat peers go to a **local
outbox** (device-only retry queue — no relay). File transfer and payment frames
fail closed. Optional Monero: `/pay` invoices, `/tip` payments, and in-app wallet
create/import (`F6`). Arti onion services are still experimental. The store is
@ -216,13 +220,13 @@ payload can contain `?`).
| `j` `k` / `↑` `↓` | Move or scroll the focused pane |
| `g` / `G` | Jump to top / bottom of the focused pane |
| `?` | Keybinding help (`Esc` closes) |
| `F2` | Share invite (`onionwire:v1:…`) |
| `F2` | Share invite (`onionwire:v2:…`, ~1.9 KB) |
| `F3` | Paste a friend's invite |
| `F4` | Rotate **onion** (locator only) |
| `F5` | Selected friend's profile (`/who`) |
| `F6` | Wallet (receive QR, balance, transfers, create/import) |
| `F7` | Node & wallet setup (wallet RPC endpoint, chain source, start/stop, live node state) |
| `F8` | Rotate **prekey** (hard cut: every friend re-pastes the invite) |
| `F8` | Rotate **prekey and ML-KEM key** (hard cut: every friend re-pastes the invite) |
| `F9` | Wallets & settings menu (`/settings`) |
| Enter | Send chat to the selected friend, or run a `/command` |
| `Esc` | Close overlay / back to Main / clear composer |
@ -243,10 +247,22 @@ Composer `/commands` (`src/tui.rs` `parse_cmd`): `/wipe`, `/wipe-all`, `/profile
There is no invite QR. `F2` opens the share screen with truncated fingerprint,
current onion, and the full payload (wrapped, mouse-select to copy):
`onionwire:v1:k=…:o=…:spk=…:sig=…`
`onionwire:v2:k=…:o=…:spk=…:kem=…:sig=…`
The `kem=` field is the 1184-byte ML-KEM-768 public key (base64url), so the
string is about 1.9 KB instead of a few hundred bytes; `C` copies the whole
payload even when the terminal is too short to display all of it. Decode still
accepts a legacy `onionwire:v1:…` invite (no `kem=`): that friend is added as a
**classical** peer and the roster says `classical` next to them. There is no
silent upgrade — only a new signed v2 invite changes that.
Give that string to a friend. They `F3` paste it. Unknown `k` asks for approval.
Same `k` already in the roster updates `onion` (and prekey) only.
Same `k` already in the roster updates `onion` (and prekey/KEM key) only.
No PQ for a legacy v1 peer: they have no `kem_pk`, so the session uses the old
`onionwire-v1` prologue with no ML-KEM secret. A v2 friend always sends the
prelude; a peer that omits it is hard-failed with `prelude required`. A v1-only
build cannot talk to a v2 friend, and that break is intentional.
## F4 rotate onion
@ -295,8 +311,13 @@ session carries. Wire format: [docs/PROTOCOL.md](docs/PROTOCOL.md).
stored). A queued chat message re-sends the *same* `rat ` frame.
- `/wipe` clears chat, payments and outbox but **keeps** ratchet state. `/wipe-all`
removes the data dir.
- There is no `/reset`. State drops when the friend's prekey changes (you
`F3`-paste a refreshed invite).
- 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).
- 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.