cryptonite-0.15: Cryptography Primitives sink

LicenseBSD-style
MaintainerVincent Hanquez <vincent@snarc.org>
Stabilitystable
Portabilitygood
Safe HaskellNone
LanguageHaskell2010

Crypto.Random

Contents

Description

 

Synopsis

Deterministic instances

data ChaChaDRG

ChaCha Deterministic Random Generator

data SystemDRG

A referentially transparent System representation of the random evaluated out of the system.

Holding onto a specific DRG means that all the already evaluated bytes will be consistently replayed.

There's no need to reseed this DRG, as only pure entropy is represented here.

Instances

data Seed

Seed

seedNew :: MonadRandom randomly => randomly Seed

Create a new Seed from system entropy

seedFromInteger :: Integer -> Seed

Convert an integer to a Seed

seedToInteger :: Seed -> Integer

Convert a Seed to an integer

Deterministic Random class

getSystemDRG :: IO SystemDRG

Grab one instance of the System DRG

drgNew :: MonadRandom randomly => randomly ChaChaDRG

Create a new DRG from system entropy

drgNewSeed :: Seed -> ChaChaDRG

Create a new DRG from a seed

drgNewTest :: (Word64, Word64, Word64, Word64, Word64) -> ChaChaDRG

Create a new DRG from 5 Word64.

This is a convenient interface to create deterministic interface for quickcheck style testing.

It can also be used in other contexts provided the input has been properly randomly generated.

withDRG :: DRG gen => gen -> MonadPseudoRandom gen a -> (a, gen)

Run a pure computation with a Deterministic Random Generator in the MonadPseudoRandom

withRandomBytes :: (ByteArray ba, DRG g) => g -> Int -> (ba -> a) -> (a, g)

Generate len random bytes and mapped the bytes to the function f.

This is equivalent to use Control.Arrow first with randomBytesGenerate

class DRG gen where

A Deterministic Random Generator (DRG) class

Methods

randomBytesGenerate :: ByteArray byteArray => Int -> gen -> (byteArray, gen)

Generate N bytes of randomness from a DRG

Random abstraction

class (Functor m, Monad m) => MonadRandom m where

A monad constraint that allows to generate random bytes

Methods

getRandomBytes :: ByteArray byteArray => Int -> m byteArray

data MonadPseudoRandom gen a

A simple Monad class very similar to a State Monad with the state being a DRG.

Instances