Opaque tag representing the hash state struct crypto_generichash_state used by the C API.
To use a CryptoGenericHashState, use withGenericHashState.
:: a typeCtrl KGHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05
Modulelibsodium-bindings-0.0.1.1Haskell2010
This API computes a fixed-length fingerprint for an arbitrarily long message. It is backed by the BLAKE2b algorithm.
Sample use cases:
File integrity checking
Creating unique identifiers to index arbitrarily long data
⚠️ Do not use this API module to hash passwords!
Whenever there is a Ptr CryptoGenericHashState, it must point to enough memory
to hold the hash state.
This is at least cryptoGenericHashBytesMin, at most
cryptoGenericHashBytesMax, and should typically be cryptoGenericHashBytes.
It is the caller's responsibility to ensure that this holds.
Opaque tag representing the hash state struct crypto_generichash_state used by the C API.
To use a CryptoGenericHashState, use withGenericHashState.
cryptoGenericHash Put a fingerprint of the message (the in parameter) of length inlen into
the out buffer.
The minimum recommended output size (outlen) is cryptoGenericHashBytes.
However, for specific use cases, the size can be any value between cryptoGenericHashBytesMin (included)
and cryptoGenericHashBytesMax (included).
The key parameter can be Foreign.nullPtr and keylen can be 0. In this case, a message will always have the same fingerprint
But a key can also be specified. A message will always have the same fingerprint for a given key, but different
keys used to hash the same message are very likely to produce distinct fingerprints.
In particular, the key can be used to make sure that different applications generate different fingerprints even
if they process the same data.
The recommended key size is cryptoGenericHashKeyBytes bytes.
However, the key size can be any value between 0 (included) and cryptoGenericHashKeyBytesMax (included). If the key is meant to be secret, the recommended minimum length is cryptoGenericHashKeyBytesMin.
See: crypto_generichash()
This function creates a key of the recommended length cryptoGenericHashKeyBytes.
This function allocates a CryptoGenericHashState of size cryptoGenericHashBytes. If you want more control over the size of the hash state, use withGenericHashStateOfSize.
⚠️ Do not leak the CryptoGenericHashState outside of the lambda, otherwise you will point at deallocated memory!
This function allocates a CryptoGenericHashState of the desired size.
Use the following constants as parameter to this function:
cryptoGenericHashBytes (32U)
Initialise a hash state with a key of a specified length, and produce an output with the specified length in bytes.
The Ptr CUChar argument must point to enough memory to hold a key,
which must also be initialised.
This is at least cryptoGenericHashKeyBytesMin, at most
cryptoGenericHashKeyBytesMax, and should typically be cryptoGenericHashKeyBytes.
It is the caller's responsibility to ensure that these hold.
If you process a message in chunks, you can sequentially process each chunk by calling cryptoGenericHashUpdate by providing a pointer to the previously initialised state, a pointer to the input chunk, and the length of the chunk in bytes.
After processing everything you need with cryptoGenericHashUpdate, you can finalise the operation with cryptoGenericHashFinal.
Size of the generated hash.
Minimum size of a generated hash
Maximum size of a generated hash
Size of a generated key
Minimum size of a generated key
Maximum size of a generated key
Size of a CryptoGenericHashState