3#ifndef USE_OPENSSL_RAND
8#ifdef ENABLE_CT_TESTING
9#include <valgrind/memcheck.h>
15 static __thread
int fd = -1;
17 if (fd < 0 && 0 > (fd = open(
"/dev/urandom", O_RDONLY)))
19 for (
size_t i = 0;
i < l;
i += n)
20 if (0 >= (n = read(fd, (
char *) x +
i, l -
i)))
22#ifdef ENABLE_CT_TESTING
23 VALGRIND_MAKE_MEM_UNDEFINED(x, l);
33static inline int randombytes_from_openssl(uint8_t *buf,
int bytes);
42 fprintf(stderr,
"Error: requested too many random bytes (%zu > %d)\n",
46 if (!randombytes_from_openssl((uint8_t*)x, l_as_int))
50#include <openssl/rand.h>
52#define RAND_POLL_RETRY 3
54int randombytes_from_openssl(uint8_t *buf,
int bytes)
57 for (
i=0;
i < RAND_POLL_RETRY;
i++) {
58 if (RAND_status() == 1)
62 if (RAND_priv_bytes(buf, bytes) != 1) {
63 fprintf(stderr,
"Failure retrieving randomness from OpenSSL\n");
void randombytes(void *x, size_t l)