git.iko.soy/typeable/entropy
on main help sign in
Add anti getentropy() flag
commitac894403df8087b58771f8d31c1207a81ace3035 authorThomas M. DuBuisson <tommd@muse.dev> dateTue 8 Mar 2022, 18:40 (5 years ago) parent0916ac5
2 files changed+14−1
cbits/random_initialized.c+4 entropy.cabal+10−1
cbits/random_initialized.c+4
@@ -6,12 +6,14 @@
66#include <unistd.h>
77
88#ifdef HAVE_GETENTROPY
9+#ifndef !DO_NOT_GET_ENTROPY
910static int ensure_pool_initialized_getentropy()
1011{
1112 char tmp;
1213 return getentropy(&tmp, sizeof(tmp));
1314}
1415#endif
16+#endif
1517
1618// Poll /dev/random to wait for randomness. This is a proxy for the /dev/urandom
1719// pool being initialized.
@@ -46,8 +48,10 @@ static int ensure_pool_initialized_poll()
4648int ensure_pool_initialized()
4749{
4850#ifdef HAVE_GETENTROPY
51+#ifndef !DO_NOT_GET_ENTROPY
4952 if (ensure_pool_initialized_getentropy() == 0)
5053 return 0;
54+#endif
5155#endif
5256
5357 return ensure_pool_initialized_poll();
entropy.cabal+10−1
@@ -1,6 +1,6 @@
11name: entropy
22
3−version: 0.4.1.7
3+version: 0.4.1.8
44description: A mostly platform independent method to obtain cryptographically strong entropy
55 (RDRAND, urandom, CryptAPI, and patches welcome)
66 Users looking for cryptographically strong (number-theoretically
@@ -24,6 +24,12 @@ tested-with: GHC == 8.2.2
2424-- data-files:
2525extra-source-files: ./cbits/getrandom.c ./cbits/random_initialized.c ./cbits/rdrand.c, ./cbits/rdrand.h, README.md
2626
27+Flag DoNotGetEntropy
28+ Description: Avoid use of the getentropy() *nix function. By default getentropy will be used
29+ if detected during compilation (this plays poorly with cross compilation).
30+ Default: False
31+ Manual: True
32+
2733custom-setup
2834 setup-depends: Cabal >= 1.10 && < 3.7
2935 , base < 5
@@ -72,6 +78,9 @@ library
7278 Build-Depends: unix
7379 c-sources: cbits/getrandom.c cbits/random_initialized.c
7480 }
81+ if flag(DoNotGetEntropy) {
82+ cc-options: -DDO_NOT_GET_ENTROPY
83+ }
7584
7685
7786source-repository head