Struct NBitKeccakState

Source
pub struct NBitKeccakState<T, const RATE: usize, const OUTPUT_SIZE: usize>
where T: Copy + Default,
{ /* 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>
where T: BitAnd + BitAndAssign + BitOr<NBitWord<T>, Output = NBitWord<T>> + BitXor<Output = T> + BitXorAssign + Copy + Default + Not<Output = T>, NBitWord<T>: From<u64> + LittleEndianBytes + Not<Output = NBitWord<T>> + Rotate + TSize<T>, u32: Sub<NBitWord<T>, Output = NBitWord<T>>,

Source§

type Hasher = NBitKeccakHasher<T, RATE, OUTPUT_SIZE>

Type of the hasher that will be created.
Source§

fn build_hasher(&self) -> Self::Hasher

Creates a new hasher. Read more
1.71.0 · Source§

fn hash_one<T>(&self, x: T) -> u64
where T: Hash, Self: Sized, Self::Hasher: Hasher,

Calculates the hash of a single value. Read more
Source§

impl<T, const RATE: usize, const OUTPUT_SIZE: usize> BytesLen for NBitKeccakState<T, RATE, OUTPUT_SIZE>
where T: Copy + Default,

Source§

impl<T, const RATE: usize, const OUTPUT_SIZE: usize> Clone for NBitKeccakState<T, RATE, OUTPUT_SIZE>
where T: Copy + Default + Clone,

Source§

fn clone(&self) -> NBitKeccakState<T, RATE, OUTPUT_SIZE>

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T, const RATE: usize, const OUTPUT_SIZE: usize> Debug for NBitKeccakState<T, RATE, OUTPUT_SIZE>
where T: Copy + Default + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, const RATE: usize, const OUTPUT_SIZE: usize> Default for NBitKeccakState<T, RATE, OUTPUT_SIZE>
where T: Copy + Default + Default,

Source§

fn default() -> NBitKeccakState<T, RATE, OUTPUT_SIZE>

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

impl<T, const RATE: usize, const OUTPUT_SIZE: usize> ExtendedOutputFunction<OUTPUT_SIZE> for NBitKeccakState<T, RATE, OUTPUT_SIZE>
where T: BitAnd + BitAndAssign + BitOr<NBitWord<T>, Output = NBitWord<T>> + BitXor<Output = T> + BitXorAssign + Copy + Default + Not<Output = T>, NBitWord<T>: From<u64> + LittleEndianBytes + Rotate + TSize<T>, u32: Sub<NBitWord<T>, Output = NBitWord<T>>,

Source§

fn squeeze_u64(&self) -> u64

Source§

fn squeeze(&mut self) -> [u8; OUTPUT_SIZE]

Squeezes the output data from the sponge
Source§

impl<T, const RATE: usize, const OUTPUT_SIZE: usize> From<NBitKeccakHasher<T, RATE, OUTPUT_SIZE>> for NBitKeccakState<T, RATE, OUTPUT_SIZE>
where T: Copy + Default + BitAnd + BitAndAssign + BitOr<NBitWord<T>, Output = NBitWord<T>> + BitXor<Output = T> + BitXorAssign + Not<Output = T>, NBitWord<T>: From<u64> + LittleEndianBytes + Not<Output = NBitWord<T>> + Rotate + TSize<T>, u32: Sub<NBitWord<T>, Output = NBitWord<T>>,

Source§

fn from(value: NBitKeccakHasher<T, RATE, OUTPUT_SIZE>) -> Self

Converts to this type from the input type.
Source§

impl<T, const RATE: usize, const OUTPUT_SIZE: usize> From<NBitKeccakState<T, RATE, OUTPUT_SIZE>> for ByteArrayWrapper<OUTPUT_SIZE>
where T: BitAnd + BitAndAssign + BitOr<NBitWord<T>, Output = NBitWord<T>> + BitXor<Output = T> + BitXorAssign + Copy + Default + Not<Output = T>, NBitWord<T>: From<u64> + LittleEndianBytes + Not + Rotate + TSize<T>, u32: Sub<NBitWord<T>, Output = NBitWord<T>>,

Source§

fn from(value: NBitKeccakState<T, RATE, OUTPUT_SIZE>) -> Self

Converts to this type from the input type.
Source§

impl<T, const RATE: usize, const OUTPUT_SIZE: usize> From<NBitKeccakState<T, RATE, OUTPUT_SIZE>> for NBitKeccakHasher<T, RATE, OUTPUT_SIZE>
where T: Copy + Default + BitAnd + BitAndAssign + BitOr<NBitWord<T>, Output = NBitWord<T>> + BitXor<Output = T> + BitXorAssign + Not<Output = T>, NBitWord<T>: From<u64> + LittleEndianBytes + Not<Output = NBitWord<T>> + Rotate + TSize<T>, u32: Sub<NBitWord<T>, Output = NBitWord<T>>,

Source§

fn from(value: NBitKeccakState<T, RATE, OUTPUT_SIZE>) -> Self

Converts to this type from the input type.
Source§

impl<T, const RATE: usize, const OUTPUT_SIZE: usize> Hash for NBitKeccakState<T, RATE, OUTPUT_SIZE>
where T: Copy + Default + Hash,

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T, const RATE: usize, const OUTPUT_SIZE: usize> HashAlgorithm for NBitKeccakState<T, RATE, OUTPUT_SIZE>
where T: BitAnd + BitAndAssign + BitOr<NBitWord<T>, Output = NBitWord<T>> + BitXor<Output = T> + BitXorAssign + Copy + Default + Not<Output = T>, NBitWord<T>: From<u64> + LittleEndianBytes + Not<Output = NBitWord<T>> + Rotate + TSize<T>, u32: Sub<NBitWord<T>, Output = NBitWord<T>>,

Source§

type Padding = GenericPad<KeccakU128Size, RATE, 31>

Source§

type Output = ByteArrayWrapper<OUTPUT_SIZE>

Source§

fn hash_block(&mut self, bytes: &[u8])

Source§

fn state_to_u64(&self) -> u64

Source§

impl<T, const RATE: usize, const OUTPUT_SIZE: usize> PartialEq for NBitKeccakState<T, RATE, OUTPUT_SIZE>
where T: Copy + Default + PartialEq,

Source§

fn eq(&self, other: &NBitKeccakState<T, RATE, OUTPUT_SIZE>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, const RATE: usize, const OUTPUT_SIZE: usize> Eq for NBitKeccakState<T, RATE, OUTPUT_SIZE>
where T: Copy + Default + Eq,

Source§

impl<T, const RATE: usize, const OUTPUT_SIZE: usize> StructuralPartialEq for NBitKeccakState<T, RATE, OUTPUT_SIZE>
where T: Copy + Default,

Auto Trait Implementations§

§

impl<T, const RATE: usize, const OUTPUT_SIZE: usize> Freeze for NBitKeccakState<T, RATE, OUTPUT_SIZE>
where T: Freeze,

§

impl<T, const RATE: usize, const OUTPUT_SIZE: usize> RefUnwindSafe for NBitKeccakState<T, RATE, OUTPUT_SIZE>
where T: RefUnwindSafe,

§

impl<T, const RATE: usize, const OUTPUT_SIZE: usize> Send for NBitKeccakState<T, RATE, OUTPUT_SIZE>
where T: Send,

§

impl<T, const RATE: usize, const OUTPUT_SIZE: usize> Sync for NBitKeccakState<T, RATE, OUTPUT_SIZE>
where T: Sync,

§

impl<T, const RATE: usize, const OUTPUT_SIZE: usize> Unpin for NBitKeccakState<T, RATE, OUTPUT_SIZE>
where T: Unpin,

§

impl<T, const RATE: usize, const OUTPUT_SIZE: usize> UnwindSafe for NBitKeccakState<T, RATE, OUTPUT_SIZE>
where T: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.