From 7a85ec97898e4f35f17b855e91ff63ddaa0139c7 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Mon, 14 Apr 2014 21:59:24 -0700 Subject: [PATCH] Directly use OpenBSD's arc4random() instead of opening /dev/urandom. --- .../sysrandom/randombytes_sysrandom.c | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c b/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c index d0e25209..3bb521b9 100644 --- a/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c +++ b/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c @@ -24,6 +24,39 @@ # include #endif +#ifdef __OpenBSD__ + +uint32_t +randombytes_sysrandom(void) +{ + return arc4random(); +} + +void +randombytes_sysrandom_stir(void) +{ +} + +uint32_t +randombytes_sysrandom_uniform(const uint32_t upper_bound) +{ + return arc4random_uniform(upper_bound); +} + +void +randombytes_sysrandom_buf(void * const buf, const size_t size) +{ + return arc4random_buf(buf, size); +} + +int +randombytes_sysrandom_close(void) +{ + return 0; +} + +#else /* __OpenBSD__ */ + typedef struct SysRandom_ { #ifdef _WIN32 HCRYPTPROV hcrypt_prov; @@ -202,6 +235,8 @@ randombytes_sysrandom_uniform(const uint32_t upper_bound) return r % upper_bound; } +#endif + const char * randombytes_sysrandom_implementation_name(void) {