Struct rs_sha512::Sha512State
source · pub struct Sha512State(pub NBitWord<u64>, pub NBitWord<u64>, pub NBitWord<u64>, pub NBitWord<u64>, pub NBitWord<u64>, pub NBitWord<u64>, pub NBitWord<u64>, pub NBitWord<u64>);
Expand description
Sha512State
represents the state of a SHA-512 hashing process.
It holds intermediate hash calculations. However, it’s important to note that starting a hashing process from an
arbitrary Sha512State
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 Sha512State
extracted from a Sha512Hasher
should not be used with the expectation of
continuing the hashing operation from where it left off in the original Sha512Hasher
. 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 SHA-512 hash operation:
let hello = b"hello";
let world = b" world";
let mut default_sha512hasher = Sha512State::default().build_hasher();
default_sha512hasher.write(hello);
let intermediate_state: Sha512State = default_sha512hasher.clone().into();
default_sha512hasher.write(world);
let mut from_sha512state: Sha512Hasher = intermediate_state.into();
from_sha512state.write(world);
let default_hello_world_result = default_sha512hasher.finish();
let from_arbitrary_state_result = from_sha512state.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_sha512hasher
and from_sha512state
before the Hasher::finish
call, the results are different due to from_sha512state
be instantiated with an empty
pad while the default_sha512hasher
’s pad already is populated with b"hello"
.
Tuple Fields§
§0: NBitWord<u64>
§1: NBitWord<u64>
§2: NBitWord<u64>
§3: NBitWord<u64>
§4: NBitWord<u64>
§5: NBitWord<u64>
§6: NBitWord<u64>
§7: NBitWord<u64>
Trait Implementations§
source§impl AddAssign<Sha512BitsState> for Sha512State
impl AddAssign<Sha512BitsState> for Sha512State
source§fn add_assign(&mut self, rhs: Sha512BitsState)
fn add_assign(&mut self, rhs: Sha512BitsState)
+=
operation. Read moresource§impl BuildHasher for Sha512State
impl BuildHasher for Sha512State
source§impl Clone for Sha512State
impl Clone for Sha512State
source§fn clone(&self) -> Sha512State
fn clone(&self) -> Sha512State
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for Sha512State
impl Debug for Sha512State
source§impl Default for Sha512State
impl Default for Sha512State
source§impl From<Sha512Hasher> for Sha512State
impl From<Sha512Hasher> for Sha512State
source§fn from(value: Sha512Hasher) -> Self
fn from(value: Sha512Hasher) -> Self
source§impl From<Sha512State> for ByteArrayWrapper<BYTES_LEN>
impl From<Sha512State> for ByteArrayWrapper<BYTES_LEN>
source§fn from(value: Sha512State) -> Self
fn from(value: Sha512State) -> Self
source§impl From<Sha512State> for Sha512Hasher
impl From<Sha512State> for Sha512Hasher
source§fn from(value: Sha512State) -> Self
fn from(value: Sha512State) -> Self
source§impl Hash for Sha512State
impl Hash for Sha512State
source§impl HashAlgorithm for Sha512State
impl HashAlgorithm for Sha512State
type Padding = GenericPad<U128Size, 128, 128>
type Output = ByteArrayWrapper<BYTES_LEN>
fn hash_block(&mut self, bytes: &[u8])
fn state_to_u64(&self) -> u64
source§impl PartialEq<Sha512State> for Sha512State
impl PartialEq<Sha512State> for Sha512State
source§fn eq(&self, other: &Sha512State) -> bool
fn eq(&self, other: &Sha512State) -> bool
self
and other
values to be equal, and is used
by ==
.