misc fixes and updates

This commit is contained in:
Sergio R. Caprile committed 2024-12-27 11:16:10 -03:00
1 parent 8ce82a100e
commit 837da0e458
12 files changed
+96 -85

No files matched your search

+5 -7
View File
@@ -1,5 +1,5 @@
#include "log.h"
#include "util.h"
#include "log.h"
// Not using memset for zeroing memory, cause it can be dropped by compiler
// See https://github.com/cesanta/mongoose/pull/1265
@@ -21,24 +21,22 @@ bool mg_random(void *buf, size_t len) {
while (len--) *p++ = (unsigned char) (get_rand_32() & 255);
success = true;
#elif MG_ARCH == MG_ARCH_WIN32
static bool initialised = false;
#if defined(_MSC_VER) && _MSC_VER < 1700
static bool initialised = false;
static HCRYPTPROV hProv;
// CryptGenRandom() implementation earlier than 2008 is weak, see
// https://en.wikipedia.org/wiki/CryptGenRandom
if (initialised == false) {
if (!initialised) {
initialised = CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL,
CRYPT_VERIFYCONTEXT);
}
if (initialised == true) {
success = CryptGenRandom(hProv, len, p);
}
if (initialised) success = CryptGenRandom(hProv, len, p);
#else
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);
p[i] = (unsigned char) (rand_v & 255);
} else {
break;
}