Random: Try a little bit harder in the random bytes fallback path

pull/647/head
Jonathan G Rennison 3 months ago
parent f44ec32011
commit 17712af318

@ -10,6 +10,7 @@
#include "../stdafx.h"
#include "random_func.hpp"
#include "bitmath_func.hpp"
#include "hash_func.hpp"
#include "../debug.h"
#include <atomic>
#include <bit>
@ -143,7 +144,8 @@ void RandomBytesWithFallback(std::span<uint8_t> buf)
bool have_warned = warned_once.exchange(true);
DEBUG(misc, have_warned ? 1 : 0, "Cryptographically-strong random generator unavailable; using fallback");
for (uint i = 0; i < buf.size(); i++) {
buf[i] = static_cast<uint8_t>(InteractiveRandom());
for (uint i = 0; i < buf.size(); i ++) {
uint64_t current_time = static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now().time_since_epoch()).count());
buf[i] = static_cast<uint8_t>(SimpleHash64(current_time ^ InteractiveRandom()));
}
}

Loading…
Cancel
Save