Skip to content

Commit

Permalink
Fix getrandom on Ubuntu 16.04 (GLIBC 2.23) (#14)
Browse files Browse the repository at this point in the history
* use system call SYS_getrandom
* Add Ubuntu 16.04 to Travis CI script
  • Loading branch information
dinosaure authored Feb 26, 2020
1 parent b390b50 commit b4f3eb0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ matrix:
include:
- os: osx
env: OCAML_VERSION=4.08
- dist: xenial
env: OCAML_VERSION=4.08
notifications:
email: false
12 changes: 9 additions & 3 deletions rng/unix/mc_getrandom_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@
#include <caml/bigarray.h>

#if defined(__linux)
# include <errno.h>
// on Linux, we use getrandom and loop
#include <sys/random.h>
#include <errno.h>

# if __GLIBC__ && __GLIBC__ <= 2 && __GLIBC_MINOR__ < 25
# include <sys/syscall.h>
# define getrandom(buf, len, flags) syscall(SYS_getrandom, (buf), (len), (flags))
# else
# include <sys/random.h>
# define getrandom(buf, len, flags) getrandom((buf), (len), (flags))
# endif

void raw_getrandom (uint8_t *data, uint32_t len) {
int r, off = 0;
Expand All @@ -19,7 +26,6 @@ void raw_getrandom (uint8_t *data, uint32_t len) {
off += r;
}
}

#elif (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__))
// on BSD and macOS, loop (in pieces of 256) getentropy
#if defined(__APPLE__)
Expand Down

0 comments on commit b4f3eb0

Please sign in to comment.