pub struct HMAC<HASH: Hash + Default, const KEY_BUF_LEN: usize = LARGEST_HASHER_BLOCK_LEN> { /* private fields */ }Expand description
Internal struct for HKDF. HMAC implements RFC 2104. Can, in theory, be instantiated with hash functions other than the ones provided by this crate (even custom ones).
Implementations§
Source§impl HMAC<SHA224, 64>
impl HMAC<SHA224, 64>
Sourcepub fn keygen() -> Result<KeyMaterial<28>, RNGError>
pub fn keygen() -> Result<KeyMaterial<28>, RNGError>
Generate a key of the appropriate length for the given HMAC
Source§impl HMAC<SHA256, 64>
impl HMAC<SHA256, 64>
Sourcepub fn keygen() -> Result<KeyMaterial<32>, RNGError>
pub fn keygen() -> Result<KeyMaterial<32>, RNGError>
Generate a key of the appropriate length for the given HMAC
Source§impl HMAC<SHA384, 128>
impl HMAC<SHA384, 128>
Sourcepub fn keygen() -> Result<KeyMaterial<48>, RNGError>
pub fn keygen() -> Result<KeyMaterial<48>, RNGError>
Generate a key of the appropriate length for the given HMAC
Source§impl HMAC<SHA512, 128>
impl HMAC<SHA512, 128>
Sourcepub fn keygen() -> Result<KeyMaterial<64>, RNGError>
pub fn keygen() -> Result<KeyMaterial<64>, RNGError>
Generate a key of the appropriate length for the given HMAC
Source§impl HMAC<SHA3_224, 144>
impl HMAC<SHA3_224, 144>
Sourcepub fn keygen() -> Result<KeyMaterial<28>, RNGError>
pub fn keygen() -> Result<KeyMaterial<28>, RNGError>
Generate a key of the appropriate length for the given HMAC
Source§impl HMAC<SHA3_256, 136>
impl HMAC<SHA3_256, 136>
Sourcepub fn keygen() -> Result<KeyMaterial<32>, RNGError>
pub fn keygen() -> Result<KeyMaterial<32>, RNGError>
Generate a key of the appropriate length for the given HMAC
Trait Implementations§
Source§impl<HASH: Clone + Hash + Default, const KEY_BUF_LEN: usize> Clone for HMAC<HASH, KEY_BUF_LEN>
impl<HASH: Clone + Hash + Default, const KEY_BUF_LEN: usize> Clone for HMAC<HASH, KEY_BUF_LEN>
Source§impl<HASH: Hash + Default, const KEY_BUF_LEN: usize> MAC for HMAC<HASH, KEY_BUF_LEN>
impl<HASH: Hash + Default, const KEY_BUF_LEN: usize> MAC for HMAC<HASH, KEY_BUF_LEN>
Source§fn new(key: &impl KeyMaterialTrait) -> Result<Self, MACError>
fn new(key: &impl KeyMaterialTrait) -> Result<Self, MACError>
Source§fn new_allow_weak_key(key: &impl KeyMaterialTrait) -> Result<Self, MACError>
fn new_allow_weak_key(key: &impl KeyMaterialTrait) -> Result<Self, MACError>
Source§fn output_len(&self) -> usize
fn output_len(&self) -> usize
Source§fn mac(self, data: &[u8]) -> Vec<u8> ⓘ
fn mac(self, data: &[u8]) -> Vec<u8> ⓘ
data can be of any length, including zero bytes. Read moreSource§fn mac_out(self, data: &[u8], out: &mut [u8]) -> Result<usize, MACError>
fn mac_out(self, data: &[u8], out: &mut [u8]) -> Result<usize, MACError>
data can be of any length, including zero bytes. Read moreSource§fn verify(self, data: &[u8], mac: &[u8]) -> bool
fn verify(self, data: &[u8], mac: &[u8]) -> bool
data can be of any length, including zero bytes. Read moreSource§fn do_update(&mut self, data: &[u8])
fn do_update(&mut self, data: &[u8])
data can be of any length, including zero bytes.
do_update() is intended to be used as part of a streaming interface, and so may by called multiple times.Source§fn do_final_out(self, out: &mut [u8]) -> Result<usize, MACError>
fn do_final_out(self, out: &mut [u8]) -> Result<usize, MACError>
MACError::InvalidLength. Read moreSource§fn do_verify_final(self, mac: &[u8]) -> bool
fn do_verify_final(self, mac: &[u8]) -> bool
Source§fn max_security_strength(&self) -> SecurityStrength
fn max_security_strength(&self) -> SecurityStrength
Source§impl<const HASH_STATE_LEN: usize, const KEY_BUF_LEN: usize, HASH: Hash + Default + Suspendable<HASH_STATE_LEN>> SuspendableKeyed<HASH_STATE_LEN> for HMAC<HASH, KEY_BUF_LEN>
HMAC is a keyed algorithm, so it implements SuspendableKeyed (rather than
Suspendable) for suspending and resuming in-progress operations.
The key is deliberately NOT written into the serialized
bytes and must be re-supplied at deserialization.
impl<const HASH_STATE_LEN: usize, const KEY_BUF_LEN: usize, HASH: Hash + Default + Suspendable<HASH_STATE_LEN>> SuspendableKeyed<HASH_STATE_LEN> for HMAC<HASH, KEY_BUF_LEN>
HMAC is a keyed algorithm, so it implements SuspendableKeyed (rather than
Suspendable) for suspending and resuming in-progress operations.
The key is deliberately NOT written into the serialized
bytes and must be re-supplied at deserialization.
The serialized state is exactly the inner hasher’s state (which has already absorbed K ⊕ ipad
and any message chunks provided so far) — so this is a straight passthrough to the underlying hash’s
Suspendable impl. The re-supplied key is needed to reconstruct the material for the outer
(K ⊕ opad) step at finalization.
There is no way to detect a mismatched key on resume: the caller MUST supply the same key the HMAC was created with, otherwise the resumed operation will silently produce an incorrect MAC.