fuzz: pass the 4th bootstrap arg (hybrid ML-KEM peer key)
RatchetState::bootstrap gained remote_kem_pub in b22abd7 (PR #185), so the
fuzz target has not compiled since 2026-10-20 and the nightly fuzz job has
been red for ten days.
Pass None for the classical shape and a real ML-KEM-768 encapsulation key
(crate::kem::PK_LEN bytes, built once from a fixed 64-byte seed) for the
hybrid shape, so both bootstrap paths are fuzzed. The invariants are
unchanged: arbitrary bytes never panic, a parsed state re-serializes, and a
rejected frame rolls back to the exact pre-decrypt state.
This commit is contained in:
parent
20d2d00e4d
commit
9d93fb5cfa
1 changed files with 43 additions and 11 deletions
|
|
@ -10,26 +10,45 @@
|
|||
//! Neither call may panic, and neither may leave the state mutated on a frame
|
||||
//! it rejects (asserted in `tests/ratchet.rs`, re-checked cheaply here by
|
||||
//! re-serializing after every decrypt).
|
||||
//!
|
||||
//! Both bootstrap shapes are exercised: a classical friend (`remote_kem_pub =
|
||||
//! None`) and a hybrid friend, whose peer ML-KEM ratchet key is a real
|
||||
//! encapsulation key of `kem::PK_LEN` bytes derived from a fixed seed. A
|
||||
//! garbage key would only ever hit the "invalid encapsulation key" error path.
|
||||
#![no_main]
|
||||
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
use onionwire::kem::{self, PK_LEN, SEED_LEN};
|
||||
use onionwire::ratchet::{RatchetKeyPair, RatchetState};
|
||||
use std::sync::OnceLock;
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
// Restore path: arbitrary bytes as a persisted ratchet state.
|
||||
if let Ok(state) = RatchetState::from_bytes(data) {
|
||||
// A state that parsed must re-serialize without panicking.
|
||||
let _ = state.to_bytes();
|
||||
}
|
||||
/// A canonical ML-KEM-768 encapsulation key, built once: key generation is
|
||||
/// deterministic for a fixed seed, so this only pays for itself on iteration 1.
|
||||
fn peer_kem_pub() -> &'static [u8] {
|
||||
static PK: OnceLock<Vec<u8>> = OnceLock::new();
|
||||
PK.get_or_init(|| {
|
||||
let pk = kem::pk_from_seed(&[0x44u8; SEED_LEN]).expect("64 bytes is a valid ML-KEM seed");
|
||||
assert_eq!(pk.len(), PK_LEN, "crate ML-KEM public key length changed");
|
||||
pk
|
||||
})
|
||||
}
|
||||
|
||||
// Wire path: a fresh bootstrap epoch for every input, so one iteration can
|
||||
// never influence the next. The keys are fixed (not fuzzed) on purpose:
|
||||
// the interesting surface is `data` as the frame.
|
||||
let mut state = RatchetState::bootstrap(
|
||||
fn bootstrap(remote_kem_pub: Option<&[u8]>) -> RatchetState {
|
||||
// The keys are fixed (not fuzzed) on purpose: the interesting surface is
|
||||
// `data` as the frame.
|
||||
RatchetState::bootstrap(
|
||||
[0x42u8; 32],
|
||||
RatchetKeyPair::from_secret([0x11u8; 32]),
|
||||
[0x33u8; 32],
|
||||
);
|
||||
remote_kem_pub,
|
||||
)
|
||||
}
|
||||
|
||||
/// Feed `data` to a fresh state and hold the existing invariants: a reject must
|
||||
/// roll back, an accept must have advanced the receiving chain, and re-sending
|
||||
/// from the resulting state must not panic.
|
||||
fn exercise(remote_kem_pub: Option<&[u8]>, data: &[u8]) {
|
||||
let mut state = bootstrap(remote_kem_pub);
|
||||
let before = state.to_bytes();
|
||||
|
||||
match state.decrypt(data) {
|
||||
|
|
@ -45,4 +64,17 @@ fuzz_target!(|data: &[u8]| {
|
|||
|
||||
// Re-encrypting a byte-identical state must stay a pure function.
|
||||
let _ = state.encrypt(b"fuzz");
|
||||
}
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
// Restore path: arbitrary bytes as a persisted ratchet state.
|
||||
if let Ok(state) = RatchetState::from_bytes(data) {
|
||||
// A state that parsed must re-serialize without panicking.
|
||||
let _ = state.to_bytes();
|
||||
}
|
||||
|
||||
// Wire path: a fresh bootstrap epoch for every input, so one iteration can
|
||||
// never influence the next. Classical and hybrid, both.
|
||||
exercise(None, data);
|
||||
exercise(Some(peer_kem_pub()), data);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue