Skip to main content

CShake128

Struct CShake128 

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

SP 800-185 cSHAKE128: SHAKE128 with a customization string.

Implementations§

Source§

impl CShake128

Source

pub const RATE: usize = 168

The sponge rate in bytes, which is also bytepad’s width here.

Source

pub fn new(n: &[u8], s: &[u8]) -> Self

Start a cSHAKE with a function name n and customization s.

n is reserved for NIST-defined functions — KMAC passes "KMAC". Application customization belongs in s.

With both empty this is plain SHAKE, per SP 800-185 section 3.3, including the domain separator.

Source

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

Absorb more input.

Source

pub fn finalize_xof(self, out: &mut [u8])

Squeeze out.len() bytes.

Source

pub fn xof(n: &[u8], s: &[u8], data: &[u8], out: &mut [u8])

One-shot.

Source

pub fn absorb_bytepadded_string(&mut self, s: &[u8])

Absorb bytepad(encode_string(s), RATE).

KMAC prefixes its message with the key encoded exactly this way. It is exposed here rather than rebuilt in ic-mac because the padding width is the sponge rate, which is cSHAKE’s property and not the caller’s to know.

Trait Implementations§

Source§

impl Algorithm for CShake128

Source§

const ID: &'static str = "cshake128"

Stable ontology identifier for this algorithm.
Source§

const NAME: &'static str = "cSHAKE128"

Human-facing display name (for example "SHA-256").
Source§

impl Clone for CShake128

Source§

fn clone(&self) -> Self

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 SelfTest for CShake128

Source§

fn self_test() -> Result<()>

Two checks, neither of which needs a vector this code produced.

With no customization cSHAKE must equal SHAKE exactly, and SHAKE has its own CAST against a published FIPS 202 answer — so this inherits that evidence. Then customization must change the output, which catches a build where the prefix was silently dropped and every customized call collapsed onto plain SHAKE.

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> 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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.