mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-29 12:41:03 +00:00
Merge pull request #2933 from cesanta/win_rng
Windows: added alternative to bcrypt lib
This commit is contained in:
4 files changed
+26
-26
No files matched your search
+9
-8
@@ -16388,15 +16388,16 @@ bool mg_random(void *buf, size_t len) {
|
||||
success = CryptGenRandom(hProv, len, p);
|
||||
}
|
||||
#else
|
||||
// BCrypt is a "new generation" strong crypto API, so try it first
|
||||
static BCRYPT_ALG_HANDLE hProv;
|
||||
if (initialised == false &&
|
||||
BCryptOpenAlgorithmProvider(&hProv, BCRYPT_RNG_ALGORITHM, NULL, 0) == 0) {
|
||||
initialised = true;
|
||||
}
|
||||
if (initialised == true) {
|
||||
success = BCryptGenRandom(hProv, p, (ULONG) len, 0) == 0;
|
||||
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);
|
||||
#endif
|
||||
|
||||
#elif MG_ARCH == MG_ARCH_UNIX
|
||||
|
||||
Reference in new issue
Block a user