HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulecrypto-api-0.13.3Haskell98

Crypto.Classes.Exceptions

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.

  • 3 types
  • 5 classes
  • 20 values
  • Packagecrypto-api-0.13.3
  • Exports65
  • LanguageHaskell98
  • LicenceBSD-3-Clause
  • SourceExceptions.hs

Classes

4 declarations
classclass (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.

Methods

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

Asymetric ciphers (common ones being RSA or EC based)

classclass 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

Hashing Operations

2 declarations
valuehashFunc' :: 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.

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

Symmetric Cryptographic Operations

0 declarations

Helpers

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

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

Primitives

Key and IV construction

6 declarations

Block Cipher Modes of Operation

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

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

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

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

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

RNG Operations

12 declarations
valuenewGen :: 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.

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

valuereseed :: 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).

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

methodnewGenIO :: IO g
#

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

datadata 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

Instances6Eq, Data, Ord, Read, Show, Exception
datadata ReseedInfo
#

Constructors

Instances5Eq, Data, Ord, Read, Show
datadata CipherError
#
Instances6Eq, Data, Ord, Read, Show, Exception

Asymmetric cryptographic operations

10 declarations
classclass (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).