Safe Haskell | None |
---|---|
Language | Haskell2010 |
Secure generation of random numbers and
ByteString
s
Synopsis
-
newtype
SecureRandom
a =
SecureRandom
{
- runSecureRandom :: IO a
- deterministic :: ByteString -> MonadPseudoRandom ChaChaDRG a -> a
- randomNumber :: forall m. 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.
Instances
Monad SecureRandom Source # | |
Defined in Cardano.Crypto.Random (>>=) :: SecureRandom a -> (a -> SecureRandom b) -> SecureRandom b Source # (>>) :: SecureRandom a -> SecureRandom b -> SecureRandom b Source # return :: a -> SecureRandom a Source # |
|
Functor SecureRandom Source # | |
Defined in Cardano.Crypto.Random fmap :: (a -> b) -> SecureRandom a -> SecureRandom b Source # (<$) :: a -> SecureRandom b -> SecureRandom a Source # |
|
Applicative SecureRandom Source # | |
Defined in Cardano.Crypto.Random pure :: a -> SecureRandom a Source # (<*>) :: SecureRandom (a -> b) -> SecureRandom a -> SecureRandom b Source # liftA2 :: (a -> b -> c) -> SecureRandom a -> SecureRandom b -> SecureRandom c Source # (*>) :: SecureRandom a -> SecureRandom b -> SecureRandom b Source # (<*) :: SecureRandom a -> SecureRandom b -> SecureRandom a Source # |
|
MonadRandom SecureRandom Source # | |
Defined in Cardano.Crypto.Random getRandomBytes :: ByteArray byteArray => Int -> SecureRandom byteArray Source # |
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 :: forall 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.com
a
20051580
615030). 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]