Windows: added alternative to bcrypt lib

This commit is contained in:
robert committed 2024-10-08 09:21:13 -04:00
1 parent 8a8ff2aef0
commit 5ec26a5015
5 files changed
+27 -2

No files matched your search

+1
View File
@@ -57,6 +57,7 @@ typedef enum { false = 0, true = 1 } bool;
#endif
#include <wincrypt.h>
#pragma comment(lib, "advapi32.lib")
#elif defined(_CRT_RAND_S)
#else
#include <bcrypt.h>
#if defined(_MSC_VER)
+11
View File
@@ -30,6 +30,17 @@ bool mg_random(void *buf, size_t len) {
if (initialised == true) {
success = CryptGenRandom(hProv, len, p);
}
#elif defined(_CRT_RAND_S)
size_t i;
for (i = 0; i < len; i++) {
unsigned int rand_v;
if (rand_s(&rand_v) == 0) {
p[i] = (unsigned char)(rand_v & 255);
} else {
break;
}
}
success = (i == len);
#else
// BCrypt is a "new generation" strong crypto API, so try it first
static BCRYPT_ALG_HANDLE hProv;