Skip to main content

EntropyPool

Struct EntropyPool 

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

Thread-safe multi-source entropy pool.

Implementations§

Source§

impl EntropyPool

Source

pub fn new(seed: Option<&[u8]>) -> Self

Create an empty pool.

Source

pub fn auto() -> Self

Create a pool with all available sources on this machine.

Source

pub fn add_source(&mut self, source: Box<dyn EntropySource>, weight: f64)

Register an entropy source.

Source

pub fn source_count(&self) -> usize

Number of registered sources.

Source

pub fn collect_all(&self) -> usize

Collect entropy from every registered source in parallel.

Uses a 10s collection timeout per cycle. Slow sources are skipped and temporarily backed off to keep callers responsive.

Source

pub fn collect_all_parallel(&self, timeout_secs: f64) -> usize

Collect entropy from all sources in parallel using detached worker threads.

Slow or hung sources are skipped after timeout_secs. Timed-out sources enter a backoff window to avoid thread buildup on repeated calls.

Source

pub fn collect_all_parallel_n( &self, timeout_secs: f64, n_samples: usize, ) -> usize

Collect entropy from all sources in parallel using detached worker threads.

  • timeout_secs: max wall-clock time to wait for a collection cycle.
  • n_samples: samples requested from each source in this cycle.

Slow or hung sources are skipped after timeout_secs. Timed-out sources enter a backoff window to avoid thread buildup on repeated calls.

Source

pub fn collect_enabled(&self, enabled_names: &[String]) -> usize

Collect entropy only from sources whose names are in the given list. Uses parallel threads. Collects 1000 samples per source.

Source

pub fn collect_enabled_n( &self, enabled_names: &[String], n_samples: usize, ) -> usize

Collect n_samples of entropy from sources whose names are in the list. Smaller n_samples values are faster — use this for interactive/TUI contexts.

Source

pub fn get_raw_bytes(&self, n_bytes: usize) -> Vec<u8>

Return up to n_bytes of raw, unconditioned entropy (XOR-combined only).

No SHA-256, no DRBG, no whitening. Preserves the raw hardware noise signal for researchers studying actual device entropy characteristics.

If sources cannot provide enough bytes after several collection rounds, this returns the available bytes rather than blocking indefinitely.

Source

pub fn get_random_bytes(&self, n_bytes: usize) -> Vec<u8>

Return n_bytes of conditioned random output.

Source

pub fn get_bytes(&self, n_bytes: usize, mode: ConditioningMode) -> Vec<u8>

Return n_bytes of entropy with the specified conditioning mode.

  • Raw: XOR-combined source bytes, no whitening
  • VonNeumann: debiased but structure-preserving
  • Sha256: full cryptographic conditioning (default)
Source

pub fn health_report(&self) -> HealthReport

Health report as structured data.

Source

pub fn print_health(&self)

Pretty-print health report.

Source

pub fn get_source_bytes( &self, source_name: &str, n_bytes: usize, mode: ConditioningMode, ) -> Option<Vec<u8>>

Collect entropy from a single named source and return conditioned bytes.

Returns None if the source name doesn’t match any registered source.

Source

pub fn get_source_raw_bytes( &self, source_name: &str, n_samples: usize, ) -> Option<Vec<u8>>

Collect raw bytes from a single named source.

Returns None if no source matches the name.

Source

pub fn source_names(&self) -> Vec<String>

List all registered source names.

Source

pub fn source_infos(&self) -> Vec<SourceInfoSnapshot>

Get source info for each registered source.

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> Same for T

Source§

type Output = T

Should always be Self
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