diff options
author | Matt Corallo <git@bluematt.me> | 2017-05-22 16:01:29 -0400 |
---|---|---|
committer | Matt Corallo <git@bluematt.me> | 2017-05-22 16:01:29 -0400 |
commit | 399fb8f2d0fa9cff2f461ef2c0da5b91765987f1 (patch) | |
tree | cc5dc3bfe6f39ced25ac094bb1251963c490d94b | |
parent | daf3e7def7b9e5db7a32f5a20b5c4e09e3f0dd18 (diff) |
Add internal method to add new random data to our internal RNG state
-rw-r--r-- | src/random.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/random.cpp b/src/random.cpp index 3b9df3edaa..3c856ecfa6 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -207,6 +207,22 @@ static std::mutex cs_rng_state; static unsigned char rng_state[32] = {0}; static uint64_t rng_counter = 0; +static void AddDataToRng(void* data, size_t len) { + CSHA512 hasher; + hasher.Write((const unsigned char*)&len, sizeof(len)); + hasher.Write((const unsigned char*)data, len); + unsigned char buf[64]; + { + std::unique_lock<std::mutex> lock(cs_rng_state); + hasher.Write(rng_state, sizeof(rng_state)); + hasher.Write((const unsigned char*)&rng_counter, sizeof(rng_counter)); + ++rng_counter; + hasher.Finalize(buf); + memcpy(rng_state, buf + 32, 32); + } + memory_cleanse(buf, 64); +} + void GetStrongRandBytes(unsigned char* out, int num) { assert(num <= 32); |