From 0bb8daa7da52240a971a4ce83d97cfb62971ea78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 18 Oct 2026 16:52:41 +0200 Subject: Add crypto backend using various reference libraries --- src/crypto/reflibs/Crypto/Random/Entropy.hs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/crypto/reflibs/Crypto/Random/Entropy.hs (limited to 'src/crypto/reflibs/Crypto/Random/Entropy.hs') 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 -- cgit v1.2.3