Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make use of arc4random_buf() #1640

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading