diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-01-15 10:32:33 -0500 |
---|---|---|
committer | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-01-15 11:10:39 -0500 |
commit | 5ccc23d04e2662616c993d607a80666d021e1e5d (patch) | |
tree | 37a692eda7a71cea569bf41bd698f2b1ff493f68 /src/mongo/platform | |
parent | d26fcb64a7df86131e4951a31f07732d0d9b912f (diff) | |
download | mongo-5ccc23d04e2662616c993d607a80666d021e1e5d.tar.gz |
SERVER-1120: OpenBSD/FreeBSD fixes
Diffstat (limited to 'src/mongo/platform')
-rw-r--r-- | src/mongo/platform/random.cpp | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/mongo/platform/random.cpp b/src/mongo/platform/random.cpp index 74accea6ce5..e00fab107ca 100644 --- a/src/mongo/platform/random.cpp +++ b/src/mongo/platform/random.cpp @@ -117,7 +117,7 @@ namespace mongo { return new WinSecureRandom(); } -#elif defined(__linux__) || defined(__sunos__) || defined(__APPLE__) +#elif defined(__linux__) || defined(__sunos__) || defined(__APPLE__) || defined(__freebsd__) class InputStreamSecureRandom : public SecureRandom { public: @@ -150,25 +150,24 @@ namespace mongo { return new InputStreamSecureRandom( "/dev/urandom" ); } -#else - class SRandSecureRandom : public SecureRandom { - public: - SRandSecureRandom() { - srandomdev(); - } +#elif defined(__openbsd__) + class Arc4SecureRandom : public SecureRandom { + public: int64_t nextInt64() { - long a, b; - a = random(); - b = random(); - return ( static_cast<int64_t>(a) << 32 ) | b; + int64_t value; + arc4random_buf(&value, sizeof(value)); + return value; } }; SecureRandom* SecureRandom::create() { - return new SRandSecureRandom(); + return new Arc4SecureRandom(); } +#else + +#error Must implement SecureRandom for platform #endif |