Skip to main content

AesCtrKeyGenerator

Struct AesCtrKeyGenerator 

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

Hardware-only AES-256-CTR fast random generator.

The state contains a 128-bit counter, AES-256 encryption round keys, and a small buffered-output block. It does not contain a software AES fallback or a runtime enum that can hold one.

Implementations§

Source§

impl AesCtrKeyGenerator

Source

pub fn hardware_available() -> bool

Returns whether this process currently exposes the required AES hardware functionality for the AES-CTR backend.

Source

pub const fn state_layout() -> StateLayout

Returns the state layout for this owned generator type.

Source

pub fn from_os_entropy() -> Result<Self, Error>

Seeds a new AES-CTR generator from OS entropy.

§Errors

Returns Error::UnsupportedCpu if the required AES hardware support is unavailable. Returns Error::OsEntropy if the platform entropy source cannot provide a seed.

Source

pub fn from_seed(seed: &mut [u8; 48]) -> Result<Self, Error>

Seeds a new AES-CTR generator from explicit seed material and zeroizes the provided seed before returning.

seed[..32] is the AES-256 key and seed[32..] is the initial 128-bit little-endian counter. This constructor exists for deterministic tests and benchmarks; production callers should use Self::from_os_entropy.

§Errors

Returns Error::UnsupportedCpu if the required AES hardware support is unavailable.

Source

pub fn key_32(&mut self) -> Result<[u8; 32], Error>

Generates a 32-byte AES-256 key.

§Errors

Returns entropy, hardware, or fork-detection failures.

Source

pub fn nonce_12(&mut self) -> Result<[u8; 12], Error>

Generates a 12-byte AES-GCM nonce.

§Errors

Returns entropy, hardware, or fork-detection failures.

Trait Implementations§

Source§

impl Debug for AesCtrKeyGenerator

Source§

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

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

impl Drop for AesCtrKeyGenerator

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl KeyGenerator for AesCtrKeyGenerator

Source§

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

Fills out with AES-CTR CSPRNG output.

Source§

fn key_32(&mut self) -> Result<[u8; 32], Error>

Generates a 32-byte AES-256 key. Read more
Source§

fn nonce_12(&mut self) -> Result<[u8; 12], Error>

Generates a 12-byte AES-GCM nonce. Read more

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.