EntropyPool

Struct EntropyPool 

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

The pool: a 32-byte working key that only ever moves forward.

Implementations§

Source§

impl<S: Sha256Provider> EntropyPool<S>

Source

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

Build the pool from the stored seed.

salt is the per-boot uniqueness: chip id and reset reason are free (no flash write) and make a restored flash image derive a different stream on different hardware.

Source

pub fn next_seed(&self) -> [u8; 32]

The seed the next boot should load. Derived one-way from the working key, so a flash image reveals nothing about this session, and independent of every draw label, so committing it first leaks nothing about outputs.

Source

pub fn seed_committed(&mut self)

The caller has confirmed next_seed is in storage; draws are now permitted.

Source

pub fn is_committed(&self) -> bool

Whether draws are currently permitted.

Source

pub fn draw( &mut self, label: &[u8], out: &mut [u8], ) -> Result<(), DrawBeforeCommit>

Fill out with output bound to label, then ratchet the working key so this output can never be re-derived from later pool state.

Source

pub fn mix(&mut self, entropy: &[u8])

Fold harvested entropy into the working key.

Hash mixing means adversary-known input cannot reduce the pool’s entropy, only fail to add any — so anything cheap is fair game. Marks the pool dirty: the stored seed no longer reflects the best key we have, and the caller should persist a fresh next_seed when convenient.

Source

pub fn is_dirty(&self) -> bool

Whether a mix has made the stored seed stale.

Source

pub fn seed_refreshed(&mut self)

The caller has persisted a post-mix seed.

Trait Implementations§

Source§

impl<S> Drop for EntropyPool<S>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<S> Freeze for EntropyPool<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for EntropyPool<S>
where S: RefUnwindSafe,

§

impl<S> Send for EntropyPool<S>
where S: Send,

§

impl<S> Sync for EntropyPool<S>
where S: Sync,

§

impl<S> Unpin for EntropyPool<S>
where S: Unpin,

§

impl<S> UnwindSafe for EntropyPool<S>
where S: UnwindSafe,

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.