summaryrefslogtreecommitdiff
path: root/osrng.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2022-02-26 14:47:11 -0500
committerJeffrey Walton <noloader@gmail.com>2022-02-26 14:47:11 -0500
commit2ef3254fe1b2f57d4833b2c1ddb100874b41f4a7 (patch)
tree4ac78fb3c49d33548ff7e083e13cd0184eab0906 /osrng.cpp
parent27b7b8e4e6b3e54cca13b2faae87eb95faa0d819 (diff)
downloadcryptopp-git-2ef3254fe1b2f57d4833b2c1ddb100874b41f4a7.tar.gz
Fix NonblockingRng on Solaris
Solaris links /dev/urandom to .../devices/pseudo/random@0:urandom. We allow the link in this case.
Diffstat (limited to 'osrng.cpp')
-rw-r--r--osrng.cpp23
1 files changed, 13 insertions, 10 deletions
diff --git a/osrng.cpp b/osrng.cpp
index 804026b4..763eeff3 100644
--- a/osrng.cpp
+++ b/osrng.cpp
@@ -28,10 +28,17 @@
// so we can't completely avoid the blocking.
// https://www.freebsd.org/cgi/man.cgi?query=arc4random_buf.
#ifdef __FreeBSD__
+# define DONT_USE_O_NOFOLLOW 1
# define USE_FREEBSD_ARC4RANDOM 1
# include <stdlib.h>
#endif
+// Solaris links /dev/urandom -> .../devices/pseudo/random@0:urandom
+// Avoid O_NOFOLLOW for the Solaris platform.
+#ifdef __sun
+# define DONT_USE_O_NOFOLLOW 1
+#endif
+
#ifdef CRYPTOPP_WIN32_AVAILABLE
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
@@ -144,28 +151,24 @@ MicrosoftCryptoProvider::~MicrosoftCryptoProvider()
NonblockingRng::NonblockingRng()
{
-#ifndef CRYPTOPP_WIN32_AVAILABLE
-# ifndef USE_FREEBSD_ARC4RANDOM
-# ifdef O_NOFOLLOW
+#if !defined(CRYPTOPP_WIN32_AVAILABLE) && !defined(USE_FREEBSD_ARC4RANDOM)
+# ifndef DONT_USE_O_NOFOLLOW
const int flags = O_RDONLY|O_NOFOLLOW;
-# else
+# else
const int flags = O_RDONLY;
-# endif
+# endif
m_fd = open("/dev/urandom", flags);
if (m_fd == -1)
throw OS_RNG_Err("open /dev/urandom");
-# endif
#endif
}
NonblockingRng::~NonblockingRng()
{
-#ifndef CRYPTOPP_WIN32_AVAILABLE
-# ifndef USE_FREEBSD_ARC4RANDOM
+#if !defined(CRYPTOPP_WIN32_AVAILABLE) && !defined(USE_FREEBSD_ARC4RANDOM)
close(m_fd);
-# endif
#endif
}
@@ -249,7 +252,7 @@ void NonblockingRng::GenerateBlock(byte *output, size_t size)
BlockingRng::BlockingRng()
{
-#ifdef O_NOFOLLOW
+#ifndef DONT_USE_O_NOFOLLOW
const int flags = O_RDONLY|O_NOFOLLOW;
#else
const int flags = O_RDONLY;