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

Safe Haskell | None
Language | Haskell98

Crypto.Classes.Exceptions

Contents

- Classes
- Hashing Operations
- Symmetric Cryptographic Operations
  - Helpers
  - Primitives
- Key and IV construction
  - Block Cipher Modes of Operation
- RNG Operations
- Asymmetric cryptographic operations

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
  - outputLength :: Tagged d BitLength
  - blockLength :: Tagged d BitLength
  - initialCtx :: ctx
  - updateCtx :: ctx -> ByteString -> ctx
  - finalize :: ctx -> ByteString -> d
  - hash :: ByteString -> d
  - hash' :: ByteString -> d
- class AsymCipher p v | p -> v, v -> p
- class CryptoRandomGen g
- class Serialize k => BlockCipher k
- hashFunc' :: Hash c d => d -> ByteString -> d
- hashFunc :: Hash c d => d -> ByteString -> d
- blockSize :: BlockCipher k => Tagged k BitLength
- blockSizeBytes :: BlockCipher k => Tagged k ByteLength
- keyLength :: BlockCipher k => Tagged k BitLength
- keyLengthBytes :: BlockCipher k => Tagged k ByteLength
- incIV :: BlockCipher k => IV k -> IV k
- encryptBlock :: BlockCipher k => k -> ByteString -> ByteString
- decryptBlock :: BlockCipher k => k -> ByteString -> ByteString
- buildKey :: BlockCipher k => ByteString -> k
- buildKeyIO :: BlockCipher k => IO k
- buildKeyGen :: (CryptoRandomGen g, BlockCipher k) => g -> (k, g)
- getIV :: (BlockCipher k, CryptoRandomGen g) => g -> (IV k, g)
- getIVIO :: BlockCipher k => IO (IV k)
- zeroIV :: BlockCipher 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)
- 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)
- 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)
- 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
- 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)
- class (Serialize p, Serialize v) => Signing p v | p -> v, v -> p
- signingKeyLength :: Signing p v => v -> BitLength
- verifyingKeyLength :: Signing p v => p -> BitLength
- verify :: Signing p v => p -> ByteString -> ByteString -> Bool
- publicKeyLength :: AsymCipher p v => p -> BitLength
- privateKeyLength :: AsymCipher p v => v -> BitLength
- buildKeyPairIO :: AsymCipher p v => BitLength -> IO (Either GenError (p, v))

# Classes

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

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 Source #

Arguments

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

blockLength Source #

Arguments

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

initialCtx Source #

Arguments

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

updateCtx Source #

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 Source #

Arguments

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

hash :: ByteString -> d Source #

Hash a lazy ByteString, creating a digest

hash' :: ByteString -> d Source #

Hash a strict ByteString, creating a digest

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

Asymetric ciphers (common ones being RSA or EC based)

Minimal complete definition

buildKeyPair, encryptAsym, decryptAsym, publicKeyLength, privateKeyLength

class CryptoRandomGen g Source #

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

#### Instances

Instances details

CryptoRandomGen SystemRandom Source # |

Instance details

Defined in Crypto.Random

Methods

newGen :: ByteString -> Either GenError SystemRandom Source #

genSeedLength :: Tagged SystemRandom ByteLength Source #

genBytes :: ByteLength -> SystemRandom -> Either GenError (ByteString, SystemRandom) Source #

reseedInfo :: SystemRandom -> ReseedInfo Source #

reseedPeriod :: SystemRandom -> ReseedInfo Source #

genBytesWithEntropy :: ByteLength -> ByteString -> SystemRandom -> Either GenError (ByteString, SystemRandom) Source #

reseed :: ByteString -> SystemRandom -> Either GenError SystemRandom Source #

newGenIO :: IO SystemRandom Source #

class Serialize k => BlockCipher k Source #

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

# Hashing Operations

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

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 Source #

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.

# Symmetric Cryptographic Operations

## Helpers

blockSize Source #

Arguments

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

blockSizeBytes :: BlockCipher k => Tagged k ByteLength Source #

The number of bytes in a block cipher block

keyLength Source #

Arguments

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

keyLengthBytes :: BlockCipher k => Tagged k ByteLength Source #

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

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

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

## Primitives

encryptBlock Source #

Arguments

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

decryptBlock Source #

Arguments

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

# Key and IV construction

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

Key construction from raw material (typically including key expansion)

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

buildKeyIO :: BlockCipher k => IO k Source #

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

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

Symmetric key generation

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

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

Random `IV` generation

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

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

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

zeroIV :: BlockCipher k => IV k Source #

Obtain an `IV` made only of zeroes

## Block Cipher Modes of Operation

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

Electronic Cookbook (encryption)

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

Electronic Cookbook (decryption)

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

Cipherblock Chaining (encryption)

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

Cipherblock Chaining (decryption)

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

Counter (encryption)

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

Counter (decryption)

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

Counter (encryption)

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

Counter (decryption)

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

Ciphertext feedback (encryption)

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

Ciphertext feedback (decryption)

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

Output feedback (encryption)

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

Output feedback (decryption)

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

Cipher block chaining encryption for lazy bytestrings

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

Cipher block chaining decryption for lazy bytestrings

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

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 Source #

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 Source #

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 Source #

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 Source #

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 Source #

ECB decrypt, complementary to `ecb`.

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

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

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

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

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

Output feedback mode for lazy bytestrings

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

Output feedback mode for lazy bytestrings

# RNG Operations

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

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) Source #

`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) Source #

`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 Source #

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) Source #

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.

genSeedLength :: CryptoRandomGen g => Tagged g ByteLength Source #

Length of input entropy necessary to instantiate or reseed a generator

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

Indicates how soon a reseed is needed

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

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

newGenIO :: CryptoRandomGen g => IO g Source #

By default this uses System.Entropy to obtain entropy for `newGen`. WARNING: The default implementation opens a file handle which will never be closed!

data GenError Source #

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

Instances details

Data GenError Source # |

Instance details

Defined in Crypto.Random

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> GenError -> c GenError Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c GenError Source #

toConstr :: GenError -> Constr Source #

dataTypeOf :: GenError -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c GenError) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c GenError) Source #

gmapT :: (forall b. Data b => b -> b) -> GenError -> GenError Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> GenError -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> GenError -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> GenError -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> GenError -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> GenError -> m GenError Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> GenError -> m GenError Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> GenError -> m GenError Source #

Exception GenError Source # |
Instance details Defined in Crypto.Random Methods toException :: GenError -> SomeException Source # fromException :: SomeException -> Maybe GenError Source # displayException :: GenError -> String Source # backtraceDesired :: GenError -> Bool Source #
Read GenError Source # |
Instance details Defined in Crypto.Random Methods readsPrec :: Int -> ReadS GenError Source # readList :: ReadS [GenError] Source # readPrec :: ReadPrec GenError Source # readListPrec :: ReadPrec [GenError] Source #
Show GenError Source # |
Instance details Defined in Crypto.Random Methods showsPrec :: Int -> GenError -> ShowS Source # show :: GenError -> String Source # showList :: [GenError] -> ShowS Source #
Eq GenError Source # |
Instance details Defined in Crypto.Random Methods (==) :: GenError -> GenError -> Bool Source # (/=) :: GenError -> GenError -> Bool Source #
Ord GenError Source # |
Instance details Defined in Crypto.Random Methods compare :: GenError -> GenError -> Ordering Source # (<) :: GenError -> GenError -> Bool Source # (<=) :: GenError -> GenError -> Bool Source # (>) :: GenError -> GenError -> Bool Source # (>=) :: GenError -> GenError -> Bool Source # max :: GenError -> GenError -> GenError Source # min :: GenError -> GenError -> GenError Source #

data ReseedInfo Source #

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

Instances details

Data ReseedInfo Source # |

Instance details

Defined in Crypto.Random

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> ReseedInfo -> c ReseedInfo Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c ReseedInfo Source #

toConstr :: ReseedInfo -> Constr Source #

dataTypeOf :: ReseedInfo -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c ReseedInfo) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ReseedInfo) Source #

gmapT :: (forall b. Data b => b -> b) -> ReseedInfo -> ReseedInfo Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ReseedInfo -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ReseedInfo -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> ReseedInfo -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> ReseedInfo -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> ReseedInfo -> m ReseedInfo Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ReseedInfo -> m ReseedInfo Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ReseedInfo -> m ReseedInfo Source #

Read ReseedInfo Source # |
Instance details Defined in Crypto.Random Methods readsPrec :: Int -> ReadS ReseedInfo Source # readList :: ReadS [ReseedInfo] Source # readPrec :: ReadPrec ReseedInfo Source # readListPrec :: ReadPrec [ReseedInfo] Source #
Show ReseedInfo Source # |
Instance details Defined in Crypto.Random Methods showsPrec :: Int -> ReseedInfo -> ShowS Source # show :: ReseedInfo -> String Source # showList :: [ReseedInfo] -> ShowS Source #
Eq ReseedInfo Source # |
Instance details Defined in Crypto.Random Methods (==) :: ReseedInfo -> ReseedInfo -> Bool Source # (/=) :: ReseedInfo -> ReseedInfo -> Bool Source #
Ord ReseedInfo Source # |

Instance details

Defined in Crypto.Random

Methods

compare :: ReseedInfo -> ReseedInfo -> Ordering Source #

(<) :: ReseedInfo -> ReseedInfo -> Bool Source #

(<=) :: ReseedInfo -> ReseedInfo -> Bool Source #

(>) :: ReseedInfo -> ReseedInfo -> Bool Source #

(>=) :: ReseedInfo -> ReseedInfo -> Bool Source #

max :: ReseedInfo -> ReseedInfo -> ReseedInfo Source #

min :: ReseedInfo -> ReseedInfo -> ReseedInfo Source #

data CipherError Source #

Constructors

GenError GenError |
KeyGenFailure |

#### Instances

Instances details

Data CipherError Source # |

Instance details

Defined in Crypto.Classes.Exceptions

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> CipherError -> c CipherError Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c CipherError Source #

toConstr :: CipherError -> Constr Source #

dataTypeOf :: CipherError -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c CipherError) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CipherError) Source #

gmapT :: (forall b. Data b => b -> b) -> CipherError -> CipherError Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CipherError -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> CipherError -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> CipherError -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> CipherError -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> CipherError -> m CipherError Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> CipherError -> m CipherError Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> CipherError -> m CipherError Source #

Exception CipherError Source # |
Instance details Defined in Crypto.Classes.Exceptions Methods toException :: CipherError -> SomeException Source # fromException :: SomeException -> Maybe CipherError Source # displayException :: CipherError -> String Source # backtraceDesired :: CipherError -> Bool Source #
Read CipherError Source # |
Instance details Defined in Crypto.Classes.Exceptions Methods readsPrec :: Int -> ReadS CipherError Source # readList :: ReadS [CipherError] Source # readPrec :: ReadPrec CipherError Source # readListPrec :: ReadPrec [CipherError] Source #
Show CipherError Source # |
Instance details Defined in Crypto.Classes.Exceptions Methods showsPrec :: Int -> CipherError -> ShowS Source # show :: CipherError -> String Source # showList :: [CipherError] -> ShowS Source #
Eq CipherError Source # |
Instance details Defined in Crypto.Classes.Exceptions Methods (==) :: CipherError -> CipherError -> Bool Source # (/=) :: CipherError -> CipherError -> Bool Source #
Ord CipherError Source # |

Instance details

Defined in Crypto.Classes.Exceptions

Methods

compare :: CipherError -> CipherError -> Ordering Source #

(<) :: CipherError -> CipherError -> Bool Source #

(<=) :: CipherError -> CipherError -> Bool Source #

(>) :: CipherError -> CipherError -> Bool Source #

(>=) :: CipherError -> CipherError -> Bool Source #

max :: CipherError -> CipherError -> CipherError Source #

min :: CipherError -> CipherError -> CipherError Source #

# Asymmetric cryptographic operations

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

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) Source #

Asymmetric encryption

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

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

Asymmetric decryption

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

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

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

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

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

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

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

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

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

Build a pair of asymmetric keys using the system random generator. WARNING: This function opens a file handle which will never be closed!