}
#endif
-#ifndef WIN32
+#ifndef _WIN32
#define TRY_SEED_URANDOM
- fd = evutil_open_closeonexec(fname, O_RDONLY, 0);
+ static char *arc4random_urandom_filename = NULL;
+
+ static int arc4_seed_urandom_helper_(const char *fname)
+ {
+ unsigned char buf[ADD_ENTROPY];
+ int fd;
+ size_t n;
+
++ fd = evutil_open_closeonexec_(fname, O_RDONLY, 0);
+ if (fd<0)
+ return -1;
+ n = read_all(fd, buf, sizeof(buf));
+ close(fd);
+ if (n != sizeof(buf))
+ return -1;
+ arc4_addrandom(buf, sizeof(buf));
+ memset(buf, 0, sizeof(buf));
+ arc4_seeded_ok = 1;
+ return 0;
+ }
+
static int
arc4_seed_urandom(void)
{
}
#endif
+static void
+evutil_free_secure_rng_globals_locks(void)
+{
+#ifndef EVENT__DISABLE_THREAD_SUPPORT
+ if (arc4rand_lock != NULL) {
+ EVTHREAD_FREE_LOCK(arc4rand_lock, 0);
+ arc4rand_lock = NULL;
+ }
+#endif
+ return;
+}
+
+ int
+ evutil_secure_rng_set_urandom_device_file(char *fname)
+ {
+ #ifdef TRY_SEED_URANDOM
+ _ARC4_LOCK();
+ arc4random_urandom_filename = fname;
+ _ARC4_UNLOCK();
+ #endif
+ return 0;
+ }
+
int
evutil_secure_rng_init(void)
{