Message authentication
Last updated
Last updated
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.
A tag size of at least 256 bits is strongly recommended to obtain , which requires collision resistance.
A 256-bit key is recommended regardless of the tag size. Larger keys are unnecessary.
Fills a span with a tag computed from a message and a key.
tag
has a length less than MinTagSize
or greater than MaxTagSize
.
key
has a length less than MinKeySize
or greater than MaxKeySize
.
The tag could not be computed.
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.
tag
has a length less than MinTagSize
or greater than MaxTagSize
.
key
has a length less than MinKeySize
or greater than MaxKeySize
.
The tag could not be recomputed.
Provides support for computing a tag from several messages and a key.
hashSize
is less than MinHashSize
or greater than MaxHashSize
.
key
has a length less than MinKeySize
or greater than MaxKeySize
.
hash
has a length not equal to hashSize
.
The tag could not be computed.
Cannot update after finalizing or finalize twice (without reinitializing or restoring a cached state).
Cannot cache the state after finalizing (without reinitializing).
Cannot restore the state when it has not been cached.
The object has been disposed.
These are used for validation and/or save you defining your own constants.
Tags MUST be compared in constant time to avoid leaking information, so use the VerifyTag()
or FinalizeAndVerify()
function.
If you are making multiple calls to IncrementalBLAKE2b
with unchanging/static data at the beginning (e.g. the same key), you can cache the state to improve performance. This allows you to only process this data once and can help you quickly zero the key from memory.
CacheState()
can only cache the state once. Each subsequent call will overwrite the previously cached state. See the for when this method should be used.
With , you MUST include the nonce in the message when computing the tag.
If you intend to feed multiple variable-length inputs into the message, beware of . Please read the page for more information.
The key MUST be uniformly random. It should be the output of a , NOT randomly generated.
Do NOT use the same key for multiple purposes (e.g. encryption and authentication). You should separate keys using the same input keying material and personalisation but different salts and/or info.
The same key can be reused for multiple messages, but it is good practice to a unique key each time.