diff options
author | deraadt <> | 2014-07-20 03:24:10 +0000 |
---|---|---|
committer | deraadt <> | 2014-07-20 03:24:10 +0000 |
commit | 3ca59b9dafdbccff0d09dab3a8a8a3524767b3ed (patch) | |
tree | 9046687e16533c9e51448873939ef20cd7f9e81f /src | |
parent | a136a215cc085da2472b7cd0f2ad68850f010595 (diff) | |
download | openbsd-3ca59b9dafdbccff0d09dab3a8a8a3524767b3ed.tar.gz openbsd-3ca59b9dafdbccff0d09dab3a8a8a3524767b3ed.tar.bz2 openbsd-3ca59b9dafdbccff0d09dab3a8a8a3524767b3ed.zip |
Demonstrate how new linux getrandom() will be called, at least until
it shows up in libraries. Even the system call is probably not finalized.
Bit dissapointed it has turned out to be a descriptor-less read() with
EINVAL and EINTR error conditions, but we can work with it.
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/arc4random/getentropy_linux.c | 38 | ||||
-rw-r--r-- | src/lib/libcrypto/crypto/getentropy_linux.c | 38 |
2 files changed, 74 insertions, 2 deletions
diff --git a/src/lib/libcrypto/arc4random/getentropy_linux.c b/src/lib/libcrypto/arc4random/getentropy_linux.c index 04f21e147b..2ad844624f 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.27 2014/07/19 16:12:00 deraadt Exp $ */ | 1 | /* $OpenBSD: getentropy_linux.c,v 1.28 2014/07/20 03:24:10 deraadt 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> |
@@ -74,6 +74,7 @@ | |||
74 | int getentropy(void *buf, size_t len); | 74 | int getentropy(void *buf, size_t len); |
75 | 75 | ||
76 | static int gotdata(char *buf, size_t len); | 76 | static int gotdata(char *buf, size_t len); |
77 | static int getentropy_getrandom(void *buf, size_t len); | ||
77 | static int getentropy_urandom(void *buf, size_t len); | 78 | static int getentropy_urandom(void *buf, size_t len); |
78 | #ifdef CTL_MAXNAME | 79 | #ifdef CTL_MAXNAME |
79 | static int getentropy_sysctl(void *buf, size_t len); | 80 | static int getentropy_sysctl(void *buf, size_t len); |
@@ -92,6 +93,13 @@ getentropy(void *buf, size_t len) | |||
92 | } | 93 | } |
93 | 94 | ||
94 | /* | 95 | /* |
96 | * Try descriptor-less getrandom() | ||
97 | */ | ||
98 | ret = getentropy_getrandom(buf, len); | ||
99 | if (ret != -1) | ||
100 | return (ret); | ||
101 | |||
102 | /* | ||
95 | * Try to get entropy with /dev/urandom | 103 | * Try to get entropy with /dev/urandom |
96 | * | 104 | * |
97 | * This can fail if the process is inside a chroot or if file | 105 | * This can fail if the process is inside a chroot or if file |
@@ -177,6 +185,34 @@ gotdata(char *buf, size_t len) | |||
177 | } | 185 | } |
178 | 186 | ||
179 | static int | 187 | static int |
188 | getentropy_getrandom(void *buf, size_t len) | ||
189 | { | ||
190 | #if 0 | ||
191 | |||
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 | struct __getrandom_args args = { | ||
201 | .buf = buf; | ||
202 | .len = len; | ||
203 | .flags = 0; | ||
204 | }; | ||
205 | |||
206 | if (len > 256) | ||
207 | return (-1); | ||
208 | ret = syscall(SYS__getrandom, &args); | ||
209 | if (ret == len) | ||
210 | return (0); | ||
211 | #endif | ||
212 | return -1; | ||
213 | } | ||
214 | |||
215 | static int | ||
180 | getentropy_urandom(void *buf, size_t len) | 216 | getentropy_urandom(void *buf, size_t len) |
181 | { | 217 | { |
182 | struct stat st; | 218 | struct stat st; |
diff --git a/src/lib/libcrypto/crypto/getentropy_linux.c b/src/lib/libcrypto/crypto/getentropy_linux.c index 04f21e147b..2ad844624f 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.27 2014/07/19 16:12:00 deraadt Exp $ */ | 1 | /* $OpenBSD: getentropy_linux.c,v 1.28 2014/07/20 03:24:10 deraadt 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> |
@@ -74,6 +74,7 @@ | |||
74 | int getentropy(void *buf, size_t len); | 74 | int getentropy(void *buf, size_t len); |
75 | 75 | ||
76 | static int gotdata(char *buf, size_t len); | 76 | static int gotdata(char *buf, size_t len); |
77 | static int getentropy_getrandom(void *buf, size_t len); | ||
77 | static int getentropy_urandom(void *buf, size_t len); | 78 | static int getentropy_urandom(void *buf, size_t len); |
78 | #ifdef CTL_MAXNAME | 79 | #ifdef CTL_MAXNAME |
79 | static int getentropy_sysctl(void *buf, size_t len); | 80 | static int getentropy_sysctl(void *buf, size_t len); |
@@ -92,6 +93,13 @@ getentropy(void *buf, size_t len) | |||
92 | } | 93 | } |
93 | 94 | ||
94 | /* | 95 | /* |
96 | * Try descriptor-less getrandom() | ||
97 | */ | ||
98 | ret = getentropy_getrandom(buf, len); | ||
99 | if (ret != -1) | ||
100 | return (ret); | ||
101 | |||
102 | /* | ||
95 | * Try to get entropy with /dev/urandom | 103 | * Try to get entropy with /dev/urandom |
96 | * | 104 | * |
97 | * This can fail if the process is inside a chroot or if file | 105 | * This can fail if the process is inside a chroot or if file |
@@ -177,6 +185,34 @@ gotdata(char *buf, size_t len) | |||
177 | } | 185 | } |
178 | 186 | ||
179 | static int | 187 | static int |
188 | getentropy_getrandom(void *buf, size_t len) | ||
189 | { | ||
190 | #if 0 | ||
191 | |||
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 | struct __getrandom_args args = { | ||
201 | .buf = buf; | ||
202 | .len = len; | ||
203 | .flags = 0; | ||
204 | }; | ||
205 | |||
206 | if (len > 256) | ||
207 | return (-1); | ||
208 | ret = syscall(SYS__getrandom, &args); | ||
209 | if (ret == len) | ||
210 | return (0); | ||
211 | #endif | ||
212 | return -1; | ||
213 | } | ||
214 | |||
215 | static int | ||
180 | getentropy_urandom(void *buf, size_t len) | 216 | getentropy_urandom(void *buf, size_t len) |
181 | { | 217 | { |
182 | struct stat st; | 218 | struct stat st; |