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>
impl<'a> KbkdfBuilder<'a>
Sourcepub fn new(mode: KbkdfMode, mac: &'a MacAlg, key: &'a [u8]) -> Self
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).
Sourcepub fn digest(self, digest: &'a DigestAlg) -> Self
pub fn digest(self, digest: &'a DigestAlg) -> Self
Set the hash digest for HMAC-based derivation.
Sourcepub fn label(self, label: &'a [u8]) -> Self
pub fn label(self, label: &'a [u8]) -> Self
Set the label (identifies the purpose of the derived key).
Sourcepub fn context(self, context: &'a [u8]) -> Self
pub fn context(self, context: &'a [u8]) -> Self
Set the context (caller-specific data bound into the derivation).
Sourcepub fn counter_len(self, len: KbkdfCounterLen) -> Self
pub fn counter_len(self, len: KbkdfCounterLen) -> Self
Override the counter field length (default: 32 bits).
Sourcepub fn use_l(self, enabled: bool) -> Self
pub fn use_l(self, enabled: bool) -> Self
Control whether the length field L is included (default: true).
Sourcepub fn use_separator(self, enabled: bool) -> Self
pub fn use_separator(self, enabled: bool) -> Self
Control whether the zero-byte separator is included (default: true).
Sourcepub fn derive(self, out: &mut [u8]) -> Result<(), ErrorStack>
pub fn derive(self, out: &mut [u8]) -> Result<(), ErrorStack>
Derive key material, writing into out.
§Errors
Sourcepub fn derive_to_vec(self, len: usize) -> Result<Vec<u8>, ErrorStack>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more