Skip to main content

Kmac128

Struct Kmac128 

Source
pub struct Kmac128 { /* private fields */ }
Expand description

KMAC128 implementation

Implementations§

Source§

impl Kmac128

Source

pub fn new(key: &[u8], custom: &[u8]) -> Self

Creates a new KMAC instance with the given key and customization string

Source

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

Update with data

Source

pub fn finalize(self, output: &mut [u8]) -> Option<()>

Finalize with specified output length.

output.len() must not exceed MAX_SP800185_FIXED_OUTPUT_BYTES. For longer output, use Self::xof.

Returns None if output.len() is greater than MAX_SP800185_FIXED_OUTPUT_BYTES.

Source

pub fn verify(self, expected: &[u8]) -> Choice

Finalize and compare the MAC to expected in constant time.

The MAC output length is expected.len() (same encoding as Self::finalize with an output buffer of that length). The computed MAC is zeroized before returning.

If expected.len() is greater than MAX_SP800185_FIXED_OUTPUT_BYTES, this returns a failed comparison without allocating (or finalizing with that length), so attacker-controlled lengths cannot force large allocations.

Combine or inspect the result with subtle APIs before branching on validity if control-flow timing is a concern.

Source

pub fn finalize_with_length(self, output_len: usize) -> Option<Vec<u8>>

Finalize with specified output length and return as Vec.

Returns None if output_len is greater than MAX_SP800185_FIXED_OUTPUT_BYTES (no allocation). For longer output, use Self::xof.

Source

pub fn xof(self) -> Kmac128Reader

Returns an XOF reader for variable-length output.

SP 800-185 encodes XOF mode with right_encode(0) (output bit length zero) before squeezing.

This consumes self and finalizes the sponge; you cannot call Self::update afterward on this value.

Trait Implementations§

Source§

impl AlgorithmName for Kmac128

Source§

fn write_alg_name(f: &mut Formatter<'_>) -> Result

Write algorithm name into f. Read more
Source§

impl BlockSizeUser for Kmac128

Source§

type BlockSize = UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B1>, B0>, B1>, B0>, B0>, B0>

Size of the block in bytes.
Source§

fn block_size() -> usize

Return block size in bytes.
Source§

impl BufferKindUser for Kmac128

Source§

type BufferKind = Eager

Block buffer kind over which type operates.
Source§

impl Clone for Kmac128

Source§

fn clone(&self) -> Kmac128

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 CollisionResistance for Kmac128

Source§

type CollisionResistance = UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>

Collision resistance in bytes. Read more
Source§

impl Debug for Kmac128

Source§

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

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

impl Default for Kmac128

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl HashMarker for Kmac128

Source§

impl Reset for Kmac128

Source§

fn reset(&mut self)

Reset state to its initial value.
Source§

impl SerializableState for Kmac128

Source§

type SerializedStateSize = UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B1>, B0>, B0>, B1>, B0>, B0>, B0>, B0>

Size of serialized internal state.
Source§

fn serialize(&self) -> SerializedState<Self>

Serialize and return internal state.
Source§

fn deserialize( serialized_state: &SerializedState<Self>, ) -> Result<Self, DeserializeStateError>

Create an object from serialized internal state. Read more
Source§

impl Update for Kmac128

Source§

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

Update state using the provided data.
Source§

fn chain(self, data: impl AsRef<[u8]>) -> Self
where Self: Sized,

Digest input data in a chained manner.
Source§

impl UpdateCore for Kmac128

Source§

fn update_blocks(&mut self, blocks: &[Block<Self>])

Update state using the provided data blocks.
Source§

impl ZeroizeOnDrop for Kmac128

Available on crate feature zeroize only.

Auto Trait Implementations§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SmallBlockSizeUser for T

Source§

type _BlockSize = <T as BlockSizeUser>::BlockSize

Helper associated type equal to <Self as BlockSizeUser>::BlockSize.
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, 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.