summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2015-02-13 17:59:28 +0100
committerLars-Dominik Braun <lars@6xq.net>2015-05-02 21:36:45 +0200
commit6527e433b6856995a356e0fc0dfa5ef7816bb60f (patch)
tree652a552ac59ac28c6bcb2b7e4f57cee38853d81f
parentb9d887fc3cd3ae26c678bf35bc90c4f1d6b03888 (diff)
downloadpucket-6527e433b6856995a356e0fc0dfa5ef7816bb60f.tar.gz
pucket-6527e433b6856995a356e0fc0dfa5ef7816bb60f.tar.bz2
pucket-6527e433b6856995a356e0fc0dfa5ef7816bb60f.zip
Switch rng seed to /dev/urandom
-rw-r--r--random.c24
-rw-r--r--wscript1
2 files changed, 12 insertions, 13 deletions
diff --git a/random.c b/random.c
index f0a06c2..1a0c964 100644
--- a/random.c
+++ b/random.c
@@ -4,6 +4,12 @@
* generators, scrambled”, Sebastiano Vigna
*/
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <unistd.h>
+
#include "random.h"
uint64_t rand_u64 (randctx * const st) {
@@ -33,21 +39,15 @@ int rand_bool (randctx * const st) {
return rand_u64 (st) & 1;
}
-/* Generate random uint64_t with Intel’s rdrand instruction
- */
-static uint64_t rand64 () {
- unsigned long long rand;
- while (!__builtin_ia32_rdrand64_step (&rand));
- return rand;
-}
-
/* Seed rng with rdrand
*/
void rand_seed (randctx * const st) {
- /* seed with high-quality randomness */
- for (unsigned char i = 0; i < XORSHIFT_S; i++) {
- st->s[i] = rand64 ();
- }
+ int fd = open ("/dev/urandom", O_RDONLY);
+ assert (fd != -1);
+ int ret = read (fd, &st->s, sizeof (st->s));
+ assert (ret != -1);
+ close (fd);
+ st->p = 0;
}
#if 0
diff --git a/wscript b/wscript
index a03c295..ce03849 100644
--- a/wscript
+++ b/wscript
@@ -6,7 +6,6 @@ def configure(conf):
conf.load ('compiler_c')
conf.env.append_unique ('CFLAGS', '-std=gnu99')
- conf.env.append_unique ('CFLAGS', '-mrdrnd')
conf.check_cfg (path='xml2-config', args='--cflags --libs', package='', uselib_store='xml2')
conf.check_cc (lib='xml2', header_name='libxml/parser.h', function_name='xmlParseFile', use='xml2')