Crypto.Classes.Exceptions

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

Safe Haskell | None
Language | Haskell98

Crypto.Classes.Exceptions

Description

The module mirrors Crypto.Classes except that errors are thrown as exceptions instead of having returning types of `Either error result` or `Maybe result`.

NB This module is experimental and might go away or be re-arranged.

Synopsis

- class (Serialize d, Eq d, Ord d) => Hash ctx d | d -> ctx, ctx -> d where
- hashFunc' :: Hash c d => d -> ByteString -> d
- hashFunc :: Hash c d => d -> ByteString -> d
- class Serialize k => BlockCipher k where
- blockSize :: BlockCipher k => Tagged k BitLength
- encryptBlock :: BlockCipher k => k -> ByteString -> ByteString
- decryptBlock :: BlockCipher k => k -> ByteString -> ByteString
- keyLength :: BlockCipher k => Tagged k BitLength
- getIVIO :: BlockCipher k => IO (IV k)
- blockSizeBytes :: BlockCipher k => Tagged k ByteLength
- keyLengthBytes :: BlockCipher k => Tagged k ByteLength
- buildKeyIO :: BlockCipher k => IO k
- class AsymCipher p v | p -> v, v -> p where
- publicKeyLength :: AsymCipher p v => p -> BitLength
- privateKeyLength :: AsymCipher p v => v -> BitLength
- buildKeyPairIO :: AsymCipher p v => BitLength -> IO (Either GenError (p, v))
- class (Serialize p, Serialize v) => Signing p v | p -> v, v -> p where
- signingKeyLength :: Signing p v => v -> BitLength
- verifyingKeyLength :: Signing p v => p -> BitLength
- verify :: Signing p v => p -> ByteString -> ByteString -> Bool
- incIV :: BlockCipher k => IV k -> IV k
- zeroIV :: BlockCipher k => IV k
- class CryptoRandomGen g where
- genSeedLength :: CryptoRandomGen g => Tagged g ByteLength
- reseedInfo :: CryptoRandomGen g => g -> ReseedInfo
- reseedPeriod :: CryptoRandomGen g => g -> ReseedInfo
- newGenIO :: CryptoRandomGen g => IO g
- data GenError
  - = GenErrorOther String
  - | RequestedTooManyBytes
  - | RangeInvalid
  - | NeedReseed
  - | NotEnoughEntropy
  - | NeedsInfiniteSeed
- data ReseedInfo
  - = InXBytes !Word64
  - | InXCalls !Word64
  - | NotSoon
  - | Never
- data CipherError
  - = GenError GenError
  - | KeyGenFailure
- 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)
- ctr :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)
- unCtr :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)
- ctrLazy :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)
- unCtrLazy :: 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)
- cbcLazy :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)
- unCbcLazy :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)
- sivLazy :: BlockCipher k => k -> k -> [ByteString] -> ByteString -> Maybe ByteString
- unSivLazy :: 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
- ecbLazy :: BlockCipher k => k -> ByteString -> ByteString
- unEcbLazy :: BlockCipher k => k -> ByteString -> ByteString
- cfbLazy :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)
- unCfbLazy :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)
- ofbLazy :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)
- unOfbLazy :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k)
- buildKey :: BlockCipher k => ByteString -> k
- getIV :: (BlockCipher k, CryptoRandomGen g) => g -> (IV k, g)
- buildKeyGen :: (CryptoRandomGen g, BlockCipher k) => g -> (k, g)
- buildKeyPair :: (CryptoRandomGen g, AsymCipher p v) => g -> BitLength -> ((p, v), g)
- encryptAsym :: (CryptoRandomGen g, AsymCipher p v) => g -> p -> ByteString -> (ByteString, g)
- decryptAsym :: (CryptoRandomGen g, AsymCipher p v) => g -> v -> ByteString -> (ByteString, g)
- newGen :: CryptoRandomGen g => ByteString -> g
- genBytes :: CryptoRandomGen g => ByteLength -> g -> (ByteString, g)
- genBytesWithEntropy :: CryptoRandomGen g => ByteLength -> ByteString -> g -> (ByteString, g)
- reseed :: CryptoRandomGen g => ByteString -> g -> g
- splitGen :: CryptoRandomGen g => g -> (g, g)

# Documentation

class (Serialize d, Eq d, Ord d) => Hash ctx d | d -> ctx, ctx -> d where #

The Hash class is intended as the generic interface targeted by maintainers of Haskell digest implementations. Using this generic interface, higher level functions such as `hash` and `hash'` provide a useful API for comsumers of hash implementations.

Any instantiated implementation must handle unaligned data.

Minimum complete definition: `outputLength`, `blockLength`, `initialCtx`, `updateCtx`, and `finalize`.

Minimal complete definition

outputLength, blockLength, initialCtx, updateCtx, finalize

Methods

outputLength #

Arguments

:: Tagged d BitLength | The size of the digest when encoded

blockLength #

Arguments

:: Tagged d BitLength | The amount of data operated on in each round of the digest computation

initialCtx #

Arguments

:: ctx | An initial context, provided with the first call to `updateCtx`

updateCtx #

Arguments

:: ctx |
-> ByteString |
-> ctx | Used to update a context, repeatedly called until all data is exhausted must operate correctly for imputs of `n*blockLength` bytes for `n `elem` [0..]`

finalize #

Arguments

:: ctx |
-> ByteString |
-> d | Finializing a context, plus any message data less than the block size, into a digest

hash :: Hash ctx d => ByteString -> d #

Hash a lazy ByteString, creating a digest

hash' :: Hash ctx d => ByteString -> d #

Hash a strict ByteString, creating a digest

hashFunc' :: Hash c d => d -> ByteString -> d #

Obtain a strict hash function whose result is the same type as the given digest, which is discarded. If the type is already inferred then consider using the `hash'` function instead.

hashFunc :: Hash c d => d -> ByteString -> d #

Obtain a lazy hash function whose result is the same type as the given digest, which is discarded. If the type is already inferred then consider using the `hash` function instead.

class Serialize k => BlockCipher k where #

The BlockCipher class is intended as the generic interface targeted by maintainers of Haskell cipher implementations.

Minimum complete definition: blockSize, encryptBlock, decryptBlock, buildKey, and keyLength.

Instances must handle unaligned data

Minimal complete definition

blockSize, encryptBlock, decryptBlock, buildKey, keyLength

Methods

blockSize #

Arguments

:: Tagged k BitLength | The size of a single block; the smallest unit on which the cipher operates.

encryptBlock #

Arguments

:: k |
-> ByteString |
-> ByteString | encrypt data of size `n*blockSize` where `n `elem` [0..]` (ecb encryption)

decryptBlock #

Arguments

:: k |
-> ByteString |
-> ByteString | decrypt data of size `n*blockSize` where `n `elem` [0..]` (ecb decryption)

keyLength #

Arguments

:: Tagged k BitLength | length of the cryptographic key

ecb :: k -> ByteString -> ByteString #

Electronic Cookbook (encryption)

unEcb :: k -> ByteString -> ByteString #

Electronic Cookbook (decryption)

cbc :: k -> IV k -> ByteString -> (ByteString, IV k) #

Cipherblock Chaining (encryption)

unCbc :: k -> IV k -> ByteString -> (ByteString, IV k) #

Cipherblock Chaining (decryption)

ctr :: k -> IV k -> ByteString -> (ByteString, IV k) #

Counter (encryption)

unCtr :: k -> IV k -> ByteString -> (ByteString, IV k) #

Counter (decryption)

ctrLazy :: k -> IV k -> ByteString -> (ByteString, IV k) #

Counter (encryption)

unCtrLazy :: k -> IV k -> ByteString -> (ByteString, IV k) #

Counter (decryption)

cfb :: k -> IV k -> ByteString -> (ByteString, IV k) #

Ciphertext feedback (encryption)

unCfb :: k -> IV k -> ByteString -> (ByteString, IV k) #

Ciphertext feedback (decryption)

ofb :: k -> IV k -> ByteString -> (ByteString, IV k) #

Output feedback (encryption)

unOfb :: k -> IV k -> ByteString -> (ByteString, IV k) #

Output feedback (decryption)

cbcLazy :: k -> IV k -> ByteString -> (ByteString, IV k) #

Cipher block chaining encryption for lazy bytestrings

unCbcLazy :: k -> IV k -> ByteString -> (ByteString, IV k) #

Cipher block chaining decryption for lazy bytestrings

sivLazy :: k -> k -> [ByteString] -> ByteString -> Maybe ByteString #

SIV (Synthetic IV) mode for lazy bytestrings. The third 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.

unSivLazy :: k -> k -> [ByteString] -> ByteString -> Maybe ByteString #

SIV (Synthetic IV) for lazy bytestrings. The third 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 :: 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 :: 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.

ecbLazy :: 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.

unEcbLazy :: k -> ByteString -> ByteString #

ECB decrypt, complementary to `ecb`.

cfbLazy :: k -> IV k -> ByteString -> (ByteString, IV k) #

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

unCfbLazy :: k -> IV k -> ByteString -> (ByteString, IV k) #

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

ofbLazy :: k -> IV k -> ByteString -> (ByteString, IV k) #

Output feedback mode for lazy bytestrings

unOfbLazy :: k -> IV k -> ByteString -> (ByteString, IV k) #

Output feedback mode for lazy bytestrings

blockSize #

Arguments

:: BlockCipher k |
=> Tagged k BitLength | The size of a single block; the smallest unit on which the cipher operates.

encryptBlock #

Arguments

:: BlockCipher k |
=> k |
-> ByteString |
-> ByteString | encrypt data of size `n*blockSize` where `n `elem` [0..]` (ecb encryption)

decryptBlock #

Arguments

:: BlockCipher k |
=> k |
-> ByteString |
-> ByteString | decrypt data of size `n*blockSize` where `n `elem` [0..]` (ecb decryption)

keyLength #

Arguments

:: BlockCipher k |
=> Tagged k BitLength | length of the cryptographic key

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

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

blockSizeBytes :: BlockCipher k => Tagged k ByteLength #

The number of bytes in a block cipher block

keyLengthBytes :: BlockCipher k => Tagged k ByteLength #

The number of bytes in a block cipher key (assuming it is an even multiple of 8 bits)

buildKeyIO :: BlockCipher k => IO k #

Build a symmetric key using the system entropy (see `Entropy`)

class AsymCipher p v | p -> v, v -> p where #

Asymetric ciphers (common ones being RSA or EC based)

Minimal complete definition

buildKeyPair, encryptAsym, decryptAsym, publicKeyLength, privateKeyLength

Methods

publicKeyLength :: p -> BitLength #

privateKeyLength :: v -> BitLength #

publicKeyLength :: AsymCipher p v => p -> BitLength #

privateKeyLength :: AsymCipher p v => v -> BitLength #

buildKeyPairIO :: AsymCipher p v => BitLength -> IO (Either GenError (p, v)) #

Build a pair of asymmetric keys using the system random generator.

class (Serialize p, Serialize v) => Signing p v | p -> v, v -> p where #

A class for signing operations which inherently can not be as generic as asymetric ciphers (ex: DSA).

Minimal complete definition

sign, verify, buildSigningPair, signingKeyLength, verifyingKeyLength

Methods

verify :: p -> ByteString -> ByteString -> Bool #

signingKeyLength :: v -> BitLength #

verifyingKeyLength :: p -> BitLength #

signingKeyLength :: Signing p v => v -> BitLength #

verifyingKeyLength :: Signing p v => p -> BitLength #

verify :: Signing p v => p -> ByteString -> ByteString -> Bool #

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

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

zeroIV :: BlockCipher k => IV k #

Obtain an `IV` made only of zeroes

class CryptoRandomGen g where #

A class of random bit generators that allows for the possibility of failure, reseeding, providing entropy at the same time as requesting bytes

Minimum complete definition: `newGen`, `genSeedLength`, `genBytes`, `reseed`, `reseedInfo`, `reseedPeriod`.

Minimal complete definition

newGen, genSeedLength, genBytes, reseedInfo, reseedPeriod, reseed

Methods

genSeedLength :: Tagged g ByteLength #

Length of input entropy necessary to instantiate or reseed a generator

reseedInfo :: g -> ReseedInfo #

Indicates how soon a reseed is needed

reseedPeriod :: g -> ReseedInfo #

Indicates the period between reseeds (constant for most generators).

newGenIO :: IO g #

By default this uses System.Entropy to obtain entropy for `newGen`.

Instances

CryptoRandomGen SystemRandom # |
Methods newGen :: ByteString -> Either GenError SystemRandom # genSeedLength :: Tagged * SystemRandom ByteLength # genBytes :: ByteLength -> SystemRandom -> Either GenError (ByteString, SystemRandom) # reseedInfo :: SystemRandom -> ReseedInfo # reseedPeriod :: SystemRandom -> ReseedInfo # genBytesWithEntropy :: ByteLength -> ByteString -> SystemRandom -> Either GenError (ByteString, SystemRandom) # reseed :: ByteString -> SystemRandom -> Either GenError SystemRandom # newGenIO :: IO SystemRandom #

genSeedLength :: CryptoRandomGen g => Tagged g ByteLength #

Length of input entropy necessary to instantiate or reseed a generator

reseedInfo :: CryptoRandomGen g => g -> ReseedInfo #

Indicates how soon a reseed is needed

reseedPeriod :: CryptoRandomGen g => g -> ReseedInfo #

Indicates the period between reseeds (constant for most generators).

newGenIO :: CryptoRandomGen g => IO g #

By default this uses System.Entropy to obtain entropy for `newGen`.

data GenError #

Generator failures should always return the appropriate GenError. Note `GenError` in an instance of exception but wether or not an exception is thrown depends on if the selected generator (read: if you don't want execptions from code that uses `throw` then pass in a generator that never has an error for the used functions)

Constructors

GenErrorOther String | Misc
RequestedTooManyBytes | Requested more bytes than a single pass can generate (The maximum request is generator dependent)
RangeInvalid | When using `genInteger g (l,h)` and `logBase 2 (h - l) > (maxBound :: Int)`.
NeedReseed | Some generators cease operation after too high a count without a reseed (ex: NIST SP 800-90)
NotEnoughEntropy | For instantiating new generators (or reseeding)
NeedsInfiniteSeed | This generator can not be instantiated or reseeded with a finite seed (ex: `SystemRandom`)

Instances

Eq GenError # |
Methods (==) :: GenError -> GenError -> Bool # (/=) :: GenError -> GenError -> Bool #
Data GenError # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> GenError -> c GenError # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c GenError # toConstr :: GenError -> Constr # dataTypeOf :: GenError -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c GenError) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c GenError) # gmapT :: (forall b. Data b => b -> b) -> GenError -> GenError # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> GenError -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> GenError -> r # gmapQ :: (forall d. Data d => d -> u) -> GenError -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> GenError -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> GenError -> m GenError # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> GenError -> m GenError # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> GenError -> m GenError #
Ord GenError # |
Methods compare :: GenError -> GenError -> Ordering # (<) :: GenError -> GenError -> Bool # (<=) :: GenError -> GenError -> Bool # (>) :: GenError -> GenError -> Bool # (>=) :: GenError -> GenError -> Bool # max :: GenError -> GenError -> GenError # min :: GenError -> GenError -> GenError #
Read GenError # |
Methods readsPrec :: Int -> ReadS GenError # readList :: ReadS [GenError] # readPrec :: ReadPrec GenError # readListPrec :: ReadPrec [GenError] #
Show GenError # |
Methods showsPrec :: Int -> GenError -> ShowS # show :: GenError -> String # showList :: [GenError] -> ShowS #
Exception GenError # |
Methods toException :: GenError -> SomeException # fromException :: SomeException -> Maybe GenError # displayException :: GenError -> String #

data ReseedInfo #

Constructors

InXBytes !Word64 | Generator needs reseeded in X bytes
InXCalls !Word64 | Generator needs reseeded in X calls
NotSoon | The bound is over 2^64 bytes or calls
Never | This generator never reseeds (ex: `SystemRandom`)

Instances

Eq ReseedInfo # |
Methods (==) :: ReseedInfo -> ReseedInfo -> Bool # (/=) :: ReseedInfo -> ReseedInfo -> Bool #
Data ReseedInfo # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> ReseedInfo -> c ReseedInfo # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c ReseedInfo # toConstr :: ReseedInfo -> Constr # dataTypeOf :: ReseedInfo -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c ReseedInfo) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ReseedInfo) # gmapT :: (forall b. Data b => b -> b) -> ReseedInfo -> ReseedInfo # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ReseedInfo -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ReseedInfo -> r # gmapQ :: (forall d. Data d => d -> u) -> ReseedInfo -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> ReseedInfo -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> ReseedInfo -> m ReseedInfo # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ReseedInfo -> m ReseedInfo # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ReseedInfo -> m ReseedInfo #
Ord ReseedInfo # |
Methods compare :: ReseedInfo -> ReseedInfo -> Ordering # (<) :: ReseedInfo -> ReseedInfo -> Bool # (<=) :: ReseedInfo -> ReseedInfo -> Bool # (>) :: ReseedInfo -> ReseedInfo -> Bool # (>=) :: ReseedInfo -> ReseedInfo -> Bool # max :: ReseedInfo -> ReseedInfo -> ReseedInfo # min :: ReseedInfo -> ReseedInfo -> ReseedInfo #
Read ReseedInfo # |
Methods readsPrec :: Int -> ReadS ReseedInfo # readList :: ReadS [ReseedInfo] # readPrec :: ReadPrec ReseedInfo # readListPrec :: ReadPrec [ReseedInfo] #
Show ReseedInfo # |
Methods showsPrec :: Int -> ReseedInfo -> ShowS # show :: ReseedInfo -> String # showList :: [ReseedInfo] -> ShowS #

data CipherError #

Constructors

GenError GenError |
KeyGenFailure |

Instances

Eq CipherError # |
Methods (==) :: CipherError -> CipherError -> Bool # (/=) :: CipherError -> CipherError -> Bool #
Data CipherError # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> CipherError -> c CipherError # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c CipherError # toConstr :: CipherError -> Constr # dataTypeOf :: CipherError -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c CipherError) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CipherError) # gmapT :: (forall b. Data b => b -> b) -> CipherError -> CipherError # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CipherError -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> CipherError -> r # gmapQ :: (forall d. Data d => d -> u) -> CipherError -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> CipherError -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> CipherError -> m CipherError # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> CipherError -> m CipherError # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> CipherError -> m CipherError #
Ord CipherError # |
Methods compare :: CipherError -> CipherError -> Ordering # (<) :: CipherError -> CipherError -> Bool # (<=) :: CipherError -> CipherError -> Bool # (>) :: CipherError -> CipherError -> Bool # (>=) :: CipherError -> CipherError -> Bool # max :: CipherError -> CipherError -> CipherError # min :: CipherError -> CipherError -> CipherError #
Read CipherError # |
Methods readsPrec :: Int -> ReadS CipherError # readList :: ReadS [CipherError] # readPrec :: ReadPrec CipherError # readListPrec :: ReadPrec [CipherError] #
Show CipherError # |
Methods showsPrec :: Int -> CipherError -> ShowS # show :: CipherError -> String # showList :: [CipherError] -> ShowS #
Exception CipherError # |
Methods toException :: CipherError -> SomeException # fromException :: SomeException -> Maybe CipherError # displayException :: CipherError -> String #

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

Electronic Cookbook (encryption)

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

Electronic Cookbook (decryption)

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

Cipherblock Chaining (encryption)

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

Cipherblock Chaining (decryption)

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

Counter (encryption)

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

Counter (decryption)

ctrLazy :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k) #

Counter (encryption)

unCtrLazy :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k) #

Counter (decryption)

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

Ciphertext feedback (encryption)

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

Ciphertext feedback (decryption)

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

Output feedback (encryption)

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

Output feedback (decryption)

cbcLazy :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k) #

Cipher block chaining encryption for lazy bytestrings

unCbcLazy :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k) #

Cipher block chaining decryption for lazy bytestrings

sivLazy :: BlockCipher k => k -> k -> [ByteString] -> ByteString -> Maybe ByteString #

SIV (Synthetic IV) mode for lazy bytestrings. The third 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.

unSivLazy :: BlockCipher k => k -> k -> [ByteString] -> ByteString -> Maybe ByteString #

SIV (Synthetic IV) for lazy bytestrings. The third 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.

ecbLazy :: 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.

unEcbLazy :: BlockCipher k => k -> ByteString -> ByteString #

ECB decrypt, complementary to `ecb`.

cfbLazy :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k) #

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

unCfbLazy :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k) #

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

ofbLazy :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k) #

Output feedback mode for lazy bytestrings

unOfbLazy :: BlockCipher k => k -> IV k -> ByteString -> (ByteString, IV k) #

Output feedback mode for lazy bytestrings

buildKey :: BlockCipher k => ByteString -> k #

Key construction from raw material (typically including key expansion)

This is a wrapper that can throw a `CipherError` on exception.

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

Random `IV` generation

This is a wrapper that can throw a `GenError` on exception.

buildKeyGen :: (CryptoRandomGen g, BlockCipher k) => g -> (k, g) #

Symmetric key generation

This is a wrapper that can throw a `GenError` on exception.

buildKeyPair :: (CryptoRandomGen g, AsymCipher p v) => g -> BitLength -> ((p, v), g) #

Asymetric key generation

This is a wrapper that can throw a `GenError` on exception.

encryptAsym :: (CryptoRandomGen g, AsymCipher p v) => g -> p -> ByteString -> (ByteString, g) #

Asymmetric encryption

This is a wrapper that can throw a `GenError` on exception.

decryptAsym :: (CryptoRandomGen g, AsymCipher p v) => g -> v -> ByteString -> (ByteString, g) #

Asymmetric decryption

This is a wrapper that can throw a GenError on exception.

newGen :: CryptoRandomGen g => ByteString -> g #

Instantiate a new random bit generator. The provided bytestring should be of length >= genSeedLength. If the bytestring is shorter then the call may fail (suggested error: `NotEnoughEntropy`). If the bytestring is of sufficent length the call should always succeed.

This is a wrapper that can throw `GenError` types as exceptions.

genBytes :: CryptoRandomGen g => ByteLength -> g -> (ByteString, g) #

`genBytes len g` generates a random ByteString of length `len` and new generator. The `MonadCryptoRandom` package has routines useful for converting the ByteString to commonly needed values (but `cereal` or other deserialization libraries would also work).

This is a wrapper that can throw `GenError` types as exceptions.

genBytesWithEntropy :: CryptoRandomGen g => ByteLength -> ByteString -> g -> (ByteString, g) #

`genBytesWithEntropy g i entropy` generates `i` random bytes and use the additional input `entropy` in the generation of the requested data to increase the confidence our generated data is a secure random stream.

This is a wrapper that can throw `GenError` types as exceptions.

reseed :: CryptoRandomGen g => ByteString -> g -> g #

If the generator has produced too many random bytes on its existing seed it will throw a `NeedReseed` exception. In that case, reseed the generator using this function and a new high-entropy seed of length >= `genSeedLength`. Using bytestrings that are too short can result in an exception (`NotEnoughEntropy`).

splitGen :: CryptoRandomGen g => g -> (g, g) #

While the safety and wisdom of a splitting function depends on the properties of the generator being split, several arguments from informed people indicate such a function is safe for NIST SP 800-90 generators. (see libraries@haskell.org discussion around Sept, Oct 2010). You can find implementations of such generators in the `DRBG` package.

This is a wrapper for `splitGen` which throws errors as exceptions.