HORIZON HASKELLDocslts/ghc-9.14.x7a6c33e2026-10-12Search packagesCtrl K
Theme: |

GHC 9.14.1 · lts/ghc-9.14.x · 7a6c33e · 2026-10-12

Modulelibsodium-bindings-0.0.3.0Haskell2010

LibSodium.Bindings.SHA2

Contents
  1. Introduction
  2. SHA-256
  3. Single-part message
  4. Multi-part messages
  5. Constants
  6. HMAC-SHA-256
  7. Single-part message
  8. Multi-part messages
  9. Constants
  10. SHA-512
  11. Single-part message
  12. Multi-part messages
  13. Constants
  14. HMAC-SHA-512
  15. Single-part message
  16. Multi-part messages
  17. Constants
  18. HMAC-SHA-512-256
  19. Single-part message
  20. Multi-part messages
  21. Constants
Synopsis

Introduction

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

Single-part message

Multi-part messages

Constants

HMAC-SHA-256

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

Single-part message

Multi-part messages

Constants

HMAC-SHA-512

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

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