feat: add ratchet, streaming, SU3 reseed, and router floodfill
check / check (windows-latest) (push) Failing after 27s
check / check (ubuntu-latest) (push) Failing after 29s
check / check (macos-latest) (push) Failing after 27s

- Add ratchet/ with ECIES-X25519-AEAD-Ratchet (Proposal 144), Garlic cloves, and ECIES DatabaseLookup replies
- Add streaming/ with Ed25519-signed I2P Streaming (SYN/ACK/NACK/CLOSE/RESET, retransmit, window) and Repliable/Raw Datagrams
- Add common/su3.mbt to parse and verify reseed .su3 bundles
- Add Elligator2 encoding in crypto/ and OfflineSignature support in LeaseSet2 (flags bit 0)
- Router: NTCP2 peer pool, floodfill NetDB crawl, transit tunnel relay, and Garlic/Streaming bridge
- cmd/router: add --peer-dir, --su3, --reseed, --floodfill, --no-clock-skew
- cmd/client: add --dest for persistent destination keys
- Mark Phase 6 complete in README and document the transport scope (NTCP2 only, no SSU2)
This commit is contained in:
nandi committed 2026-11-27 22:23:46 -08:00
1 parent 8eafa11b22
commit ae72b00323
54 files changed
+9607 -704

No files matched your search

+81
View File
@@ -331,12 +331,89 @@ pub fn Ntcp2Handshake::set_ephemeral(
self.local_ephemeral = Some(ephemeral)
}
///|
/// Validates that `peer_ts` is within `max_skew_sec` of `now_sec`.
pub fn validate_clock_skew(
peer_ts : UInt32,
now_sec : UInt32,
max_skew_sec~ : UInt32 = 60U,
) -> Unit raise Ntcp2Error {
let diff = if peer_ts >= now_sec {
peer_ts - now_sec
} else {
now_sec - peer_ts
}
if diff > max_skew_sec {
raise ClockSkew(peer_ts, now_sec)
}
}
///|
/// Bounded replay cache for incoming NTCP2 ephemeral X keys (`X` de-obfuscated in Msg 1).
pub struct EphemeralReplayCache {
entries : Array[(Bytes, UInt32)]
max_entries : Int32
}
///|
pub fn EphemeralReplayCache::new(
max_entries~ : Int32 = 2048,
) -> EphemeralReplayCache {
{ entries: [], max_entries, }
}
///|
/// Returns `true` if `ephem_x` has not been seen within `window_sec` and records it,
/// or `false` if a replay was detected.
pub fn EphemeralReplayCache::check_and_insert(
self : EphemeralReplayCache,
ephem_x : Bytes,
now_sec : UInt32,
window_sec~ : UInt32 = 120U,
) -> Bool {
let mut i = 0
while i < self.entries.length() {
if now_sec > self.entries[i].1 + window_sec {
let _ = self.entries.remove(i)
} else {
if @crypto.ct_eq(self.entries[i].0, ephem_x) {
return false
}
i += 1
}
}
if self.entries.length() >= self.max_entries {
let _ = self.entries.remove(0)
}
self.entries.push((ephem_x, now_sec))
true
}
///|
/// Like `check_and_insert`, raising `Ntcp2Error::ReplayDetected` on replay.
pub fn EphemeralReplayCache::check_or_raise(
self : EphemeralReplayCache,
ephem_x : Bytes,
now_sec : UInt32,
window_sec~ : UInt32 = 120U,
) -> Unit raise Ntcp2Error {
if !self.check_and_insert(ephem_x, now_sec, window_sec~) {
raise ReplayDetected
}
}
///|
/// Returns the advertised Msg 3 Part 2 ciphertext length (including 16-byte MAC).
pub fn Ntcp2Handshake::m3p2_len(self : Ntcp2Handshake) -> Int32 {
self.m3p2_len
}
///|
/// Returns the decoded remote ephemeral X25519 key (after Msg 1 / Msg 2 head).
pub fn Ntcp2Handshake::remote_ephemeral(self : Ntcp2Handshake) -> Bytes? {
self.remote_ephemeral
}
///|
/// Initiator: writes Message 1 (SessionRequest).
/// Returns `X_obf (32B) || AEAD(options_16B) (32B) || cleartext_padding`.
@@ -404,6 +481,7 @@ pub fn Ntcp2Handshake::write_session_request(
pub fn Ntcp2Handshake::read_session_request_head(
self : Ntcp2Handshake,
head64 : Bytes,
expected_network_id~ : Byte = b'\x02',
) -> SessionRequestOptions raise Ntcp2Error {
if self.initiator || self.step != 0 {
raise InvalidState(
@@ -439,6 +517,9 @@ pub fn Ntcp2Handshake::read_session_request_head(
e => raise Noise(e)
}
let opts = SessionRequestOptions::decode(opts_bytes)
if opts.network_id != expected_network_id {
raise InvalidNetworkId(opts.network_id)
}
if opts.version != b'\x02' {
raise InvalidFormat("unsupported NTCP2 version: \{opts.version.to_int()}")
}