Use repeated SHA512 to strengthen the randomness in seed32, and feed into hasher. */
| 222 | |
| 223 | /** Use repeated SHA512 to strengthen the randomness in seed32, and feed into hasher. */ |
| 224 | static void Strengthen(const unsigned char (&seed)[32], int microseconds, CSHA512& hasher) noexcept |
| 225 | { |
| 226 | CSHA512 inner_hasher; |
| 227 | inner_hasher.Write(seed, sizeof(seed)); |
| 228 | |
| 229 | // Hash loop |
| 230 | unsigned char buffer[64]; |
| 231 | int64_t stop = GetTimeMicros() + microseconds; |
| 232 | do { |
| 233 | for (int i = 0; i < 1000; ++i) { |
| 234 | inner_hasher.Finalize(buffer); |
| 235 | inner_hasher.Reset(); |
| 236 | inner_hasher.Write(buffer, sizeof(buffer)); |
| 237 | } |
| 238 | // Benchmark operation and feed it into outer hasher. |
| 239 | int64_t perf = GetPerformanceCounter(); |
| 240 | hasher.Write((const unsigned char*)&perf, sizeof(perf)); |
| 241 | } while (GetTimeMicros() < stop); |
| 242 | |
| 243 | // Produce output from inner state and feed it to outer hasher. |
| 244 | inner_hasher.Finalize(buffer); |
| 245 | hasher.Write(buffer, sizeof(buffer)); |
| 246 | // Try to clean up. |
| 247 | inner_hasher.Reset(); |
| 248 | memory_cleanse(buffer, sizeof(buffer)); |
| 249 | } |
| 250 | |
| 251 | #ifndef WIN32 |
| 252 | /** Fallback: get 32 bytes of system entropy from /dev/urandom. The most |
no test coverage detected