diff options
Diffstat (limited to 'src/crypto/reflibs/Crypto/Random/Entropy.hs')
| -rw-r--r-- | src/crypto/reflibs/Crypto/Random/Entropy.hs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/crypto/reflibs/Crypto/Random/Entropy.hs b/src/crypto/reflibs/Crypto/Random/Entropy.hs new file mode 100644 index 0000000..d0685e4 --- /dev/null +++ b/src/crypto/reflibs/Crypto/Random/Entropy.hs @@ -0,0 +1,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 |