Skip to content

Commit

Permalink
UUID: Use the non-cryptographic variant of the boost::uuid
Browse files Browse the repository at this point in the history
Since Boost 1.67.0 the default UUID generator is cryptographically
strong, which is neat but quite slower. Since we don't need that,
just use the fastest version.
  • Loading branch information
rgacogne committed Dec 8, 2020
1 parent 714a6e1 commit 0acc8b3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pdns/uuid-utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@

#include <boost/uuid/uuid_generators.hpp>

thread_local boost::uuids::random_generator t_uuidGenerator;
// The default of:
// boost::uuids::random_generator
// is safe for crypto operations since 1.67.0, but much slower.
thread_local boost::uuids::basic_random_generator<boost::random::mt19937> t_uuidGenerator;

boost::uuids::uuid getUniqueID()
{
// not safe for crypto, but it could be with Boost >= 1.67.0 by using boost::uuids::random_generator,
// which is slower
return t_uuidGenerator();
}

Expand Down
1 change: 1 addition & 0 deletions pdns/uuid-utils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_io.hpp>

/* Not safe for crypto, see the definition for more information */
boost::uuids::uuid getUniqueID();
boost::uuids::uuid getUniqueID(const std::string& str);

0 comments on commit 0acc8b3

Please sign in to comment.