Skip to main content

HashDrbg

Struct HashDrbg 

Source
pub struct HashDrbg<H: Digest> { /* private fields */ }
Expand description

Hash_DRBG internal state (SP 800-90A §10.1.1.1): the value V, the constant C (both seedlen octets), and the reseed_counter.

V and C are secret. H fixes the hash and thereby seedlen.

Implementations§

Source§

impl<H: Digest> HashDrbg<H>

Source

pub fn instantiate( entropy_input: &[u8], nonce: &[u8], personalization: &[u8], ) -> Result<Self, Error>

Instantiate a Hash_DRBG (SP 800-90A §10.1.1.2).

  • entropy_input — at least security_strength bits (§8.6.3); the caller owns the entropy source. Enforced here as 8·len ≥ security_strength.
  • nonce — at least security_strength/2 bits (§8.6.7).
  • personalization — optional, may be empty (§8.7.1).
  seed_material = entropy_input || nonce || personalization_string
  V = Hash_df(seed_material, seedlen)
  C = Hash_df(0x00 || V, seedlen)
  reseed_counter = 1
Source

pub fn reseed( &mut self, entropy_input: &[u8], additional_input: &[u8], ) -> Result<(), Error>

Reseed a Hash_DRBG (SP 800-90A §10.1.1.3).

  seed_material = 0x01 || V || entropy_input || additional_input
  V = Hash_df(seed_material, seedlen)
  C = Hash_df(0x00 || V, seedlen)
  reseed_counter = 1
Source

pub fn generate( &mut self, out: &mut [u8], additional_input: &[u8], ) -> Result<(), Error>

Generate pseudorandom bits (SP 800-90A §10.1.1.4).

Fills out with 8·out.len() pseudorandom bits.

  if reseed_counter > reseed_interval: return "Reseed required"
  if additional_input != Null:
      w = Hash(0x02 || V || additional_input)
      V = (V + w) mod 2^seedlen
  returned_bits = Hashgen(requested_bits, V)
  H = Hash(0x03 || V)
  V = (V + H + C + reseed_counter) mod 2^seedlen
  reseed_counter += 1

Auto Trait Implementations§

§

impl<H> Freeze for HashDrbg<H>

§

impl<H> RefUnwindSafe for HashDrbg<H>
where H: RefUnwindSafe,

§

impl<H> Send for HashDrbg<H>
where H: Send,

§

impl<H> Sync for HashDrbg<H>
where H: Sync,

§

impl<H> Unpin for HashDrbg<H>
where H: Unpin,

§

impl<H> UnsafeUnpin for HashDrbg<H>

§

impl<H> UnwindSafe for HashDrbg<H>
where H: UnwindSafe,

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.