Class CryptoHChaCha20
- Namespace
- LibSodium
- Assembly
- LibSodium.Net.dll
Deterministically derives 32-byte subkeys using the HChaCha20 core function from a key, a salt-like input and optional domain context.
public static class CryptoHChaCha20
- Inheritance
-
CryptoHChaCha20
- Inherited Members
Fields
ContextLen
Length of the context (16 bytes), used for domain separation.
public const int ContextLen = 16
Field Value
InputLen
Length of the input (16 bytes).
public const int InputLen = 16
Field Value
KeyLen
Length of the master key (32 bytes).
public const int KeyLen = 32
Field Value
SubKeyLen
Length of the derived subkey (32 bytes).
public const int SubKeyLen = 32
Field Value
Methods
DeriveSubkey(SecureMemory<byte>, SecureMemory<byte>, ReadOnlySpan<byte>, ReadOnlySpan<byte>)
Derives a 32-byte subkey from a master key using the HChaCha20 function. This function is suitable for fast, deterministic key derivation with domain separation.
public static void DeriveSubkey(SecureMemory<byte> masterKey, SecureMemory<byte> subKey, ReadOnlySpan<byte> input, ReadOnlySpan<byte> context = default)
Parameters
masterKey
SecureMemory<byte>The 32-byte master key stored in secure memory.
subKey
SecureMemory<byte>The secure memory output buffer for the derived subkey (must be exactly 32 bytes).
input
ReadOnlySpan<byte>A 16-byte salt-like input used to calculate the subkey.
context
ReadOnlySpan<byte>An optional 16-byte context used for domain separation. If not provided, libsodium uses an internal default.
Exceptions
- ArgumentException
Thrown if any parameter has an invalid length.
- LibSodiumException
Thrown if the native function fails.
DeriveSubkey(SecureMemory<byte>, SecureMemory<byte>, ReadOnlySpan<byte>, string)
Derives a 32-byte subkey from a master key using the HChaCha20 function. This function is suitable for fast, deterministic key derivation with domain separation.
public static void DeriveSubkey(SecureMemory<byte> masterKey, SecureMemory<byte> subKey, ReadOnlySpan<byte> input, string context)
Parameters
masterKey
SecureMemory<byte>The 32-byte master key stored in secure memory.
subKey
SecureMemory<byte>The secure memory output buffer for the derived subkey (must be exactly 32 bytes).
input
ReadOnlySpan<byte>A 16-byte salt-like input used to calculate the subkey.
context
stringA string whose UTF-8 representation must not exceed 16 bytes. This is used for domain separation.
Exceptions
- ArgumentException
Thrown if any parameter has an invalid length.
- LibSodiumException
Thrown if the native function fails.
DeriveSubkey(ReadOnlySpan<byte>, Span<byte>, ReadOnlySpan<byte>, ReadOnlySpan<byte>)
Derives a 32-byte subkey from a master key using the HChaCha20 function. This function is suitable for fast, deterministic key derivation with domain separation.
public static void DeriveSubkey(ReadOnlySpan<byte> masterKey, Span<byte> subKey, ReadOnlySpan<byte> input, ReadOnlySpan<byte> context = default)
Parameters
masterKey
ReadOnlySpan<byte>The 32-byte master key.
subKey
Span<byte>The output buffer for the derived subkey (must be exactly 32 bytes).
input
ReadOnlySpan<byte>A 16-byte salt-like input used to calculate the subkey.
context
ReadOnlySpan<byte>An optional 16-byte context used for domain separation. If not provided, libsodium uses an internal default.
Exceptions
- ArgumentException
Thrown if any parameter has an invalid length.
- LibSodiumException
Thrown if the native function fails.
DeriveSubkey(ReadOnlySpan<byte>, Span<byte>, ReadOnlySpan<byte>, string)
Derives a 32-byte subkey from a master key using the HChaCha20 function. This function is suitable for fast, deterministic key derivation with domain separation.
public static void DeriveSubkey(ReadOnlySpan<byte> masterKey, Span<byte> subKey, ReadOnlySpan<byte> input, string context)
Parameters
masterKey
ReadOnlySpan<byte>The 32-byte master key.
subKey
Span<byte>The output buffer for the derived subkey (must be exactly 32 bytes).
input
ReadOnlySpan<byte>A 16-byte salt-like input used to calculate the subkey.
context
stringA string whose UTF-8 representation must not exceed 16 bytes. This is used for domain separation.
Exceptions
- ArgumentException
Thrown if any parameter has an invalid length.
- LibSodiumException
Thrown if the native function fails.