This documentation is slowly being reviewed, so you may see some inconsistencies between sections.
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Hashing

Purpose

BLAKE2b is a cryptographic hash function. It takes a message of any size and produces a 128-bit to 512-bit hash.

This hash acts as a fingerprint for the data. Hashes can be used to uniquely identify messages, detect corruption, detect duplicate data, and index data in a hash table.

It is also possible to personalize the output for your application/a specific use case via a constant and to randomize hashing by using a salt. The former provides domain separation, helping to avoid collisions between applications/use cases. The latter can also be used for this purpose but is primarily designed for digital signature schemes.

However, unkeyed hashes do not provide authentication (e.g., for Encrypt-then-MAC). Furthermore, they should be avoided for key derivation. Use the linked APIs instead.

Usage

ComputeHash

Fills a span with a hash computed from a message.

BLAKE2b.ComputeHash(Span<byte> hash, ReadOnlySpan<byte> message)

Exceptions

ArgumentOutOfRangeException

hash has a length less than MinHashSize or greater than MaxHashSize.

CryptographicException

Error computing hash.

ComputeHash

Fills a span with a personalized and/or salted hash computed from a message.

Exceptions

ArgumentOutOfRangeException

hash has a length less than MinHashSize or greater than MaxHashSize.

ArgumentOutOfRangeException

personalization and salt both have a length of 0.

ArgumentOutOfRangeException

personalization has a length greater than 0 but not equal to PersonalizationSize.

ArgumentOutOfRangeException

salt has a length greater than 0 but not equal to SaltSize.

CryptographicException

Error computing personalized/salted hash.

IncrementalBLAKE2b

Provides support for computing a hash from several messages.

Exceptions

ArgumentOutOfRangeException

hashSize is less than MinHashSize or greater than MaxHashSize.

ArgumentOutOfRangeException

personalization has a length greater than 0 but not equal to PersonalizationSize.

ArgumentOutOfRangeException

salt has a length greater than 0 but not equal to SaltSize.

ArgumentOutOfRangeException

hash has a length not equal to hashSize.

OutOfMemoryException

Allocating memory for the state failed.

CryptographicException

Error initializing/updating/finalizing hash function state.

InvalidOperationException

Cannot update after finalizing or finalize twice (without reinitializing or restoring a cached state).

InvalidOperationException

Cannot cache the state after finalizing (without reinitializing).

InvalidOperationException

Cannot restore the state when it has not been cached or when the current hash size differs from what was cached.

InvalidOperationException

Methods cannot be called from multiple threads simultaneously.

ObjectDisposedException

The object has been disposed.

Constants

These are used for validation and/or save you defining your own constants.

Notes

The security level of BLAKE2b is 1/2 the output length (e.g., 128-bit security for a 256-bit hash).​

Last updated