libsodium-bindings-0.0.1.1: FFI bindings to libsodium
Copyright(C) Hécate Moonlight 2023
LicenseBSD-3-Clause
MaintainerThe Haskell Cryptography Group
StabilityStable
PortabilityGHC only
Safe HaskellNone
LanguageHaskell2010

LibSodium.Bindings.AEAD

Description

 
Synopsis

Introduction

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

cryptoAEADXChaCha20Poly1305IETFEncrypt Source #

Arguments

:: Ptr CUChar

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

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

-> Ptr CUChar

Message to be encrypted.

-> CULLong

Message length.

-> Ptr CUChar

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

-> CULLong

Additional data length.

-> Ptr CUChar

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

-> Ptr CUChar

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

-> Ptr CUChar

Secret key of size cryptoAEADXChaCha20Poly1305IETFKeyBytes.

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

Since: 0.0.1.0

cryptoAEADXChaCha20Poly1305IETFDecrypt Source #

Arguments

:: Ptr CUChar

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

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

-> Ptr CUChar

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

-> Ptr CUChar

Ciphertext to decrypt.

-> CULLong

Ciphertext length.

-> Ptr CUChar

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

-> CULLong

Additional data length.

-> Ptr CUChar

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

-> Ptr CUChar

Secret key of size cryptoAEADXChaCha20Poly1305IETFKeyBytes.

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

Since: 0.0.1.0

cryptoAEADXChaCha20Poly1305IETFEncryptDetached Source #

Arguments

:: Ptr CUChar

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

-> Ptr CUChar

The authentication tag. Has length cryptoAEADXChaCha20Poly1305IETFABytes.

-> Ptr CULLong

Length of the authentication tag buffer.

-> Ptr CUChar

Message to be encrypted.

-> CULLong

Length of input message.

-> Ptr CUChar

Additional, non-confidential data.

-> CULLong

Length of the additional, non-confidential data.

-> Ptr CUChar

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

-> Ptr CUChar

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

-> Ptr CUChar

Secret key of size cryptoAEADXChaCha20Poly1305IETFKeyBytes.

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

Since: 0.0.1.0

cryptoAEADXChaCha20Poly1305IETFDecryptDetached Source #

Arguments

:: Ptr CUChar

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

-> Ptr CUChar

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

-> Ptr CUChar

Ciphertext to be decrypted.

-> CULLong

Length of the ciphertext.

-> Ptr CUChar

The authentication tag. Has length cryptoAEADXChaCha20Poly1305IETFABytes.

-> Ptr CUChar

Additional, non-confidential data.

-> CULLong

Length of the additional, non-confidential data.

-> Ptr CUChar

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

-> Ptr CUChar

Secret key of size cryptoAEADXChaCha20Poly1305IETFKeyBytes.

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

Since: 0.0.1.0

Constants

cryptoAEADXChaCha20Poly1305IETFKeyBytes :: CSize Source #

Recommended length of a key for this construction.

See: crypto_aead_xchacha20poly1305_ietf_KEYBYTES

Since: 0.0.1.0

cryptoAEADXChaCha20Polt1305IETFPubBytes :: CSize Source #

Recommended length of a nonce for this construction.

See: crypto_aead_xchacha20poly1305_ietf_NPUBBYTES

Since: 0.0.1.0

cryptoAEADXChaCha20Poly1305IETFABytes :: CSize Source #

Recommended length for the authentication tag.

See: crypto_aead_xchacha20poly1305_ietf_ABYTES

Since: 0.0.1.0