Struct HashX

Source
pub struct HashX {
    pub(crate) register_key: SipState,
    pub(crate) program: RuntimeProgram,
}
Expand description

Pre-built hash program that can be rapidly computed with different inputs

The program and initial state representation are not specified in this public interface, but std::fmt::Debug can describe program internals.

Fields§

§register_key: SipState

Keys used to generate an initial register state from the hash input

Half of the key material generated from seed bytes go into the random program generator, and the other half are saved here for use in each hash invocation.

§program: RuntimeProgram

A prepared randomly generated hash program

In compiled runtimes this will be executable code, and in the interpreter it’s a list of instructions. There is no stable API for program information, but the Debug trait will list programs in either format.

Implementations§

Source§

impl HashX

Source

pub const FULL_SIZE: usize = 32usize

The maximum available output size for Self::hash_to_bytes()

Source

pub fn new(seed: &[u8]) -> Result<Self, Error>

Generate a new hash function with the supplied seed.

Source

pub fn runtime(&self) -> Runtime

Check which actual program runtime is in effect.

By default we try to generate code at runtime to accelerate the hash function, but we fall back to an interpreter if this fails. The compiler can be disabled entirely using RuntimeOption::InterpretOnly and HashXBuilder.

Source

pub fn hash_to_u64(&self, input: u64) -> u64

Calculate the first 64-bit word of the hash, without converting to bytes.

Source

pub fn hash_to_bytes(&self, input: u64) -> [u8; 32]

Calculate the hash function at its full output width, returning a fixed size byte array.

Source

pub(crate) fn hash_to_regs(&self, input: u64) -> RegisterFile

Common setup for hashes with any output format

Trait Implementations§

Source§

impl Debug for HashX

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for HashX

§

impl RefUnwindSafe for HashX

§

impl Send for HashX

§

impl Sync for HashX

§

impl Unpin for HashX

§

impl UnwindSafe for HashX

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> Same for T

Source§

type Output = T

Should always be Self
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.