chat: pad plaintext to a normative length ladder
All checks were successful
ci / test (pull_request) Successful in 15m47s
ci / sdk (pull_request) Successful in 1m31s

Chat plaintext is padded inside the ratchet AEAD to one of
256/512/1024/2048/4096/8192/16384/32768 bytes, with an explicit big-endian
uint16 pad_len followed by the body and random fill. An observer sees only
the bucket; the padding is authenticated by ChaCha20-Poly1305 and by the
Noise session. The receiver trusts pad_len only, rejects an overrun before
appending or persisting anything, and never infers a boundary from trailing
bytes. fil chunks are unchanged.

docs/PROTOCOL.md gains a normative Length buckets section, THREAT_MODEL
replaces the no-padding limit, README notes the bucketed chat length.
This commit is contained in:
agent 2026-10-20 12:38:04 -04:00
commit 7fa3edcdb4
No known key found for this signature in database
8 changed files with 517 additions and 11 deletions

View file

@ -16,6 +16,7 @@ use std::sync::{Arc, Mutex};
use onionwire::Store;
use onionwire::node::{encode_chat_frame, ingest_chat_frame};
use onionwire::outbox::{BoxFut, Deliverer, Outbox, OutboxStatus};
use onionwire::padding;
use onionwire::ratchet::{HEADER_OFFSET, MAX_SKIP, RatchetState};
use onionwire::session::Keys;
@ -250,7 +251,7 @@ async fn a_snapshot_heals_only_once_the_ratchet_key_it_held_has_been_replaced()
// What the snapshot can still read: exactly the skipped key it was holding,
// once. Everything it already consumed is gone.
assert_eq!(
snapshot.decrypt(&frames[0]).unwrap(),
padding::decode(&snapshot.decrypt(&frames[0]).expect("skipped key")).unwrap(),
b"m0",
"a skipped key it legitimately holds"
);
@ -300,7 +301,7 @@ async fn a_snapshot_heals_only_once_the_ratchet_key_it_held_has_been_replaced()
// documented Double Ratchet hop, and it is why the claim below is worded
// about the epoch that requires a secret minted after the compromise.
assert_eq!(
snapshot.decrypt(&a3).unwrap(),
padding::decode(&snapshot.decrypt(&a3).expect("one hop")).unwrap(),
b"a3",
"the epoch built on the key the snapshot already held"
);