Skip to main content

HKDF

Struct HKDF 

Source
pub struct HKDF;
Expand description

HMAC-based Key Derivation Function (HKDF) implementation using SHA-512.

HKDF is a key derivation function based on HMAC, standardized in RFC 5869. It derives cryptographically strong keys from input keying material.

The HKDF process consists of two stages:

  1. Extract: Takes input keying material and an optional salt, produces a pseudorandom key (PRK)
  2. Expand: Takes the PRK and optional context info, generates output keying material

§Examples

let prk = hmac_sha512::HKDF::extract(b"salt value", b"input key material");

let mut okm = [0u8; 128];
hmac_sha512::HKDF::expand(&mut okm, prk, b"application info");

Implementations§

Source§

impl HKDF

Source

pub fn extract(salt: impl AsRef<[u8]>, ikm: impl AsRef<[u8]>) -> [u8; 64]

Performs the HKDF-Extract function.

Extracts a pseudorandom key from the input keying material using the optional salt.

§Arguments
  • salt - Optional salt value (a non-secret random value)
  • ikm - Input keying material (the secret input)
§Returns

A 64-byte pseudorandom key

Source

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

Performs the HKDF-Expand function.

Expands the pseudorandom key into output keying material of the desired length.

§Arguments
  • out - Buffer to receive the output keying material
  • prk - Pseudorandom key (from the extract step)
  • info - Optional context and application specific information
§Panics

Panics if the requested output length is greater than 255 * 64 bytes (16320 bytes).

Auto Trait Implementations§

§

impl Freeze for HKDF

§

impl RefUnwindSafe for HKDF

§

impl Send for HKDF

§

impl Sync for HKDF

§

impl Unpin for HKDF

§

impl UnwindSafe for HKDF

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.