Table of Contents

Class ConcatKdf

Namespace
CryptoHives.Foundation.Security.Cryptography.Kdf
Assembly
CryptoHives.Foundation.Security.Cryptography.dll

Implements the Concatenation Key Derivation Function (Concat KDF) as defined in NIST SP 800-56A §5.8.1 and NIST SP 800-56C rev2 Option 1.

public static class ConcatKdf
Inheritance
ConcatKdf
Inherited Members

Examples

// Hash-based: derive 32 bytes from ECDH shared secret
using var sha256 = SHA256.Create();
byte[] derivedKey = ConcatKdf.DeriveKey(sha256, sharedSecret, 32, otherInfo);

// HMAC-based: derive 32 bytes with salt
byte[] derivedKey = ConcatKdf.DeriveKey(
    key => new HmacSha256(key),
    sharedSecret, 32, otherInfo, salt);

Remarks

Concat KDF is a single-step key derivation function used to derive keying material from a shared secret (e.g., from ECDH key agreement). Each iteration computes: Hash(counter ‖ Z ‖ OtherInfo) with a 32-bit big-endian counter starting at 1.

Two variants are supported:

This KDF is used in ECDH key agreement (NIST SP 800-56A), JOSE/JWE (RFC 7518), and various ECC-based protocols.

Methods

DeriveKey(HmacFactory, byte[], int, byte[]?, byte[]?)

Derives keying material using the HMAC-based Concat KDF.

public static byte[] DeriveKey(HmacFactory hmacFactory, byte[] sharedSecret, int outputLength, byte[]? otherInfo = null, byte[]? salt = null)

Parameters

hmacFactory HmacFactory

A factory that creates an IMac instance keyed with the given key.

sharedSecret byte[]

The shared secret (Z).

outputLength int

The desired length of the derived keying material in bytes.

otherInfo byte[]

Supplementary public information. If null, treated as empty.

salt byte[]

The optional salt used as the HMAC key. If null, defaults to a zero-filled byte array.

Returns

byte[]

The derived keying material.

Exceptions

ArgumentNullException

hmacFactory or sharedSecret is null.

ArgumentOutOfRangeException

outputLength is less than 1.

DeriveKey(HmacFactory, ReadOnlySpan<byte>, Span<byte>, ReadOnlySpan<byte>, ReadOnlySpan<byte>)

Derives keying material using the HMAC-based Concat KDF.

public static void DeriveKey(HmacFactory hmacFactory, ReadOnlySpan<byte> sharedSecret, Span<byte> output, ReadOnlySpan<byte> otherInfo, ReadOnlySpan<byte> salt)

Parameters

hmacFactory HmacFactory

A factory that creates an IMac instance keyed with the given key.

sharedSecret ReadOnlySpan<byte>

The shared secret (Z), typically from a key agreement such as ECDH.

output Span<byte>

The destination buffer to receive the derived keying material.

otherInfo ReadOnlySpan<byte>

Supplementary public information.

salt ReadOnlySpan<byte>

The optional salt used as the HMAC key. If empty, defaults to a zero-filled byte array of length MacSize.

Exceptions

ArgumentNullException

hmacFactory is null.

ArgumentException

output is empty.

DeriveKey(HashAlgorithm, byte[], int, byte[]?)

Derives keying material using the hash-based Concat KDF.

public static byte[] DeriveKey(HashAlgorithm hash, byte[] sharedSecret, int outputLength, byte[]? otherInfo = null)

Parameters

hash HashAlgorithm

The hash algorithm to use.

sharedSecret byte[]

The shared secret (Z).

outputLength int

The desired length of the derived keying material in bytes.

otherInfo byte[]

Supplementary public information. If null, treated as empty.

Returns

byte[]

The derived keying material.

Exceptions

ArgumentNullException

hash or sharedSecret is null.

ArgumentOutOfRangeException

outputLength is less than 1.

DeriveKey(HashAlgorithm, ReadOnlySpan<byte>, Span<byte>, ReadOnlySpan<byte>)

Derives keying material using the hash-based Concat KDF.

public static void DeriveKey(HashAlgorithm hash, ReadOnlySpan<byte> sharedSecret, Span<byte> output, ReadOnlySpan<byte> otherInfo)

Parameters

hash HashAlgorithm

The hash algorithm to use. The instance is reused across iterations via ComputeHash(byte[]).

sharedSecret ReadOnlySpan<byte>

The shared secret (Z), typically from a key agreement such as ECDH.

output Span<byte>

The destination buffer to receive the derived keying material.

otherInfo ReadOnlySpan<byte>

Supplementary public information (e.g., algorithm ID, party info, key length).

Exceptions

ArgumentNullException

hash is null.

ArgumentException

output is empty.