31 #if defined(__WIN32__) || defined(WIN32) || defined(__CYGWIN32__)
51 #if defined(linux) || defined(__linux) || defined(__linux__) || defined(__APPLE__)
52 #define RANDOM_DEVICE "/dev/urandom"
54 #if defined(__WIN32__) || defined(WIN32) || defined(__CYGWIN32__)
55 #define RANDOM_WIN32 1
70 #if defined(RANDOM_DEVICE)
71 int fd = open(RANDOM_DEVICE, O_RDONLY);
74 int len = read(fd, bytes, size);
75 if (len == (
int)size) {
79 }
else if (len >= 0) {
82 }
else if (errno != EINTR) {
84 perror(RANDOM_DEVICE);
90 perror(RANDOM_DEVICE);
92 #elif defined(RANDOM_WIN32)
94 HCRYPTPROV provider = 0;
95 memset(bytes, 0, size);
96 if (CryptAcquireContextW(&provider, 0, 0, PROV_RSA_FULL,
97 CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) {
98 CryptGenRandom(provider, size, bytes);
99 CryptReleaseContext(provider, 0);
103 fprintf(stderr,
"Do not know how to generate random numbers! Abort!\n");
107 #ifdef ED25519_CUSTOMRANDOM
111 void ed25519_randombytes_unsafe(
void *p,
size_t len)
void noise_rand_bytes(void *bytes, size_t size)
Gets cryptographically-strong random bytes from the operating system.
Internal definitions for the library.