summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbcook <>2014-08-16 17:21:56 +0000
committerbcook <>2014-08-16 17:21:56 +0000
commit3d2b3709ef615f448f930446b6be45e86d99e121 (patch)
tree701058bfac5c41cde9d8166f828591fe39396f9c
parentb84c34616978bc8f3ea82a0dd558239cc583e2af (diff)
downloadopenbsd-3d2b3709ef615f448f930446b6be45e86d99e121.tar.gz
openbsd-3d2b3709ef615f448f930446b6be45e86d99e121.tar.bz2
openbsd-3d2b3709ef615f448f930446b6be45e86d99e121.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@
-rw-r--r--src/lib/libcrypto/arc4random/getentropy_linux.c23
-rw-r--r--src/lib/libcrypto/crypto/getentropy_linux.c23
2 files changed, 20 insertions, 26 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)
187static int 189static int
188getentropy_getrandom(void *buf, size_t len) 190getentropy_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
209static int 206static int
diff --git a/src/lib/libcrypto/crypto/getentropy_linux.c b/src/lib/libcrypto/crypto/getentropy_linux.c
index 59bc3628a6..a84f7ad888 100644
--- a/src/lib/libcrypto/crypto/getentropy_linux.c
+++ b/src/lib/libcrypto/crypto/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)
187static int 189static int
188getentropy_getrandom(void *buf, size_t len) 190getentropy_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
209static int 206static int