aboutsummaryrefslogtreecommitdiff
path: root/arc4random.c
diff options
context:
space:
mode:
authorJosh Gao <jmgao@google.com>2017-08-10 12:30:25 -0700
committerJosh Gao <jmgao@google.com>2017-08-10 12:30:47 -0700
commit83a0c9c65a60a92d3ea5542596b3ba56db492c37 (patch)
tree64bb0c050c4db9ad9d721e05e3e199bfd02e60b0 /arc4random.c
parentaf241a5c8c2cde0fab7d7d563276c1095b00e3b4 (diff)
downloadlibevent-83a0c9c65a60a92d3ea5542596b3ba56db492c37.tar.gz
Revert "Upgrade to 2.1.8-stable (2017-01-22)." and "Probably Mac build fix?"android-o-iot-preview-5o-iot-preview-5
This reverts commits 2a572d125a91a4aafd3ad8ce87259fc640fa0763 and af241a5c8c2cde0fab7d7d563276c1095b00e3b4, which break tombstoned. Bug: http://b/64543673 Test: manual + treehugger
Diffstat (limited to 'arc4random.c')
-rw-r--r--arc4random.c49
1 files changed, 24 insertions, 25 deletions
diff --git a/arc4random.c b/arc4random.c
index a2338e6..3977339 100644
--- a/arc4random.c
+++ b/arc4random.c
@@ -50,8 +50,7 @@
#endif
#ifndef ARC4RANDOM_NO_INCLUDES
-#include "evconfig-private.h"
-#ifdef _WIN32
+#ifdef WIN32
#include <wincrypt.h>
#include <process.h>
#else
@@ -59,7 +58,7 @@
#include <unistd.h>
#include <sys/param.h>
#include <sys/time.h>
-#ifdef EVENT__HAVE_SYS_SYSCTL_H
+#ifdef _EVENT_HAVE_SYS_SYSCTL_H
#include <sys/sysctl.h>
#endif
#endif
@@ -80,7 +79,7 @@ struct arc4_stream {
unsigned char s[256];
};
-#ifdef _WIN32
+#ifdef WIN32
#define getpid _getpid
#define pid_t int
#endif
@@ -121,7 +120,7 @@ arc4_addrandom(const unsigned char *dat, int datlen)
rs.j = rs.i;
}
-#ifndef _WIN32
+#ifndef WIN32
static ssize_t
read_all(int fd, unsigned char *buf, size_t count)
{
@@ -141,7 +140,7 @@ read_all(int fd, unsigned char *buf, size_t count)
}
#endif
-#ifdef _WIN32
+#ifdef WIN32
#define TRY_SEED_WIN32
static int
arc4_seed_win32(void)
@@ -168,8 +167,8 @@ arc4_seed_win32(void)
}
#endif
-#if defined(EVENT__HAVE_SYS_SYSCTL_H) && defined(EVENT__HAVE_SYSCTL)
-#if EVENT__HAVE_DECL_CTL_KERN && EVENT__HAVE_DECL_KERN_RANDOM && EVENT__HAVE_DECL_RANDOM_UUID
+#if defined(_EVENT_HAVE_SYS_SYSCTL_H) && defined(_EVENT_HAVE_SYSCTL)
+#if _EVENT_HAVE_DECL_CTL_KERN && _EVENT_HAVE_DECL_KERN_RANDOM && _EVENT_HAVE_DECL_RANDOM_UUID
#define TRY_SEED_SYSCTL_LINUX
static int
arc4_seed_sysctl_linux(void)
@@ -206,7 +205,7 @@ arc4_seed_sysctl_linux(void)
}
#endif
-#if EVENT__HAVE_DECL_CTL_KERN && EVENT__HAVE_DECL_KERN_ARND
+#if _EVENT_HAVE_DECL_CTL_KERN && _EVENT_HAVE_DECL_KERN_ARND
#define TRY_SEED_SYSCTL_BSD
static int
arc4_seed_sysctl_bsd(void)
@@ -245,7 +244,7 @@ arc4_seed_sysctl_bsd(void)
return 0;
}
#endif
-#endif /* defined(EVENT__HAVE_SYS_SYSCTL_H) */
+#endif /* defined(_EVENT_HAVE_SYS_SYSCTL_H) */
#ifdef __linux__
#define TRY_SEED_PROC_SYS_KERNEL_RANDOM_UUID
@@ -261,7 +260,7 @@ arc4_seed_proc_sys_kernel_random_uuid(void)
unsigned char entropy[64];
int bytes, n, i, nybbles;
for (bytes = 0; bytes<ADD_ENTROPY; ) {
- fd = evutil_open_closeonexec_("/proc/sys/kernel/random/uuid", O_RDONLY, 0);
+ fd = evutil_open_closeonexec("/proc/sys/kernel/random/uuid", O_RDONLY, 0);
if (fd < 0)
return -1;
n = read(fd, buf, sizeof(buf));
@@ -270,8 +269,8 @@ arc4_seed_proc_sys_kernel_random_uuid(void)
return -1;
memset(entropy, 0, sizeof(entropy));
for (i=nybbles=0; i<n; ++i) {
- if (EVUTIL_ISXDIGIT_(buf[i])) {
- int nyb = evutil_hex_char_to_int_(buf[i]);
+ if (EVUTIL_ISXDIGIT(buf[i])) {
+ int nyb = evutil_hex_char_to_int(buf[i]);
if (nybbles & 1) {
entropy[nybbles/2] |= nyb;
} else {
@@ -292,7 +291,7 @@ arc4_seed_proc_sys_kernel_random_uuid(void)
}
#endif
-#ifndef _WIN32
+#ifndef WIN32
#define TRY_SEED_URANDOM
static char *arc4random_urandom_filename = NULL;
@@ -302,7 +301,7 @@ static int arc4_seed_urandom_helper_(const char *fname)
int fd;
size_t n;
- fd = evutil_open_closeonexec_(fname, O_RDONLY, 0);
+ fd = evutil_open_closeonexec(fname, O_RDONLY, 0);
if (fd<0)
return -1;
n = read_all(fd, buf, sizeof(buf));
@@ -454,9 +453,9 @@ ARC4RANDOM_EXPORT int
arc4random_stir(void)
{
int val;
- ARC4_LOCK_();
+ _ARC4_LOCK();
val = arc4_stir();
- ARC4_UNLOCK_();
+ _ARC4_UNLOCK();
return val;
}
#endif
@@ -466,7 +465,7 @@ ARC4RANDOM_EXPORT void
arc4random_addrandom(const unsigned char *dat, int datlen)
{
int j;
- ARC4_LOCK_();
+ _ARC4_LOCK();
if (!rs_initialized)
arc4_stir();
for (j = 0; j < datlen; j += 256) {
@@ -476,7 +475,7 @@ arc4random_addrandom(const unsigned char *dat, int datlen)
* crazy like passing us all the files in /var/log. */
arc4_addrandom(dat + j, datlen - j);
}
- ARC4_UNLOCK_();
+ _ARC4_UNLOCK();
}
#endif
@@ -485,27 +484,27 @@ ARC4RANDOM_EXPORT ARC4RANDOM_UINT32
arc4random(void)
{
ARC4RANDOM_UINT32 val;
- ARC4_LOCK_();
+ _ARC4_LOCK();
arc4_count -= 4;
arc4_stir_if_needed();
val = arc4_getword();
- ARC4_UNLOCK_();
+ _ARC4_UNLOCK();
return val;
}
#endif
ARC4RANDOM_EXPORT void
-arc4random_buf(void *buf_, size_t n)
+arc4random_buf(void *_buf, size_t n)
{
- unsigned char *buf = buf_;
- ARC4_LOCK_();
+ unsigned char *buf = _buf;
+ _ARC4_LOCK();
arc4_stir_if_needed();
while (n--) {
if (--arc4_count <= 0)
arc4_stir();
buf[n] = arc4_getbyte();
}
- ARC4_UNLOCK_();
+ _ARC4_UNLOCK();
}
#ifndef ARC4RANDOM_NOUNIFORM