saltine-0.1.0.0: Cryptography that's easy to digest (NaCl/libsodium bindings).

Copyright(c) Thomas DuBuisson 2017
LicenseMIT
Maintainerme@jspha.com
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Crypto.Saltine.Core.AEAD

Description

Secret-key authenticated encryption with additional data (AEAD): Crypto.Saltine.Core.AEAD

The aead function encrypts and authenticates a message ByteString and additional authenticated data ByteString using a secret key and a nonce. The aeadOpen function verifies and decrypts a ciphertext ByteString using a secret key and a nonce. If the ciphertext fails validation, aeadOpen returns Nothing.

The Crypto.Saltine.Core.AEAD module is designed to meet the standard notions of privacy and authenticity for a secret-key authenticated-encryption scheme using nonces. For formal definitions see, e.g., Bellare and Namprempre, "Authenticated encryption: relations among notions and analysis of the generic composition paradigm," Lecture Notes in Computer Science 1976 (2000), 531–545, http://www-cse.ucsd.edu/~mihir/papers/oem.html.

Note that the length is not hidden. Note also that it is the caller's responsibility to ensure the uniqueness of nonces—for example, by using nonce 1 for the first message, nonce 2 for the second message, etc. Nonces are long enough that randomly generated nonces have negligible risk of collision.

Synopsis

Documentation

data Key Source #

An opaque secretbox cryptographic key.

Instances

Eq Key Source # 

Methods

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

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

Ord Key Source # 

Methods

compare :: Key -> Key -> Ordering #

(<) :: Key -> Key -> Bool #

(<=) :: Key -> Key -> Bool #

(>) :: Key -> Key -> Bool #

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

max :: Key -> Key -> Key #

min :: Key -> Key -> Key #

IsEncoding Key Source # 

data Nonce Source #

An opaque secretbox nonce.

aead Source #

Arguments

:: Key 
-> Nonce 
-> ByteString

Message

-> ByteString

AAD

-> ByteString

Ciphertext

Encrypts a message. It is infeasible for an attacker to decrypt the message so long as the Nonce is never repeated.

aeadOpen Source #

Arguments

:: Key 
-> Nonce 
-> ByteString

Ciphertext

-> ByteString

AAD

-> Maybe ByteString

Message

Decrypts a message. Returns Nothing if the keys and message do not match.

aeadDetached Source #

Arguments

:: Key 
-> Nonce 
-> ByteString

Message

-> ByteString

AAD

-> (ByteString, ByteString)

Tag, Ciphertext

Encrypts a message. It is infeasible for an attacker to decrypt the message so long as the Nonce is never repeated.

aeadOpenDetached Source #

Arguments

:: Key 
-> Nonce 
-> ByteString

Tag

-> ByteString

Ciphertext

-> ByteString

AAD

-> Maybe ByteString

Message

Decrypts a message. Returns Nothing if the keys and message do not match.

newKey :: IO Key Source #

Creates a random key of the correct size for secretbox.

newNonce :: IO Nonce Source #

Creates a random nonce of the correct size for secretbox.