pub struct Shake256State<const OUTPUT_SIZE: usize> { /* private fields */ }
Expand description
Shake256State
represents the state of a SHAKE256 hashing process.
It holds intermediate hash calculations. However, it’s important to note that starting a hashing process from an
arbitrary Shake256State
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 Shake256State
extracted from a Shake256Hasher
should not be used with the expectation of continuing
the hashing operation from where it left off in the original Shake256Hasher
. 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 SHAKE256 hash operation:
let hello = b"hello";
let world = b" world";
let default_shake256state = Shake256State::<32>::default();
let mut default_shake256hasher = default_shake256state.build_hasher();
default_shake256hasher.write(hello);
let intermediate_state: Shake256State<32> = default_shake256hasher.clone().into();
default_shake256hasher.write(world);
let mut from_shake256state: Shake256Hasher<32> = intermediate_state.into();
from_shake256state.write(world);
let default_hello_world_result = default_shake256hasher.finish();
let from_arbitrary_state_result = from_shake256state.finish();
assert_ne!(default_hello_world_result, from_arbitrary_state_result);
§Note
In this example, even though the internal states are the same between default_shake256hasher
and from_shake256state
before the Hasher::finish_xof
call, the results are different due to from_shake256state
being instantiated with an empty
pad while the default_shake256hasher
’s pad is already populated with b"hello"
.
Trait Implementations§
Source§impl<const OUTPUT_SIZE: usize> BuildHasher for Shake256State<OUTPUT_SIZE>
impl<const OUTPUT_SIZE: usize> BuildHasher for Shake256State<OUTPUT_SIZE>
Source§type Hasher = Shake256Hasher<OUTPUT_SIZE>
type Hasher = Shake256Hasher<OUTPUT_SIZE>
Source§fn build_hasher(&self) -> <Shake256State<OUTPUT_SIZE> as BuildHasher>::Hasher
fn build_hasher(&self) -> <Shake256State<OUTPUT_SIZE> as BuildHasher>::Hasher
Source§impl<const OUTPUT_SIZE: usize> BytesLen for Shake256State<OUTPUT_SIZE>
impl<const OUTPUT_SIZE: usize> BytesLen for Shake256State<OUTPUT_SIZE>
Source§impl<const OUTPUT_SIZE: usize> Clone for Shake256State<OUTPUT_SIZE>
impl<const OUTPUT_SIZE: usize> Clone for Shake256State<OUTPUT_SIZE>
Source§fn clone(&self) -> Shake256State<OUTPUT_SIZE>
fn clone(&self) -> Shake256State<OUTPUT_SIZE>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more