crypton-0.32: Cryptography Primitives sink
LicenseBSD-style
MaintainerVincent Hanquez <vincent@snarc.org>
StabilityStable
PortabilityExcellent
Safe HaskellSafe-Inferred
LanguageHaskell2010

Crypto.Cipher.Types

Description

Symmetric cipher basic types

Synopsis

Cipher classes

class Cipher cipher where Source #

Symmetric cipher class.

Methods

cipherInit :: ByteArray key => key -> CryptoFailable cipher Source #

Initialize a cipher context from a key

cipherName :: cipher -> String Source #

Cipher name

cipherKeySize :: cipher -> KeySizeSpecifier Source #

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

Instances

Instances details
Cipher AES128 Source # 
Instance details

Defined in Crypto.Cipher.AES

Cipher AES192 Source # 
Instance details

Defined in Crypto.Cipher.AES

Cipher AES256 Source # 
Instance details

Defined in Crypto.Cipher.AES

Cipher Blowfish Source # 
Instance details

Defined in Crypto.Cipher.Blowfish

Cipher Blowfish128 Source # 
Instance details

Defined in Crypto.Cipher.Blowfish

Cipher Blowfish256 Source # 
Instance details

Defined in Crypto.Cipher.Blowfish

Cipher Blowfish448 Source # 
Instance details

Defined in Crypto.Cipher.Blowfish

Cipher Blowfish64 Source # 
Instance details

Defined in Crypto.Cipher.Blowfish

Cipher CAST5 Source # 
Instance details

Defined in Crypto.Cipher.CAST5

Cipher Camellia128 Source # 
Instance details

Defined in Crypto.Cipher.Camellia

Cipher DES Source # 
Instance details

Defined in Crypto.Cipher.DES

Cipher DES_EDE2 Source # 
Instance details

Defined in Crypto.Cipher.TripleDES

Cipher DES_EDE3 Source # 
Instance details

Defined in Crypto.Cipher.TripleDES

Cipher DES_EEE2 Source # 
Instance details

Defined in Crypto.Cipher.TripleDES

Cipher DES_EEE3 Source # 
Instance details

Defined in Crypto.Cipher.TripleDES

Cipher Twofish128 Source # 
Instance details

Defined in Crypto.Cipher.Twofish

Cipher Twofish192 Source # 
Instance details

Defined in Crypto.Cipher.Twofish

Cipher Twofish256 Source # 
Instance details

Defined in Crypto.Cipher.Twofish

class Cipher cipher => BlockCipher cipher where Source #

Symmetric block cipher class

Minimal complete definition

blockSize, ecbEncrypt, ecbDecrypt

Methods

blockSize :: cipher -> Int Source #

Return the size of block required for this block cipher

ecbEncrypt :: ByteArray ba => cipher -> ba -> ba Source #

Encrypt blocks

the input string need to be multiple of the block size

ecbDecrypt :: ByteArray ba => cipher -> ba -> ba Source #

Decrypt blocks

the input string need to be multiple of the block size

cbcEncrypt :: ByteArray ba => cipher -> IV cipher -> ba -> ba Source #

encrypt using the CBC mode.

input need to be a multiple of the blocksize

cbcDecrypt :: ByteArray ba => cipher -> IV cipher -> ba -> ba Source #

decrypt using the CBC mode.

input need to be a multiple of the blocksize

cfbEncrypt :: ByteArray ba => cipher -> IV cipher -> ba -> ba Source #

encrypt using the CFB mode.

input need to be a multiple of the blocksize

cfbDecrypt :: ByteArray ba => cipher -> IV cipher -> ba -> ba Source #

decrypt using the CFB mode.

input need to be a multiple of the blocksize

ctrCombine :: ByteArray ba => cipher -> IV cipher -> ba -> ba Source #

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

aeadInit :: ByteArrayAccess iv => AEADMode -> cipher -> iv -> CryptoFailable (AEAD cipher) Source #

Initialize a new AEAD State

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

Instances

Instances details
BlockCipher AES128 Source # 
Instance details

Defined in Crypto.Cipher.AES

Methods

blockSize :: AES128 -> Int Source #

ecbEncrypt :: ByteArray ba => AES128 -> ba -> ba Source #

ecbDecrypt :: ByteArray ba => AES128 -> ba -> ba Source #

cbcEncrypt :: ByteArray ba => AES128 -> IV AES128 -> ba -> ba Source #

cbcDecrypt :: ByteArray ba => AES128 -> IV AES128 -> ba -> ba Source #

cfbEncrypt :: ByteArray ba => AES128 -> IV AES128 -> ba -> ba Source #

cfbDecrypt :: ByteArray ba => AES128 -> IV AES128 -> ba -> ba Source #

ctrCombine :: ByteArray ba => AES128 -> IV AES128 -> ba -> ba Source #

aeadInit :: ByteArrayAccess iv => AEADMode -> AES128 -> iv -> CryptoFailable (AEAD AES128) Source #

BlockCipher AES192 Source # 
Instance details

Defined in Crypto.Cipher.AES

Methods

blockSize :: AES192 -> Int Source #

ecbEncrypt :: ByteArray ba => AES192 -> ba -> ba Source #

ecbDecrypt :: ByteArray ba => AES192 -> ba -> ba Source #

cbcEncrypt :: ByteArray ba => AES192 -> IV AES192 -> ba -> ba Source #

cbcDecrypt :: ByteArray ba => AES192 -> IV AES192 -> ba -> ba Source #

cfbEncrypt :: ByteArray ba => AES192 -> IV AES192 -> ba -> ba Source #

cfbDecrypt :: ByteArray ba => AES192 -> IV AES192 -> ba -> ba Source #

ctrCombine :: ByteArray ba => AES192 -> IV AES192 -> ba -> ba Source #

aeadInit :: ByteArrayAccess iv => AEADMode -> AES192 -> iv -> CryptoFailable (AEAD AES192) Source #

BlockCipher AES256 Source # 
Instance details

Defined in Crypto.Cipher.AES

Methods

blockSize :: AES256 -> Int Source #

ecbEncrypt :: ByteArray ba => AES256 -> ba -> ba Source #

ecbDecrypt :: ByteArray ba => AES256 -> ba -> ba Source #

cbcEncrypt :: ByteArray ba => AES256 -> IV AES256 -> ba -> ba Source #

cbcDecrypt :: ByteArray ba => AES256 -> IV AES256 -> ba -> ba Source #

cfbEncrypt :: ByteArray ba => AES256 -> IV AES256 -> ba -> ba Source #

cfbDecrypt :: ByteArray ba => AES256 -> IV AES256 -> ba -> ba Source #

ctrCombine :: ByteArray ba => AES256 -> IV AES256 -> ba -> ba Source #

aeadInit :: ByteArrayAccess iv => AEADMode -> AES256 -> iv -> CryptoFailable (AEAD AES256) Source #

BlockCipher Blowfish Source # 
Instance details

Defined in Crypto.Cipher.Blowfish

BlockCipher Blowfish128 Source # 
Instance details

Defined in Crypto.Cipher.Blowfish

BlockCipher Blowfish256 Source # 
Instance details

Defined in Crypto.Cipher.Blowfish

BlockCipher Blowfish448 Source # 
Instance details

Defined in Crypto.Cipher.Blowfish

BlockCipher Blowfish64 Source # 
Instance details

Defined in Crypto.Cipher.Blowfish

BlockCipher CAST5 Source # 
Instance details

Defined in Crypto.Cipher.CAST5

Methods

blockSize :: CAST5 -> Int Source #

ecbEncrypt :: ByteArray ba => CAST5 -> ba -> ba Source #

ecbDecrypt :: ByteArray ba => CAST5 -> ba -> ba Source #

cbcEncrypt :: ByteArray ba => CAST5 -> IV CAST5 -> ba -> ba Source #

cbcDecrypt :: ByteArray ba => CAST5 -> IV CAST5 -> ba -> ba Source #

cfbEncrypt :: ByteArray ba => CAST5 -> IV CAST5 -> ba -> ba Source #

cfbDecrypt :: ByteArray ba => CAST5 -> IV CAST5 -> ba -> ba Source #

ctrCombine :: ByteArray ba => CAST5 -> IV CAST5 -> ba -> ba Source #

aeadInit :: ByteArrayAccess iv => AEADMode -> CAST5 -> iv -> CryptoFailable (AEAD CAST5) Source #

BlockCipher Camellia128 Source # 
Instance details

Defined in Crypto.Cipher.Camellia

BlockCipher DES Source # 
Instance details

Defined in Crypto.Cipher.DES

Methods

blockSize :: DES -> Int Source #

ecbEncrypt :: ByteArray ba => DES -> ba -> ba Source #

ecbDecrypt :: ByteArray ba => DES -> ba -> ba Source #

cbcEncrypt :: ByteArray ba => DES -> IV DES -> ba -> ba Source #

cbcDecrypt :: ByteArray ba => DES -> IV DES -> ba -> ba Source #

cfbEncrypt :: ByteArray ba => DES -> IV DES -> ba -> ba Source #

cfbDecrypt :: ByteArray ba => DES -> IV DES -> ba -> ba Source #

ctrCombine :: ByteArray ba => DES -> IV DES -> ba -> ba Source #

aeadInit :: ByteArrayAccess iv => AEADMode -> DES -> iv -> CryptoFailable (AEAD DES) Source #

BlockCipher DES_EDE2 Source # 
Instance details

Defined in Crypto.Cipher.TripleDES

BlockCipher DES_EDE3 Source # 
Instance details

Defined in Crypto.Cipher.TripleDES

BlockCipher DES_EEE2 Source # 
Instance details

Defined in Crypto.Cipher.TripleDES

BlockCipher DES_EEE3 Source # 
Instance details

Defined in Crypto.Cipher.TripleDES

BlockCipher Twofish128 Source # 
Instance details

Defined in Crypto.Cipher.Twofish

BlockCipher Twofish192 Source # 
Instance details

Defined in Crypto.Cipher.Twofish

BlockCipher Twofish256 Source # 
Instance details

Defined in Crypto.Cipher.Twofish

class BlockCipher cipher => BlockCipher128 cipher where Source #

class of block cipher with a 128 bits block size

Minimal complete definition

Nothing

Methods

xtsEncrypt Source #

Arguments

:: ByteArray ba 
=> (cipher, cipher) 
-> IV cipher

Usually represent the Data Unit (e.g. disk sector)

-> DataUnitOffset

Offset in the data unit in number of blocks

-> ba

Plaintext

-> ba

Ciphertext

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 Source #

Arguments

:: ByteArray ba 
=> (cipher, cipher) 
-> IV cipher

Usually represent the Data Unit (e.g. disk sector)

-> DataUnitOffset

Offset in the data unit in number of blocks

-> ba

Ciphertext

-> ba

Plaintext

decrypt using the XTS mode.

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

Instances

Instances details
BlockCipher128 AES128 Source # 
Instance details

Defined in Crypto.Cipher.AES

Methods

xtsEncrypt :: ByteArray ba => (AES128, AES128) -> IV AES128 -> DataUnitOffset -> ba -> ba Source #

xtsDecrypt :: ByteArray ba => (AES128, AES128) -> IV AES128 -> DataUnitOffset -> ba -> ba Source #

BlockCipher128 AES192 Source # 
Instance details

Defined in Crypto.Cipher.AES

Methods

xtsEncrypt :: ByteArray ba => (AES192, AES192) -> IV AES192 -> DataUnitOffset -> ba -> ba Source #

xtsDecrypt :: ByteArray ba => (AES192, AES192) -> IV AES192 -> DataUnitOffset -> ba -> ba Source #

BlockCipher128 AES256 Source # 
Instance details

Defined in Crypto.Cipher.AES

Methods

xtsEncrypt :: ByteArray ba => (AES256, AES256) -> IV AES256 -> DataUnitOffset -> ba -> ba Source #

xtsDecrypt :: ByteArray ba => (AES256, AES256) -> IV AES256 -> DataUnitOffset -> ba -> ba Source #

class Cipher cipher => StreamCipher cipher where Source #

Symmetric stream cipher class

Methods

streamCombine :: ByteArray ba => cipher -> ba -> (ba, cipher) Source #

Combine using the stream cipher

type DataUnitOffset = Word32 Source #

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

data KeySizeSpecifier Source #

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

AEAD functions

data AEADMode Source #

AEAD Mode

Instances

Instances details
Show AEADMode Source # 
Instance details

Defined in Crypto.Cipher.Types.Base

Eq AEADMode Source # 
Instance details

Defined in Crypto.Cipher.Types.Base

data CCM_M Source #

Instances

Instances details
Show CCM_M Source # 
Instance details

Defined in Crypto.Cipher.Types.Base

Methods

showsPrec :: Int -> CCM_M -> ShowS #

show :: CCM_M -> String #

showList :: [CCM_M] -> ShowS #

Eq CCM_M Source # 
Instance details

Defined in Crypto.Cipher.Types.Base

Methods

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

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

data CCM_L Source #

Constructors

CCM_L2 
CCM_L3 
CCM_L4 

Instances

Instances details
Show CCM_L Source # 
Instance details

Defined in Crypto.Cipher.Types.Base

Methods

showsPrec :: Int -> CCM_L -> ShowS #

show :: CCM_L -> String #

showList :: [CCM_L] -> ShowS #

Eq CCM_L Source # 
Instance details

Defined in Crypto.Cipher.Types.Base

Methods

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

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

data AEADModeImpl st Source #

AEAD Implementation

Constructors

AEADModeImpl 

Fields

data AEAD cipher Source #

Authenticated Encryption with Associated Data algorithms

Constructors

forall st. AEAD 

Fields

aeadAppendHeader :: ByteArrayAccess aad => AEAD cipher -> aad -> AEAD cipher Source #

Append some header information to an AEAD context

aeadEncrypt :: ByteArray ba => AEAD cipher -> ba -> (ba, AEAD cipher) Source #

Encrypt some data and update the AEAD context

aeadDecrypt :: ByteArray ba => AEAD cipher -> ba -> (ba, AEAD cipher) Source #

Decrypt some data and update the AEAD context

aeadFinalize :: AEAD cipher -> Int -> AuthTag Source #

Finalize the AEAD context and return the authentication tag

aeadSimpleEncrypt Source #

Arguments

:: (ByteArrayAccess aad, ByteArray ba) 
=> AEAD a

A new AEAD Context

-> aad

Optional Authentication data header

-> ba

Optional Plaintext

-> Int

Tag length

-> (AuthTag, ba)

Authentication tag and ciphertext

Simple AEAD encryption

aeadSimpleDecrypt Source #

Arguments

:: (ByteArrayAccess aad, ByteArray ba) 
=> AEAD a

A new AEAD Context

-> aad

Optional Authentication data header

-> ba

Ciphertext

-> AuthTag

The authentication tag

-> Maybe ba

Plaintext

Simple AEAD decryption

Initial Vector type and constructor

data IV c Source #

an IV parametrized by the cipher

Instances

Instances details
Eq (IV c) Source # 
Instance details

Defined in Crypto.Cipher.Types.Block

Methods

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

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

BlockCipher c => ByteArrayAccess (IV c) Source # 
Instance details

Defined in Crypto.Cipher.Types.Block

Methods

length :: IV c -> Int #

withByteArray :: IV c -> (Ptr p -> IO a) -> IO a #

copyByteArrayToPtr :: IV c -> Ptr p -> IO () #

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

Create an IV for a specified block cipher

nullIV :: BlockCipher c => IV c Source #

Create an IV that is effectively representing the number 0

ivAdd :: IV c -> Int -> IV c Source #

Increment an IV by a number.

Assume the IV is in Big Endian format.

Authentification Tag

newtype AuthTag Source #

Authentication Tag for AE cipher mode

Constructors

AuthTag 

Fields

Instances

Instances details
Show AuthTag Source # 
Instance details

Defined in Crypto.Cipher.Types.Base

NFData AuthTag Source # 
Instance details

Defined in Crypto.Cipher.Types.Base

Methods

rnf :: AuthTag -> () #

Eq AuthTag Source # 
Instance details

Defined in Crypto.Cipher.Types.Base

Methods

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

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

ByteArrayAccess AuthTag Source # 
Instance details

Defined in Crypto.Cipher.Types.Base

Methods

length :: AuthTag -> Int #

withByteArray :: AuthTag -> (Ptr p -> IO a) -> IO a #

copyByteArrayToPtr :: AuthTag -> Ptr p -> IO () #