cardano-crypto-wrapper-1.5.1.3: Cryptographic primitives used in Byron era of the Cardano project
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cardano.Crypto.Random

Description

Secure generation of random numbers and ByteStrings

Synopsis

Documentation

newtype SecureRandom a Source #

You can use runSecureRandom on any MonadRandom computation to use the operating system entropy source to satisfy every request for randomness. That is, this does not use a fixed entropy pool shared across all requests; it gets entropy from the operating system for every request.

This is suitable for key generation but is inappropriate for other uses since it can quickly drain the operating system entropy.

Constructors

SecureRandom 

Fields

Instances

Instances details
Applicative SecureRandom Source # 
Instance details

Defined in Cardano.Crypto.Random

Functor SecureRandom Source # 
Instance details

Defined in Cardano.Crypto.Random

Methods

fmap ∷ (a → b) → SecureRandom a → SecureRandom b Source #

(<$) ∷ a → SecureRandom b → SecureRandom a Source #

Monad SecureRandom Source # 
Instance details

Defined in Cardano.Crypto.Random

MonadRandom SecureRandom Source # 
Instance details

Defined in Cardano.Crypto.Random

Methods

getRandomBytesByteArray byteArray ⇒ IntSecureRandom byteArray Source #

deterministicByteStringMonadPseudoRandom ChaChaDRG a → a Source #

You can use deterministic on any MonadRandom computation to make it use a seed (hopefully produced by a Really Secure™ randomness source). The seed has to have enough entropy to make this function secure.

randomNumber ∷ ∀ m. MonadRandom m ⇒ Integer → m Integer Source #

Generate a random number in range [0, n)

We want to avoid modulo bias, so we use the arc4random_uniform implementation (http:/stackoverflow.coma20051580615030). Specifically, we repeatedly generate a random number in range [0, 2^x) until we hit on something outside of [0, 2^x mod n), which means that it'll be in range [2^x mod n, 2^x). The amount of numbers in this interval is guaranteed to be divisible by n, and thus applying mod to it will be safe.

randomNumberInRangeMonadRandom m ⇒ IntegerInteger → m Integer Source #

Generate a random number in range [a, b]