Commit e5c1baf1 authored by Edric Milaret's avatar Edric Milaret Committed by Adrien Béraud

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
parent 7ca89c65
# OPENDHT
OPENDHT_VERSION := 4ad1495e393917ab292fabdd9a918f86d43df13f
OPENDHT_VERSION := 930e3e890bae83356ab04959c37aab970717dd05
OPENDHT_URL := https://github.com/savoirfairelinux/opendht/archive/$(OPENDHT_VERSION).tar.gz
PKGS += opendht
......
......@@ -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
......
......@@ -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();
......
......@@ -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)));
}
......
......@@ -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 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment