This repository has been archived by the owner on May 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
libevent-000.patch
73 lines (65 loc) · 2.14 KB
/
libevent-000.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
diff --git a/configure.ac b/configure.ac
index 7528d37..24b65dc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -342,6 +334,7 @@ AC_CHECK_FUNCS([ \
accept4 \
arc4random \
arc4random_buf \
+ arc4random_addrandom \
eventfd \
epoll_create1 \
fcntl \
diff --git a/evutil_rand.c b/evutil_rand.c
index 046a14b..3aef9cb 100644
--- a/evutil_rand.c
+++ b/evutil_rand.c
@@ -184,6 +184,24 @@ ev_arc4random_buf(void *buf, size_t n)
arc4random_buf(buf, n);
}
+/*
+ * The arc4random included in libevent implements arc4random_addrandom().
+ *
+ * OpenBSD libc/crypt/arc4random.c migrated to ChaCha20 since 1.25 and
+ * have removed arc4random_addrandom() since 1.26. Since then, other libcs
+ * followed suit (e.g. Android's own libc). But libevent's arc4random.c
+ * copy still implement arc4random_addrandom().
+ *
+ * See also:
+ *
+ * - https://github.com/measurement-kit/libevent/commit/8b275d967d7ffd95d5cc12069aef35669126c6d9
+ * - https://bugzilla.mozilla.org/show_bug.cgi?id=931354
+ * - https://bug931354.bmoattachments.org/attachment.cgi?id=829728
+ */
+#ifndef EVENT__HAVE_ARC4RANDOM_ADDRANDOM
+#define EVENT__HAVE_ARC4RANDOM_ADDRANDOM 1
+#endif
+
#endif /* } !EVENT__HAVE_ARC4RANDOM */
void
@@ -195,8 +213,10 @@ evutil_secure_rng_get_bytes(void *buf, size_t n)
void
evutil_secure_rng_add_bytes(const char *buf, size_t n)
{
+#if defined EVENT__HAVE_ARC4RANDOM_ADDRANDOM
arc4random_addrandom((unsigned char*)buf,
n>(size_t)INT_MAX ? INT_MAX : (int)n);
+#endif
}
void
diff --git a/openssl-compat.h b/openssl-compat.h
index 69afc71..8e3556a 100644
--- a/openssl-compat.h
+++ b/openssl-compat.h
@@ -1,7 +1,7 @@
#ifndef OPENSSL_COMPAT_H
#define OPENSSL_COMPAT_H
-#if OPENSSL_VERSION_NUMBER < 0x10100000L
+#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined LIBRESSL_VERSION_NUMBER
static inline BIO_METHOD *BIO_meth_new(int type, const char *name)
{
@@ -30,6 +30,6 @@ static inline BIO_METHOD *BIO_meth_new(int type, const char *name)
#define TLS_method SSLv23_method
-#endif /* OPENSSL_VERSION_NUMBER < 0x10100000L */
+#endif /* OPENSSL_VERSION_NUMBER < 0x10100000L || defined LIBRESSL_VERSION_NUMBER */
#endif /* OPENSSL_COMPAT_H */