mirror of
https://git.jami.net/savoirfairelinux/jami-daemon.git
synced 2025-08-12 22:09:25 +08:00
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
This commit is contained in:

committed by
Guillaume Roguez

parent
f47429097e
commit
a5acbc5a51
@ -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)));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user