[Cryptography] Is Ron right on randomness
Bill Cox
waywardgeek at gmail.com
Mon Dec 5 20:26:12 EST 2016
On Thu, Dec 1, 2016 at 8:14 AM, Theodore Ts'o <tytso at mit.edu> wrote:
> On Wed, Nov 30, 2016 at 05:59:24AM -0800, Bill Cox wrote:
> > I just learned on another thread that Linux provided a fixed API. The
> new
> > right answer on Linux is to call getrandom:
> >
> > https://git.kernel.org/cgit/linux/kernel/git/torvalds/
> linux.git/commit/?id=c6e9d6f3
> >
> > It's in linux 3.17. My Ubuntu 14.04 laptop upgraded to 3.19, so I had
> > it... Then it upgraded to 4.2.0, and now I no longer have it. Grrr...
>
> Huh? It most certainly is in 4.2.0. What were you saying about noise
> on these threads being aggravating?
>
> % git show v4.2:drivers/char/random.c | grep getrandom
> SYSCALL_DEFINE3(getrandom, char __user *, buf, size_t, count,
>
> - Ted
>
There is still something wrong. I've tried a more recent 4.4.0-51-generic
kernel in Ubuntu 14.04, with no luck. There is no SYS_getrandom syscall
available through the syscall function, nor getrandom in libc. I'm running
x64. I see this:
/lib/modules/4.4.0-51-generic/build/arch/x86/include/generated/asm/syscalls_64.h:__SYSCALL_COMMON(318,
sys_getrandom, sys_getrandom)
So, it looks like it is in the kernel. Here's the latest code I tried to
compile with gcc -Wall foo.c:
#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>
#include <linux/random.h>
#include <stdio.h>
int main() {
unsigned char buffer[32];
int numBytes = syscall(SYS_getrandom, buffer, 32, 0);
printf("bytes read = %u\n", numBytes);
return 0;
}
This gives:
foo.c: In function ‘main’:
foo.c:10:28: error: ‘SYS_getrandom’ undeclared (first use in this function)
int numBytes = syscall(SYS_getrandom, buffer, 32, 0);
^
foo.c:10:28: note: each undeclared identifier is reported only once for
each function it appears in
Various combinations of includes also fail. There is no instance of
getrandom under /usr/include.
How can I access getrandom? Is this a Debian/Ubuntu bug?
Bill
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.metzdowd.com/pipermail/cryptography/attachments/20161205/a0bc8777/attachment.html>
More information about the cryptography
mailing list