From 4ac23de3c7a99ea9a88a233801fe5d72a1095fe4 Mon Sep 17 00:00:00 2001 From: TLINDEN Date: Sat, 16 Nov 2013 14:30:32 +0100 Subject: [PATCH] fixed linux portability, use libsodium random*() stuff --- include/pcp/platform.h | 31 ++++--------------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/include/pcp/platform.h b/include/pcp/platform.h index d664735..f025384 100644 --- a/include/pcp/platform.h +++ b/include/pcp/platform.h @@ -57,39 +57,16 @@ #ifndef HAVE_ARC4RANDOM_BUF -// shitty OS. we've got to use other stuff +// shitty OS. we're using libsodium's implementation -#include -#include -#include -#include - -static inline FILE *__getranddev() { - FILE *R; - if((R = fopen("/dev/urandom", "rb")) == NULL) { - // not even this is here! what a shame - if((R = fopen("/dev/random", "rb")) == NULL) { - // not available or depleted. that's too bad - fprintf(stderr, "ERROR: /dev/urandom not available, /dev/random is depleted.\n"); - fprintf(stderr, "That's horrible for you but a nightmare for me. I die. Bye.\n"); - exit(2); - } - } - return R; -} +#include static inline u_int32_t arc4random() { - uint32_t x; - FILE *R = __getranddev(); - fread(&x, sizeof(uint32_t), 1, R); - fclose(R); - return x; + return randombytes_random(); } static inline void arc4random_buf(void *buf, size_t nbytes) { - FILE *R = __getranddev(); - fread(buf, nbytes, 1, R); - fclose(R); + randombytes(buf, nbytes); }