summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKurt Roeckx <kurt@roeckx.be>2023-03-05 16:56:56 +0100
committerGitHub <noreply@github.com>2023-03-05 16:56:56 +0100
commit4e6375e84c5215c4f67b1698fc9cd666a5163525 (patch)
tree8ed2056789dc207c75e2ff0d86f750ab2ac35ba6
parent3a0cf34ba5d18ce64f59513d2f34f1c7cd439325 (diff)
downloadlibevent-4e6375e84c5215c4f67b1698fc9cd666a5163525.tar.gz
Always have evutil_secure_rng_add_bytes available (#1427)
When libevent doesn't provide random the arc4 function, but they come from libc, there is no need to call this function, so make it do nothing. Fixes: #1393
-rw-r--r--evutil_rand.c4
-rw-r--r--include/event2/util.h5
2 files changed, 5 insertions, 4 deletions
diff --git a/evutil_rand.c b/evutil_rand.c
index 139d0d03..c60b9d56 100644
--- a/evutil_rand.c
+++ b/evutil_rand.c
@@ -190,14 +190,14 @@ evutil_secure_rng_get_bytes(void *buf, size_t n)
ev_arc4random_buf(buf, n);
}
-#if !defined(EVENT__HAVE_ARC4RANDOM) || defined(EVENT__HAVE_ARC4RANDOM_ADDRANDOM)
void
evutil_secure_rng_add_bytes(const char *buf, size_t n)
{
+#if !defined(EVENT__HAVE_ARC4RANDOM) || defined(EVENT__HAVE_ARC4RANDOM_ADDRANDOM)
arc4random_addrandom((unsigned char*)buf,
n>(size_t)INT_MAX ? INT_MAX : (int)n);
-}
#endif
+}
void
evutil_free_secure_rng_globals_(void)
diff --git a/include/event2/util.h b/include/event2/util.h
index dc190426..ec406965 100644
--- a/include/event2/util.h
+++ b/include/event2/util.h
@@ -878,7 +878,6 @@ int evutil_secure_rng_init(void);
EVENT2_EXPORT_SYMBOL
int evutil_secure_rng_set_urandom_device_file(char *fname);
-#if !defined(EVENT__HAVE_ARC4RANDOM) || defined(EVENT__HAVE_ARC4RANDOM_ADDRANDOM)
/** Seed the random number generator with extra random bytes.
You should almost never need to call this function; it should be
@@ -890,12 +889,14 @@ int evutil_secure_rng_set_urandom_device_file(char *fname);
contains a fairly large amount of strong entropy. Doing so is
notoriously hard: most people who try get it wrong. Watch out!
+ This function does nothing when the system provides arc4random()
+ function because it will provide proper entropy.
+
@param dat a buffer full of a strong source of random numbers
@param datlen the number of bytes to read from datlen
*/
EVENT2_EXPORT_SYMBOL
void evutil_secure_rng_add_bytes(const char *dat, size_t datlen);
-#endif
#ifdef __cplusplus
}