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

  • 7 values

Introduction

0 declarations

With XChaCha20-Poly1305-IETF, you can encrypt a message witha key and a nonce to keept it confidential, as well as compute an authentication tag to make sure that the message has not been tampered with.

A typical use case for additional data is to authenticate protocol-specific metadata about the message, such as its length and encoding.

For a deeper dive into the limitations of the implementation, please refer to the manual: https://doc.libsodium.org/secret-key_cryptography/aead#limitations

Operations

4 declarations
valuecryptoAEADXChaCha20Poly1305IETFEncrypt
  1. :: Ptr CUChar

    Output buffer. Contains the encrypted message, authentication tag, and non-confidential additional data.

  2. -> Ptr CULLong

    Size of computed output. Should be message length plus cryptoAEADXChaCha20Poly1305IETFABytes. If set to nullPtr, then no bytes will be written to this buffer.

  3. -> Ptr CUChar

    Message to be encrypted.

  4. -> CULLong

    Message length.

  5. -> Ptr CUChar

    Non-confidential additional data. Can be null with additional data length of 0 if no additional data is required.

  6. -> CULLong

    Additional data length.

  7. -> Ptr CUChar

    nsec, a parameter not used in this function. Should always be nullPtr.

  8. -> Ptr CUChar

    Public nonce of size cryptoAEADXChaCha20Polt1305IETFPubBytes. Should never be reused with the same key. Nonces can be generated using randombytesBuf.

  9. -> Ptr CUChar
  10. -> IO CInt

    Returns -1 on failure, 0 on success.

#

This function encrypts a message, and then appends the authentication tag to the encrypted message.

See: crypto_aead_xchacha20poly1305_ietf_encrypt()

valuecryptoAEADXChaCha20Poly1305IETFDecrypt
  1. :: Ptr CUChar

    Output buffer. At most the cipher text length minus cryptoAEADXChaCha20Poly1305IETFABytes will be put into this.

  2. -> Ptr CULLong

    Size of computed output. Should be message length plus cryptoAEADXChaCha20Poly1305IETFABytes. If set to nullPtr, then no bytes will be written to this buffer.

  3. -> Ptr CUChar

    nsec, a parameter not used in this function. Should always be nullPtr.

  4. -> Ptr CUChar

    Ciphertext to decrypt.

  5. -> CULLong

    Ciphertext length.

  6. -> Ptr CUChar

    Non-confidential additional data. Can be null with additional data length of 0 if no additional data is required.

  7. -> CULLong

    Additional data length.

  8. -> Ptr CUChar

    Public nonce of size cryptoAEADXChaCha20Polt1305IETFPubBytes. Should never be reused with the same key. Nonces can be generated using randombytesBuf.

  9. -> Ptr CUChar
  10. -> IO CInt

    Returns -1 on failure, 0 on success.

#

This function verifies that an encrypted ciphertext includes a valid tag.

See: crypto_aead_xchacha20poly1305_ietf_decrypt()

valuecryptoAEADXChaCha20Poly1305IETFEncryptDetached
  1. :: Ptr CUChar

    Output buffer. Contains the encrypted message with length equal to the message.

  2. -> Ptr CUChar

    The authentication tag. Has length cryptoAEADXChaCha20Poly1305IETFABytes.

  3. -> Ptr CULLong

    Length of the authentication tag buffer.

  4. -> Ptr CUChar

    Message to be encrypted.

  5. -> CULLong

    Length of input message.

  6. -> Ptr CUChar

    Additional, non-confidential data.

  7. -> CULLong

    Length of the additional, non-confidential data.

  8. -> Ptr CUChar

    Not used in this particular construction, should always be nullPtr.

  9. -> Ptr CUChar

    Public nonce of size cryptoAEADXChaCha20Polt1305IETFPubBytes. Should never be reused with the same key. Nonces can be generated using randombytesBuf.

  10. -> Ptr CUChar
  11. -> IO CInt

    Returns -1 on failure, 0 on success.

#

This is the "detached" version of the encryption function. The encrypted message and authentication tag are output to different buffers instead of the tag being appended to the encrypted message.

See: crypto_aead_xchacha20poly1305_ietf_encrypt_detached()

valuecryptoAEADXChaCha20Poly1305IETFDecryptDetached
  1. :: Ptr CUChar

    If the tag is valid, the ciphertext is decrypted and put into this buffer.

  2. -> Ptr CUChar

    Not used in this particular construction, should always be nullPtr.

  3. -> Ptr CUChar

    Ciphertext to be decrypted.

  4. -> CULLong

    Length of the ciphertext.

  5. -> Ptr CUChar

    The authentication tag. Has length cryptoAEADXChaCha20Poly1305IETFABytes.

  6. -> Ptr CUChar

    Additional, non-confidential data.

  7. -> CULLong

    Length of the additional, non-confidential data.

  8. -> Ptr CUChar

    Public nonce of size cryptoAEADXChaCha20Polt1305IETFPubBytes. Should never be reused with the same key. Nonces can be generated using randombytesBuf.

  9. -> Ptr CUChar
  10. -> IO CInt

    Returns 0 on success, -1 if tag is not valid.

#

This is the "detached" version of the decryption function. Verifies that the authentication tag is valid for the ciphertext, key, nonce, and additional data.

See: crypto_aead_xchacha20poly1305_ietf_decrypt_detached()

Constants

3 declarations