Merge pull request #12 from ibotty/master

copy withRandomBytes from crypto-random
This commit is contained in:
Vincent Hanquez 2015-06-14 19:39:52 +01:00
commit 268f059470

View File

@ -13,6 +13,7 @@ module Crypto.Random
, drgNew
, drgNewTest
, withDRG
, withRandomBytes
, DRG(..)
-- * Random abstraction
, MonadRandom(..)
@ -22,7 +23,7 @@ module Crypto.Random
import Crypto.Random.Types
import Crypto.Random.ChaChaDRG
import Crypto.Random.Entropy
import Data.ByteArray (ScrubbedBytes)
import Data.ByteArray (ByteArray, ScrubbedBytes)
import Crypto.Internal.Imports
-- | Create a new DRG from system entropy
@ -38,3 +39,10 @@ drgNew = initialize <$> (getEntropy 40 :: IO ScrubbedBytes)
-- has been properly randomly generated.
drgNewTest :: (Word64, Word64, Word64, Word64, Word64) -> ChaChaDRG
drgNewTest = initializeWords
-- | Generate @len random bytes and mapped the bytes to the function @f.
--
-- This is equivalent to use Control.Arrow 'first' with 'randomBytesGenerate'
withRandomBytes :: (ByteArray ba, DRG g) => g -> Int -> (ba -> a) -> (a, g)
withRandomBytes rng len f = (f bs, rng')
where (bs, rng') = randomBytesGenerate len rng