@@ -5,17 +5,37 @@ security applications by calling out to either windows crypto api, unix/linux's
5`/dev/urandom`. Hardware RNGs (currently RDRAND, patches welcome) are supported
5`/dev/urandom`. Hardware RNGs (currently RDRAND, patches welcome) are supported
6via the `hardwareRNG` function.
6via the `hardwareRNG` function.
8−If you wish to obtain an XOR of the hardware and system RNG consider:
8+## Quick Start
10+To simply get random bytes use `getEntropy`:
15+ build-depends: base, entropy, bytestring
17+import qualified Data.ByteString as BS
21+main = print . BS.unpack =<< getEntropy 16
22+-- Example output: [241,191,215,193,225,27,121,244,16,155,252,41,131,38,6,100]
25+## Faster Randoms from Hardware
27+Most x86 systems include a hardware random number generator. These can be
28+faster but require more trust in the platform:
11−import Data.Bits (xor)
12import qualified Data.ByteString as B
31import qualified Data.ByteString as B
13−import qualified Control.Exception as X
32+import System.Entropy
34+eitherRNG :: Int -> IO B.ByteString
35+eitherRNG sz = maybe (getEntropy sz) pure =<< getHardwareEntropy sz
15−xorRNG sz = do hw <- hardwareRNG sz
37+main :: IO ()
16− h <- openHandle
38+main = print . B.unpack =<< eitherRNG 32
17− sys <- hGetEntropy h `X.finally` closeHandle h
18− pure $ B.pack $ B.zipWith xor hw sys
21This package supports Windows, {li,u}nix, QNX, and has preliminary support for HaLVM.
41This package supports Windows, {li,u}nix, QNX, and has preliminary support for HaLVM.