Skip to main content

HMAC

Struct HMAC 

Source
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>

Source

pub fn keygen() -> Result<KeyMaterial<28>, RNGError>

Generate a key of the appropriate length for the given HMAC

Source§

impl HMAC<SHA256, 64>

Source

pub fn keygen() -> Result<KeyMaterial<32>, RNGError>

Generate a key of the appropriate length for the given HMAC

Source§

impl HMAC<SHA384, 128>

Source

pub fn keygen() -> Result<KeyMaterial<48>, RNGError>

Generate a key of the appropriate length for the given HMAC

Source§

impl HMAC<SHA512, 128>

Source

pub fn keygen() -> Result<KeyMaterial<64>, RNGError>

Generate a key of the appropriate length for the given HMAC

Source§

impl HMAC<SHA3_224, 144>

Source

pub fn keygen() -> Result<KeyMaterial<28>, RNGError>

Generate a key of the appropriate length for the given HMAC

Source§

impl HMAC<SHA3_256, 136>

Source

pub fn keygen() -> Result<KeyMaterial<32>, RNGError>

Generate a key of the appropriate length for the given HMAC

Source§

impl HMAC<SHA3_384, 104>

Source

pub fn keygen() -> Result<KeyMaterial<48>, RNGError>

Generate a key of the appropriate length for the given HMAC

Source§

impl HMAC<SHA3_512, 72>

Source

pub fn keygen() -> Result<KeyMaterial<64>, 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>

Source§

fn clone(&self) -> HMAC<HASH, KEY_BUF_LEN>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<HASH: Hash + Default, const KEY_BUF_LEN: usize> Debug for HMAC<HASH, KEY_BUF_LEN>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<HASH: Hash + Default, const KEY_BUF_LEN: usize> Display for HMAC<HASH, KEY_BUF_LEN>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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>

Create a new MAC instance with the given key. Read more
Source§

fn new_allow_weak_key(key: &impl KeyMaterialTrait) -> Result<Self, MACError>

Create a new HMAC instance with the given key. Read more
Source§

fn output_len(&self) -> usize

The size of the output in bytes.
Source§

fn mac(self, data: &[u8]) -> Vec<u8>

One-shot API that computes a MAC for the provided data. data can be of any length, including zero bytes. Read more
Source§

fn mac_out(self, data: &[u8], out: &mut [u8]) -> Result<usize, MACError>

One-shot API that computes a MAC for the provided data and writes it into the provided output slice. data can be of any length, including zero bytes. Read more
Source§

fn verify(self, data: &[u8], mac: &[u8]) -> bool

One-shot API that verifies a MAC for the provided data. data can be of any length, including zero bytes. Read more
Source§

fn do_update(&mut self, data: &[u8])

Provide a chunk of data to be absorbed into the MAC. 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(self) -> Vec<u8>

Finish absorbing input and produce the MAC value.
Source§

fn do_final_out(self, out: &mut [u8]) -> Result<usize, MACError>

Depending on the underlying MAC implementation, NIST may require that the library enforce a minimum length on the mac output value. See documentation for the underlying implementation to see conditions under which it throws MACError::InvalidLength. Read more
Source§

fn do_verify_final(self, mac: &[u8]) -> bool

Internally, this will re-compute the MAC value and then compare it to the provided mac value using constant-time comparison. It is highly encouraged to use this utility function instead of comparing mac values for equality yourself. Read more
Source§

fn max_security_strength(&self) -> SecurityStrength

Returns the maximum security strength that this KDF is capable of supporting, based on the underlying primitives.
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.

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.

Source§

type Key = dyn KeyMaterialTrait

The type of key that must be re-supplied to resume this object.
Source§

fn suspend(self) -> [u8; HASH_STATE_LEN]

Suspend operation by serializing out the state of the object. Read more
Source§

fn from_suspended( state: [u8; HASH_STATE_LEN], key: &Self::Key, ) -> Result<Self, SuspendableError>

Resume operation from a serialized state and the key. Read more

Auto Trait Implementations§

§

impl<HASH, const KEY_BUF_LEN: usize> Freeze for HMAC<HASH, KEY_BUF_LEN>
where HASH: Freeze,

§

impl<HASH, const KEY_BUF_LEN: usize> RefUnwindSafe for HMAC<HASH, KEY_BUF_LEN>
where HASH: RefUnwindSafe,

§

impl<HASH, const KEY_BUF_LEN: usize> Send for HMAC<HASH, KEY_BUF_LEN>
where HASH: Send,

§

impl<HASH, const KEY_BUF_LEN: usize> Sync for HMAC<HASH, KEY_BUF_LEN>
where HASH: Sync,

§

impl<HASH, const KEY_BUF_LEN: usize> Unpin for HMAC<HASH, KEY_BUF_LEN>
where HASH: Unpin,

§

impl<HASH, const KEY_BUF_LEN: usize> UnsafeUnpin for HMAC<HASH, KEY_BUF_LEN>
where HASH: UnsafeUnpin,

§

impl<HASH, const KEY_BUF_LEN: usize> UnwindSafe for HMAC<HASH, KEY_BUF_LEN>
where HASH: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.