Message authentication

Purpose

BLAKE2barrow-up-right is a cryptographic hash function and message authentication code (MAC). As a MAC, it takes a message of any size and a 256-bit to 512-bit key and produces a 128-bit to 512-bit tag.

This tag allows you to verify that a message has not been tampered with. A change to the message or the use of a different key will result in a different tag, at which point you should throw an error.

circle-exclamation
circle-check

Usage

ComputeTag

Fills a span with a tag computed from a message and a key.

BLAKE2b.ComputeTag(Span<byte> tag, ReadOnlySpan<byte> message, ReadOnlySpan<byte> key)

Exceptions

ArgumentOutOfRangeExceptionarrow-up-right

tag has a length less than MinTagSize or greater than MaxTagSize.

ArgumentOutOfRangeExceptionarrow-up-right

key has a length less than MinKeySize or greater than MaxKeySize.

CryptographicExceptionarrow-up-right

The tag could not be computed.

VerifyTag

Verifies that a tag is correct in constant time for a given message and key. It returns true if the tag is valid and false otherwise.

Exceptions

ArgumentOutOfRangeExceptionarrow-up-right

tag has a length less than MinTagSize or greater than MaxTagSize.

ArgumentOutOfRangeExceptionarrow-up-right

key has a length less than MinKeySize or greater than MaxKeySize.

CryptographicExceptionarrow-up-right

The tag could not be recomputed.

IncrementalBLAKE2b

Provides support for computing a tag from several messages and a key.

circle-exclamation

Exceptions

ArgumentOutOfRangeExceptionarrow-up-right

hashSize is less than MinHashSize or greater than MaxHashSize.

ArgumentOutOfRangeExceptionarrow-up-right

key has a length less than MinKeySize or greater than MaxKeySize.

ArgumentOutOfRangeExceptionarrow-up-right

hash has a length not equal to hashSize.

CryptographicExceptionarrow-up-right

The tag could not be computed.

InvalidOperationExceptionarrow-up-right

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

InvalidOperationExceptionarrow-up-right

Cannot cache the state after finalizing (without reinitializing).

InvalidOperationExceptionarrow-up-right

Cannot restore the state when it has not been cached.

ObjectDisposedExceptionarrow-up-right

The object has been disposed.

Constants

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

Notes

triangle-exclamation
triangle-exclamation
triangle-exclamation
triangle-exclamation
triangle-exclamation
circle-check
circle-check
circle-info

The security level of BLAKE2b against a generic attack on hash-based MACs is 1/2 the output length (e.g. 128-bit security for a 256-bit tag).​ However, the security level is equal to the output length for typical attacks against MACs (e.g. 256-bit security for a 256-bit tag). Both types of attacks are completely impractical.

Last updated