From 252ea41be8bab992dadabec0e4f1d77650949f4c Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Tue, 24 Dec 2019 14:01:42 -0800 Subject: fixes #1038 Linux should use getentropy or getrandom --- src/platform/posix/posix_config.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/platform/posix/posix_config.h b/src/platform/posix/posix_config.h index 9afa70c8..2abe51b4 100644 --- a/src/platform/posix/posix_config.h +++ b/src/platform/posix/posix_config.h @@ -1,5 +1,5 @@ // -// Copyright 2016 Garrett D'Amore +// Copyright 2019 Staysail Systems, Inc. // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -36,20 +36,30 @@ // #define NNG_USE_GETENTROPY // #define NNG_USE_ARC4RANDOM // #define NNG_USE_DEVURANDOM -// Thesse are options for obtaining entropy to seed the pRNG. +// These are options for obtaining entropy to seed the pRNG. // All known modern UNIX variants can support NNG_USE_DEVURANDOM, // but the other options are better still, but not portable. #include #ifdef NNG_PLATFORM_POSIX - +#if !defined(NNG_USE_DEVURANDOM) && !defined(NNG_USE_GETENTROPY) && \ + !defined(NNG_USE_GETRANDOM) && !defined(NNG_USE_ARC4RANDOM) +#if defined(NNG_HAVE_GETENTROPY) +#define NNG_USE_GETENTROPY 1 +#elif defined(NNG_HAVE_GETRANDOM) +#define NNG_USE_GETRANDOM 1 +#elif defined(NNG_HAVE_ARC4RANDOM) +#define NNG_USE_ARC4RANDOM +#else // It should never hurt to use DEVURANDOM, since if the device does not // exist then we won't open it. (Provided: it would be bad if the device // exists but has somehow very very different semantics. We don't know // of any such concerns.) This won't be used if any of the other options // are defined and work. #define NNG_USE_DEVURANDOM 1 +#endif +#endif #define NNG_USE_CLOCKID CLOCK_REALTIME #ifndef CLOCK_REALTIME -- cgit v1.2.3-70-g09d2