pub struct RistrettoHash<H> { /* private fields */ }Expand description
RistrettoHash represents a hash function for multi-sets.
A multi-set is a collection of objects, where any given object may appear multiple times. This hash function will accept the objects in different orders, and with different groupings, but always return the same result for the same multi-set.
This allows incrementally calculating such a multi-set hash without keeping the entire set in memory.
This struct is parameterized by a hash function with 512 bits of output. For example, SHA-512.
This is called RistrettoHash, because this function internally uses
the Ristretto group to implement its commutative hashing.
§Examples
In the usual case, you add in different byte slices, with multiplicity For example,
to hash the set {cat, cat, dog, dog}, you could do:
use digest::Digest;
use sha2::Sha512;
let mut hash = RistrettoHash::<Sha512>::default();
hash.add(b"cat", 2);
hash.add(b"dog", 2);This is equivalent to hashing the same number of objects, with a different grouping and order:
use digest::Digest;
let mut hash = RistrettoHash::<Sha512>::default();
hash.add(b"dog", 1);
hash.add(b"cat", 1);
hash.add(b"cat", 1);
hash.add(b"dog", 1);You can also hash objects in multiple pieces using the update method:
use digest::Digest;
let mut hash = RistrettoHash::<Sha512>::default();
hash.update(b"d");
hash.update(b"og");
hash.end_update(2);
hash.add(b"cat", 2);If you use update, you must call end_update before adding another object,
or calling finalize to get the output of the hash function.
Implementations§
Source§impl<H: Digest<OutputSize = U64> + Default> RistrettoHash<H>
impl<H: Digest<OutputSize = U64> + Default> RistrettoHash<H>
Sourcepub fn add(&mut self, data: impl AsRef<[u8]>, multiplicity: u64)
pub fn add(&mut self, data: impl AsRef<[u8]>, multiplicity: u64)
This function adds a complete object to the hash.
This function takes a multiplicity, which is equivalent to calling the function multiple times, but is much more efficient.
Sourcepub fn end_update(&mut self, multiplicity: u64)
pub fn end_update(&mut self, multiplicity: u64)
This function should be called to mark the end of an object provided with update.
This must always be called after calls to update, otherwise panics will happen
when finalizing or adding new objects.
If called without any prior calls to update, this function is equivalent
to calling add with an empty slice.
Trait Implementations§
Source§impl<H: Clone> Clone for RistrettoHash<H>
impl<H: Clone> Clone for RistrettoHash<H>
Source§fn clone(&self) -> RistrettoHash<H>
fn clone(&self) -> RistrettoHash<H>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<H: Default> Default for RistrettoHash<H>
impl<H: Default> Default for RistrettoHash<H>
Source§fn default() -> RistrettoHash<H>
fn default() -> RistrettoHash<H>
Source§impl<H: Reset> FixedOutput for RistrettoHash<H>
impl<H: Reset> FixedOutput for RistrettoHash<H>
Source§type OutputSize = UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>
type OutputSize = UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>
Source§fn finalize_into(self, out: &mut GenericArray<u8, Self::OutputSize>)
fn finalize_into(self, out: &mut GenericArray<u8, Self::OutputSize>)
Source§fn finalize_into_reset(&mut self, out: &mut GenericArray<u8, Self::OutputSize>)
fn finalize_into_reset(&mut self, out: &mut GenericArray<u8, Self::OutputSize>)
Source§fn finalize_fixed(self) -> GenericArray<u8, Self::OutputSize>where
Self: Sized,
fn finalize_fixed(self) -> GenericArray<u8, Self::OutputSize>where
Self: Sized,
Source§fn finalize_fixed_reset(&mut self) -> GenericArray<u8, Self::OutputSize>
fn finalize_fixed_reset(&mut self) -> GenericArray<u8, Self::OutputSize>
Source§impl<H: Reset> Reset for RistrettoHash<H>
impl<H: Reset> Reset for RistrettoHash<H>
Source§impl<H: Update> Update for RistrettoHash<H>
impl<H: Update> Update for RistrettoHash<H>
Source§fn update(&mut self, data: impl AsRef<[u8]>)
fn update(&mut self, data: impl AsRef<[u8]>)
update hashes in part of an object.
This method is used to hash an object in multiple different parts.
These updates must be finished by calling end_update to mark the end
of the object, and its multiplicity.
Failing to call end_update before adding a new object with add or
finalizing the hash will panic.
Auto Trait Implementations§
impl<H> Freeze for RistrettoHash<H>where
H: Freeze,
impl<H> RefUnwindSafe for RistrettoHash<H>where
H: RefUnwindSafe,
impl<H> Send for RistrettoHash<H>where
H: Send,
impl<H> Sync for RistrettoHash<H>where
H: Sync,
impl<H> Unpin for RistrettoHash<H>where
H: Unpin,
impl<H> UnwindSafe for RistrettoHash<H>where
H: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<D> Digest for D
impl<D> Digest for D
Source§type OutputSize = <D as FixedOutput>::OutputSize
type OutputSize = <D as FixedOutput>::OutputSize
DigestSource§fn update(&mut self, data: impl AsRef<[u8]>)
fn update(&mut self, data: impl AsRef<[u8]>)
Source§fn finalize(self) -> GenericArray<u8, <D as Digest>::OutputSize>
fn finalize(self) -> GenericArray<u8, <D as Digest>::OutputSize>
Source§fn finalize_reset(&mut self) -> GenericArray<u8, <D as Digest>::OutputSize>
fn finalize_reset(&mut self) -> GenericArray<u8, <D as Digest>::OutputSize>
Source§fn output_size() -> usize
fn output_size() -> usize
Source§fn digest(data: &[u8]) -> GenericArray<u8, <D as Digest>::OutputSize>
fn digest(data: &[u8]) -> GenericArray<u8, <D as Digest>::OutputSize>
data. It will handle
hasher creation, data feeding and finalization. Read more