git.iko.soy/typeable/entropy
on 5fda502 help sign in
42 lines 1.1 kB history raw
1{-# LANGUAGE CPP, ForeignFunctionInterface, BangPatterns, ScopedTypeVariables #-}
2{-|
3 Maintainer: Thomas.DuBuisson@gmail.com
4 Stability: beta
5 Portability: portable
7 Obtain entropy from system sources or x86 RDRAND when available.
9 Currently supporting:
11 - Windows via CryptoAPO
12 - *nix systems via @\/dev\/urandom@
13 - QNX
14 - Xen only when RDRAND is available.
15-}
17module System.Entropy
18 ( getEntropy,
19#if defined(isWindows)
20 module System.EntropyWindows
21 ) where
22import System.EntropyWindows
23#else
24 module System.EntropyNix
25 ) where
26import System.EntropyNix
27#endif
29import qualified Data.ByteString as B
31-- |Inefficiently get a specific number of bytes of cryptographically
32-- secure random data using the system-specific facilities.
33--
34-- Use '/dev/urandom' on *nix and CryptAPI when on Windows. In short,
35-- this entropy is considered cryptographically secure but not true
36-- entropy.
37getEntropy :: Int -> IO B.ByteString
38getEntropy n = do
39 h <- openHandle
40 e <- hGetEntropy h n
41 closeHandle h
42 return e