crypto-rng-0.1.0.1: Cryptographic random number generator.

Safe HaskellNone
LanguageHaskell2010

Crypto.RNG

Contents

Description

Support for generation of cryptographically secure random numbers, based on the DRBG package.

This is a convenience layer on top of DRBG, which allows you to pull random values by means of the method random, while keeping the state of the random number generator (RNG) inside a monad. The state is protected by an MVar, which means that concurrent generation of random values from several threads works straight out of the box.

The access to the RNG state is captured by a class. By making instances of this class, client code can enjoy RNG generation from their own monads.

Synopsis

CryproRNG class

Generation of strings and numbers

data CryptoRNGState Source #

The random number generator state. It sits inside an MVar to support concurrent thread access.

newCryptoRNGState :: MonadIO m => m CryptoRNGState Source #

Create a new CryptoRNGState, based on system entropy.

unsafeCryptoRNGState :: MonadIO m => ByteString -> m CryptoRNGState Source #

Create a new CryptoRNGState, based on a bytestring seed. Should only be used for testing.

randomBytesIO Source #

Arguments

:: ByteLength

number of bytes to generate

-> CryptoRNGState 
-> IO ByteString 

Generate given number of cryptographically secure random bytes.

randomR :: (CryptoRNG m, Integral a) => (a, a) -> m a Source #

Generate a cryptographically secure random number in given, closed range.

Generation of values in other types

class Random a where Source #

Class for generating cryptographically secure random values.

Minimal complete definition

random

Methods

random :: CryptoRNG m => m a Source #

boundedIntegralRandom :: forall m a. (CryptoRNG m, Integral a, Bounded a) => m a Source #

Helper function for making Random instances.

Monad transformer for carrying rng state

data CryptoRNGT m a Source #

Monad transformer with RNG state.

Instances

MonadTrans CryptoRNGT Source # 

Methods

lift :: Monad m => m a -> CryptoRNGT m a #

MonadTransControl CryptoRNGT Source # 

Associated Types

type StT (CryptoRNGT :: (* -> *) -> * -> *) a :: * #

Methods

liftWith :: Monad m => (Run CryptoRNGT -> m a) -> CryptoRNGT m a #

restoreT :: Monad m => m (StT CryptoRNGT a) -> CryptoRNGT m a #

MonadBase b m => MonadBase b (CryptoRNGT m) Source # 

Methods

liftBase :: b α -> CryptoRNGT m α #

MonadBaseControl b m => MonadBaseControl b (CryptoRNGT m) Source # 

Associated Types

type StM (CryptoRNGT m :: * -> *) a :: * #

Methods

liftBaseWith :: (RunInBase (CryptoRNGT m) b -> b a) -> CryptoRNGT m a #

restoreM :: StM (CryptoRNGT m) a -> CryptoRNGT m a #

Monad m => Monad (CryptoRNGT m) Source # 

Methods

(>>=) :: CryptoRNGT m a -> (a -> CryptoRNGT m b) -> CryptoRNGT m b #

(>>) :: CryptoRNGT m a -> CryptoRNGT m b -> CryptoRNGT m b #

return :: a -> CryptoRNGT m a #

fail :: String -> CryptoRNGT m a #

Functor m => Functor (CryptoRNGT m) Source # 

Methods

fmap :: (a -> b) -> CryptoRNGT m a -> CryptoRNGT m b #

(<$) :: a -> CryptoRNGT m b -> CryptoRNGT m a #

Applicative m => Applicative (CryptoRNGT m) Source # 

Methods

pure :: a -> CryptoRNGT m a #

(<*>) :: CryptoRNGT m (a -> b) -> CryptoRNGT m a -> CryptoRNGT m b #

(*>) :: CryptoRNGT m a -> CryptoRNGT m b -> CryptoRNGT m b #

(<*) :: CryptoRNGT m a -> CryptoRNGT m b -> CryptoRNGT m a #

MonadIO m => MonadIO (CryptoRNGT m) Source # 

Methods

liftIO :: IO a -> CryptoRNGT m a #

Alternative m => Alternative (CryptoRNGT m) Source # 

Methods

empty :: CryptoRNGT m a #

(<|>) :: CryptoRNGT m a -> CryptoRNGT m a -> CryptoRNGT m a #

some :: CryptoRNGT m a -> CryptoRNGT m [a] #

many :: CryptoRNGT m a -> CryptoRNGT m [a] #

MonadPlus m => MonadPlus (CryptoRNGT m) Source # 

Methods

mzero :: CryptoRNGT m a #

mplus :: CryptoRNGT m a -> CryptoRNGT m a -> CryptoRNGT m a #

MonadThrow m => MonadThrow (CryptoRNGT m) Source # 

Methods

throwM :: Exception e => e -> CryptoRNGT m a #

MonadCatch m => MonadCatch (CryptoRNGT m) Source # 

Methods

catch :: Exception e => CryptoRNGT m a -> (e -> CryptoRNGT m a) -> CryptoRNGT m a #

MonadMask m => MonadMask (CryptoRNGT m) Source # 

Methods

mask :: ((forall a. CryptoRNGT m a -> CryptoRNGT m a) -> CryptoRNGT m b) -> CryptoRNGT m b #

uninterruptibleMask :: ((forall a. CryptoRNGT m a -> CryptoRNGT m a) -> CryptoRNGT m b) -> CryptoRNGT m b #

MonadIO m => CryptoRNG (CryptoRNGT m) Source # 
type StT CryptoRNGT a Source # 
type StM (CryptoRNGT m) a Source # 

mapCryptoRNGT :: (m a -> n b) -> CryptoRNGT m a -> CryptoRNGT n b Source #