Skip to main content

ReseedingRng

Struct ReseedingRng 

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

A OxiRng wrapper that automatically reseeds from OS entropy after generating a configurable number of bytes (default: 1 MiB).

This implements a forward-secrecy interval consistent with NIST SP 800-90A §9.2 recommendations. After each reseed the internal byte counter resets.

§Observability

Use ReseedingRng::bytes_generated to inspect how many bytes have been produced since the last reseed.

Implementations§

Source§

impl ReseedingRng

Source

pub fn new() -> Result<Self, CryptoError>

Create a new ReseedingRng with the default 1 MiB reseed threshold.

Source

pub fn with_threshold(threshold: u64) -> Result<Self, CryptoError>

Create a new ReseedingRng with a custom reseed threshold (bytes).

A threshold of 0 would reseed on every call — technically valid but very slow. Reasonable values are 64 KiB to 64 MiB.

Source

pub fn bytes_generated(&self) -> u64

Number of bytes generated since the last reseed.

Source

pub fn reseed_threshold(&self) -> u64

Configured reseed threshold in bytes.

Source

pub fn reseed(&mut self) -> Result<(), CryptoError>

Reseed immediately from OS entropy, regardless of the threshold.

Trait Implementations§

Source§

impl Debug for ReseedingRng

Source§

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

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

impl Rng for ReseedingRng

Source§

fn fill(&mut self, dst: &mut [u8]) -> Result<(), CryptoError>

Fill dst with cryptographically secure random bytes.
Source§

impl TryRng for ReseedingRng

Source§

type Error = CryptoError

The type returned in the event of a RNG error. Read more
Source§

fn try_next_u32(&mut self) -> Result<u32, Self::Error>

Return the next random u32.
Source§

fn try_next_u64(&mut self) -> Result<u64, Self::Error>

Return the next random u64.
Source§

fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Self::Error>

Fill dst entirely with random data.
Source§

impl TryCryptoRng for ReseedingRng

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<R> TryRngCore for R
where R: TryRng,

Source§

type Error = <R as TryRng>::Error

👎Deprecated since 0.10.0:

use TryRng instead

Error type.
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,