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
impl RngSource
Sourcepub fn from_seed(seed: &[u8; 32]) -> Self
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.
Sourcepub fn from_os_entropy() -> Result<Self, RngError>
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.
Sourcepub fn split(&mut self) -> Self
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.
Sourcepub fn fill_bytes(&mut self, buf: &mut [u8])
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.