MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / RandAddSeedPerfmon

Function RandAddSeedPerfmon

src/commons/random.cpp:47–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45}
46
47void RandAddSeedPerfmon()
48{
49 RandAddSeed();
50
51#ifdef WIN32
52 // Don't need this on Linux, OpenSSL automatically uses /dev/urandom
53 // Seed with the entire set of perfmon data
54
55 // This can take up to 2 seconds, so only do it every 10 minutes
56 static int64_t nLastPerfmon;
57 if (GetTime() < nLastPerfmon + 10 * 60)
58 return;
59 nLastPerfmon = GetTime();
60
61 std::vector<unsigned char> vData(250000, 0);
62 long ret = 0;
63 unsigned long nSize = 0;
64 const size_t nMaxSize = 10000000; // Bail out at more than 10MB of performance data
65 while (true) {
66 nSize = vData.size();
67 ret = RegQueryValueExA(HKEY_PERFORMANCE_DATA, "Global", NULL, NULL, begin_ptr(vData), &nSize);
68 if (ret != ERROR_MORE_DATA || vData.size() >= nMaxSize)
69 break;
70 vData.resize(std::max((vData.size() * 3) / 2, nMaxSize)); // Grow size of buffer exponentially
71 }
72 RegCloseKey(HKEY_PERFORMANCE_DATA);
73 if (ret == ERROR_SUCCESS) {
74 RAND_add(begin_ptr(vData), nSize, nSize / 100.0);
75 memory_cleanse(begin_ptr(vData), nSize);
76 // LogPrint("rand", "%lu bytes\n", nSize);
77 } else {
78 static bool warned = false; // Warn only once
79 if (!warned) {
80 LogPrint(BCLog::INFO, "[WARN] RegQueryValueExA(HKEY_PERFORMANCE_DATA) failed with code %i\n", ret);
81 warned = true;
82 }
83 }
84#endif
85}
86
87void GetRandBytes(unsigned char* buf, int num)
88{

Callers 3

AppInitFunction · 0.85
EncryptWalletMethod · 0.85
MakeNewKeyMethod · 0.85

Calls 6

RandAddSeedFunction · 0.85
GetTimeFunction · 0.85
begin_ptrFunction · 0.85
memory_cleanseFunction · 0.85
sizeMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected