From ea887211a60de537d8761e2a1d50ef25c65e9f3f Mon Sep 17 00:00:00 2001 From: bcook <> Date: Sat, 15 Dec 2018 15:10:12 +0000 Subject: [PATCH] Backport getentropy changes from deraadt@ on MAIN Saw a mention somewhere a while back that the gotdata() function in here could creates non-uniformity since very short fetches of 0 would be excluded. blocks of 0 are just as random as any other data, including blocks of 4 4 4.. This is a misguided attempt to identify errors from the entropy churn/gather code doesn't make sense, errors don't happen. ok bcook --- src/lib/libcrypto/arc4random/getentropy_aix.c | 33 +++------------- .../libcrypto/arc4random/getentropy_hpux.c | 33 +++------------- .../libcrypto/arc4random/getentropy_linux.c | 39 ++++--------------- src/lib/libcrypto/arc4random/getentropy_osx.c | 33 +++------------- .../libcrypto/arc4random/getentropy_solaris.c | 33 +++------------- 5 files changed, 27 insertions(+), 144 deletions(-) diff --git a/src/lib/libcrypto/arc4random/getentropy_aix.c b/src/lib/libcrypto/arc4random/getentropy_aix.c index ff48ae70..d204694b 100644 --- a/src/lib/libcrypto/arc4random/getentropy_aix.c +++ b/src/lib/libcrypto/arc4random/getentropy_aix.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getentropy_aix.c,v 1.5 2016/08/07 03:27:21 tb Exp $ */ +/* $OpenBSD: getentropy_aix.c,v 1.5.8.1 2018/12/15 15:10:12 bcook Exp $ */ /* * Copyright (c) 2015 Michael Felt @@ -60,7 +60,6 @@ int getentropy(void *buf, size_t len); -static int gotdata(char *buf, size_t len); static int getentropy_urandom(void *buf, size_t len, const char *path, int devfscheck); static int getentropy_fallback(void *buf, size_t len); @@ -118,22 +117,6 @@ getentropy(void *buf, size_t len) return (ret); } -/* - * Basic sanity checking; wish we could do better. - */ -static int -gotdata(char *buf, size_t len) -{ - char any_set = 0; - size_t i; - - for (i = 0; i < len; ++i) - any_set |= buf[i]; - if (any_set == 0) - return (-1); - return (0); -} - static int getentropy_urandom(void *buf, size_t len, const char *path, int devfscheck) { @@ -179,10 +162,8 @@ start: i += ret; } close(fd); - if (gotdata(buf, len) == 0) { - errno = save_errno; - return (0); /* satisfied */ - } + errno = save_errno; + return (0); /* satisfied */ nodevrandom: errno = EIO; return (-1); @@ -416,10 +397,6 @@ getentropy_fallback(void *buf, size_t len) } explicit_bzero(&ctx, sizeof ctx); explicit_bzero(results, sizeof results); - if (gotdata(buf, len) == 0) { - errno = save_errno; - return (0); /* satisfied */ - } - errno = EIO; - return (-1); + errno = save_errno; + return (0); /* satisfied */ } diff --git a/src/lib/libcrypto/arc4random/getentropy_hpux.c b/src/lib/libcrypto/arc4random/getentropy_hpux.c index 3ae6a6aa..c44176ec 100644 --- a/src/lib/libcrypto/arc4random/getentropy_hpux.c +++ b/src/lib/libcrypto/arc4random/getentropy_hpux.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getentropy_hpux.c,v 1.5 2016/08/07 03:27:21 tb Exp $ */ +/* $OpenBSD: getentropy_hpux.c,v 1.5.8.1 2018/12/15 15:10:12 bcook Exp $ */ /* * Copyright (c) 2014 Theo de Raadt @@ -64,7 +64,6 @@ int getentropy(void *buf, size_t len); -static int gotdata(char *buf, size_t len); static int getentropy_urandom(void *buf, size_t len, const char *path, int devfscheck); static int getentropy_fallback(void *buf, size_t len); @@ -122,22 +121,6 @@ getentropy(void *buf, size_t len) return (ret); } -/* - * Basic sanity checking; wish we could do better. - */ -static int -gotdata(char *buf, size_t len) -{ - char any_set = 0; - size_t i; - - for (i = 0; i < len; ++i) - any_set |= buf[i]; - if (any_set == 0) - return (-1); - return (0); -} - static int getentropy_urandom(void *buf, size_t len, const char *path, int devfscheck) { @@ -183,10 +166,8 @@ start: i += ret; } close(fd); - if (gotdata(buf, len) == 0) { - errno = save_errno; - return (0); /* satisfied */ - } + errno = save_errno; + return (0); /* satisfied */ nodevrandom: errno = EIO; return (-1); @@ -410,10 +391,6 @@ getentropy_fallback(void *buf, size_t len) } explicit_bzero(&ctx, sizeof ctx); explicit_bzero(results, sizeof results); - if (gotdata(buf, len) == 0) { - errno = save_errno; - return (0); /* satisfied */ - } - errno = EIO; - return (-1); + errno = save_errno; + return (0); /* satisfied */ } diff --git a/src/lib/libcrypto/arc4random/getentropy_linux.c b/src/lib/libcrypto/arc4random/getentropy_linux.c index 408d7fda..116e4e39 100644 --- a/src/lib/libcrypto/arc4random/getentropy_linux.c +++ b/src/lib/libcrypto/arc4random/getentropy_linux.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getentropy_linux.c,v 1.45 2018/03/13 22:53:28 bcook Exp $ */ +/* $OpenBSD: getentropy_linux.c,v 1.45.4.1 2018/12/15 15:10:12 bcook Exp $ */ /* * Copyright (c) 2014 Theo de Raadt @@ -73,7 +73,6 @@ int getentropy(void *buf, size_t len); -static int gotdata(char *buf, size_t len); #if defined(SYS_getrandom) && defined(GRND_NONBLOCK) static int getentropy_getrandom(void *buf, size_t len); #endif @@ -177,22 +176,6 @@ getentropy(void *buf, size_t len) return (ret); } -/* - * Basic sanity checking; wish we could do better. - */ -static int -gotdata(char *buf, size_t len) -{ - char any_set = 0; - size_t i; - - for (i = 0; i < len; ++i) - any_set |= buf[i]; - if (any_set == 0) - return (-1); - return (0); -} - #if defined(SYS_getrandom) && defined(GRND_NONBLOCK) static int getentropy_getrandom(void *buf, size_t len) @@ -261,10 +244,8 @@ start: i += ret; } close(fd); - if (gotdata(buf, len) == 0) { - errno = save_errno; - return (0); /* satisfied */ - } + errno = save_errno; + return (0); /* satisfied */ nodevrandom: errno = EIO; return (-1); @@ -292,10 +273,8 @@ getentropy_sysctl(void *buf, size_t len) goto sysctlfailed; i += chunk; } - if (gotdata(buf, len) == 0) { - errno = save_errno; - return (0); /* satisfied */ - } + errno = save_errno; + return (0); /* satisfied */ sysctlfailed: errno = EIO; return (-1); @@ -541,10 +520,6 @@ getentropy_fallback(void *buf, size_t len) } explicit_bzero(&ctx, sizeof ctx); explicit_bzero(results, sizeof results); - if (gotdata(buf, len) == 0) { - errno = save_errno; - return (0); /* satisfied */ - } - errno = EIO; - return (-1); + errno = save_errno; + return (0); /* satisfied */ } diff --git a/src/lib/libcrypto/arc4random/getentropy_osx.c b/src/lib/libcrypto/arc4random/getentropy_osx.c index 2a5f83f3..bfcad34f 100644 --- a/src/lib/libcrypto/arc4random/getentropy_osx.c +++ b/src/lib/libcrypto/arc4random/getentropy_osx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getentropy_osx.c,v 1.11 2016/09/03 15:24:09 bcook Exp $ */ +/* $OpenBSD: getentropy_osx.c,v 1.11.8.1 2018/12/15 15:10:12 bcook Exp $ */ /* * Copyright (c) 2014 Theo de Raadt @@ -82,7 +82,6 @@ int getentropy(void *buf, size_t len); -static int gotdata(char *buf, size_t len); static int getentropy_urandom(void *buf, size_t len); static int getentropy_fallback(void *buf, size_t len); @@ -142,22 +141,6 @@ getentropy(void *buf, size_t len) return (ret); } -/* - * Basic sanity checking; wish we could do better. - */ -static int -gotdata(char *buf, size_t len) -{ - char any_set = 0; - size_t i; - - for (i = 0; i < len; ++i) - any_set |= buf[i]; - if (any_set == 0) - return (-1); - return (0); -} - static int getentropy_urandom(void *buf, size_t len) { @@ -203,10 +186,8 @@ start: i += ret; } close(fd); - if (gotdata(buf, len) == 0) { - errno = save_errno; - return (0); /* satisfied */ - } + errno = save_errno; + return (0); /* satisfied */ nodevrandom: errno = EIO; return (-1); @@ -431,10 +412,6 @@ getentropy_fallback(void *buf, size_t len) } explicit_bzero(&ctx, sizeof ctx); explicit_bzero(results, sizeof results); - if (gotdata(buf, len) == 0) { - errno = save_errno; - return (0); /* satisfied */ - } - errno = EIO; - return (-1); + errno = save_errno; + return (0); /* satisfied */ } diff --git a/src/lib/libcrypto/arc4random/getentropy_solaris.c b/src/lib/libcrypto/arc4random/getentropy_solaris.c index f0fcdcf2..ace74691 100644 --- a/src/lib/libcrypto/arc4random/getentropy_solaris.c +++ b/src/lib/libcrypto/arc4random/getentropy_solaris.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getentropy_solaris.c,v 1.12 2016/08/07 03:27:21 tb Exp $ */ +/* $OpenBSD: getentropy_solaris.c,v 1.12.8.1 2018/12/15 15:10:12 bcook Exp $ */ /* * Copyright (c) 2014 Theo de Raadt @@ -68,7 +68,6 @@ int getentropy(void *buf, size_t len); -static int gotdata(char *buf, size_t len); static int getentropy_urandom(void *buf, size_t len, const char *path, int devfscheck); static int getentropy_fallback(void *buf, size_t len); @@ -148,22 +147,6 @@ getentropy(void *buf, size_t len) return (ret); } -/* - * Basic sanity checking; wish we could do better. - */ -static int -gotdata(char *buf, size_t len) -{ - char any_set = 0; - size_t i; - - for (i = 0; i < len; ++i) - any_set |= buf[i]; - if (any_set == 0) - return (-1); - return (0); -} - static int getentropy_urandom(void *buf, size_t len, const char *path, int devfscheck) { @@ -210,10 +193,8 @@ start: i += ret; } close(fd); - if (gotdata(buf, len) == 0) { - errno = save_errno; - return (0); /* satisfied */ - } + errno = save_errno; + return (0); /* satisfied */ nodevrandom: errno = EIO; return (-1); @@ -436,10 +417,6 @@ getentropy_fallback(void *buf, size_t len) } explicit_bzero(&ctx, sizeof ctx); explicit_bzero(results, sizeof results); - if (gotdata(buf, len) == 0) { - errno = save_errno; - return (0); /* satisfied */ - } - errno = EIO; - return (-1); + errno = save_errno; + return (0); /* satisfied */ }