copy withRandomBytes from crypto-random
This commit is contained in:
parent
9cc4ffdd04
commit
ff36164305
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user