blob: d0685e472aae029af9b8239112644fdf19cec378 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
module Crypto.Random.Entropy (
getEntropy,
) where
import Foreign.C.Error
import Foreign.C.Types
import Foreign.Marshal.Alloc
import Foreign.Ptr
import Data.ByteString (ByteString)
import Data.ByteString.Unsafe
getEntropy :: Int -> IO ByteString
getEntropy n = do
bytes <- mallocBytes n
throwErrnoIfMinus1_ "getentropy" $ c_getentropy bytes (fromIntegral n)
unsafePackMallocCStringLen ( bytes, n )
foreign import ccall "unistd.h getentropy" c_getentropy :: Ptr CChar -> CSize -> IO CInt
|