Crate marsupial

Source
Expand description

A Rust wrapper around the eXtended Keccak Code Package implementation of the KangarooTwelve cryptographic hash function

§Examples

// hash an input all at once
let hash1 = marsupial::hash::<KT128>(b"foobarbaz");

// hash an input incrementally
let mut hasher = Hasher::<KT128>::new();
hasher.update(b"foo");
hasher.update(b"bar");
hasher.update(b"baz");
let hash2 = hasher.finalize();
assert_eq!(hash1, hash2);

// extended output. `OutputReader` also implements `Read`
let mut hasher = Hasher::<KT128>::new();
hasher.update(b"foobarbaz");
let mut output_reader = hasher.finalize_xof();
let mut output = [0; 1000];
output_reader.squeeze(&mut output);
assert_eq!(&output[..32], hash1.as_bytes());

// emit the hash as hexadecimal (does not work for now)
//println!("{}", hash1.to_hex());

Structs§

Hash
An output of the default size, 32 bytes, which provides constant-time equality checking
Hasher
An incremental hash state that can accept any number of writes
KT128
The security strength level associated with the KT128 extendable output function
KT256
The security strength level associated with the KT256 extendable output function
OutputReader
An incremental reader for extended output, returned by Hasher::finalize_xof and Hasher::finalize_custom_xof

Traits§

SecurityLevel
A trait representing a valid Hasher security level

Functions§

hash
Hash a slice of bytes all at once. For multiple writes, the optional customization string, or extended output bytes, see Hasher