Skip to main content

Crate bab_rs

Crate bab_rs 

Source
Expand description

An implementation of the Bab family of hash functions.

The crate root exposes the WILLIAM3 instantiation of Bab, which is a concrete hash function you can use immediately. The generic module provides parmaterisable implementations of Bab, which you can use to define your own hash functions.

use bab_rs::{batch_hash, William3Hasher, William3Digest, WIDTH, Hasher, HasherWrite};
let mut hasher = William3Hasher::new();
hasher.write(&[0, 1, 2]);
hasher.write(&[3, 4]);
let incrementally_computed_hash = hasher.finish();

let mut batch_digest = William3Digest::default();
batch_hash(&[0, 1, 2, 3, 4], &mut batch_digest);

assert_eq!(
    hasher.finish(),
    batch_digest,
);

§Features

The william3 feature controls whether the implementations of WILLIAM3 are included. This feature is enabled by default.

The dev feature adds implementations of the Arbitrary trait to various types. This feature is not enabled by default.

§WILLIAM3 APIs

We provide three different styles of APIs to use the WILLIAM3 hash function:

Modules§

generic
The Bab family of hash functions, generically: you determine details such as digest sizes and hash computation through explicit parameters.
storage
String storage, with efficient hash computation and optimised verifiable streaming.

Structs§

William3Digest
A WILLIAM3 digest of a string.
William3Hasher
A stateful hasher for incrementally computing WILLIAM3 digests.

Constants§

CHUNK_SIZE
The number of bytes in a WILLIAM3.
WIDTH
The number of bytes in a WILLIAM3 digest.

Traits§

Hasher
A trait for hashing an arbitrary stream of bytes. The write methods are defined in the HasherWrite trait.
HasherWrite
A trait for writing data to a hasher.

Functions§

batch_hash
Computes the WILLIAM3 digest of the given input bytes, and writes it into out.
batch_hash_keyed
Computes the keyed WILLIAM3 digest of the given input bytes for a given key, and writes the digest into out.

Type Aliases§

Chunk
A convenient type alias for a Bab chunk of data.
Label
A convenient type alias for the labels of the Merkle tree used by Bab.