@@ -47,7 +47,7 @@ import Foreign.Marshal.Alloc (alloca)
4747import Foreign.Marshal.Utils (toBool)
4848import Foreign.Storable (peek)
4949
50−#ifdef arch_x86_64
50+#ifdef HAVE_RDRAND
5151foreign import ccall unsafe "cpu_has_rdrand"
5252 c_cpu_has_rdrand :: IO CInt
5353
@@ -60,7 +60,7 @@ cpuHasRdRand = (/= 0) `fmap` c_cpu_has_rdrand
6060
6161data CryptHandle
6262 = CH Word32
63−#ifdef arch_x86_64
63+#ifdef HAVE_RDRAND
6464 | UseRdRand
6565#endif
6666
@@ -111,7 +111,7 @@ cryptReleaseCtx h = do
111111-- on platforms without a secure RNG!
112112getEntropy :: Int -> IO B.ByteString
113113getEntropy n = do
114−#ifdef arch_x86_64
114+#ifdef HAVE_RDRAND
115115 b <- cpuHasRdRand
116116 if b then hGetEntropy UseRdRand n
117117 else do
@@ -125,7 +125,7 @@ getEntropy n = do
125125-- |Open a handle from which random data can be read
126126openHandle :: IO CryptHandle
127127openHandle = do
128−#ifdef arch_x86_64
128+#ifdef HAVE_RDRAND
129129 b <- cpuHasRdRand
130130 if b then return UseRdRand
131131 else do
@@ -138,7 +138,7 @@ closeHandle (CH h) = cryptReleaseCtx h
138138-- |Read from `CryptHandle`
139139hGetEntropy :: CryptHandle -> Int -> IO B.ByteString
140140hGetEntropy (CH h) = cryptGenRandom h
141−#ifdef arch_x86_64
141+#ifdef HAVE_RDRAND
142142hGetEntropy UseRdRand =
143143 B.create n $ \ptr -> do
144144 r <- c_get_rand_bytes (castPtr ptr) (fromIntegral n)
@@ -150,7 +150,6 @@ hGetEntropy UseRdRand =
150150{- Not windows, assuming nix with a /dev/urandom -}
151151import Foreign.C.Types
152152import Foreign.Ptr
153−import Data.ByteString.Internal as B
154153
155154source :: FilePath
156155source = "/dev/urandom"
@@ -158,14 +157,14 @@ source = "/dev/urandom"
158157-- |Handle for manual resource mangement
159158data CryptHandle
160159 = CH Handle
161−#ifdef arch_x86_64
160+#ifdef HAVE_RDRAND
162161 | UseRdRand
163162#endif
164163
165164-- |Open a `CryptHandle`
166165openHandle :: IO CryptHandle
167166openHandle = do
168−#ifdef arch_x86_64
167+#ifdef HAVE_RDRAND
169168 b <- cpuHasRdRand
170169 if b then return UseRdRand
171170 else do
@@ -175,14 +174,14 @@ openHandle = do
175174-- |Close the `CryptHandle`
176175closeHandle :: CryptHandle -> IO ()
177176closeHandle (CH h) = hClose h
178−#ifdef arch_x86_64
177+#ifdef HAVE_RDRAND
179178closeHandle UseRdRand = return ()
180179#endif
181180
182181-- |Read random data from a `CryptHandle`
183182hGetEntropy :: CryptHandle -> Int -> IO B.ByteString
184183hGetEntropy (CH h) = B.hGet h
185−#ifdef arch_x86_64
184+#ifdef HAVE_RDRAND
186185hGetEntropy UseRdRand = \n -> do
187186 B.create n $ \ptr -> do
188187 r <- c_get_rand_bytes (castPtr ptr) (fromIntegral n)
@@ -190,7 +189,7 @@ hGetEntropy UseRdRand = \n -> do
190189 (fail "RDRand failed to gather entropy")
191190#endif
192191
193−#ifdef arch_x86_64
192+#ifdef HAVE_RDRAND
194193foreign import ccall unsafe "cpu_has_rdrand"
195194 c_cpu_has_rdrand :: IO CInt
196195
@@ -209,7 +208,7 @@ cpuHasRdRand = (/= 0) `fmap` c_cpu_has_rdrand
209208-- entropy.
210209getEntropy :: Int -> IO B.ByteString
211210getEntropy n = do
212−#if arch_x86_64
211+#ifdef HAVE_RDRAND
213212 b <- cpuHasRdRand
214213 if b then hGetEntropy UseRdRand n
215214 else do