Table of Contents

Class Sp800108

Namespace
Kdf108
Assembly
Kdf108.dll

Key derivation from a uniformly random key-derivation key, per NIST SP 800-108 Rev. 1.

public static class Sp800108
Inheritance
Sp800108
Inherited Members

Remarks

Every method takes secrets as spans and returns a new array that the caller owns. Clear it with Clear(Array) when you are done. Invalid parameters throw KdfParameterException. For dependency injection and logging, use ISp800108Kdf.

Methods

Derive(ReadOnlySpan<byte>, Prf, KeyExpansion, BitLength)

Derives key material with any SP 800-108 mode and counter layout.

public static byte[] Derive(ReadOnlySpan<byte> keyDerivationKey, Prf prf, KeyExpansion expansion, BitLength length)

Parameters

keyDerivationKey ReadOnlySpan<byte>

The key-derivation key K_IN.

prf Prf

The PRF.

expansion KeyExpansion

The mode, fixed input, and counter layout.

length BitLength

The output length L.

Returns

byte[]

Derive(ReadOnlySpan<byte>, Prf, ReadOnlySpan<byte>, ReadOnlySpan<byte>, BitLength)

Derives key material in counter mode with a 32-bit counter and the conventional fixed input Label || 0x00 || Context || [L]32. This is the right call for most applications.

public static byte[] Derive(ReadOnlySpan<byte> keyDerivationKey, Prf prf, ReadOnlySpan<byte> label, ReadOnlySpan<byte> context, BitLength length)

Parameters

keyDerivationKey ReadOnlySpan<byte>

The key-derivation key K_IN.

prf Prf

The PRF, for example Prf.Hmac(NistHashAlgorithm.Sha256).

label ReadOnlySpan<byte>

Identifies the purpose of the derived key.

context ReadOnlySpan<byte>

Binds the key to the parties, session, or other context.

length BitLength

The output length L.

Returns

byte[]

DeriveKmac(ReadOnlySpan<byte>, KmacVariant, ReadOnlySpan<byte>, ReadOnlySpan<byte>, BitLength)

The KMAC-based KDF from SP 800-108 Rev. 1 §4.4: one KMAC call with Context as input and Label as customization.

public static byte[] DeriveKmac(ReadOnlySpan<byte> keyDerivationKey, KmacVariant variant, ReadOnlySpan<byte> label, ReadOnlySpan<byte> context, BitLength length)

Parameters

keyDerivationKey ReadOnlySpan<byte>

The KMAC key. At least 16 bytes for KMAC128 or 32 bytes for KMAC256.

variant KmacVariant

KMAC128 or KMAC256.

label ReadOnlySpan<byte>

The KMAC customization string S.

context ReadOnlySpan<byte>

The KMAC input X.

length BitLength

The output length L. Must be a whole number of bytes.

Returns

byte[]

FixedInput(ReadOnlySpan<byte>, ReadOnlySpan<byte>, BitLength)

Builds the conventional fixed input Label || 0x00 || Context || [L]32 from SP 800-108r1 §4, with L as a 32-bit big-endian bit count.

public static byte[] FixedInput(ReadOnlySpan<byte> label, ReadOnlySpan<byte> context, BitLength length)

Parameters

label ReadOnlySpan<byte>
context ReadOnlySpan<byte>
length BitLength

Returns

byte[]