Add 256 bits of entropy gathered from hardware to hasher. Do nothing if not supported. */
| 208 | |
| 209 | /** Add 256 bits of entropy gathered from hardware to hasher. Do nothing if not supported. */ |
| 210 | void SeedHardwareSlow(CSHA512& hasher) noexcept { |
| 211 | #if defined(__x86_64__) || defined(__amd64__) || defined(__i386__) |
| 212 | // When we want 256 bits of entropy, prefer RdSeed over RdRand, as it's |
| 213 | // guaranteed to produce independent randomness on every call. |
| 214 | if (g_rdseed_supported) { |
| 215 | for (int i = 0; i < 4; ++i) { |
| 216 | uint64_t out = GetRdSeed(); |
| 217 | hasher.Write((const unsigned char*)&out, sizeof(out)); |
| 218 | } |
| 219 | return; |
| 220 | } |
| 221 | // When falling back to RdRand, XOR the result of 1024 results. |
| 222 | // This guarantees a reseeding occurs between each. |
| 223 | if (g_rdrand_supported) { |
| 224 | for (int i = 0; i < 4; ++i) { |
| 225 | uint64_t out = 0; |
| 226 | for (int j = 0; j < 1024; ++j) out ^= GetRdRand(); |
| 227 | hasher.Write((const unsigned char*)&out, sizeof(out)); |
| 228 | } |
| 229 | return; |
| 230 | } |
| 231 | #endif |
| 232 | } |
| 233 | |
| 234 | /** Use repeated SHA512 to strengthen the randomness in seed32, and feed into hasher. */ |
| 235 | void Strengthen(const unsigned char (&seed)[32], SteadyClock::duration dur, CSHA512& hasher) noexcept |
no test coverage detected