Skip to main content

RngSource

Struct RngSource 

Source
pub struct RngSource { /* private fields */ }
Expand description

BLAKE3-keyed PRNG.

RngSource consumes 32 bytes of seed material (deterministic mode via from_seed) or OS entropy (os-entropy feature, from_os_entropy) and produces a monotonic byte stream via BLAKE3’s eXtendable Output Function.

§Drop semantics

On drop, seed is zeroized via Zeroizing<[u8; 32]>. The internal XOF state is replaced with a sentinel zero-keyed reader; the discarded reader drops normally — allocator-dependent behavior, not internal-state wipe (blake3 does not expose that surface). Best-effort defense-in-depth.

§Debug redaction

Debug prints RngSource { .. } only — seed bytes and XOF state are never exposed.

Implementations§

Source§

impl RngSource

Source

pub fn from_seed(seed: &[u8; 32]) -> Self

Construct a deterministic RngSource from a 32-byte seed.

Stream is produced via BLAKE3 KDF mode: Hasher::new_derive_key(KDF_CONTEXT).update(seed).finalize_xof(). Two RngSource instances built from the same seed produce byte-identical streams across all targets.

Callers holding seed material in a non-Zeroizing buffer should wrap it themselves — this constructor only zeroizes the internal copy, not the caller’s source bytes.

Source

pub fn from_os_entropy() -> Result<Self, RngError>

Construct an RngSource from OS entropy (getrandom).

Returns Err(RngError::OsEntropyUnavailable) when the OS CSPRNG is unreachable (kernel pre-init / WASM without crypto interface). Never panics.

Source

pub fn split(&mut self) -> Self

Derive an independent child RngSource from this stream.

32 bytes are consumed from the parent XOF stream and used as the child seed. Parent and child streams are independent — consuming one does not advance the other, and both remain deterministic given the original seed. Typical use: server / table / hand 3-level split for multiplayer deal isolation.

Source

pub fn fill_bytes(&mut self, buf: &mut [u8])

Fill buf with buf.len() bytes from the XOF stream.

Stream advance is monotonic — each call advances exactly buf.len() bytes (entropy accounting). Timing is bounded by buf.len() only; no input-dependent timing leak.

Trait Implementations§

Source§

impl Debug for RngSource

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for RngSource

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.