KbkdfBuilder

Struct KbkdfBuilder 

Source
pub struct KbkdfBuilder<'a> { /* private fields */ }
Expand description

KBKDF key-derivation builder (NIST SP 800-108).

Supports both HMAC-based and CMAC-based PRFs.

let key = KbkdfBuilder::new(KbkdfMode::Counter, &hmac_alg, &master_key)
    .digest(&sha256)
    .label(b"my label")
    .context(b"my context")
    .derive_to_vec(32)?;

Implementations§

Source§

impl<'a> KbkdfBuilder<'a>

Source

pub fn new(mode: KbkdfMode, mac: &'a MacAlg, key: &'a [u8]) -> Self

Create a KBKDF builder.

  • mode — counter or feedback.
  • mac — MAC algorithm (HMAC or CMAC).
  • key — the key derivation key (KDK).
Source

pub fn digest(self, digest: &'a DigestAlg) -> Self

Set the hash digest for HMAC-based derivation.

Source

pub fn label(self, label: &'a [u8]) -> Self

Set the label (identifies the purpose of the derived key).

Source

pub fn context(self, context: &'a [u8]) -> Self

Set the context (caller-specific data bound into the derivation).

Source

pub fn salt(self, salt: &'a [u8]) -> Self

Set the salt / feedback IV (feedback mode only).

Source

pub fn counter_len(self, len: KbkdfCounterLen) -> Self

Override the counter field length (default: 32 bits).

Source

pub fn use_l(self, enabled: bool) -> Self

Control whether the length field L is included (default: true).

Source

pub fn use_separator(self, enabled: bool) -> Self

Control whether the zero-byte separator is included (default: true).

Source

pub fn derive(self, out: &mut [u8]) -> Result<(), ErrorStack>

Derive key material, writing into out.

§Errors
Source

pub fn derive_to_vec(self, len: usize) -> Result<Vec<u8>, ErrorStack>

Derive len bytes, returning them in a freshly allocated Vec<u8>.

§Errors

Auto Trait Implementations§

§

impl<'a> Freeze for KbkdfBuilder<'a>

§

impl<'a> RefUnwindSafe for KbkdfBuilder<'a>

§

impl<'a> Send for KbkdfBuilder<'a>

§

impl<'a> Sync for KbkdfBuilder<'a>

§

impl<'a> Unpin for KbkdfBuilder<'a>

§

impl<'a> UnwindSafe for KbkdfBuilder<'a>

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.