| 18 | #include <bcrypt.h> |
| 19 | |
| 20 | bool cbm_secure_random(void *buffer, size_t length) { |
| 21 | if (!buffer && length != 0) { |
| 22 | return false; |
| 23 | } |
| 24 | uint8_t *cursor = buffer; |
| 25 | while (length > 0) { |
| 26 | ULONG chunk = length > UINT32_MAX ? UINT32_MAX : (ULONG)length; |
| 27 | if (BCryptGenRandom(NULL, cursor, chunk, BCRYPT_USE_SYSTEM_PREFERRED_RNG) < 0) { |
| 28 | return false; |
| 29 | } |
| 30 | cursor += chunk; |
| 31 | length -= chunk; |
| 32 | } |
| 33 | return true; |
| 34 | } |
| 35 | |
| 36 | #else |
| 37 |
no outgoing calls
no test coverage detected