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
keyDerivationKeyReadOnlySpan<byte>The key-derivation key K_IN.
prfPrfThe PRF.
expansionKeyExpansionThe mode, fixed input, and counter layout.
lengthBitLengthThe 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
keyDerivationKeyReadOnlySpan<byte>The key-derivation key K_IN.
prfPrfThe PRF, for example
Prf.Hmac(NistHashAlgorithm.Sha256).labelReadOnlySpan<byte>Identifies the purpose of the derived key.
contextReadOnlySpan<byte>Binds the key to the parties, session, or other context.
lengthBitLengthThe 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
keyDerivationKeyReadOnlySpan<byte>The KMAC key. At least 16 bytes for KMAC128 or 32 bytes for KMAC256.
variantKmacVariantKMAC128 or KMAC256.
labelReadOnlySpan<byte>The KMAC customization string S.
contextReadOnlySpan<byte>The KMAC input X.
lengthBitLengthThe 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
labelReadOnlySpan<byte>contextReadOnlySpan<byte>lengthBitLength
Returns
- byte[]