crypto-rng-0.1.1.0: 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.

Methods

random :: CryptoRNG m => m a Source #

Instances
Random Int Source # 
Instance details

Defined in Crypto.RNG

Methods

random :: CryptoRNG m => m Int Source #

Random Int16 Source # 
Instance details

Defined in Crypto.RNG

Methods

random :: CryptoRNG m => m Int16 Source #

Random Int32 Source # 
Instance details

Defined in Crypto.RNG

Methods

random :: CryptoRNG m => m Int32 Source #

Random Int64 Source # 
Instance details

Defined in Crypto.RNG

Methods

random :: CryptoRNG m => m Int64 Source #

Random Word Source # 
Instance details

Defined in Crypto.RNG

Methods

random :: CryptoRNG m => m Word Source #

Random Word8 Source # 
Instance details

Defined in Crypto.RNG

Methods

random :: CryptoRNG m => m Word8 Source #

Random Word16 Source # 
Instance details

Defined in Crypto.RNG

Methods

random :: CryptoRNG m => m Word16 Source #

Random Word32 Source # 
Instance details

Defined in Crypto.RNG

Methods

random :: CryptoRNG m => m Word32 Source #

Random Word64 Source # 
Instance details

Defined in Crypto.RNG

Methods

random :: CryptoRNG m => m Word64 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 # 
Instance details

Defined in Crypto.RNG

Methods

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

MonadTransControl CryptoRNGT Source # 
Instance details

Defined in Crypto.RNG

Associated Types

type StT CryptoRNGT a :: Type #

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 # 
Instance details

Defined in Crypto.RNG

Methods

liftBase :: b α -> CryptoRNGT m α #

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

Defined in Crypto.RNG

Associated Types

type StM (CryptoRNGT m) a :: Type #

Methods

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

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

MonadError e m => MonadError e (CryptoRNGT m) Source # 
Instance details

Defined in Crypto.RNG

Methods

throwError :: e -> CryptoRNGT m a #

catchError :: CryptoRNGT m a -> (e -> CryptoRNGT m a) -> CryptoRNGT m a #

Monad m => Monad (CryptoRNGT m) Source # 
Instance details

Defined in Crypto.RNG

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 # 
Instance details

Defined in Crypto.RNG

Methods

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

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

Applicative m => Applicative (CryptoRNGT m) Source # 
Instance details

Defined in Crypto.RNG

Methods

pure :: a -> CryptoRNGT m a #

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

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

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

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

MonadIO m => MonadIO (CryptoRNGT m) Source # 
Instance details

Defined in Crypto.RNG

Methods

liftIO :: IO a -> CryptoRNGT m a #

Alternative m => Alternative (CryptoRNGT m) Source # 
Instance details

Defined in Crypto.RNG

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 # 
Instance details

Defined in Crypto.RNG

Methods

mzero :: CryptoRNGT m a #

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

MonadThrow m => MonadThrow (CryptoRNGT m) Source # 
Instance details

Defined in Crypto.RNG

Methods

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

MonadCatch m => MonadCatch (CryptoRNGT m) Source # 
Instance details

Defined in Crypto.RNG

Methods

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

MonadMask m => MonadMask (CryptoRNGT m) Source # 
Instance details

Defined in Crypto.RNG

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 #

generalBracket :: CryptoRNGT m a -> (a -> ExitCase b -> CryptoRNGT m c) -> (a -> CryptoRNGT m b) -> CryptoRNGT m (b, c) #

MonadIO m => CryptoRNG (CryptoRNGT m) Source # 
Instance details

Defined in Crypto.RNG

type StT CryptoRNGT a Source # 
Instance details

Defined in Crypto.RNG

type StM (CryptoRNGT m) a Source # 
Instance details

Defined in Crypto.RNG

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