From e5c1baf1f6cc56e99749f59e9f28e4b1ef60e2cc Mon Sep 17 00:00:00 2001 From: Edric Milaret <edric.ladent-milaret@savoirfairelinux.com> Date: Wed, 29 Jul 2015 14:40:18 -0400 Subject: [PATCH] win32: use dht random_device implementation - this patch bump opendht (needed a header not installed) - still use std::random_device on linux Issue: #76261 Change-Id: Ie8a5c26b74b00900f55576384c2db0605903e3e1 --- contrib/src/opendht/rules.mak | 2 +- src/account.cpp | 16 ++++++++-------- src/manager.cpp | 14 ++++++-------- src/sip/sdp.cpp | 13 ++++++++----- src/upnp/upnp_context.cpp | 13 ++++++++----- 5 files changed, 31 insertions(+), 27 deletions(-) diff --git a/contrib/src/opendht/rules.mak b/contrib/src/opendht/rules.mak index e34a351526..df9807ec52 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 27dab8e91c..eef99e734c 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 23b252b644..4689c2c04c 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 7727d642d8..92b7982dc4 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 68317d3f62..64ebdabdfe 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 */ -- GitLab