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

Apisupport linux getrandom #146

Closed
wants to merge 9 commits into from
Closed

Conversation

gperciva
Copy link
Member

No description provided.

@gperciva gperciva mentioned this pull request Jul 19, 2018
@gperciva gperciva added the draft not for merging (yet) label Jul 19, 2018
@gperciva
Copy link
Member Author

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)
Copy link
Member Author

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.

Copy link
Member Author

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) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 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?

  2. 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 than buflen 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.
@gperciva gperciva force-pushed the apisupport-linux-getrandom branch from 0001e48 to eba809b Compare August 2, 2018 03:20
@gperciva gperciva closed this Sep 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
draft not for merging (yet)
Development

Successfully merging this pull request may close these issues.

1 participant