Copyright | (c) Piyush P Kurur 2019 |
---|---|
License | Apache-2.0 OR BSD-3-Clause |
Maintainer | Piyush P Kurur <ppk@iitpkd.ac.in> |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
| The interface for an aead construction using a stream cipher like chacha20 and authenticator like poly1305.
Synopsis
- unsafeLock :: Encodable plain => Key Cipher -> Nounce Cipher -> plain -> Locked
- unlock :: Encodable plain => Key Cipher -> Locked -> Maybe plain
- type Locked = AEAD Cipher AuthTag
- type AuthTag = Prim
- type Cipher = Prim
- unsafeLockWith :: (Encodable plain, Encodable aad) => aad -> Key Cipher -> Nounce Cipher -> plain -> Locked
- unlockWith :: (Encodable plain, Encodable aad) => aad -> Key Cipher -> Locked -> Maybe plain
- unsafeToNounce :: AEAD c t -> Nounce c
- unsafeToCipherText :: AEAD c t -> ByteString
- unsafeToAuthTag :: AEAD c t -> t
- unsafeLocked :: Nounce Cipher -> ByteString -> AuthTag -> Locked
- data AEADMem
- name :: String
- description :: String
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.
:: (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.
:: (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.
- The key, nounce pair used to encrypt the data is incorrect.
- The Authenticated additional data (
aad
) is incorrect. - The Locked message is of the wrong type and hence the
fromByteString
failed. - 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 #
unsafeToCipherText :: AEAD c t -> ByteString #
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.
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.
- Initialise with key either using the
initialise
function or, by using theWriteAccessible
instance using the `mem. - Initialise the nounce
We are then all set to go.
Instances
WriteAccessible AEADMem Source # | |
Defined in Interface writeAccess :: AEADMem -> [Access] afterWriteAdjustment :: AEADMem -> IO () | |
Memory AEADMem Source # | |
Defined in Interface memoryAlloc :: Alloc AEADMem unsafeToPointer :: AEADMem -> Ptr Word8 | |
Initialisable AEADMem (Key Cipher) Source # | Initialise with the key of the cipher. |
Defined in Interface initialise :: Key Cipher -> AEADMem -> IO () | |
Initialisable AEADMem (Nounce Cipher) Source # | Initialise after the key is already initialised. |
Defined in Interface initialise :: Nounce Cipher -> AEADMem -> IO () |
description :: String Source #