Shake128

Struct Shake128 

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

The SHAKE128 extendable-output function

§Examples

const PSEUDO_RANDOM_BYTES: [u8; 32] = Shake128::new()
    .update(b"The quick brown fox ")
    .update(b"jumps over the lazy dog")
    .finalize();

assert_eq!(
    [
        0xf4, 0x20, 0x2e, 0x3c, 0x58, 0x52, 0xf9, 0x18, 0x2a, 0x04, 0x30, 0xfd, 0x81, 0x44,
        0xf0, 0xa7, 0x4b, 0x95, 0xe7, 0x41, 0x7e, 0xca, 0xe1, 0x7d, 0xb0, 0xf8, 0xcf, 0xee,
        0xd0, 0xe3, 0xe6, 0x6e,
    ],
    PSEUDO_RANDOM_BYTES,
);
const ROUND_CONSTANTS_LEN: usize = 16;
const ROUND_CONSTANTS: [u128; ROUND_CONSTANTS_LEN] = {
    let shake = Shake128::new()
        .update(b"The quick brown fox ")
        .update(b"jumps over the lazy dog");
    let mut reader = shake.finalize_xof();
    let mut output = [0; ROUND_CONSTANTS_LEN];
    let mut i = 0;
    while i < ROUND_CONSTANTS_LEN {
        let buf: [u8; 16];
        (reader, buf) = reader.read();
        output[i] = u128::from_be_bytes(buf);
        i += 1;
    }
    output
};

assert_eq!(
    [
        324498722242859095401832112442782838951,
        100470442341479765851591908475476895342,
        241049111671168257801898223573666863059,
        139197826094415251816510671569090212218,
        73371475849610774600276735485442220492,
        321031806373587100556524628628207173306,
        70553598458795679727810425741185559539,
        297273966300911440566694043047331846682,
        112409550095757610585880508546188812219,
        9460513120811775587939596453044060211,
        211668019939948365501534576791633315998,
        50002500201489421996668063727168431450,
        333627932176661322387974747609682513723,
        182198809023207418976073231225478277370,
        318669594573585197479605797034214181928,
        298412008578376288352503392148066037786,
    ],
    ROUND_CONSTANTS,
);

Implementations§

Source§

impl Shake128

Source

pub const fn new() -> Shake128

Constructs a new hasher

Source

pub const fn update(self, input: &[u8]) -> Self

Absorbs additional input

Can be called multiple times.

Source

pub const fn finalize_xof(&self) -> XofReader

Retrieves an extendable-output function (XOF) reader for current hasher instance

Source

pub const fn finalize<const N: usize>(&self) -> [u8; N]

Finalizes the context and compute the output

Trait Implementations§

Source§

impl Default for Shake128

Source§

fn default() -> Self

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

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> 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, 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.