Shake256

Struct Shake256 

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

The SHAKE256 extendable-output function

§Examples

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

assert_eq!(
    [
        0x2f, 0x67, 0x13, 0x43, 0xd9, 0xb2, 0xe1, 0x60, 0x4d, 0xc9, 0xdc, 0xf0, 0x75, 0x3e,
        0x5f, 0xe1, 0x5c, 0x7c, 0x64, 0xa0, 0xd2, 0x83, 0xcb, 0xbf, 0x72, 0x2d, 0x41, 0x1a,
        0x0e, 0x36, 0xf6, 0xca, 0x1d, 0x01, 0xd1, 0x36, 0x9a, 0x23, 0x53, 0x9c, 0xd8, 0x0f,
        0x7c, 0x05, 0x4b, 0x6e, 0x5d, 0xaf, 0x9c, 0x96, 0x2c, 0xad, 0x5b, 0x8e, 0xd5, 0xbd,
        0x11, 0x99, 0x8b, 0x40, 0xd5, 0x73, 0x44, 0x42
    ],
    PSEUDO_RANDOM_BYTES,
);
#![feature(const_mut_refs)]
const ROUND_CONSTANTS_LEN: usize = 16;
const ROUND_CONSTANTS: [u128; ROUND_CONSTANTS_LEN] = {
    let shake = Shake256::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!(
    [
        63008913119763991345740861509526773729,
        122934861405288129899227865927808120522,
        38557047524252432877084375354350394799,
        208139318032057588670393890858232661058,
        253672765511221901359815901266029094236,
        24673942916364082950221119418287074493,
        314501551299016784988697613270261126631,
        55846473543301730160082510643706458461,
        74217159387677683656408416866508597390,
        103097936643341605695740861737581768184,
        43427127028232698635034841870476065529,
        30671809218547569588332151812578484838,
        234968987069139406291454845949508600001,
        174416227018858056231916805199588046174,
        206220167108618043277683992075133751175,
        50389517484914419772600260972881863524,
    ],
    ROUND_CONSTANTS,
);

Implementations§

Source§

impl Shake256

Source

pub const fn new() -> Shake256

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 Shake256

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.