| License | BSD-style |
|---|---|
| Maintainer | Vincent Hanquez <vincent@snarc.org> |
| Stability | Stable |
| Portability | Excellent |
| Safe Haskell | None |
| Language | Haskell2010 |
Crypto.Cipher.Types
Description
Symmetric cipher basic types
Synopsis
- class Cipher cipher where
- cipherInit :: ByteArray key => key -> CryptoFailable cipher
- cipherName :: cipher -> String
- cipherKeySize :: cipher -> KeySizeSpecifier
- class Cipher cipher => BlockCipher cipher where
- blockSize :: cipher -> Int
- ecbEncrypt :: ByteArray ba => cipher -> ba -> ba
- ecbDecrypt :: ByteArray ba => cipher -> ba -> ba
- cbcEncrypt :: ByteArray ba => cipher -> IV cipher -> ba -> ba
- cbcDecrypt :: ByteArray ba => cipher -> IV cipher -> ba -> ba
- cfbEncrypt :: ByteArray ba => cipher -> IV cipher -> ba -> ba
- cfbDecrypt :: ByteArray ba => cipher -> IV cipher -> ba -> ba
- ctrCombine :: ByteArray ba => cipher -> IV cipher -> ba -> ba
- aeadInit :: ByteArrayAccess iv => AEADMode -> cipher -> iv -> CryptoFailable (AEAD cipher)
- class BlockCipher cipher => BlockCipher128 cipher where
- xtsEncrypt :: ByteArray ba => (cipher, cipher) -> IV cipher -> DataUnitOffset -> ba -> ba
- xtsDecrypt :: ByteArray ba => (cipher, cipher) -> IV cipher -> DataUnitOffset -> ba -> ba
- class Cipher cipher => StreamCipher cipher where
- streamCombine :: ByteArray ba => cipher -> ba -> (ba, cipher)
- type DataUnitOffset = Word32
- data KeySizeSpecifier
- = KeySizeRange Int Int
- | KeySizeEnum [Int]
- | KeySizeFixed Int
- data AEADMode
- data CCM_M
- data CCM_L
- minimumTagLength :: Int
- data AEAD cipher = AEAD {
- aeadModeImpl :: AEADModeImpl st
- aeadState :: !st
- data AEADModeImpl st = AEADModeImpl {
- aeadImplAppendHeader :: forall ba. ByteArrayAccess ba => st -> ba -> st
- aeadImplEncrypt :: forall ba. ByteArray ba => st -> ba -> (ba, st)
- aeadImplDecrypt :: forall ba. ByteArray ba => st -> ba -> (ba, st)
- aeadImplFinalize :: st -> Int -> AuthTag
- aeadAppendHeader :: ByteArrayAccess aad => AEAD cipher -> aad -> AEAD cipher
- aeadEncrypt :: ByteArray ba => AEAD cipher -> ba -> (ba, AEAD cipher)
- aeadDecrypt :: ByteArray ba => AEAD cipher -> ba -> (ba, AEAD cipher)
- aeadFinalize :: AEAD cipher -> Int -> AuthTag
- aeadSimpleEncrypt :: (ByteArrayAccess aad, ByteArray ba) => AEAD a -> aad -> ba -> Int -> (AuthTag, ba)
- aeadSimpleDecrypt :: (ByteArrayAccess aad, ByteArray ba) => AEAD a -> aad -> ba -> AuthTag -> Maybe ba
- tryAeadSimpleDecrypt :: (ByteArrayAccess aad, ByteArray ba) => AEAD a -> aad -> ba -> Int -> AuthTag -> Maybe ba
- data IV c
- makeIV :: (ByteArrayAccess b, BlockCipher c) => b -> Maybe (IV c)
- nullIV :: BlockCipher c => IV c
- ivAdd :: IV c -> Int -> IV c
- newtype AuthTag = AuthTag {}
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
class Cipher cipher => BlockCipher cipher where Source #
Symmetric block cipher class
Minimal complete definition
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
class BlockCipher cipher => BlockCipher128 cipher where Source #
class of block cipher with a 128 bits block size
Minimal complete definition
Nothing
Methods
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
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
| BlockCipher128 AES128 Source # | |
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 # | |
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 # | |
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 |
Instances
| Show KeySizeSpecifier Source # | |
Defined in Crypto.Cipher.Types.Base Methods showsPrec :: Int -> KeySizeSpecifier -> ShowS # show :: KeySizeSpecifier -> String # showList :: [KeySizeSpecifier] -> ShowS # | |
| Eq KeySizeSpecifier Source # | |
Defined in Crypto.Cipher.Types.Base Methods (==) :: KeySizeSpecifier -> KeySizeSpecifier -> Bool # (/=) :: KeySizeSpecifier -> KeySizeSpecifier -> Bool # | |
AEAD functions
minimumTagLength :: Int Source #
The shortest authentication tag any mode here produces, four bytes
(CCM_M4). Modes that truncate their tag -- GCM and OCB3 -- will
compute one of whatever length they are asked for, down to nothing, so
aeadSimpleDecrypt refuses a shorter tag than this rather than
authenticate fewer bytes than any supported mode ever emits.
Algorithm and context for AEAD(Authenticated Encryption with Associated/Additional Data)
Constructors
| AEAD | |
Fields
| |
data AEADModeImpl st Source #
AEAD Implementation
Constructors
| AEADModeImpl | |
Fields
| |
aeadAppendHeader :: ByteArrayAccess aad => AEAD cipher -> aad -> AEAD cipher Source #
Adding associated/additional data to the AEAD context.
aeadEncrypt :: ByteArray ba => AEAD cipher -> ba -> (ba, AEAD cipher) Source #
Encrypting plaintext and update the AEAD context.
aeadDecrypt :: ByteArray ba => AEAD cipher -> ba -> (ba, AEAD cipher) Source #
Decrypting ciphertext and update the AEAD context.
aeadFinalize :: AEAD cipher -> Int -> AuthTag Source #
Finalizing the AEAD context and returning the authentication tag.
Arguments
| :: (ByteArrayAccess aad, ByteArray ba) | |
| => AEAD a | An AEAD Context |
| -> aad | Associated/additional data |
| -> ba | Plaintext |
| -> Int | Tag length |
| -> (AuthTag, ba) | Authentication tag and ciphertext |
Simple AEAD encryption.
Arguments
| :: (ByteArrayAccess aad, ByteArray ba) | |
| => AEAD a | An AEAD Context |
| -> aad | Associated/additional data |
| -> ba | Ciphertext |
| -> AuthTag | The authentication tag |
| -> Maybe ba | Plaintext |
Simple AEAD decryptio.
The number of bytes compared is the length of authTag. That is the
caller's choice of tag length, so a caller reading a tag off the wire
must check its length against the one it expects: passing an
attacker-supplied tag straight in lets the attacker pick how much of it
is verified. Tags shorter than minimumTagLength are rejected
outright.
Arguments
| :: (ByteArrayAccess aad, ByteArray ba) | |
| => AEAD a | An AEAD Context |
| -> aad | Associated/additional data |
| -> ba | Ciphertext |
| -> Int | The tag length to authenticate, which the tag must match |
| -> AuthTag | The authentication tag |
| -> Maybe ba | Plaintext |
Simple AEAD decryption with the tag length given by the caller.
aeadSimpleDecrypt authenticates as many octets as the tag it is handed is
long. That is the caller's choice only for as long as the tag is: one read
off the wire is the peer's, and an attacker who truncates it picks how much
of it gets verified, down to minimumTagLength.
Here the length is a separate argument and a tag that is not exactly that long is refused before anything is compared, so the peer cannot weaken the check. Prefer this wherever the tag is attacker reachable.
Initial Vector type and constructor
an IV parametrized by the cipher
Instances
| Eq (IV c) Source # | |
| BlockCipher c => ByteArrayAccess (IV c) Source # | |
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.