diff options
| author | bcook <> | 2014-08-16 17:21:56 +0000 |
|---|---|---|
| committer | bcook <> | 2014-08-16 17:21:56 +0000 |
| commit | 408eab1e65d65540efc82e6ec61695cebcc06a66 (patch) | |
| tree | 701058bfac5c41cde9d8166f828591fe39396f9c /src/lib/libcrypto/arc4random/getentropy_linux.c | |
| parent | e63c84100a7abdf2dd60c84d272c6dea7a8490b5 (diff) | |
| download | openbsd-408eab1e65d65540efc82e6ec61695cebcc06a66.tar.gz openbsd-408eab1e65d65540efc82e6ec61695cebcc06a66.tar.bz2 openbsd-408eab1e65d65540efc82e6ec61695cebcc06a66.zip | |
getrandom(2) support for getentropy_linux
This enables support for the new getrandom(2) syscall in Linux 3.17.
If the call exists and fails, return a failure in getentropy(2) emulation as
well. This adds a EINTR check in case the urandom pool is not initialized.
Tested on Fedora Rawhide with 3.17rc0 and Ubuntu 14.04
ok deraadt@
Diffstat (limited to 'src/lib/libcrypto/arc4random/getentropy_linux.c')
| -rw-r--r-- | src/lib/libcrypto/arc4random/getentropy_linux.c | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/src/lib/libcrypto/arc4random/getentropy_linux.c b/src/lib/libcrypto/arc4random/getentropy_linux.c index 59bc3628a6..a84f7ad888 100644 --- a/src/lib/libcrypto/arc4random/getentropy_linux.c +++ b/src/lib/libcrypto/arc4random/getentropy_linux.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: getentropy_linux.c,v 1.32 2014/07/22 01:15:58 bcook Exp $ */ | 1 | /* $OpenBSD: getentropy_linux.c,v 1.33 2014/08/16 17:21:56 bcook Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org> | 4 | * Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org> |
| @@ -98,6 +98,8 @@ getentropy(void *buf, size_t len) | |||
| 98 | ret = getentropy_getrandom(buf, len); | 98 | ret = getentropy_getrandom(buf, len); |
| 99 | if (ret != -1) | 99 | if (ret != -1) |
| 100 | return (ret); | 100 | return (ret); |
| 101 | if (errno != ENOSYS) | ||
| 102 | return (-1); | ||
| 101 | 103 | ||
| 102 | /* | 104 | /* |
| 103 | * Try to get entropy with /dev/urandom | 105 | * Try to get entropy with /dev/urandom |
| @@ -187,23 +189,18 @@ gotdata(char *buf, size_t len) | |||
| 187 | static int | 189 | static int |
| 188 | getentropy_getrandom(void *buf, size_t len) | 190 | getentropy_getrandom(void *buf, size_t len) |
| 189 | { | 191 | { |
| 190 | #if 0 | 192 | #ifdef SYS_getrandom |
| 191 | 193 | int ret; | |
| 192 | /* Hand-definitions until the API becomes commonplace */ | ||
| 193 | #ifndef SYS__getrandom | ||
| 194 | #ifdef __LP64__ | ||
| 195 | #define SYS__getrandom 317 | ||
| 196 | #else | ||
| 197 | #define SYS__getrandom 354 | ||
| 198 | #endif | ||
| 199 | #endif | ||
| 200 | if (len > 256) | 194 | if (len > 256) |
| 201 | return (-1); | 195 | return (-1); |
| 202 | ret = syscall(SYS__getrandom, buf, len, 0); | 196 | do { |
| 197 | ret = syscall(SYS_getrandom, buf, len, 0); | ||
| 198 | } while (ret == -1 && errno == EINTR); | ||
| 199 | |||
| 203 | if (ret == len) | 200 | if (ret == len) |
| 204 | return (0); | 201 | return (0); |
| 205 | #endif | 202 | #endif |
| 206 | return -1; | 203 | return (-1); |
| 207 | } | 204 | } |
| 208 | 205 | ||
| 209 | static int | 206 | static int |
