summaryrefslogtreecommitdiff
path: root/src/mongo/bson
diff options
context:
space:
mode:
authorBilly Donahue <billy.donahue@mongodb.com>2019-10-02 04:42:39 +0000
committerevergreen <evergreen@mongodb.com>2019-10-02 04:42:39 +0000
commit96da177c6ae7b7ed0f29983ad033d8a59524b0b2 (patch)
tree87a713b2be96453134555b1856e5f7dea07a1b0f /src/mongo/bson
parent059656a32ed8ed7e780c4b12bb3c4e101c1f90f4 (diff)
downloadmongo-96da177c6ae7b7ed0f29983ad033d8a59524b0b2.tar.gz
SERVER-43641 upgrade random.h
Respecify PseudoRandom and SecureRandom as template instances of a `mongo::RandomBase<Urbg>` (Urbg is a UniformRandomBitGenerator). They will only vary in which algorithm they use for their source bits, and should otherwise support the same exact operations (e.g. `nextCanonicalDouble`). Fix range and stats errors in the implementations of those RandomBase methods, and specify them in terms of the vetted `<random>` facilities. Test uniformity of nextInt32(max), which uses an inappropriate ( x % max) operation. Verify that refactor fixes this issue. Just keep a shared urandom file descriptor open. SecureRandom add fill, remove create, fix callers Obsoletes SERVER-43643 Re: SecureRandom 8kiB buffering
Diffstat (limited to 'src/mongo/bson')
-rw-r--r--src/mongo/bson/oid.cpp13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/mongo/bson/oid.cpp b/src/mongo/bson/oid.cpp
index 0f08d6c56b6..ebceefa04fa 100644
--- a/src/mongo/bson/oid.cpp
+++ b/src/mongo/bson/oid.cpp
@@ -54,9 +54,9 @@ OID::InstanceUnique _instanceUnique;
MONGO_INITIALIZER_GENERAL(OIDGeneration, MONGO_NO_PREREQUISITES, ("default"))
(InitializerContext* context) {
- std::unique_ptr<SecureRandom> entropy(SecureRandom::create());
- counter = std::make_unique<AtomicWord<int64_t>>(entropy->nextInt64());
- _instanceUnique = OID::InstanceUnique::generate(*entropy);
+ SecureRandom entropy;
+ counter = std::make_unique<AtomicWord<int64_t>>(entropy.nextInt64());
+ _instanceUnique = OID::InstanceUnique::generate(entropy);
return Status::OK();
}
@@ -72,9 +72,8 @@ OID::Increment OID::Increment::next() {
}
OID::InstanceUnique OID::InstanceUnique::generate(SecureRandom& entropy) {
- int64_t rand = entropy.nextInt64();
OID::InstanceUnique u;
- std::memcpy(u.bytes, &rand, kInstanceUniqueSize);
+ entropy.fill(u.bytes, kInstanceUniqueSize);
return u;
}
@@ -119,8 +118,8 @@ size_t OID::Hasher::operator()(const OID& oid) const {
}
void OID::regenMachineId() {
- std::unique_ptr<SecureRandom> entropy(SecureRandom::create());
- _instanceUnique = InstanceUnique::generate(*entropy);
+ SecureRandom entropy;
+ _instanceUnique = InstanceUnique::generate(entropy);
}
unsigned OID::getMachineId() {