git.iko.soy/typeable/entropy
on main help sign in
Merge pull request #64 from TomMD/fix/remove-more-xen
0916ac5Thomas M. DuBuisson
System/Entropy.hs−3
@@ -11,7 +11,6 @@
11 - Windows via CryptoAPI
11 - Windows via CryptoAPI
12 - *nix systems via @\/dev\/urandom@
12 - *nix systems via @\/dev\/urandom@
13 - Includes QNX
13 - Includes QNX
14− - Xen (only when RDRAND is available)
15 - ghcjs/browser via JavaScript crypto API.
14 - ghcjs/browser via JavaScript crypto API.
16-}
15-}
17
16
@@ -28,8 +27,6 @@ module System.Entropy
28import System.EntropyGhcjs
27import System.EntropyGhcjs
29#elif defined(isWindows)
28#elif defined(isWindows)
30import System.EntropyWindows
29import System.EntropyWindows
31−#elif XEN
32−import System.EntropyXen
33#else
30#else
34import System.EntropyNix
31import System.EntropyNix
35#endif
32#endif
System/EntropyXen.hsdeleted−76
@@ -1,76 +0,0 @@
1−{-# LANGUAGE CPP, ForeignFunctionInterface, BangPatterns, ScopedTypeVariables #-}
2−{-|
3− Maintainer: Thomas.DuBuisson@gmail.com
4− Stability: beta
5− Portability: portable
6−
7− Obtain entropy from RDRAND when available.
8−
9−-}
10−
11−module System.EntropyXen
12− ( CryptHandle
13− , openHandle
14− , hGetEntropy
15− , closeHandle
16− , hardwareRandom
17− ) where
18−
19−import Control.Monad (liftM, when)
20−import Data.ByteString as B
21−import System.IO.Error (mkIOError, eofErrorType, ioeSetErrorString)
22−
23−import Foreign (allocaBytes)
24−import Foreign.Ptr
25−import Foreign.C.Types
26−import Data.ByteString.Internal as B
27−
28−#ifdef arch_i386
29−-- See .cabal wrt GCC 4.8.2 asm compilation bug
30−#undef HAVE_RDRAND
31−#endif
32−
33−#ifndef HAVE_RDRAND
34−#error "The entropy package requires RDRAND support when using the halvm/Xen"
35−#endif
36−data CryptHandle = UseRdRand -- or die trying
37−
38−-- |Open a `CryptHandle`
39−openHandle :: IO CryptHandle
40−openHandle = do
41− b <- cpuHasRdRand
42− if b then return UseRdRand
43− else nonRDRandHandle
44− where
45− nonRDRandHandle :: IO CryptHandle
46− nonRDRandHandle = error "entropy: On halvm there is no entropy other than RDRAND."
47−
48−-- |Close the `CryptHandle`
49−closeHandle :: CryptHandle -> IO ()
50−closeHandle UseRdRand = return ()
51−
52−-- | Get random values from the hardware RNG or return Nothing if no
53−-- supported hardware RNG is available.
54−--
55−-- Supported hardware:
56−-- * RDRAND
57−-- * Patches welcome
58−hardwareRandom :: Int -> IO (Maybe B.ByteString)
59−hardwareRandom sz = Just <$> hGetEntropy UseRdRand sz
60−
61−-- |Read random data from a `CryptHandle`, which uses RDRAND (when on Xen)
62−hGetEntropy :: CryptHandle -> Int -> IO B.ByteString
63−hGetEntropy UseRdRand = \n -> do
64− B.create n $ \ptr -> do
65− r <- c_get_rand_bytes (castPtr ptr) (fromIntegral n)
66− when (r /= 0)
67− (fail "RDRand failed to gather entropy")
68−
69−foreign import ccall unsafe "cpu_has_rdrand"
70− c_cpu_has_rdrand :: IO CInt
71−
72−foreign import ccall unsafe "get_rand_bytes"
73− c_get_rand_bytes :: Ptr CUChar -> CSize -> IO CInt
74−
75−cpuHasRdRand :: IO Bool
76−cpuHasRdRand = (/= 0) `fmap` c_cpu_has_rdrand
entropy.cabal+3−20
@@ -16,8 +16,6 @@ homepage: https://github.com/TomMD/entropy
16bug-reports: https://github.com/TomMD/entropy/issues
16bug-reports: https://github.com/TomMD/entropy/issues
17stability: stable
17stability: stable
18
18
19−-- build-type: Simple
20−-- ^^ Used for HaLVM
21build-type: Custom
19build-type: Custom
22
20
23-- ^^ Test for RDRAND support using 'ghc'
21-- ^^ Test for RDRAND support using 'ghc'
@@ -26,14 +24,6 @@ tested-with: GHC == 8.2.2
26-- data-files:
24-- data-files:
27extra-source-files: ./cbits/getrandom.c ./cbits/random_initialized.c ./cbits/rdrand.c, ./cbits/rdrand.h, README.md
25extra-source-files: ./cbits/getrandom.c ./cbits/random_initialized.c ./cbits/rdrand.c, ./cbits/rdrand.h, README.md
28
26
29−-- Notice to compile with HaLVM the above 'build-type' must be changed
30−-- to 'Simple' instead of 'Custom'. The current build system naively
31−-- runs GHC to determine if the compiler supports RDRAND before proceeding.
32−flag halvm
33− description: Build for the HaLVM
34− default: False
35−
36−
37custom-setup
27custom-setup
38 setup-depends: Cabal >= 1.10 && < 3.7
28 setup-depends: Cabal >= 1.10 && < 3.7
39 , base < 5
29 , base < 5
@@ -50,10 +40,7 @@ library
50 if os(windows)
40 if os(windows)
51 other-modules: System.EntropyWindows
41 other-modules: System.EntropyWindows
52 else {
42 else {
53− if os(halvm)
54− other-modules: System.EntropyXen
55− else
56− other-modules: System.EntropyNix
43+ other-modules: System.EntropyNix
57 }
44 }
58 }
45 }
59 other-extensions: CPP, ForeignFunctionInterface, BangPatterns,
46 other-extensions: CPP, ForeignFunctionInterface, BangPatterns,
@@ -67,9 +54,6 @@ library
67 , jsaddle
54 , jsaddle
68 }
55 }
69 else {
56 else {
70− if(os(halvm))
71− cpp-options: -DXEN -DHAVE_RDRAND
72− cc-options: -DXEN -DHAVE_RDRAND
73 if arch(x86_64)
57 if arch(x86_64)
74 cpp-options: -Darch_x86_64
58 cpp-options: -Darch_x86_64
75 cc-options: -Darch_x86_64 -O2
59 cc-options: -Darch_x86_64 -O2
@@ -85,9 +69,8 @@ library
85 cc-options: -DisWindows
69 cc-options: -DisWindows
86 extra-libraries: advapi32
70 extra-libraries: advapi32
87 else
71 else
88− if !os(halvm)
89− Build-Depends: unix
72+ Build-Depends: unix
90− c-sources: cbits/getrandom.c cbits/random_initialized.c
73+ c-sources: cbits/getrandom.c cbits/random_initialized.c
91 }
74 }
92
75
93
76