pub struct TupleHash(/* private fields */);Expand description
Tuple Hash.
TupleHash is a SHA-3-derived hash function with variable-length output that is designed to
simply hash a tuple of input strings, any or all of which may be empty strings, in an
unambiguous way. Such a tuple may consist of any number of strings, including zero, and is
represented as a sequence of strings or variables in parentheses like (“a”, “b”, “c”,…,“z”) in this
document.
TupleHash is designed to provide a generic, misuse-resistant way to combine a sequence of
strings for hashing such that, for example, a TupleHash computed on the tuple (“abc” ,“d”) will
produce a different hash value than a TupleHash computed on the tuple (“ab”,“cd”), even though
all the remaining input parameters are kept the same, and the two resulting concatenated strings,
without string encoding, are identical.
TupleHash supports two security strengths: 128 bits and 256 bits. Changing any input to the
function, including the requested output length, will almost certainly change the final output.
Implementations§
Source§impl TupleHash
impl TupleHash
pub fn new_tuplehash128(custom: &[u8]) -> Self
pub fn new_tuplehash256(custom: &[u8]) -> Self
pub fn update<T: AsRef<[u8]>>(&mut self, input: &[T])
pub fn finalize(self, buf: &mut [u8])
Sourcepub fn xof(self) -> XofReader
pub fn xof(self) -> XofReader
A function on bit strings in which the output can be extended to any desired length.
Some applications of TupleHash may not know the number of output bits they will need until
after the outputs begin to be produced. For these applications, TupleHash can also be used as a
XOF (i.e., the output can be extended to any desired length), which mimics the behavior of
cSHAKE.