ppad-aead-0.3.1: 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

-> Either Error (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.

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

-> Either Error ByteString 

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

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

Error information

data Error Source #

Error values.

Constructors

InvalidKey

the provided key was not 256 bits long

InvalidNonce

the provided nonce was not 96 bits long

InvalidMAC

the provided MAC does not authenticate the ciphertext

Instances

Instances details
Show Error Source # 
Instance details

Defined in Crypto.AEAD.ChaCha20Poly1305

Methods

showsPrec :: Int -> Error -> ShowS #

show :: Error -> String #

showList :: [Error] -> ShowS #

Eq Error Source # 
Instance details

Defined in Crypto.AEAD.ChaCha20Poly1305

Methods

(==) :: Error -> Error -> Bool #

(/=) :: Error -> Error -> Bool #