The documentation is currently 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.

Key derivation

Purpose

BLAKE2b can be used as a key derivation function (KDF) for high-entropy keys. It takes the following parameters to produce 256 to 512 bits of output keying material:

  • 256 to 512 bits of input keying material (e.g., a shared secret).

  • A 128-bit personalization constant (e.g., an application/protocol name).

  • A 128-bit salt (e.g., a counter or random data).

  • Optional contextual info of any length (e.g., an explanation of what the key will be used for).

This allows you to derive new, distinct keys from a high-entropy master key. For example, separate keys for encryption and authentication with Encrypt-then-MAC by changing the personalization constant, salt, and/or info.

Usage

DeriveKey

Fills a span with output keying material computed from input keying material, a personalization constant, a salt, and optional additional contextual info.

BLAKE2b.DeriveKey(Span<byte> outputKeyingMaterial, ReadOnlySpan<byte> inputKeyingMaterial, ReadOnlySpan<byte> personalization, ReadOnlySpan<byte> salt = default, ReadOnlySpan<byte> info = default)

Exceptions

ArgumentOutOfRangeException

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

ArgumentOutOfRangeException

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

ArgumentOutOfRangeException

personalization has a length not equal to PersonalizationSize.

ArgumentOutOfRangeException

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

CryptographicException

The key could not be derived.

IncrementalBLAKE2b

Provides support for computing output keying material from several messages.

Exceptions

ArgumentOutOfRangeException

hashSize is less than MinHashSize or greater than MaxHashSize.

ArgumentOutOfRangeException

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

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.

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

Last updated