| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Cardano.Crypto.Random
Description
Secure generation of random numbers and ByteStrings
Synopsis
- newtype SecureRandom a = SecureRandom {
- runSecureRandom ∷ IO a
- deterministic ∷ ByteString → MonadPseudoRandom ChaChaDRG a → a
- randomNumber ∷ MonadRandom m ⇒ Integer → m Integer
- randomNumberInRange ∷ MonadRandom m ⇒ Integer → Integer → m Integer
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
| MonadRandom SecureRandom Source # | |
Defined in Cardano.Crypto.Random Methods getRandomBytes ∷ ByteArray byteArray ⇒ Int → SecureRandom byteArray Source # | |
| Applicative SecureRandom Source # | |
Defined in Cardano.Crypto.Random Methods pure ∷ a → SecureRandom a # (<*>) ∷ SecureRandom (a → b) → SecureRandom a → SecureRandom b # liftA2 ∷ (a → b → c) → SecureRandom a → SecureRandom b → SecureRandom c # (*>) ∷ SecureRandom a → SecureRandom b → SecureRandom b # (<*) ∷ SecureRandom a → SecureRandom b → SecureRandom a # | |
| Functor SecureRandom Source # | |
Defined in Cardano.Crypto.Random Methods fmap ∷ (a → b) → SecureRandom a → SecureRandom b # (<$) ∷ a → SecureRandom b → SecureRandom a # | |
| Monad SecureRandom Source # | |
Defined in Cardano.Crypto.Random Methods (>>=) ∷ SecureRandom a → (a → SecureRandom b) → SecureRandom b # (>>) ∷ SecureRandom a → SecureRandom b → SecureRandom b # return ∷ a → SecureRandom a # | |
deterministic ∷ ByteString → MonadPseudoRandom 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 ∷ 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.
randomNumberInRange ∷ MonadRandom m ⇒ Integer → Integer → m Integer Source #
Generate a random number in range [a, b]