hash.h¶
BLAKE3: one-shot digests, a batch of equal-length inputs, an incremental hasher, and a digest chain.
Every digest is BLAKE3_OUT_LEN (32) bytes, the vendored library’s constant. No function allocates; the caller owns every buffer, and no input may overlap an output.
Note
Thread-safe. A hasher state belongs to one thread at a time.
Functions
-
void hash_blake3(uint8_t *out, const uint8_t *in, uint64_t len)¶
Writes the digest of a byte string.
- Parameters:
out – [out] Receives
BLAKE3_OUT_LENbytes.in – [in] The bytes to hash.
len – [in] Their count.
-
bool hash_blake3_batch_fits(uint64_t len)¶
Reports whether hash_blake3_batch() takes inputs of
lenbytes across the SIMD lanes: nonzero and at most 1024, one BLAKE3 chunk.Past a chunk an input is a tree of chunks, which the lane-parallel core does not do; such inputs are still hashed, one at a time. A length that is not a whole number of 64-byte blocks has its last block compressed one input at a time, so it gains less than a whole-block length.
- Parameters:
len – [in] Bytes per input.
- Returns:
true when the batch runs lane-parallel.
-
void hash_blake3_batch(uint8_t *out, const uint8_t *in, uint64_t count, uint64_t len)¶
Writes the digests of
countindependent inputs oflenbytes each, laid out end to end.Each digest equals hash_blake3() of that input alone. A large batch is split across the library’s threads (parallel.h); the digests are the same at any number of them.
- Parameters:
out – [out] Receives
count * BLAKE3_OUT_LENbytes.in – [in]
count * lenbytes, input after input.count – [in] Inputs.
len – [in] Bytes per input.
-
uint64_t hash_blake3_stream_size(void)¶
Returns the bytes a hasher state takes, for hash_blake3_stream_init().
- Returns:
The state size in bytes.
-
void hash_blake3_stream_init(void *state)¶
Starts an incremental hash in caller-owned memory.
- Parameters:
state – [out] hash_blake3_stream_size() bytes, any alignment.
-
void hash_blake3_stream_update(void *state, const uint8_t *in, uint64_t len)¶
Feeds bytes to an incremental hash.
- Parameters:
state – [inout] A state from hash_blake3_stream_init().
in – [in] The bytes.
len – [in] Their count.
-
void hash_blake3_stream_digest(const void *state, uint8_t out[BLAKE3_OUT_LEN])¶
Writes the digest of everything fed so far; the state stays usable and more may follow.
- Parameters:
state – [in] A state from hash_blake3_stream_init().
out – [out] Receives the digest.
-
void hash_blake3_chain(uint8_t state[BLAKE3_OUT_LEN], const uint8_t *in, uint64_t count, uint64_t len)¶
Advances a digest chain over parts of one length:
state = H(state | part), part after part, in place.- Parameters:
state – [inout] The chain’s digest, replaced by the new one.
in – [in]
count * lenbytes, part after part.count – [in] Parts.
len – [in] Bytes per part.