crypton-2.2.5: Cryptography Primitives
LicenseBSD-style
MaintainerVincent Hanquez <vincent@snarc.org>
Stabilityexperimental
PortabilityGood
Safe HaskellNone
LanguageHaskell2010

Crypto.Random.Types

Description

 
Synopsis

Documentation

class Monad m => MonadRandom (m :: Type -> Type) where Source #

A monad constraint that allows to generate random bytes

Everything in this library that draws a key, a nonce or a signature's randomness draws it through this class, and cannot tell a strong source from a weak one. The two instances below are the ones to reach for: IO reads the system entropy source, and MonadPseudoRandom runs a DRG seeded from it.

An instance of your own is held to the same standard. A generator that another party can predict, or that repeats, yields keys and signatures that give away what they are meant to keep -- so the deliberately repeatable instance that makes a test reproducible is not one to ship with.

Methods

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

Instances

Instances details
MonadRandom IO Source #

Through the generator of SysDRG: a ChaCha20 generator per operating system thread, reseeded from the system. Where that cannot be seeded -- a system with no getrandom(2) or getentropy(3), which includes Windows for now -- this is the system entropy source directly, as it was before the generator existed.

Instance details

Defined in Crypto.Random.Types

Methods

getRandomBytes :: ByteArray byteArray => Int -> IO byteArray Source #

DRG gen => MonadRandom (MonadPseudoRandom gen) Source # 
Instance details

Defined in Crypto.Random.Types

Methods

getRandomBytes :: ByteArray byteArray => Int -> MonadPseudoRandom gen byteArray Source #

data MonadPseudoRandom gen a Source #

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

Instances

Instances details
DRG gen => Applicative (MonadPseudoRandom gen) Source # 
Instance details

Defined in Crypto.Random.Types

Methods

pure :: a -> MonadPseudoRandom gen a #

(<*>) :: MonadPseudoRandom gen (a -> b) -> MonadPseudoRandom gen a -> MonadPseudoRandom gen b #

liftA2 :: (a -> b -> c) -> MonadPseudoRandom gen a -> MonadPseudoRandom gen b -> MonadPseudoRandom gen c #

(*>) :: MonadPseudoRandom gen a -> MonadPseudoRandom gen b -> MonadPseudoRandom gen b #

(<*) :: MonadPseudoRandom gen a -> MonadPseudoRandom gen b -> MonadPseudoRandom gen a #

DRG gen => Functor (MonadPseudoRandom gen) Source # 
Instance details

Defined in Crypto.Random.Types

Methods

fmap :: (a -> b) -> MonadPseudoRandom gen a -> MonadPseudoRandom gen b #

(<$) :: a -> MonadPseudoRandom gen b -> MonadPseudoRandom gen a #

DRG gen => Monad (MonadPseudoRandom gen) Source # 
Instance details

Defined in Crypto.Random.Types

Methods

(>>=) :: MonadPseudoRandom gen a -> (a -> MonadPseudoRandom gen b) -> MonadPseudoRandom gen b #

(>>) :: MonadPseudoRandom gen a -> MonadPseudoRandom gen b -> MonadPseudoRandom gen b #

return :: a -> MonadPseudoRandom gen a #

DRG gen => MonadRandom (MonadPseudoRandom gen) Source # 
Instance details

Defined in Crypto.Random.Types

Methods

getRandomBytes :: ByteArray byteArray => Int -> MonadPseudoRandom gen byteArray Source #

class DRG gen where Source #

A Deterministic Random Generator (DRG) class

Methods

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

Generate N bytes of randomness from a DRG

Instances

Instances details
DRG ChaChaDRG Source # 
Instance details

Defined in Crypto.Random.ChaChaDRG

Methods

randomBytesGenerate :: ByteArray byteArray => Int -> ChaChaDRG -> (byteArray, ChaChaDRG) Source #

DRG SystemDRG Source # 
Instance details

Defined in Crypto.Random.SystemDRG

Methods

randomBytesGenerate :: ByteArray byteArray => Int -> SystemDRG -> (byteArray, SystemDRG) Source #

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

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