crypto-cipher-types-0.0.9: Generic cryptography cipher types

LicenseBSD-style
MaintainerVincent Hanquez <vincent@snarc.org>
StabilityStable
PortabilityExcellent
Safe HaskellNone
LanguageHaskell98

Crypto.Cipher.Types

Contents

Description

symmetric cipher basic types

Synopsis

Cipher classes

class Cipher cipher where #

Symmetric cipher class.

Minimal complete definition

cipherInit, cipherName, cipherKeySize

Methods

cipherInit :: Key cipher -> cipher #

Initialize a cipher context from a key

cipherName :: cipher -> String #

Cipher name

cipherKeySize :: cipher -> KeySizeSpecifier #

return the size of the key required for this cipher. Some cipher accept any size for key

class Cipher cipher => BlockCipher cipher where #

Symmetric block cipher class

Minimal complete definition

blockSize, ecbEncrypt, ecbDecrypt

Methods

blockSize :: cipher -> Int #

Return the size of block required for this block cipher

ecbEncrypt :: cipher -> ByteString -> ByteString #

Encrypt blocks

the input string need to be multiple of the block size

ecbDecrypt :: cipher -> ByteString -> ByteString #

Decrypt blocks

the input string need to be multiple of the block size

cbcEncrypt :: cipher -> IV cipher -> ByteString -> ByteString #

encrypt using the CBC mode.

input need to be a multiple of the blocksize

cbcDecrypt :: cipher -> IV cipher -> ByteString -> ByteString #

decrypt using the CBC mode.

input need to be a multiple of the blocksize

cfbEncrypt :: cipher -> IV cipher -> ByteString -> ByteString #

encrypt using the CFB mode.

input need to be a multiple of the blocksize

cfbDecrypt :: cipher -> IV cipher -> ByteString -> ByteString #

decrypt using the CFB mode.

input need to be a multiple of the blocksize

ctrCombine :: cipher -> IV cipher -> ByteString -> ByteString #

combine using the CTR mode.

CTR mode produce a stream of randomized data that is combined (by XOR operation) with the input stream.

encryption and decryption are the same operation.

input can be of any size

xtsEncrypt :: (cipher, cipher) -> IV cipher -> DataUnitOffset -> ByteString -> ByteString #

encrypt using the XTS mode.

input need to be a multiple of the blocksize, and the cipher need to process 128 bits block only

xtsDecrypt :: (cipher, cipher) -> IV cipher -> DataUnitOffset -> ByteString -> ByteString #

decrypt using the XTS mode.

input need to be a multiple of the blocksize, and the cipher need to process 128 bits block only

aeadInit :: Byteable iv => AEADMode -> cipher -> iv -> Maybe (AEAD cipher) #

Initialize a new AEAD State

When Nothing is returns, it means the mode is not handled.

class Cipher cipher => StreamCipher cipher where #

Symmetric stream cipher class

Minimal complete definition

streamCombine

Methods

streamCombine :: cipher -> ByteString -> (ByteString, cipher) #

Combine using the stream cipher

type DataUnitOffset = Word32 #

Offset inside an XTS data unit, measured in block size.

data KeySizeSpecifier #

Different specifier for key size in bytes

Constructors

KeySizeRange Int Int

in the range [min,max]

KeySizeEnum [Int]

one of the specified values

KeySizeFixed Int

a specific size

data KeyError #

Possible Error that can be reported when initializating a key

data AEAD cipher #

Authenticated Encryption with Associated Data algorithms

Constructors

AEAD cipher (AEADState cipher) 

data AEADState cipher #

Wrapper for any AEADState

Constructors

AEADModeImpl cipher st => AEADState st 

data AEADMode #

AEAD Mode

class BlockCipher cipher => AEADModeImpl cipher state where #

Class of AEAD Mode implementation

Methods

aeadStateAppendHeader :: cipher -> state -> ByteString -> state #

aeadStateEncrypt :: cipher -> state -> ByteString -> (ByteString, state) #

aeadStateDecrypt :: cipher -> state -> ByteString -> (ByteString, state) #

aeadStateFinalize :: cipher -> state -> Int -> AuthTag #

cfb8Encrypt :: BlockCipher a => a -> IV a -> ByteString -> ByteString #

Encrypt using CFB mode in 8 bit output

Effectively turn a Block cipher in CFB mode into a Stream cipher

cfb8Decrypt :: BlockCipher a => a -> IV a -> ByteString -> ByteString #

Decrypt using CFB mode in 8 bit output

Effectively turn a Block cipher in CFB mode into a Stream cipher

AEAD functions

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

aeadSimpleEncrypt #

Arguments

:: BlockCipher a 
=> AEAD a

A new AEAD Context

-> ByteString

Optional Authentified Header

-> ByteString

Optional Plaintext

-> Int

Tag length

-> (AuthTag, ByteString)

Authentification tag and ciphertext

Simple AEAD encryption

aeadSimpleDecrypt #

Arguments

:: BlockCipher a 
=> AEAD a

A new AEAD Context

-> ByteString

Optional Authentified Header

-> ByteString

Optional Plaintext

-> AuthTag

Tag length

-> Maybe ByteString

Plaintext

Simple AEAD decryption

Key type and constructor

data Key c #

a Key parametrized by the cipher

Instances

Eq (Key c) # 

Methods

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

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

Byteable (Key c) # 

Methods

toBytes :: Key c -> ByteString #

byteableLength :: Key c -> Int #

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

ToSecureMem (Key c) # 

Methods

toSecureMem :: Key c -> SecureMem #

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

Create a Key for a specified cipher

Initial Vector type and constructor

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.

Authentification Tag

newtype AuthTag #

Authentification Tag for AE cipher mode

Constructors

AuthTag ByteString