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
impl HashX
Sourcepub const FULL_SIZE: usize = 32usize
pub const FULL_SIZE: usize = 32usize
The maximum available output size for Self::hash_to_bytes()
Sourcepub fn new(seed: &[u8]) -> Result<Self, Error>
pub fn new(seed: &[u8]) -> Result<Self, Error>
Generate a new hash function with the supplied seed.
Sourcepub fn runtime(&self) -> Runtime
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
.
Sourcepub fn hash_to_u64(&self, input: u64) -> u64
pub fn hash_to_u64(&self, input: u64) -> u64
Calculate the first 64-bit word of the hash, without converting to bytes.
Sourcepub fn hash_to_bytes(&self, input: u64) -> [u8; 32]
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.
Sourcepub(crate) fn hash_to_regs(&self, input: u64) -> RegisterFile
pub(crate) fn hash_to_regs(&self, input: u64) -> RegisterFile
Common setup for hashes with any output format