-
Notifications
You must be signed in to change notification settings - Fork 11
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
Apisupport linux getrandom #146
Conversation
This includes #145 Apisupport. I'm less certain about some parts of this, but I figured it was ok as a starting place for discussion. |
{ | ||
char buf[BUFLEN]; | ||
|
||
if (getrandom(buf, BUFLEN, 0) != BUFLEN) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if we want to actually check that we can get bytes from getrandom()
, or just let this auto-succeed and handle the possible failure in the calling function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I meant to add this comment to apisupport/apisupport_linux_getrandom.c
, not this file.
@@ -34,6 +39,16 @@ entropy_read(uint8_t * buf, size_t buflen) | |||
goto err0; | |||
} | |||
|
|||
#ifdef APISUPPORT_LINUX_GETRANDOM | |||
if (apisupport_linux_getrandom()) { | |||
if (getrandom(buf, buflen, 0) != (ssize_t)buflen) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
Do we want to move this to a separate
.c
file? Since this doesn't require any additional compiler flags and it's so short, that seemed excessive. Or I could move it to a separate function in the same file? -
The
entropy_read()
function is general, although we're only calling it for 32 or 48 bytes. In theory,getrandom()
on Linux should never return fewer bytes thanbuflen
as long as it's less than 256. Not that I'm suggesting that we don't check the value, of course.
I was more wondering if it would be useful to have an entropy_read_byte_buflen()
[yes, silly name] to indicate that it's intended for small buffers.
Specifically, I did: - s/cpu/api/g - s/CPU/API/g - removed the CPU features from the bottom of the file The "run-time" detection might be overkill, but I'm not certain that it will never be useful, so I figured I'd include it.
These are changes that can't be imported directly into other projects due to merge conflicts.
Although getrandom() was added in Linux 3.17 (2014-10), it was only added to glibc in 2.25 (2017-02), and Linux distros are cautious about upgrading to a new libc. In those cases, getrandom() is only available if you use syscall(2) to do an indirect system call. For example, Debian 9 "stretch" (2017-06) still uses 2.24, whereas Ubuntu 18.04 has glibc 2.27.
0001e48
to
eba809b
Compare
No description provided.