Add 256 bits of entropy gathered from hardware to hasher. Do nothing if not supported. */
| 197 | |
| 198 | /** Add 256 bits of entropy gathered from hardware to hasher. Do nothing if not supported. */ |
| 199 | static void SeedHardwareSlow(CSHA512& hasher) noexcept { |
| 200 | #if defined(__x86_64__) || defined(__amd64__) || defined(__i386__) |
| 201 | // When we want 256 bits of entropy, prefer RdSeed over RdRand, as it's |
| 202 | // guaranteed to produce independent randomness on every call. |
| 203 | if (g_rdseed_supported) { |
| 204 | for (int i = 0; i < 4; ++i) { |
| 205 | uint64_t out = GetRdSeed(); |
| 206 | hasher.Write((const unsigned char*)&out, sizeof(out)); |
| 207 | } |
| 208 | return; |
| 209 | } |
| 210 | // When falling back to RdRand, XOR the result of 1024 results. |
| 211 | // This guarantees a reseeding occurs between each. |
| 212 | if (g_rdrand_supported) { |
| 213 | for (int i = 0; i < 4; ++i) { |
| 214 | uint64_t out = 0; |
| 215 | for (int j = 0; j < 1024; ++j) out ^= GetRdRand(); |
| 216 | hasher.Write((const unsigned char*)&out, sizeof(out)); |
| 217 | } |
| 218 | return; |
| 219 | } |
| 220 | #endif |
| 221 | } |
| 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 |
no test coverage detected