| 81 | } |
| 82 | |
| 83 | void secure_random_fill(void *bytes, unsigned length) |
| 84 | { |
| 85 | ensure_secure_random_init(); |
| 86 | #if defined(CONF_FAMILY_WINDOWS) |
| 87 | if(!CryptGenRandom(secure_random_data.provider, length, (unsigned char *)bytes)) |
| 88 | { |
| 89 | const DWORD LastError = GetLastError(); |
| 90 | dbg_assert_failed("CryptGenRandom failure (%ld '%s')", LastError, windows_format_system_message(LastError).c_str()); |
| 91 | } |
| 92 | #else |
| 93 | dbg_assert(length == io_read(secure_random_data.urandom, bytes, length), "io_read returned with a short read"); |
| 94 | #endif |
| 95 | } |
| 96 | |
| 97 | // From https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2. |
| 98 | static unsigned int find_next_power_of_two_minus_one(unsigned int n) |