git.iko.soy/typeable/entropy
on main help sign in
Remove more bits related to HaLVM (no longer supported)
commit3e76a6eb79d69cb18f1beeb4ff352aeca4b8bd83 authorThomas M. DuBuisson <tommd@muse.dev> dateTue 2 Nov 2021, 07:56 (5 years ago) parent03ae01c
3 files changed+3−99
System/Entropy.hs−3 System/EntropyXen.hs−76 entropy.cabal+3−20
System/Entropy.hs−3
@@ -11,7 +11,6 @@
1111 - Windows via CryptoAPI
1212 - *nix systems via @\/dev\/urandom@
1313 - Includes QNX
14− - Xen (only when RDRAND is available)
1514 - ghcjs/browser via JavaScript crypto API.
1615-}
1716
@@ -28,8 +27,6 @@ module System.Entropy
2827import System.EntropyGhcjs
2928#elif defined(isWindows)
3029import System.EntropyWindows
31−#elif XEN
32−import System.EntropyXen
3330#else
3431import System.EntropyNix
3532#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
1616bug-reports: https://github.com/TomMD/entropy/issues
1717stability: stable
1818
19−-- build-type: Simple
20−-- ^^ Used for HaLVM
2119build-type: Custom
2220
2321-- ^^ Test for RDRAND support using 'ghc'
@@ -26,14 +24,6 @@ tested-with: GHC == 8.2.2
2624-- data-files:
2725extra-source-files: ./cbits/getrandom.c ./cbits/random_initialized.c ./cbits/rdrand.c, ./cbits/rdrand.h, README.md
2826
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−
3727custom-setup
3828 setup-depends: Cabal >= 1.10 && < 3.7
3929 , base < 5
@@ -50,10 +40,7 @@ library
5040 if os(windows)
5141 other-modules: System.EntropyWindows
5242 else {
53− if os(halvm)
54− other-modules: System.EntropyXen
55− else
56− other-modules: System.EntropyNix
43+ other-modules: System.EntropyNix
5744 }
5845 }
5946 other-extensions: CPP, ForeignFunctionInterface, BangPatterns,
@@ -67,9 +54,6 @@ library
6754 , jsaddle
6855 }
6956 else {
70− if(os(halvm))
71− cpp-options: -DXEN -DHAVE_RDRAND
72− cc-options: -DXEN -DHAVE_RDRAND
7357 if arch(x86_64)
7458 cpp-options: -Darch_x86_64
7559 cc-options: -Darch_x86_64 -O2
@@ -85,9 +69,8 @@ library
8569 cc-options: -DisWindows
8670 extra-libraries: advapi32
8771 else
88− if !os(halvm)
89− Build-Depends: unix
90− c-sources: cbits/getrandom.c cbits/random_initialized.c
72+ Build-Depends: unix
73+ c-sources: cbits/getrandom.c cbits/random_initialized.c
9174 }
9275
9376