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.SHA2

  • 5 types
  • 44 values

Introduction

0 declarations

The SHA-256 and SHA-512 functions are provided for interoperability with other applications. If you are looking for a generic hash function and not specifically SHA-2, using LibSodium.Bindings.GenericHashing (BLAKE2b) might be a better choice. These functions are also not suitable for hashing passwords or deriving keys from passwords. Use LibSodium.Bindings.PasswordHashing instead.

Only use these functions for interoperability with 3rd party services.

These functions are not keyed and are thus deterministic. In addition, the untruncated versions are vulnerable to length extension attacks. A message can be hashed in a single pass, but a streaming API is also available to process a message as a sequence of multiple chunks.

SHA-256

0 declarations

Single-part message

Multi-part messages

Constants

HMAC-SHA-256

0 declarations

Single-part message

valuecryptoAuthHMACSHA256
  1. :: Ptr CUChar

    A pointer to the buffer holding the authenticator.

  2. -> Ptr CUChar

    A pointer to the message to be authenticated.

  3. -> CULLong

    The length of the message to be authenticated.

  4. -> Ptr CUChar

    A pointer to the secret key used for authentication, of length cryptoAuthHMACSHA256Bytes.

  5. -> IO CInt

    Returns 0 on success, -1 on error.

#

Authenticate a message given its size and a secret key, and produce an authenticator to be validated with cryptoAuthHMACSHA256Verify.

See: crypto_auth_hmacsha256().

Multi-part messages

valuecryptoAuthHMACSHA256Update
  1. :: Ptr CryptoAuthHMACSHA256State

    A pointer to an initialised hash state. Cannot be Foreign.nullPtr.

  2. -> Ptr CUChar

    A pointer to the message to authenticate.

  3. -> CULLong

    The size of the message to authenticate.

  4. -> IO CInt

    Returns 0 on success, -1 on error.

#

Add a new chunk to the message that will eventually be hashed.

After all parts have been supplied, cryptoAuthHMACSHA256Final can be used to finalise the operation and get the final hash.

See: crypto_auth_hmacsha256_update()

valuecryptoAuthHMACSHA256Final
  1. :: Ptr CryptoAuthHMACSHA256State

    A pointer to an initialised hash state. Cannot be Foreign.nullPtr.

  2. -> Ptr CUChar

    A pointer to the buffer that will hold the authenticator.

  3. -> IO CInt

    Returns 0 on success, -1 on error.

#

Finalise the hashing of a message. The final hash is padded with extra zeros if necessary, then put in a buffer.

After this operation, the buffer containing the CryptoAuthHMACSHA256State is emptied and cannot be relied upon.

See: crypto_auth_hmacsha256_final()

Constants

SHA-512

0 declarations

Single-part message

Multi-part messages

Constants

HMAC-SHA-512

0 declarations

Single-part message

valuecryptoAuthHMACSHA512
  1. :: Ptr CUChar

    A pointer to the buffer holding the authenticator.

  2. -> Ptr CUChar

    A pointer to the message to be authenticated.

  3. -> CULLong

    The length of the message to be authenticated.

  4. -> Ptr CUChar

    A pointer to the secret key used for authentication, of length cryptoAuthHMACSHA512Bytes.

  5. -> IO CInt

    Returns 0 on success, -1 on error.

#

Authenticate a message given its size and a secret key, and produce an authenticator to be validated with cryptoAuthHMACSHA512Verify.

See: crypto_auth_hmacsha512().

Multi-part messages

valuecryptoAuthHMACSHA512Update
  1. :: Ptr CryptoAuthHMACSHA512State

    A pointer to an initialised hash state. Cannot be Foreign.nullPtr.

  2. -> Ptr CUChar

    A pointer to the message to authenticate.

  3. -> CULLong

    The size of the message to authenticate.

  4. -> IO CInt

    Returns 0 on success, -1 on error.

#

Add a new chunk to the message that will eventually be hashed.

After all parts have been supplied, cryptoAuthHMACSHA512Final can be used to finalise the operation and get the final hash.

See: crypto_auth_hmacsha512_update()

valuecryptoAuthHMACSHA512Final
  1. :: Ptr CryptoAuthHMACSHA512State

    A pointer to an initialised hash state. Cannot be Foreign.nullPtr.

  2. -> Ptr CUChar

    A pointer to the buffer that will hold the authenticator.

  3. -> IO CInt

    Returns 0 on success, -1 on error.

#

Finalise the hashing of a message. The final hash is padded with extra zeros if necessary, then put in a buffer.

After this operation, the buffer containing the CryptoAuthHMACSHA512State is emptied and cannot be relied upon.

See: crypto_auth_hmacsha512_final()

Constants

HMAC-SHA-512-256

0 declarations

HMAC-SHA-512-256 is implemented as HMAC-SHA-512 with the output truncated to 256 bits. This is slightly faster than HMAC-SHA-256. Note that this construction is not the same as HMAC-SHA-512/256, which is HMAC using the SHA-512/256 function.

Single-part message

valuecryptoAuthHMACSHA512256
  1. :: Ptr CUChar

    A pointer to the buffer holding the authenticator.

  2. -> Ptr CUChar

    A pointer to the message to be authenticated.

  3. -> CULLong

    The length of the message to be authenticated.

  4. -> Ptr CUChar

    A pointer to the secret key used for authentication, of length cryptoAuthHMACSHA512256Bytes.

  5. -> IO CInt

    Returns 0 on success, -1 on error.

#

Authenticate a message given its size and a secret key, and produce an authenticator to be validated with cryptoAuthHMACSHA512256Verify.

See: crypto_auth_hmacsha512256().

Multi-part messages

valuecryptoAuthHMACSHA512256Update
  1. :: Ptr CryptoAuthHMACSHA512256State

    A pointer to an initialised hash state. Cannot be Foreign.nullPtr.

  2. -> Ptr CUChar

    A pointer to the message to authenticate.

  3. -> CULLong

    The size of the message to authenticate.

  4. -> IO CInt

    Returns 0 on success, -1 on error.

#

Add a new chunk to the message that will eventually be hashed.

After all parts have been supplied, cryptoAuthHMACSHA512256Final can be used to finalise the operation and get the final hash.

See: crypto_auth_hmacsha512256_update()

valuecryptoAuthHMACSHA512256Final
  1. :: Ptr CryptoAuthHMACSHA512256State

    A pointer to an initialised hash state. Cannot be Foreign.nullPtr.

  2. -> Ptr CUChar

    A pointer to the buffer that will hold the authenticator.

  3. -> IO CInt

    Returns 0 on success, -1 on error.

#

Finalise the hashing of a message. The final hash is padded with extra zeros if necessary, then put in a buffer.

After this operation, the buffer containing the CryptoAuthHMACSHA512256State is emptied and cannot be relied upon.

See: crypto_auth_hmacsha512256_final()

Constants