cryptocipher-0.6.2: Symmetrical block and stream ciphers.

LicenseBSD-style
MaintainerVincent Hanquez <vincent@snarc.org>
Stabilitystable
Portabilitygood
Safe HaskellNone
LanguageHaskell98

Crypto.Cipher

Contents

Description

All the cipher functionalities are available through the BlockCipher and StreamCipher classes.

A simplified example (with simplified error handling):

import Crypto.Cipher
import Data.ByteString (ByteString)
import qualified Data.ByteString as B

initAES256 :: ByteString -> AES256
initAES256 = either (error . show) cipherInit . makeKey

cbcEncryption :: AES256 -> ByteString -> ByteString -> ByteString
cbcEncryption ctx ivRaw plainText = cbcEncrypt ctx iv plainText
  where iv = maybe (error "invalid IV") id $ ivRaw

Synopsis

Cipher classes

class Cipher cipher where #

Symmetric cipher class.

Instances

Cipher AES 
Cipher AES128 
Cipher AES192 
Cipher AES256 
Cipher Blowfish 
Cipher Blowfish64 
Cipher Blowfish128 
Cipher Blowfish256 
Cipher Blowfish448 
Cipher Camellia128 
Cipher DES 
Cipher DES_EEE3 
Cipher DES_EDE3 
Cipher DES_EEE2 
Cipher DES_EDE2 

class Cipher cipher => BlockCipher cipher where #

Symmetric block cipher class

Minimal complete definition

blockSize, ecbEncrypt, ecbDecrypt

Instances

BlockCipher AES 
BlockCipher AES128 
BlockCipher AES192 
BlockCipher AES256 
BlockCipher Blowfish 
BlockCipher Blowfish64 
BlockCipher Blowfish128 
BlockCipher Blowfish256 
BlockCipher Blowfish448 
BlockCipher Camellia128 
BlockCipher DES 
BlockCipher DES_EEE3 
BlockCipher DES_EDE3 
BlockCipher DES_EEE2 
BlockCipher DES_EDE2 

class Cipher cipher => StreamCipher cipher where #

Symmetric stream cipher class

Key

data Key c :: * -> * #

a Key parametrized by the cipher

Instances

Eq (Key c) 

Methods

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

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

ToSecureMem (Key c) 

Methods

toSecureMem :: Key c -> SecureMem

Byteable (Key c) 

Methods

toBytes :: Key c -> ByteString

byteableLength :: Key c -> Int

withBytePtr :: Key c -> (Ptr Word8 -> IO b) -> IO b

makeKey :: (ToSecureMem b, Cipher c) => b -> Either KeyError (Key c) #

Create a Key for a specified cipher

Initialization Vector (IV)

data IV c :: * -> * #

an IV parametrized by the cipher

Instances

Eq (IV c) 

Methods

(==) :: IV c -> IV c -> Bool #

(/=) :: IV c -> IV c -> Bool #

Byteable (IV c) 

Methods

toBytes :: IV c -> ByteString

byteableLength :: IV c -> Int

withBytePtr :: IV c -> (Ptr Word8 -> IO b) -> IO b

makeIV :: (Byteable b, BlockCipher c) => b -> Maybe (IV c) #

Create an IV for a specified block cipher

nullIV :: BlockCipher c => IV c #

Create an IV that is effectively representing the number 0

ivAdd :: BlockCipher c => IV c -> Int -> IV c #

Increment an IV by a number.

Assume the IV is in Big Endian format.

Authenticated Encryption with Associated Data (AEAD)

data AEAD cipher :: * -> * #

Authenticated Encryption with Associated Data algorithms

aeadAppendHeader :: BlockCipher a => AEAD a -> ByteString -> AEAD a #

Append associated data into the AEAD state

aeadEncrypt :: BlockCipher a => AEAD a -> ByteString -> (ByteString, AEAD a) #

Encrypt input and append into the AEAD state

aeadDecrypt :: BlockCipher a => AEAD a -> ByteString -> (ByteString, AEAD a) #

Decrypt input and append into the AEAD state

aeadFinalize :: BlockCipher a => AEAD a -> Int -> AuthTag #

Finalize the AEAD state and create an authentification tag

Cipher implementations

data AES128 :: * #

AES with 128 bit key

data AES192 :: * #

AES with 192 bit key

data AES256 :: * #

AES with 256 bit key