pub struct NBitKeccakState<T, const RATE: usize, const OUTPUT_SIZE: usize>{ /* private fields */ }
Expand description
NBitKeccakState
represents the state of a Keccak-nBits hashing process.
It holds intermediate hash calculations. However, it’s important to note that starting a hashing process from an
arbitrary NBitKeccakState
is not equivalent to resuming the original process that produced that state. Instead, it
begins a new hashing process with a different set of initial values.
Therefore, a NBitKeccakState
extracted from a KeccakNBitsHasher
should not be used with the expectation of
continuing the hashing operation from where it left off in the original KeccakNBitsHasher
. It is a snapshot of a
particular point in the process, not a means to resume the process.
§Example
This example demonstrates how to persist the state of a Keccak-nBits hash operation:
let hello = b"hello";
let world = b" world";
const RATE: usize = 6;
const OUTPUT_SIZE: usize = 24;
let mut default_keccakhasher = NBitKeccakState::<u8, RATE, OUTPUT_SIZE>::default().build_hasher();
default_keccakhasher.write(hello);
let intermediate_state: NBitKeccakState<u8, RATE, OUTPUT_SIZE> = default_keccakhasher.clone().into();
default_keccakhasher.write(world);
let mut from_keccakstate: NBitKeccakHasher<u8, RATE, OUTPUT_SIZE> = intermediate_state.into();
from_keccakstate.write(world);
let default_hello_world_result = default_keccakhasher.finish();
let from_arbitrary_state_result = from_keccakstate.finish();
assert_ne!(default_hello_world_result, from_arbitrary_state_result);
§Note
In this example, even though the internal state are the same between default_keccakhasher
and from_keccakstate
before the Hasher::finish
call, the results are different due to from_keccakstate
being instantiated with an
empty pad while the default_keccakhasher
’s pad is already populated with b"hello"
.
Trait Implementations§
Source§impl<T, const RATE: usize, const OUTPUT_SIZE: usize> BuildHasher for NBitKeccakState<T, RATE, OUTPUT_SIZE>
impl<T, const RATE: usize, const OUTPUT_SIZE: usize> BuildHasher for NBitKeccakState<T, RATE, OUTPUT_SIZE>
Source§type Hasher = NBitKeccakHasher<T, RATE, OUTPUT_SIZE>
type Hasher = NBitKeccakHasher<T, RATE, OUTPUT_SIZE>
Source§fn build_hasher(&self) -> Self::Hasher
fn build_hasher(&self) -> Self::Hasher
Source§impl<T, const RATE: usize, const OUTPUT_SIZE: usize> BytesLen for NBitKeccakState<T, RATE, OUTPUT_SIZE>
impl<T, const RATE: usize, const OUTPUT_SIZE: usize> BytesLen for NBitKeccakState<T, RATE, OUTPUT_SIZE>
Source§impl<T, const RATE: usize, const OUTPUT_SIZE: usize> Clone for NBitKeccakState<T, RATE, OUTPUT_SIZE>
impl<T, const RATE: usize, const OUTPUT_SIZE: usize> Clone for NBitKeccakState<T, RATE, OUTPUT_SIZE>
Source§fn clone(&self) -> NBitKeccakState<T, RATE, OUTPUT_SIZE>
fn clone(&self) -> NBitKeccakState<T, RATE, OUTPUT_SIZE>
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<T, const RATE: usize, const OUTPUT_SIZE: usize> Debug for NBitKeccakState<T, RATE, OUTPUT_SIZE>
impl<T, const RATE: usize, const OUTPUT_SIZE: usize> Debug for NBitKeccakState<T, RATE, OUTPUT_SIZE>
Source§impl<T, const RATE: usize, const OUTPUT_SIZE: usize> Default for NBitKeccakState<T, RATE, OUTPUT_SIZE>
impl<T, const RATE: usize, const OUTPUT_SIZE: usize> Default for NBitKeccakState<T, RATE, OUTPUT_SIZE>
Source§fn default() -> NBitKeccakState<T, RATE, OUTPUT_SIZE>
fn default() -> NBitKeccakState<T, RATE, OUTPUT_SIZE>
Source§impl<T, const RATE: usize, const OUTPUT_SIZE: usize> ExtendedOutputFunction<OUTPUT_SIZE> for NBitKeccakState<T, RATE, OUTPUT_SIZE>
impl<T, const RATE: usize, const OUTPUT_SIZE: usize> ExtendedOutputFunction<OUTPUT_SIZE> for NBitKeccakState<T, RATE, OUTPUT_SIZE>
fn squeeze_u64(&self) -> u64
Source§fn squeeze(&mut self) -> [u8; OUTPUT_SIZE]
fn squeeze(&mut self) -> [u8; OUTPUT_SIZE]
Source§impl<T, const RATE: usize, const OUTPUT_SIZE: usize> From<NBitKeccakHasher<T, RATE, OUTPUT_SIZE>> for NBitKeccakState<T, RATE, OUTPUT_SIZE>
impl<T, const RATE: usize, const OUTPUT_SIZE: usize> From<NBitKeccakHasher<T, RATE, OUTPUT_SIZE>> for NBitKeccakState<T, RATE, OUTPUT_SIZE>
Source§fn from(value: NBitKeccakHasher<T, RATE, OUTPUT_SIZE>) -> Self
fn from(value: NBitKeccakHasher<T, RATE, OUTPUT_SIZE>) -> Self
Source§impl<T, const RATE: usize, const OUTPUT_SIZE: usize> From<NBitKeccakState<T, RATE, OUTPUT_SIZE>> for ByteArrayWrapper<OUTPUT_SIZE>
impl<T, const RATE: usize, const OUTPUT_SIZE: usize> From<NBitKeccakState<T, RATE, OUTPUT_SIZE>> for ByteArrayWrapper<OUTPUT_SIZE>
Source§fn from(value: NBitKeccakState<T, RATE, OUTPUT_SIZE>) -> Self
fn from(value: NBitKeccakState<T, RATE, OUTPUT_SIZE>) -> Self
Source§impl<T, const RATE: usize, const OUTPUT_SIZE: usize> From<NBitKeccakState<T, RATE, OUTPUT_SIZE>> for NBitKeccakHasher<T, RATE, OUTPUT_SIZE>
impl<T, const RATE: usize, const OUTPUT_SIZE: usize> From<NBitKeccakState<T, RATE, OUTPUT_SIZE>> for NBitKeccakHasher<T, RATE, OUTPUT_SIZE>
Source§fn from(value: NBitKeccakState<T, RATE, OUTPUT_SIZE>) -> Self
fn from(value: NBitKeccakState<T, RATE, OUTPUT_SIZE>) -> Self
Source§impl<T, const RATE: usize, const OUTPUT_SIZE: usize> Hash for NBitKeccakState<T, RATE, OUTPUT_SIZE>
impl<T, const RATE: usize, const OUTPUT_SIZE: usize> Hash for NBitKeccakState<T, RATE, OUTPUT_SIZE>
Source§impl<T, const RATE: usize, const OUTPUT_SIZE: usize> HashAlgorithm for NBitKeccakState<T, RATE, OUTPUT_SIZE>
impl<T, const RATE: usize, const OUTPUT_SIZE: usize> HashAlgorithm for NBitKeccakState<T, RATE, OUTPUT_SIZE>
type Padding = GenericPad<KeccakU128Size, RATE, 31>
type Output = ByteArrayWrapper<OUTPUT_SIZE>
fn hash_block(&mut self, bytes: &[u8])
fn state_to_u64(&self) -> u64
Source§impl<T, const RATE: usize, const OUTPUT_SIZE: usize> PartialEq for NBitKeccakState<T, RATE, OUTPUT_SIZE>
impl<T, const RATE: usize, const OUTPUT_SIZE: usize> PartialEq for NBitKeccakState<T, RATE, OUTPUT_SIZE>
Source§fn eq(&self, other: &NBitKeccakState<T, RATE, OUTPUT_SIZE>) -> bool
fn eq(&self, other: &NBitKeccakState<T, RATE, OUTPUT_SIZE>) -> bool
self
and other
values to be equal, and is used by ==
.