raaz-0.3.2: Fast and type safe cryptography.
Copyright(c) Piyush P Kurur 2019
LicenseApache-2.0 OR BSD-3-Clause
MaintainerPiyush P Kurur <ppk@iitpkd.ac.in>
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Interface

Description

| The interface for an aead construction using a stream cipher like chacha20 and authenticator like poly1305.

Synopsis

Locking and unlocking stuff

unsafeLock :: Encodable plain => Key Cipher -> Nounce Cipher -> plain -> Locked Source #

Generate a locked version of an unencrypted object. You will need the exact same key and nounce to unlock the object.

unlock :: Encodable plain => Key Cipher -> Locked -> Maybe plain Source #

Unlock the encrypted packet.

Additional data.

type Locked = AEAD Cipher AuthTag Source #

The locked message.

type AuthTag = Prim Source #

The associated message authenticator.

type Cipher = Prim Source #

The associated cipher.

unsafeLockWith Source #

Arguments

:: (Encodable plain, Encodable aad) 
=> aad

the authenticated additional data.

-> Key Cipher

The key for the stream cipher

-> Nounce Cipher

The nounce used by the stream cipher.

-> plain

the unencrypted object

-> Locked 

This function takes the plain text and the additional data, and constructs the associated Locked message. A peer who has the right (key, nounce) pair and the aad can recover the unencrypted object using the unlockWith function.

unlockWith Source #

Arguments

:: (Encodable plain, Encodable aad) 
=> aad

the authenticated additional data.

-> Key Cipher

The key for the stream cipher

-> Locked

The encrypted authenticated version of the data.

-> Maybe plain 

Unlock an encrypted authenticated version of the data given the additional data, key, and nounce. An attempt to unlock the element can result in Nothing if either of the following is true.

  1. The key, nounce pair used to encrypt the data is incorrect.
  2. The Authenticated additional data (aad) is incorrect.
  3. The Locked message is of the wrong type and hence the fromByteString failed.
  4. The Locked message has been tampered.

The interface provided above makes it impossible to know which of the above errors occurred. This is a deliberate design as revealing the nature of the failure can leak information to a potential attacker.

unsafeToNounce :: AEAD c t -> Nounce c #

unsafeToAuthTag :: AEAD c t -> t #

unsafeLocked :: Nounce Cipher -> ByteString -> AuthTag -> Locked Source #

Create the locked message from the associated Nounce, cipher text, and the authentication tag.

data AEADMem Source #

The internal memory used for computing the AEAD packet. When using this memory for packet computation, it is important to initalise the memory in the following order.

  1. Initialise with key either using the initialise function or, by using the WriteAccessible instance using the `mem.
  2. Initialise the nounce

We are then all set to go.

Instances

Instances details
WriteAccessible AEADMem Source # 
Instance details

Defined in Interface

Methods

writeAccess :: AEADMem -> [Access]

afterWriteAdjustment :: AEADMem -> IO ()

Memory AEADMem Source # 
Instance details

Defined in Interface

Initialisable AEADMem (Key Cipher) Source #

Initialise with the key of the cipher.

Instance details

Defined in Interface

Methods

initialise :: Key Cipher -> AEADMem -> IO ()

Initialisable AEADMem (Nounce Cipher) Source #

Initialise after the key is already initialised.

Instance details

Defined in Interface

Methods

initialise :: Nounce Cipher -> AEADMem -> IO ()