diff --git a/contrib/src/opendht/rules.mak b/contrib/src/opendht/rules.mak index e34a351526fb3dc155f5292ffe980d1f217c4bb3..df9807ec52a86ef84b20416216c1630331dc7408 100644 --- a/contrib/src/opendht/rules.mak +++ b/contrib/src/opendht/rules.mak @@ -1,5 +1,5 @@ # OPENDHT -OPENDHT_VERSION := 4ad1495e393917ab292fabdd9a918f86d43df13f +OPENDHT_VERSION := 930e3e890bae83356ab04959c37aab970717dd05 OPENDHT_URL := https://github.com/savoirfairelinux/opendht/archive/$(OPENDHT_VERSION).tar.gz PKGS += opendht diff --git a/src/account.cpp b/src/account.cpp index 27dab8e91c44c88c962f381e79806741187aa486..eef99e734ce7550ca3934e50a7aa964a06ece855 100644 --- a/src/account.cpp +++ b/src/account.cpp @@ -47,6 +47,13 @@ #include "logger.h" #include "manager.h" +#if HAVE_DHT +#include <opendht/rng.h> +using random_device = dht::crypto::random_device; +#else +using random_device = std::random_device; +#endif + #include "client/ring_signal.h" #include "account_schema.h" #include "string_utils.h" @@ -111,15 +118,8 @@ Account::Account(const std::string &accountID) , mailBox_() , upnp_(new upnp::Controller()) { -#ifndef _WIN32 - std::random_device rdev; + random_device rdev; std::seed_seq seed {rdev(), rdev()}; -#else - int seed_data[std::mt19937::state_size]; - std::default_random_engine dre(std::chrono::system_clock::now().time_since_epoch().count()); - std::generate_n(seed_data, std::mt19937::state_size, std::ref(dre)); - std::seed_seq seed(std::begin(seed_data), std::end(seed_data)); -#endif rand_.seed(seed); // Initialize the codec order, used when creating a new account diff --git a/src/manager.cpp b/src/manager.cpp index 23b252b644253277ec3788c0829dfb653b75610c..4689c2c04c39a7f2408ae6789bff5db6c0e9e690 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -50,6 +50,10 @@ #include "string_utils.h" #if HAVE_DHT #include "ringdht/ringaccount.h" +#include <opendht/rng.h> +using random_device = dht::crypto::random_device; +#else +using random_device = std::random_device; #endif #include "call_factory.h" @@ -221,15 +225,9 @@ Manager::Manager() : { // initialize random generator // mt19937_64 should be seeded with 2 x 32 bits -#ifndef _WIN32 - std::random_device rdev; + + random_device rdev; std::seed_seq seed {rdev(), rdev()}; -#else - int seed_data[std::mt19937::state_size]; - std::default_random_engine dre(std::chrono::system_clock::now().time_since_epoch().count()); - std::generate_n(seed_data, std::mt19937::state_size, std::ref(dre)); - std::seed_seq seed(std::begin(seed_data), std::end(seed_data)); -#endif rand_.seed(seed); ring::libav_utils::ring_avcodec_init(); diff --git a/src/sip/sdp.cpp b/src/sip/sdp.cpp index 7727d642d8cdeae08c804eadf1dc7d131fd3dbb8..92b7982dc488748315a2ddc2da6e9de4c7457c4f 100644 --- a/src/sip/sdp.cpp +++ b/src/sip/sdp.cpp @@ -52,6 +52,13 @@ #include "system_codec_container.h" #include "intrin.h" // for UNUSED +#if HAVE_DHT +#include <opendht/rng.h> +using random_device = dht::crypto::random_device; +#else +using random_device = std::random_device; +#endif + #include <algorithm> #include <cassert> @@ -132,11 +139,7 @@ static void randomFill(std::vector<uint8_t>& dest) { std::uniform_int_distribution<uint8_t> rand_byte(0, 255); -#ifndef _WIN32 - std::random_device rdev; -#else - std::default_random_engine rdev(std::chrono::system_clock::now().time_since_epoch().count()); -#endif + random_device rdev; std::generate(dest.begin(), dest.end(), std::bind(rand_byte, std::ref(rdev))); } diff --git a/src/upnp/upnp_context.cpp b/src/upnp/upnp_context.cpp index 68317d3f62131768f1660241ae467a3f6e9876a8..64ebdabdfe94d03f09d591351a6ebc3f62174748 100644 --- a/src/upnp/upnp_context.cpp +++ b/src/upnp/upnp_context.cpp @@ -53,6 +53,13 @@ #include "upnp_igd.h" #include "intrin.h" +#if HAVE_DHT +#include <opendht/rng.h> +using random_device = dht::crypto::random_device; +#else +using random_device = std::random_device; +#endif + namespace ring { namespace upnp { /** @@ -285,11 +292,7 @@ static uint16_t generateRandomPort() { /* obtain a random number from hardware */ -#ifndef _WIN32 - static std::random_device rd; -#else - static std::default_random_engine rd(std::chrono::system_clock::now().time_since_epoch().count()); -#endif + static random_device rd; /* seed the generator */ static std::mt19937 gen(rd()); /* define the range */