From e1f433d2c47f623ceb5d1d1aee7605fefb71b846 Mon Sep 17 00:00:00 2001 From: Billy Donahue Date: Wed, 9 Oct 2019 17:09:10 +0000 Subject: SERVER-43641 upgrade random.h This reverts commit a40b196bd3cecd0b66a6323f57e6f08efe0af392. --- src/mongo/util/uuid.cpp | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'src/mongo/util/uuid.cpp') diff --git a/src/mongo/util/uuid.cpp b/src/mongo/util/uuid.cpp index d729777cf30..63ca7bc1e2d 100644 --- a/src/mongo/util/uuid.cpp +++ b/src/mongo/util/uuid.cpp @@ -43,7 +43,7 @@ namespace mongo { namespace { Mutex uuidGenMutex; -auto uuidGen = SecureRandom::create(); +SecureRandom uuidGen; // Regex to match valid version 4 UUIDs with variant bits set std::regex uuidRegex("[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}", @@ -97,19 +97,12 @@ bool UUID::isRFC4122v4() const { } UUID UUID::gen() { - int64_t randomWords[2]; - + UUIDStorage randomBytes; { stdx::lock_guard lk(uuidGenMutex); - - // Generate 128 random bits - randomWords[0] = uuidGen->nextInt64(); - randomWords[1] = uuidGen->nextInt64(); + uuidGen.fill(&randomBytes, sizeof(randomBytes)); } - UUIDStorage randomBytes; - memcpy(&randomBytes, randomWords, sizeof(randomBytes)); - // Set version in high 4 bits of byte 6 and variant in high 2 bits of byte 8, see RFC 4122, // section 4.1.1, 4.1.2 and 4.1.3. randomBytes[6] &= 0x0f; -- cgit v1.2.1