diff options
Diffstat (limited to 'src/lib/libcrypto/arc4random/getentropy_linux.c')
-rw-r--r-- | src/lib/libcrypto/arc4random/getentropy_linux.c | 39 |
1 files changed, 7 insertions, 32 deletions
diff --git a/src/lib/libcrypto/arc4random/getentropy_linux.c b/src/lib/libcrypto/arc4random/getentropy_linux.c index 408d7fda34..6b220be311 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.45 2018/03/13 22:53:28 bcook Exp $ */ | 1 | /* $OpenBSD: getentropy_linux.c,v 1.46 2018/11/20 08:04:28 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> |
@@ -73,7 +73,6 @@ | |||
73 | 73 | ||
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); | ||
77 | #if defined(SYS_getrandom) && defined(GRND_NONBLOCK) | 76 | #if defined(SYS_getrandom) && defined(GRND_NONBLOCK) |
78 | static int getentropy_getrandom(void *buf, size_t len); | 77 | static int getentropy_getrandom(void *buf, size_t len); |
79 | #endif | 78 | #endif |
@@ -177,22 +176,6 @@ getentropy(void *buf, size_t len) | |||
177 | return (ret); | 176 | return (ret); |
178 | } | 177 | } |
179 | 178 | ||
180 | /* | ||
181 | * Basic sanity checking; wish we could do better. | ||
182 | */ | ||
183 | static int | ||
184 | gotdata(char *buf, size_t len) | ||
185 | { | ||
186 | char any_set = 0; | ||
187 | size_t i; | ||
188 | |||
189 | for (i = 0; i < len; ++i) | ||
190 | any_set |= buf[i]; | ||
191 | if (any_set == 0) | ||
192 | return (-1); | ||
193 | return (0); | ||
194 | } | ||
195 | |||
196 | #if defined(SYS_getrandom) && defined(GRND_NONBLOCK) | 179 | #if defined(SYS_getrandom) && defined(GRND_NONBLOCK) |
197 | static int | 180 | static int |
198 | getentropy_getrandom(void *buf, size_t len) | 181 | getentropy_getrandom(void *buf, size_t len) |
@@ -261,10 +244,8 @@ start: | |||
261 | i += ret; | 244 | i += ret; |
262 | } | 245 | } |
263 | close(fd); | 246 | close(fd); |
264 | if (gotdata(buf, len) == 0) { | 247 | errno = save_errno; |
265 | errno = save_errno; | 248 | return (0); /* satisfied */ |
266 | return (0); /* satisfied */ | ||
267 | } | ||
268 | nodevrandom: | 249 | nodevrandom: |
269 | errno = EIO; | 250 | errno = EIO; |
270 | return (-1); | 251 | return (-1); |
@@ -292,10 +273,8 @@ getentropy_sysctl(void *buf, size_t len) | |||
292 | goto sysctlfailed; | 273 | goto sysctlfailed; |
293 | i += chunk; | 274 | i += chunk; |
294 | } | 275 | } |
295 | if (gotdata(buf, len) == 0) { | 276 | errno = save_errno; |
296 | errno = save_errno; | 277 | return (0); /* satisfied */ |
297 | return (0); /* satisfied */ | ||
298 | } | ||
299 | sysctlfailed: | 278 | sysctlfailed: |
300 | errno = EIO; | 279 | errno = EIO; |
301 | return (-1); | 280 | return (-1); |
@@ -541,10 +520,6 @@ getentropy_fallback(void *buf, size_t len) | |||
541 | } | 520 | } |
542 | explicit_bzero(&ctx, sizeof ctx); | 521 | explicit_bzero(&ctx, sizeof ctx); |
543 | explicit_bzero(results, sizeof results); | 522 | explicit_bzero(results, sizeof results); |
544 | if (gotdata(buf, len) == 0) { | 523 | errno = save_errno; |
545 | errno = save_errno; | 524 | return (0); /* satisfied */ |
546 | return (0); /* satisfied */ | ||
547 | } | ||
548 | errno = EIO; | ||
549 | return (-1); | ||
550 | } | 525 | } |