Skip to content

Commit

Permalink
Make use of arc4random_buf()
Browse files Browse the repository at this point in the history
Make use of arc4random_buf() if it exists. Supported on
FreeBSD/NetBSD/OpenBSD/Solaris/Linux.
  • Loading branch information
brad0 committed Feb 3, 2024
1 parent 3510239 commit c361616
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ AC_CHECK_FUNCS([sendfile])
# connections.
AC_CHECK_FUNCS([getline])

# Check for arc4random_buf().
AC_CHECK_FUNCS([arc4random_buf])

# Check for packet pacing socket option (Linux only for now).
AC_CACHE_CHECK([SO_MAX_PACING_RATE socket option],
[iperf3_cv_header_so_max_pacing_rate],
Expand Down
6 changes: 5 additions & 1 deletion src/iperf_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@
#include "iperf_api.h"

/*
* Read entropy from /dev/urandom
* Read entropy using arc4random_buf() if exists, otherwise from /dev/urandom
* Errors are fatal.
* Returns 0 on success.
*/
int readentropy(void *out, size_t outsize)
{
#ifdef HAVE_ARC4RANDOM_BUF
arc4random_buf(out, outsize);
#else
static FILE *frandom;
static const char rndfile[] = "/dev/urandom";

Expand All @@ -75,6 +78,7 @@ int readentropy(void *out, size_t outsize)
rndfile,
feof(frandom) ? "EOF" : strerror(errno));
}
#endif
return 0;
}

Expand Down

0 comments on commit c361616

Please sign in to comment.