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,
);
#![feature(const_mut_refs)]
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 mut buf = [0; 16];
        reader.read(&mut buf);
        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

Constructs a new hasher

Absorbs additional input

Can be called multiple times.

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

Finalizes the context and compute the output

Trait Implementations

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.