crypto-api-0.10.2: A generic interface for cryptographic operations

Portability | portable
Stability | beta
Maintainer | Thomas.DuBuisson@gmail.com
Safe Haskell | None

Crypto.Modes

Contents

- Initialization Vector Type, Modifiers (for all ciphers, all modes that use IVs)
- Blockcipher modes. Names with a prime (') means strict, without a prime means lazy bytestrings.
- Authentication modes
- Combined modes (nothing here yet)

Description

Authors: Thomas DuBuisson, Francisco Blas Izquierdo Riera (klondike)

Generic mode implementations useable by any correct BlockCipher instance Be aware there are no tests for CFB mode yet. See `Crypto`.

Synopsis

- data IV k
- getIV :: (BlockCipher k, CryptoRandomGen g) => g -> Either GenError (IV k, g)
- getIVIO :: BlockCipher k => IO (IV k)
- zeroIV :: BlockCipher k => IV k
- incIV :: BlockCipher k => IV k -> IV k
- dblIV :: BlockCipher k => IV k -> IV k
- ecb :: BlockCipher k => k -> ByteString -> ByteString
- unEcb :: BlockCipher k => k -> ByteString -> ByteString
- cbc :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)
- unCbc :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)
- cfb :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)
- unCfb :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)
- ofb :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)
- unOfb :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)
- ecb' :: BlockCipher k => k -> ByteString -> ByteString
- unEcb' :: BlockCipher k => k -> ByteString -> ByteString
- cbc' :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)
- unCbc' :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)
- cfb' :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)
- unCfb' :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)
- ofb' :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)
- unOfb' :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)
- ctr :: BlockCipher k => (IV k -> IV k) -> k -> IV k -> ByteString -> (ByteString, IV k)
- unCtr :: BlockCipher k => (IV k -> IV k) -> k -> IV k -> ByteString -> (ByteString, IV k)
- ctr' :: BlockCipher k => (IV k -> IV k) -> k -> IV k -> ByteString -> (ByteString, IV k)
- unCtr' :: BlockCipher k => (IV k -> IV k) -> k -> IV k -> ByteString -> (ByteString, IV k)
- siv :: BlockCipher k => k -> k -> [ByteString] -> ByteString -> Maybe ByteString
- unSiv :: BlockCipher k => k -> k -> [ByteString] -> ByteString -> Maybe ByteString
- siv' :: BlockCipher k => k -> k -> [ByteString] -> ByteString -> Maybe ByteString
- unSiv' :: BlockCipher k => k -> k -> [ByteString] -> ByteString -> Maybe ByteString
- cbcMac' :: BlockCipher k => k -> ByteString -> ByteString
- cbcMac :: BlockCipher k => k -> ByteString -> ByteString
- cMac :: BlockCipher k => k -> ByteString -> ByteString
- cMac' :: BlockCipher k => k -> ByteString -> ByteString

# Initialization Vector Type, Modifiers (for all ciphers, all modes that use IVs)

data IV k

Initilization Vectors for BlockCipher implementations (IV k) are used for various modes and guarrenteed to be blockSize bits long. The common ways to obtain an IV are to generate one (`getIV` or `getIVIO`) or to use one provided with the ciphertext (using the `Serialize` instance of IV).

`zeroIV` also exists and is of particular use for starting `ctr` mode with a fresh key.

Instances

Eq (IV k) |
Ord (IV k) |
Show (IV k) |
BlockCipher k => Serialize (IV k) |

getIV :: (BlockCipher k, CryptoRandomGen g) => g -> Either GenError (IV k, g)

Obtain an `IV` using the provided CryptoRandomGenerator.

getIVIO :: BlockCipher k => IO (IV k)

Obtain an `IV` using the system entropy (see `Random`)

zeroIV :: BlockCipher k => IV k

Obtain an `IV` made only of zeroes

incIV :: BlockCipher k => IV k -> IV k

Increase an `IV` by one. This is way faster than decoding, increasing, encoding

dblIV :: BlockCipher k => IV k -> IV k

Perform doubling as defined by the CMAC and SIV papers

# Blockcipher modes. Names with a prime (') means strict, without a prime means lazy bytestrings.

ecb :: BlockCipher k => k -> ByteString -> ByteString

Cook book mode - not really a mode at all. If you don't know what you're doing, don't use this mode^H^H^H^H library.

unEcb :: BlockCipher k => k -> ByteString -> ByteString

ECB decrypt, complementary to `ecb`.

cbc :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)

Cipher block chaining encryption for lazy bytestrings

unCbc :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)

Cipher block chaining decryption for lazy bytestrings

cfb :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)

Ciphertext feed-back encryption mode for lazy bytestrings (with s == blockSize)

unCfb :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)

Ciphertext feed-back decryption mode for lazy bytestrings (with s == blockSize)

ofb :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)

Output feedback mode for lazy bytestrings

unOfb :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)

Output feedback mode for lazy bytestrings

ecb' :: BlockCipher k => k -> ByteString -> ByteString

Like `ecb` but for strict bytestrings

unEcb' :: BlockCipher k => k -> ByteString -> ByteString

Decryption complement to `ecb'`

cbc' :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)

Cipher block chaining encryption mode on strict bytestrings

unCbc' :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)

Cipher block chaining decryption for strict bytestrings

cfb' :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)

Ciphertext feed-back encryption mode for strict bytestrings (with s == blockSize)

unCfb' :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)

Ciphertext feed-back decryption mode for strict bytestrings (with s == blockSize)

ofb' :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)

Output feedback mode for strict bytestrings

unOfb' :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)

Output feedback mode for strict bytestrings

ctr :: BlockCipher k => (IV k -> IV k) -> k -> IV k -> ByteString -> (ByteString, IV k)

Counter mode for lazy bytestrings

unCtr :: BlockCipher k => (IV k -> IV k) -> k -> IV k -> ByteString -> (ByteString, IV k)

Counter mode for lazy bytestrings

ctr' :: BlockCipher k => (IV k -> IV k) -> k -> IV k -> ByteString -> (ByteString, IV k)

Counter mode for strict bytestrings

unCtr' :: BlockCipher k => (IV k -> IV k) -> k -> IV k -> ByteString -> (ByteString, IV k)

Counter mode for strict bytestrings

siv :: BlockCipher k => k -> k -> [ByteString] -> ByteString -> Maybe ByteString

SIV (Synthetic IV) mode for lazy bytestrings. First argument is the optional list of bytestrings to be authenticated but not encrypted As required by the specification this algorithm may return nothing when certain constraints aren't met.

unSiv :: BlockCipher k => k -> k -> [ByteString] -> ByteString -> Maybe ByteString

SIV (Synthetic IV) for lazy bytestrings. First argument is the optional list of bytestrings to be authenticated but not encrypted. As required by the specification this algorithm may return nothing when authentication fails.

siv' :: BlockCipher k => k -> k -> [ByteString] -> ByteString -> Maybe ByteString

SIV (Synthetic IV) mode for strict bytestrings. First argument is the optional list of bytestrings to be authenticated but not encrypted. As required by the specification this algorithm may return nothing when certain constraints aren't met.

unSiv' :: BlockCipher k => k -> k -> [ByteString] -> ByteString -> Maybe ByteString

SIV (Synthetic IV) for strict bytestrings First argument is the optional list of bytestrings to be authenticated but not encrypted As required by the specification this algorithm may return nothing when authentication fails.

# Authentication modes

cbcMac' :: BlockCipher k => k -> ByteString -> ByteString

Cipher block chaining message authentication

cbcMac :: BlockCipher k => k -> ByteString -> ByteString

Cipher block chaining message authentication

cMac :: BlockCipher k => k -> ByteString -> ByteString

Obtain the cmac for lazy bytestrings

cMac' :: BlockCipher k => k -> ByteString -> ByteString

Obtain the cmac for strict bytestrings

# Combined modes (nothing here yet)