Skip to main content

Crate commutative_hasher

Crate commutative_hasher 

Source
Expand description

This crate provides a hasher that makes it possible to hash a stream of data that is provided out of order. It does so by taking advantage of the fact that the addition of points on an elliptic curve is commutative. The stream of data is split into blocks, each block is mapped to a Ristretto point, and all those points are added together. As a result, it is possible to process the blocks in any order and still obtain the same hash value.

There are two different hashers provided by this crate. They have different properties, but always return the same hash value for the same inputs:

  • ParallelHasher - Use this to process a stream of data in parallel. It requires that the data is provided to the hasher in multiples of the block size.
  • SequentialHasher - Use this to process a stream of data serially. The data can be provided to the hasher in any sizes. It will internally buffer the computation to ensure that each full block is processed appropriately.

When a data stream is complete, you must call finalize() on the hasher to obtain a CommutativeHashDigest, which provides access to the hash value as either bytes or a hex string for serialization. It also provides ways to deserialize a hex string and compare different values.

Re-exports§

pub use digest;

Structs§

CommutativeHashDigest
Wrapper struct that represents a hash value from a commutative hasher. It provides serialization and other helpers.
ParallelHasher
ParallelHasher is a hasher that can be used to efficiently generate a hash value from a large amount of data. It does not require the data to be provided in order, instead requiring that the location of each piece of provided data within the complete data stream is provided.
SequentialHasher
SequentialHasher is a hasher that can be used to generate the same hash values that ParallelHasher generates, but without the limitation that the data must be provided in chunks whose sizes are multiples of the block size.

Enums§

CommutativeHashDigestError
CommutativeHashDigestError represents errors that can arise when generating a CommutativeHashDigest.
ParallelHasherError
ParallelHasherError represents possible errors that could be returned by a ParallelHasher.

Type Aliases§

Result
Result