ppad-aead-0.1.0: A pure AEAD-ChaCha20-Poly1305 construction
Copyright(c) 2025 Jared Tobin
LicenseMIT
MaintainerJared Tobin <jared@ppad.tech>
Safe HaskellNone
LanguageHaskell2010

Crypto.AEAD.ChaCha20Poly1305

Description

A pure AEAD-ChaCha20-Poly1305 implementation, as specified by RFC 8439.

Synopsis

AEAD construction

encrypt Source #

Arguments

:: ByteString

arbitrary-length additional authenticated data

-> ByteString

256-bit key

-> ByteString

96-bit nonce

-> ByteString

arbitrary-length plaintext

-> (ByteString, ByteString)

(ciphertext, 128-bit MAC)

Perform authenticated encryption on a plaintext and some additional authenticated data, given a 256-bit key and 96-bit nonce, using AEAD-ChaCha20-Poly1305.

Produces a ciphertext and 128-bit message authentication code pair.

Providing an invalid key or nonce will result in an ErrorCall exception being thrown.

>>> let key = "don't tell anyone my secret key!"
>>> let non = "or my nonce!"
>>> let pan = "and here's my plaintext"
>>> let aad = "i approve this message"
>>> let (cip, mac) = encrypt aad key nonce pan
>>> (cip, mac)
<(ciphertext, 128-bit MAC)>

decrypt Source #

Arguments

:: ByteString

arbitrary-length AAD

-> ByteString

256-bit key

-> ByteString

96-bit nonce

-> (ByteString, ByteString)

(arbitrary-length ciphertext, 128-bit MAC)

-> Maybe ByteString 

Decrypt an authenticated ciphertext, given a message authentication code and some additional authenticated data, via a 256-bit key and 96-bit nonce.

Returns Nothing if the MAC fails to validate.

Providing an invalid key or nonce will result in an ErrorCall exception being thrown.

>>> decrypt aad key non (cip, mac)
Just "and here's my plaintext"
>>> decrypt aad key non (cip, "it's a valid mac")
Nothing