Commit a5acbc5a authored by Edric Milaret's avatar Edric Milaret Committed by Guillaume Roguez

dht: fix random generators on Windows

This patch should fix DHT calls on Window platform.

Replacing random_device (deterministic on Windows because of
no /dev/urandom/ support) with a default_random_engine with a time seed.
It's a less secure way of doing it (vulnerable to time attack).

Refs #72538
Refs #72700

Change-Id: I259f80144eeee6732cc969ecb224544a53d7ccf1
parent f4742909
......@@ -106,8 +106,15 @@ Account::Account(const std::string &accountID)
, mailBox_()
, upnp_(new upnp::Controller())
{
#ifndef _WIN32
std::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
......
......@@ -225,8 +225,15 @@ Manager::Manager() :
{
// initialize random generator
// mt19937_64 should be seeded with 2 x 32 bits
#ifndef _WIN32
std::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();
......
......@@ -132,7 +132,11 @@ 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
std::generate(dest.begin(), dest.end(), std::bind(rand_byte, std::ref(rdev)));
}
......
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