mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-11 17:51:04 +00:00
Use secure randomness to seed internal RNG
This commit is contained in:
parent
785c042f1f
commit
1281173e50
4 changed files with 18 additions and 18 deletions
16
src/main.cpp
16
src/main.cpp
|
@ -700,12 +700,18 @@ static bool init_common(const Settings &cmd_args, int argc, char *argv[])
|
|||
init_log_streams(cmd_args);
|
||||
|
||||
// Initialize random seed
|
||||
{
|
||||
u32 seed = static_cast<u32>(time(nullptr)) << 16;
|
||||
seed |= porting::getTimeUs() & 0xffff;
|
||||
srand(seed);
|
||||
mysrand(seed);
|
||||
u64 seed;
|
||||
if (!porting::secure_rand_fill_buf(&seed, sizeof(seed))) {
|
||||
verbosestream << "Secure randomness not available to seed global RNG." << std::endl;
|
||||
std::ostringstream oss;
|
||||
// some stuff that's hard to predict:
|
||||
oss << time(nullptr) << porting::getTimeUs() << argc << g_settings_path;
|
||||
print_version(oss);
|
||||
std::string data = oss.str();
|
||||
seed = murmur_hash_64_ua(data.c_str(), data.size(), 0xc0ffee);
|
||||
}
|
||||
srand(seed);
|
||||
mysrand(seed);
|
||||
|
||||
// Initialize HTTP fetcher
|
||||
httpfetch_init(g_settings->getS32("curl_parallel_limit"));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue