]> granicus.if.org Git - libevent/commitdiff
Merge remote-tracking branch 'origin/patches-2.0'
authorNick Mathewson <nickm@torproject.org>
Tue, 6 Aug 2013 21:29:34 +0000 (17:29 -0400)
committerNick Mathewson <nickm@torproject.org>
Tue, 6 Aug 2013 21:29:34 +0000 (17:29 -0400)
Conflicts:
arc4random.c

1  2 
arc4random.c
evutil_rand.c
include/event2/util.h

diff --cc arc4random.c
index 8a6c3d24ce3275b6fad5184faa3f84d156f9381f,048057031408d9e2f7f68af50ad55c1087ce1bd2..016cae66d90d8fd0b231d100c306764191a72023
@@@ -292,8 -291,29 +292,29 @@@ arc4_seed_proc_sys_kernel_random_uuid(v
  }
  #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)
  {
diff --cc evutil_rand.c
index 38814e4cc2865c2eae8a6f08bde90fc854464971,3c2c81de4250f1bb610abeaf4e9a679be777d29c..584d9495ad0217086770233f88ebf82e88ff97b4
@@@ -132,18 -129,17 +138,29 @@@ evutil_secure_rng_global_setup_locks_(c
  }
  #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)
  {
Simple merge