diff --git a/neqo-crypto/src/p11.rs b/neqo-crypto/src/p11.rs index a3161ba196..c235bb869c 100644 --- a/neqo-crypto/src/p11.rs +++ b/neqo-crypto/src/p11.rs @@ -295,23 +295,27 @@ thread_local! { static CURRENT_VALUE: std::cell::Cell = const { std::cell::Cell::new(0) }; } -/// Fill a buffer with randomness. (Unless compiled with the `disable-random` feature, in which case -/// it fills the buffer with a predictable sequence of bytes.) +#[cfg(feature = "disable-random")] +/// Fill a buffer with a predictable sequence of bytes. +pub fn randomize>(mut buf: B) -> B { + let m_buf = buf.as_mut(); + for v in m_buf.iter_mut() { + *v = CURRENT_VALUE.get(); + CURRENT_VALUE.set(v.wrapping_add(1)); + } + buf +} + +/// Fill a buffer with randomness. /// /// # Panics /// /// When `size` is too large or NSS fails. +#[cfg(not(feature = "disable-random"))] pub fn randomize>(mut buf: B) -> B { let m_buf = buf.as_mut(); - if cfg!(feature = "disable-random") { - for v in m_buf.iter_mut() { - *v = CURRENT_VALUE.get(); - CURRENT_VALUE.set(v.wrapping_add(1)); - } - } else { - let len = std::os::raw::c_int::try_from(m_buf.len()).unwrap(); - secstatus_to_res(unsafe { PK11_GenerateRandom(m_buf.as_mut_ptr(), len) }).unwrap(); - } + let len = std::os::raw::c_int::try_from(m_buf.len()).unwrap(); + secstatus_to_res(unsafe { PK11_GenerateRandom(m_buf.as_mut_ptr(), len) }).unwrap(); buf } diff --git a/neqo-transport/src/connection/mod.rs b/neqo-transport/src/connection/mod.rs index 2cbd8eeaad..65347ef57b 100644 --- a/neqo-transport/src/connection/mod.rs +++ b/neqo-transport/src/connection/mod.rs @@ -1515,7 +1515,7 @@ impl Connection { } else { "client_initial" }; - neqo_common::write_item_to_fuzzing_corpus(target, &payload); + neqo_common::write_item_to_fuzzing_corpus(target, &payload[..]); } qlog::packet_received(&mut self.qlog, &packet, &payload);