pub struct FuzzRng { /* private fields */ }Expand description
An RNG that expands a fuzzer byte slice into an infinite deterministic stream.
§Design
FuzzRng maps a fuzzer-controlled byte slice to output blocks.
For each block counter ctr, it:
- Reads a wrapping
u64-wide window from the input bytes. - Xors in
ctrand a domain constant. - Applies a SplitMix64-style finalizer.
input bytes (len = N):
[b0 b1 b2 ... b(N-1)]
block ctr = i:
word_i bytes = [b(i+0)%N, b(i+1)%N, ... b(i+7)%N]
word_i = big-endian u64 of those bytes
out_i = mix64(word_i ^ i ^ DOMAIN)§Why this mapping
Hashing the full input once and then seeding a PRNG makes tiny input changes look globally unrelated. This adapter avoids that by using a sliding window keyed by the block counter.
byte k affects anchors:
i in [k-(BLOCK_BYTES-1), ..., k] (mod N)§Worked Example
With N = 4, input bytes repeat inside each block:
input: [a b c d]
ctr=0: word bytes [a b c d a b c d]
ctr=1: word bytes [b c d a b c d a]
ctr=2: word bytes [c d a b c d a b]
...Even for low-entropy input like [0 0 0 0], output still changes because
ctr is mixed into every block before finalization.
fill_bytes serves output from cached block bytes so callers get a stable
byte stream regardless of whether they request randomness as next_u64,
next_u32, or arbitrary byte slices.
Implementations§
Trait Implementations§
Source§impl From<Entropy> for FuzzRng
Available on neither commonware_stability_BETA nor commonware_stability_DELTA nor commonware_stability_EPSILON nor commonware_stability_GAMMA nor commonware_stability_RESERVED.
impl From<Entropy> for FuzzRng
commonware_stability_BETA nor commonware_stability_DELTA nor commonware_stability_EPSILON nor commonware_stability_GAMMA nor commonware_stability_RESERVED.Source§impl From<FuzzRng> for Box<dyn CryptoRng + Send + 'static>
Available on neither commonware_stability_BETA nor commonware_stability_DELTA nor commonware_stability_EPSILON nor commonware_stability_GAMMA nor commonware_stability_RESERVED.Boxes the rng for runtimes that take a dynamic rng (e.g. the deterministic runtime’s
Config::with_rng).
impl From<FuzzRng> for Box<dyn CryptoRng + Send + 'static>
commonware_stability_BETA nor commonware_stability_DELTA nor commonware_stability_EPSILON nor commonware_stability_GAMMA nor commonware_stability_RESERVED.Boxes the rng for runtimes that take a dynamic rng (e.g. the deterministic runtime’s
Config::with_rng).
impl TryCryptoRng for FuzzRng
commonware_stability_BETA nor commonware_stability_DELTA nor commonware_stability_EPSILON nor commonware_stability_GAMMA nor commonware_stability_RESERVED.Auto Trait Implementations§
impl Freeze for FuzzRng
impl RefUnwindSafe for FuzzRng
impl Send for FuzzRng
impl Sync for FuzzRng
impl Unpin for FuzzRng
impl UnsafeUnpin for FuzzRng
impl UnwindSafe for FuzzRng
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<R> CryptoRng for R
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<R> RngCore for Rwhere
R: Rng,
Source§impl<R> RngExt for R
impl<R> RngExt for R
Source§fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
StandardUniform distribution. Read moreSource§fn random_iter<T>(self) -> Iter<StandardUniform, Self, T> ⓘ
fn random_iter<T>(self) -> Iter<StandardUniform, Self, T> ⓘ
Source§fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
Source§fn random_bool(&mut self, p: f64) -> bool
fn random_bool(&mut self, p: f64) -> bool
p of being true. Read moreSource§fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
numerator/denominator of being
true. Read more