Changeset View
Changeset View
Standalone View
Standalone View
src/random.cpp
Show First 20 Lines • Show All 167 Lines • ▼ Show 20 Lines | while (true) { | ||||
} | } | ||||
// Grow size of buffer exponentially | // Grow size of buffer exponentially | ||||
vData.resize(std::max((vData.size() * 3) / 2, nMaxSize)); | vData.resize(std::max((vData.size() * 3) / 2, nMaxSize)); | ||||
} | } | ||||
RegCloseKey(HKEY_PERFORMANCE_DATA); | RegCloseKey(HKEY_PERFORMANCE_DATA); | ||||
if (ret == ERROR_SUCCESS) { | if (ret == ERROR_SUCCESS) { | ||||
RAND_add(vData.data(), nSize, nSize / 100.0); | RAND_add(vData.data(), nSize, nSize / 100.0); | ||||
memory_cleanse(vData.data(), nSize); | memory_cleanse(vData.data(), nSize); | ||||
LogPrint(BCLog::RAND, "%s: %lu bytes\n", __func__, nSize); | |||||
} else { | } else { | ||||
// Warn only once | // Performance data is only a best-effort attempt at improving the | ||||
static bool warned = false; | // situation when the OS randomness (and other sources) aren't | ||||
if (!warned) { | // adequate. As a result, failure to read it is isn't considered | ||||
LogPrintf("%s: Warning: RegQueryValueExA(HKEY_PERFORMANCE_DATA) " | // critical, so we don't call RandFailure(). | ||||
"failed with code %i\n", | // TODO: Add logging when the logger is made functional before global | ||||
__func__, ret); | // constructors have been invoked. | ||||
warned = true; | |||||
} | |||||
} | } | ||||
#endif | #endif | ||||
} | } | ||||
#ifndef WIN32 | #ifndef WIN32 | ||||
/** | /** | ||||
* Fallback: get 32 bytes of system entropy from /dev/urandom. The most | * Fallback: get 32 bytes of system entropy from /dev/urandom. The most | ||||
* compatible way to get cryptographic randomness on UNIX-ish platforms. | * compatible way to get cryptographic randomness on UNIX-ish platforms. | ||||
▲ Show 20 Lines • Show All 308 Lines • Show Last 20 Lines |