Skip to main content

CtrDrbg

Struct CtrDrbg 

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

CTR_DRBG internal state (SP 800-90A §10.2.1.1): Key (keylen octets) and V (blocklen octets), plus reseed_counter. Both are secret.

keylen (and thus seedlen) is fixed at instantiation by the entropy / key width; AES width is selected by key length exactly as the existing Aes core does.

Implementations§

Source§

impl CtrDrbg

Source

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

Instantiate a CTR_DRBG with a derivation function (SP 800-90A §10.2.1.3.2).

key_len selects the AES width (16 / 24 / 32). Entropy / nonce / personalization lengths are unconstrained beyond min-entropy (8·entropy_input.len() ≥ security_strength, §8.6.3).

  seed_material = entropy_input || nonce || personalization_string
  seed_material = Block_Cipher_df(seed_material, seedlen)
  Key = 0^keylen ; V = 0^blocklen
  (Key, V) = CTR_DRBG_Update(seed_material, Key, V)
  reseed_counter = 1
Source

pub fn instantiate_no_df( key_len: usize, entropy_input: &[u8], personalization: &[u8], ) -> Result<Self, Error>

Instantiate a CTR_DRBG without a derivation function (SP 800-90A §10.2.1.3.1).

The entropy input must be full-entropy and exactly seedlen octets. personalization, if non-empty, must also be exactly seedlen octets (it is entropy XOR pers; a shorter pers is padded with zeros per §10.2.1.3.1 note, but CAVP supplies full-length or empty). No nonce is used in no-df mode.

Source

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

Reseed a CTR_DRBG (SP 800-90A §10.2.1.4). Uses the df iff the instance was instantiated with one.

With df: seed_material = Block_Cipher_df(entropy || additional, seedlen). Without df: seed_material = entropy XOR (additional padded), and both must be exactly seedlen octets.

Source

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

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

  if reseed_counter > reseed_interval: return "Reseed required"
  if additional_input != Null:
      if using df: additional_input = Block_Cipher_df(additional_input, seedlen)
      else        : additional_input = additional_input padded to seedlen
      (Key, V) = CTR_DRBG_Update(additional_input, Key, V)
  else additional_input = 0^seedlen
  temp = ""
  while len(temp) < requested_bits:
      V = (V + 1) mod 2^blocklen
      temp = temp || Block_Encrypt(Key, V)
  returned_bits = leftmost requested_bits of temp
  (Key, V) = CTR_DRBG_Update(additional_input, Key, V)
  reseed_counter += 1

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, 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.