Class CryptoShortHash
- Namespace
- LibSodium
- Assembly
- LibSodium.Net.dll
Provides a high-level interface to the libsodium short-input hash function, based on SipHash-2-4.
public static class CryptoShortHash
- Inheritance
-
CryptoShortHash
- Inherited Members
Remarks
This function is optimized for short messages and uses a 16-byte secret key to protect against hash-flooding attacks. It is not suitable for general-purpose cryptographic hashing.
🧂 https://libsodium.gitbook.io/doc/hashing/short-input_hashing
Fields
HashLen
Hash length in bytes (8).
public const int HashLen = 8
Field Value
KeyLen
Key length in bytes (16).
public const int KeyLen = 16
Field Value
Methods
ComputeHash(Span<byte>, ReadOnlySpan<byte>, SecureMemory<byte>)
Computes a short hash (SipHash-2-4) of the given message using the provided 16-byte key. The key must remain secret. This function will not provide any mitigations against DoS attacks if the key is known from attackers.
public static void ComputeHash(Span<byte> hash, ReadOnlySpan<byte> message, SecureMemory<byte> key)
Parameters
hash
Span<byte>A buffer of exactly 8 bytes to receive the output.
message
ReadOnlySpan<byte>The message to hash.
key
SecureMemory<byte>A 16-byte secret key.
Exceptions
- ArgumentException
Thrown if the key or hash buffer is not of expected length.
- LibSodiumException
Thrown if the hashing operation fails.
ComputeHash(Span<byte>, ReadOnlySpan<byte>, ReadOnlySpan<byte>)
Computes a short hash (SipHash-2-4) of the given message using the provided 16-byte key. The key must remain secret. This function will not provide any mitigations against DoS attacks if the key is known from attackers.
public static void ComputeHash(Span<byte> hash, ReadOnlySpan<byte> message, ReadOnlySpan<byte> key)
Parameters
hash
Span<byte>A buffer of exactly 8 bytes to receive the output.
message
ReadOnlySpan<byte>The message to hash.
key
ReadOnlySpan<byte>A 16-byte secret key.
Exceptions
- ArgumentException
Thrown if the key or hash buffer is not of expected length.
- LibSodiumException
Thrown if the hashing operation fails.