cipher-aes-0.2.6: Fast AES cipher implementation with advanced mode of operations

Portabilitygood
Stabilitystable
MaintainerVincent Hanquez <vincent@snarc.org>
Safe HaskellNone

Crypto.Cipher.AES

Contents

Description

 

Synopsis

block cipher data types

data AES Source

AES Context (pre-processed key)

data AES128 Source

AES with 128 bit key

data AES192 Source

AES with 192 bit key

data AES256 Source

AES with 256 bit key

Authenticated encryption block cipher types

creation

initAES :: Byteable b => b -> AESSource

Initialize a new context with a key

Key need to be of length 16, 24 or 32 bytes. any other values will cause undefined behavior

initKey :: Byteable b => b -> AESSource

Deprecated: use initAES

misc

genCTRSource

Arguments

:: Byteable iv 
=> AES

Cipher Key.

-> iv

usually a 128 bit integer.

-> Int

length of bytes required.

-> ByteString 

generate a counter mode pad. this is generally xor-ed to an input to make the standard counter mode block operations.

if the length requested is not a multiple of the block cipher size, more data will be returned, so that the returned bytestring is a multiple of the block cipher size.

encryption

encryptECB :: AES -> ByteString -> ByteStringSource

encrypt using Electronic Code Book (ECB)

encryptCBCSource

Arguments

:: Byteable iv 
=> AES

AES Context

-> iv

Initial vector

-> ByteString

plaintext

-> ByteString

ciphertext

encrypt using Cipher Block Chaining (CBC)

encryptCTRSource

Arguments

:: Byteable iv 
=> AES

AES Context

-> iv

initial vector, usually representing a 128 bit integer

-> ByteString

plaintext input

-> ByteString

ciphertext output

encrypt using Counter mode (CTR)

in CTR mode encryption and decryption is the same operation.

encryptXTSSource

Arguments

:: Byteable iv 
=> (AES, AES)

AES cipher and tweak context

-> iv

a 128 bits IV, typically a sector or a block offset in XTS

-> Word32

number of rounds to skip, also seen a 16 byte offset in the sector or block.

-> ByteString

input to encrypt

-> ByteString

output encrypted

encrypt using XTS

the first key is the normal block encryption key the second key is used for the initial block tweak

encryptGCMSource

Arguments

:: Byteable iv 
=> AES

AES Context

-> iv

IV initial vector of any size

-> ByteString

data to authenticate (AAD)

-> ByteString

data to encrypt

-> (ByteString, AuthTag)

ciphertext and tag

encrypt using Galois counter mode (GCM) return the encrypted bytestring and the tag associated

note: encrypted data is identical to CTR mode in GCM, however a tag is also computed.

decryption

decryptECB :: AES -> ByteString -> ByteStringSource

decrypt using Electronic Code Book (ECB)

decryptCBC :: Byteable iv => AES -> iv -> ByteString -> ByteStringSource

decrypt using Cipher block chaining (CBC)

decryptCTRSource

Arguments

:: Byteable iv 
=> AES

AES Context

-> iv

initial vector, usually representing a 128 bit integer

-> ByteString

ciphertext input

-> ByteString

plaintext output

decrypt using Counter mode (CTR).

in CTR mode encryption and decryption is the same operation.

decryptXTSSource

Arguments

:: Byteable iv 
=> (AES, AES)

AES cipher and tweak context

-> iv

a 128 bits IV, typically a sector or a block offset in XTS

-> Word32

number of rounds to skip, also seen a 16 byte offset in the sector or block.

-> ByteString

input to decrypt

-> ByteString

output decrypted

decrypt using XTS

decryptGCMSource

Arguments

:: Byteable iv 
=> AES

Key

-> iv

IV initial vector of any size

-> ByteString

data to authenticate (AAD)

-> ByteString

data to decrypt

-> (ByteString, AuthTag)

plaintext and tag

decrypt using Galois Counter Mode (GCM)