License | BSD-style |
---|---|
Maintainer | Vincent Hanquez <vincent@snarc.org> |
Stability | stable |
Portability | good |
Safe Haskell | None |
Language | Haskell98 |
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
- class Cipher cipher where
- cipherInit :: Key cipher -> cipher
- cipherName :: cipher -> String
- cipherKeySize :: cipher -> KeySizeSpecifier
- class Cipher cipher => BlockCipher cipher where
- blockSize :: cipher -> Int
- ecbEncrypt :: cipher -> ByteString -> ByteString
- ecbDecrypt :: cipher -> ByteString -> ByteString
- cbcEncrypt :: cipher -> IV cipher -> ByteString -> ByteString
- cbcDecrypt :: cipher -> IV cipher -> ByteString -> ByteString
- cfbEncrypt :: cipher -> IV cipher -> ByteString -> ByteString
- cfbDecrypt :: cipher -> IV cipher -> ByteString -> ByteString
- ctrCombine :: cipher -> IV cipher -> ByteString -> ByteString
- xtsEncrypt :: (cipher, cipher) -> IV cipher -> DataUnitOffset -> ByteString -> ByteString
- xtsDecrypt :: (cipher, cipher) -> IV cipher -> DataUnitOffset -> ByteString -> ByteString
- aeadInit :: Byteable iv => AEADMode -> cipher -> iv -> Maybe (AEAD cipher)
- class Cipher cipher => StreamCipher cipher where
- streamCombine :: cipher -> ByteString -> (ByteString, cipher)
- data Key c :: * -> *
- makeKey :: (ToSecureMem b, Cipher c) => b -> Either KeyError (Key c)
- data IV c :: * -> *
- makeIV :: (Byteable b, BlockCipher c) => b -> Maybe (IV c)
- nullIV :: BlockCipher c => IV c
- ivAdd :: BlockCipher c => IV c -> Int -> IV c
- data AEAD cipher :: * -> *
- aeadAppendHeader :: BlockCipher a => AEAD a -> ByteString -> AEAD a
- aeadEncrypt :: BlockCipher a => AEAD a -> ByteString -> (ByteString, AEAD a)
- aeadDecrypt :: BlockCipher a => AEAD a -> ByteString -> (ByteString, AEAD a)
- aeadFinalize :: BlockCipher a => AEAD a -> Int -> AuthTag
- data AES128 :: *
- data AES192 :: *
- data AES256 :: *
- data Blowfish :: *
- data Blowfish64 :: *
- data Blowfish128 :: *
- data Blowfish256 :: *
- data Blowfish448 :: *
- data DES :: *
- data DES_EEE3 :: *
- data DES_EDE3 :: *
- data DES_EEE2 :: *
- data DES_EDE2 :: *
- data Camellia128 :: *
Cipher classes
Symmetric cipher class.
class Cipher cipher => BlockCipher cipher where #
Symmetric block cipher class
Minimal complete definition
Instances
class Cipher cipher => StreamCipher cipher where #
Symmetric stream cipher class
Key
a Key parametrized by the cipher
makeKey :: (ToSecureMem b, Cipher c) => b -> Either KeyError (Key c) #
Create a Key for a specified cipher
Initialization Vector (IV)
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)
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
AES with 128 bit key
Instances
AES with 192 bit key
Instances
AES with 256 bit key
Instances
3DES with 3 different keys used all in the same direction
3DES with 3 different keys used in alternative direction
3DES where the first and third keys are equal, used in the same direction
3DES where the first and third keys are equal, used in alternative direction