aboutsummaryrefslogtreecommitdiff
path: root/src/random.cpp
diff options
context:
space:
mode:
authorMatt Corallo <git@bluematt.me>2017-05-22 16:01:52 -0400
committerMatt Corallo <git@bluematt.me>2017-05-22 16:01:52 -0400
commit888cce57a67c901b89c86cc645f275071d021285 (patch)
tree14106f6de281a105033abba873dc6007c7be7180 /src/random.cpp
parent399fb8f2d0fa9cff2f461ef2c0da5b91765987f1 (diff)
downloadbitcoin-888cce57a67c901b89c86cc645f275071d021285.tar.xz
Add perf counter data to GetStrongRandBytes state in scheduler
Diffstat (limited to 'src/random.cpp')
-rw-r--r--src/random.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/random.cpp b/src/random.cpp
index 3c856ecfa6..de7553c825 100644
--- a/src/random.cpp
+++ b/src/random.cpp
@@ -203,6 +203,23 @@ void GetRandBytes(unsigned char* buf, int num)
}
}
+static void AddDataToRng(void* data, size_t len);
+
+void RandAddSeedSleep()
+{
+ int64_t nPerfCounter1 = GetPerformanceCounter();
+ std::this_thread::sleep_for(std::chrono::milliseconds(1));
+ int64_t nPerfCounter2 = GetPerformanceCounter();
+
+ // Combine with and update state
+ AddDataToRng(&nPerfCounter1, sizeof(nPerfCounter1));
+ AddDataToRng(&nPerfCounter2, sizeof(nPerfCounter2));
+
+ memory_cleanse(&nPerfCounter1, sizeof(nPerfCounter1));
+ memory_cleanse(&nPerfCounter2, sizeof(nPerfCounter2));
+}
+
+
static std::mutex cs_rng_state;
static unsigned char rng_state[32] = {0};
static uint64_t rng_counter = 0;