mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-22 11:36:21 +00:00
Windows: added alternative to bcrypt lib
This commit is contained in:
1 parent
8a8ff2aef0
commit
5ec26a5015
5 files changed
+27
-2
No files matched your search
@@ -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
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user