| 31 | static struct SECURE_RANDOM_DATA secure_random_data = {}; |
| 32 | |
| 33 | static void ensure_secure_random_init() |
| 34 | { |
| 35 | std::call_once(secure_random_data.initialized_once_flag, []() { |
| 36 | #if defined(CONF_FAMILY_WINDOWS) |
| 37 | if(!CryptAcquireContext(&secure_random_data.provider, nullptr, nullptr, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) |
| 38 | { |
| 39 | const DWORD LastError = GetLastError(); |
| 40 | dbg_assert_failed("Failed to initialize secure random: CryptAcquireContext failure (%ld '%s')", LastError, windows_format_system_message(LastError).c_str()); |
| 41 | } |
| 42 | #else |
| 43 | secure_random_data.urandom = io_open("/dev/urandom", IOFLAG_READ); |
| 44 | dbg_assert(secure_random_data.urandom != nullptr, "Failed to initialize secure random: failed to open /dev/urandom"); |
| 45 | #endif |
| 46 | }); |
| 47 | } |
| 48 | |
| 49 | void generate_password(char *buffer, unsigned length, const unsigned short *random, unsigned random_length) |
| 50 | { |
no test coverage detected