HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulelibsodium-bindings-0.0.1.1Haskell2010

LibSodium.Bindings.GenericHashing

  • 1 type
  • 14 values

Introduction

0 declarations

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.

Operations

8 declarations
valuecryptoGenericHash
  1. :: Ptr CUChar

    out parameter.

  2. -> CSize

    outlen parameter.

  3. -> Ptr CUChar

    in parameter.

  4. -> CULLong

    inlen parameter.

  5. -> Ptr CUChar

    key parameter.

  6. -> CSize

    keylen parameter.

  7. -> IO CInt

    Returns 0 on success, -1 on error.

#

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()

valuecryptoGenericHashInit
  1. :: Ptr CryptoGenericHashState

    Pointer to the hash state

  2. -> Ptr CUChar

    Pointer to a key

  3. -> CSize

    Length of the key

  4. -> CSize

    Length of the result

  5. -> IO CInt

    Returns 0 on success, -1 on error.

#

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.

See: crypto_generichash_init()

Constants

7 declarations