Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F10615180
D4391.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
D4391.diff
View Options
diff --git a/src/random.cpp b/src/random.cpp
--- a/src/random.cpp
+++ b/src/random.cpp
@@ -79,7 +79,7 @@
static std::atomic<bool> hwrand_initialized{false};
static bool rdrand_supported = false;
static constexpr uint32_t CPUID_F1_ECX_RDRAND = 0x40000000;
-static void RDRandInit() {
+static void InitHardwareRand() {
uint32_t eax, ebx, ecx, edx;
if (__get_cpuid(1, &eax, &ebx, &ecx, &edx) && (ecx & CPUID_F1_ECX_RDRAND)) {
rdrand_supported = true;
@@ -87,7 +87,7 @@
hwrand_initialized.store(true);
}
-static void RDRandReport() {
+static void ReportHardwareRand() {
assert(hwrand_initialized.load(std::memory_order_relaxed));
if (rdrand_supported) {
// This must be done in a separate function, as HWRandInit() may be
@@ -98,11 +98,17 @@
}
#else
-static void RDRandInit() {}
-static void RDRandReport() {}
+/**
+ * Access to other hardware random number generators could be added here later,
+ * assuming it is sufficiently fast (in the order of a few hundred CPU cycles).
+ * Slower sources should probably be invoked separately, and/or only from
+ * RandAddSeedSleep (which is called during idle background operation).
+ */
+static void InitHardwareRand() {}
+static void ReportHardwareRand() {}
#endif
-static bool GetHWRand(uint8_t *ent32) {
+static bool GetHardwareRand(uint8_t *ent32) {
#if defined(__x86_64__) || defined(__amd64__) || defined(__i386__)
assert(hwrand_initialized.load(std::memory_order_relaxed));
if (rdrand_supported) {
@@ -306,7 +312,7 @@
uint8_t m_state[32] = {0};
uint64_t m_counter = 0;
- explicit RNGState() { RDRandInit(); }
+ explicit RNGState() { InitHardwareRand(); }
};
RNGState &GetRNGState() {
@@ -368,7 +374,7 @@
hasher.Write(buf, 32);
// Third source: HW RNG, if available.
- if (GetHWRand(buf)) {
+ if (GetHardwareRand(buf)) {
hasher.Write(buf, 32);
}
@@ -526,5 +532,5 @@
// Invoke RNG code to trigger initialization (if not already performed)
GetRNGState();
- RDRandReport();
+ ReportHardwareRand();
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 22, 10:00 (16 h, 41 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4559212
Default Alt Text
D4391.diff (2 KB)
Attached To
D4391: Rename some hardware RNG related functions
Event Timeline
Log In to Comment