Skip to main content

Hkdf

Struct Hkdf 

Source
pub struct Hkdf<M: Mac>(/* private fields */);
Expand description

HKDF instantiated with the MAC M.

Implementations§

Source§

impl<M: Mac> Hkdf<M>

Source

pub fn extract(salt: &[u8], ikm: &[u8], prk: &mut [u8]) -> Result<()>

HKDF-Extract: compress arbitrary input keying material into a PRK.

An empty salt is replaced by HashLen zero bytes, as RFC 5869 requires.

Source

pub fn expand(prk: &[u8], info: &[u8], out: &mut [u8]) -> Result<()>

HKDF-Expand: stretch a PRK to out.len() bytes bound to info.

Keys a MAC with prk for every block of output. Deriving several outputs from one PRK – TLS 1.3 takes a key, an IV and a finished key from each traffic secret – is cheaper through Self::expand_from, which keys once.

Source

pub fn expand_from(keyed: &M, info: &[u8], out: &mut [u8]) -> Result<()>
where M: Clone,

HKDF-Expand from a MAC already keyed with the PRK.

keyed is M::new(prk), made once and kept. Each block of output starts from a clone of it rather than from the key, so the key setup – for HMAC, two compressions of the padded key – is paid when keyed is made and not again per call or per block. The output is exactly Self::expand’s for the same PRK.

RFC 5869 requires the PRK to be at least HashLen bytes. expand checks that; here the key is already inside keyed, so making it from a PRK of the right length is the caller’s part.

Trait Implementations§

Source§

impl<M: Mac> Algorithm for Hkdf<M>

Source§

const ID: &'static str = M::ID

Stable ontology identifier for this algorithm.
Source§

const NAME: &'static str = "HKDF"

Human-facing display name (for example "SHA-256").
Source§

impl<M: Mac> Kdf for Hkdf<M>

Source§

fn derive(secret: &[u8], salt: &[u8], info: &[u8], out: &mut [u8]) -> Result<()>

One-shot extract-then-expand.

Source§

impl SelfTest for Hkdf<HmacSha256>

Source§

fn self_test() -> Result<()>

Run the algorithm’s known-answer test. Read more

Auto Trait Implementations§

§

impl<M> Freeze for Hkdf<M>
where PhantomData<M>: Freeze,

§

impl<M> RefUnwindSafe for Hkdf<M>

§

impl<M> Send for Hkdf<M>
where PhantomData<M>: Send,

§

impl<M> Sync for Hkdf<M>
where PhantomData<M>: Sync,

§

impl<M> Unpin for Hkdf<M>
where PhantomData<M>: Unpin,

§

impl<M> UnsafeUnpin for Hkdf<M>

§

impl<M> UnwindSafe for Hkdf<M>

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.