diff --git a/Crypto/Internal/Memory.hs b/Crypto/Internal/Memory.hs index ef710ad..a4dda51 100644 --- a/Crypto/Internal/Memory.hs +++ b/Crypto/Internal/Memory.hs @@ -1,5 +1,5 @@ -- | --- Module : Crypto.Internal.Bytes +-- Module : Crypto.Internal.Memory -- License : BSD-style -- Maintainer : Vincent Hanquez -- Stability : stable diff --git a/Crypto/Random/Entropy.hs b/Crypto/Random/Entropy.hs index d80251d..dee5108 100644 --- a/Crypto/Random/Entropy.hs +++ b/Crypto/Random/Entropy.hs @@ -10,15 +10,12 @@ module Crypto.Random.Entropy ) where import Data.Maybe (catMaybes) -import Data.SecureMem +import Crypto.Internal.ByteArray -import Crypto.Random.Types import Crypto.Random.Entropy.Unsafe -- | Get some entropy from the system source of entropy -getEntropy :: Int -> IO Random +getEntropy :: ByteArray byteArray => Int -> IO byteArray getEntropy n = do backends <- catMaybes `fmap` sequence supportedBackends - out <- allocateSecureMem n - withSecureMemPtr out $ replenish n backends - return $ Random out + byteArrayAlloc n (replenish n backends) diff --git a/Crypto/Random/EntropyPool.hs b/Crypto/Random/EntropyPool.hs index e22bbe1..1151f79 100644 --- a/Crypto/Random/EntropyPool.hs +++ b/Crypto/Random/EntropyPool.hs @@ -14,7 +14,7 @@ module Crypto.Random.EntropyPool import Control.Concurrent.MVar import Crypto.Random.Entropy.Unsafe -import Crypto.Random.Types +import Crypto.Internal.ByteArray import Data.SecureMem import Data.Word (Word8) import Data.Maybe (catMaybes) @@ -66,8 +66,5 @@ getEntropyPtr (EntropyPool backends posM sm) n outPtr = copyLoop (d `plusPtr` m) s (wrappedPos + m) (left - m) -- | Grab a chunk of entropy from the entropy pool. -getEntropyFrom :: EntropyPool -> Int -> IO Random -getEntropyFrom pool n = do - out <- allocateSecureMem n - withSecureMemPtr out $ getEntropyPtr pool n - return $ Random out +getEntropyFrom :: ByteArray byteArray => EntropyPool -> Int -> IO byteArray +getEntropyFrom pool n = byteArrayAlloc n (getEntropyPtr pool n)