HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

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.

Contents
  1. Classes
  2. Hashing Operations
  3. Symmetric Cryptographic Operations
  4. Helpers
  5. Primitives
  6. Key and IV construction
  7. Block Cipher Modes of Operation
  8. RNG Operations
  9. Asymmetric cryptographic operations
Synopsis
  • Packagecrypto-api-0.13.3
  • Exports65
  • LanguageHaskell98
  • LicenceBSD-3-Clause
  • SourceExceptions.hs

Classes

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

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

Helpers

Primitives

Key and IV construction

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

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.

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.

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

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