pub trait Hasher {
type Digest: Digest;
const COLLISION_RESISTANCE: u32;
// Required methods
fn hash(bytes: &[u8]) -> Self::Digest;
fn merge(values: &[Self::Digest; 2]) -> Self::Digest;
fn merge_many(values: &[Self::Digest]) -> Self::Digest;
fn merge_with_int(seed: Self::Digest, value: u64) -> Self::Digest;
}
Expand description
Defines a cryptographic hash function.
This trait defines hash procedures for the following inputs:
- A sequence of bytes.
- Two digests - this is intended for use in Merkle tree constructions.
- A digests and a u64 value - this intended for use in PRNG or PoW contexts.
Required Associated Constants§
Sourceconst COLLISION_RESISTANCE: u32
const COLLISION_RESISTANCE: u32
Collision resistance of the hash function measured in bits.
Required Associated Types§
Required Methods§
Sourcefn merge(values: &[Self::Digest; 2]) -> Self::Digest
fn merge(values: &[Self::Digest; 2]) -> Self::Digest
Returns a hash of two digests. This method is intended for use in construction of Merkle trees.
Sourcefn merge_many(values: &[Self::Digest]) -> Self::Digest
fn merge_many(values: &[Self::Digest]) -> Self::Digest
Returns a hash of many digests.
Sourcefn merge_with_int(seed: Self::Digest, value: u64) -> Self::Digest
fn merge_with_int(seed: Self::Digest, value: u64) -> Self::Digest
Returns hash(seed
|| value
). This method is intended for use in PRNG and PoW contexts.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl Hasher for Blake3_160
impl Hasher for Blake3_160
Source§const COLLISION_RESISTANCE: u32 = 80u32
const COLLISION_RESISTANCE: u32 = 80u32
Blake3 collision resistance is 80-bits for 20-bytes output.
type Digest = Blake3Digest<20>
fn hash(bytes: &[u8]) -> <Blake3_160 as Hasher>::Digest
fn merge( values: &[<Blake3_160 as Hasher>::Digest; 2], ) -> <Blake3_160 as Hasher>::Digest
fn merge_many( values: &[<Blake3_160 as Hasher>::Digest], ) -> <Blake3_160 as Hasher>::Digest
fn merge_with_int( seed: <Blake3_160 as Hasher>::Digest, value: u64, ) -> <Blake3_160 as Hasher>::Digest
Source§impl Hasher for Keccak256
impl Hasher for Keccak256
Source§const COLLISION_RESISTANCE: u32 = 128u32
const COLLISION_RESISTANCE: u32 = 128u32
Keccak256 collision resistance is 128-bits for 32-bytes output.