Page MenuHome GnuPG

Add getrandom support for the BSDs
Closed, ResolvedPublic

Description

FreeBSD 12 has a getrandom syscall; see D471 for discussion

Event Timeline

In FreeBSD, getrandom(3) became available, when getrandom(2) was added. <-- This is my theory.
If this is true, just use getrandom(3), not using getrandom(2) by syscall.

Besides, glibc (>= 2.25) have getrandom(3) now (reference: https://old.lwn.net/Articles/711013/).

OpenBSD uses getentropy(2). glibc (>= 2.25) has getentropy(3), too.

I think we should stick with the syscall for Linux.

Confirmed my theory of getentropy(3): https://reviews.freebsd.org/rS331279

Since our usage of getrandom is with flag 0, which is same as getentropy, I think that it's good to add HAVE_GETENTROPY feature macro to support getentropy for *BSD (both of FreeBSD and OpenBSD in mind).

My point is: Let us support OpenBSD too.

This is mine:

Update to prefer syscall on GNU/Linux (no need to audit libc implementation):

In my patch, for OpenBSD and FreeBSD (well, other than GNU/Linux), it uses getentropy if available. For GNU/Linux, we use the local macro of getentropy (regardless of the availability of the function), keeping exactly same behavior of syscall with __NR_getrandom.

Sorry for long reply, your change looks ok even though dunno it is meaningful those _gcry_pre_syscall ()/_gcry_post_syscall () surrounding get entropy for example.

These are hooks so that co-operative thread libraries (like ntph) are able to yield control to the system's thread's implementation.

gniibe claimed this task.

Pushed to master, fixing about return value of getentropy. Tested on FreeBSD 12. Tested on FreeBSD 11 where getentropy is not available.