Killed bcrypt, replaced with rand_s

This commit is contained in:
robert 2024-10-29 10:41:10 -04:00
parent 5ec26a5015
commit f394df840e
5 changed files with 12 additions and 37 deletions

View File

@ -16385,7 +16385,7 @@ bool mg_random(void *buf, size_t len) {
if (initialised == true) {
success = CryptGenRandom(hProv, len, p);
}
#elif defined(_CRT_RAND_S)
#else
size_t i;
for (i = 0; i < len; i++) {
unsigned int rand_v;
@ -16396,16 +16396,6 @@ bool mg_random(void *buf, size_t len) {
}
}
success = (i == len);
#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;
}
#endif
#elif MG_ARCH == MG_ARCH_UNIX

View File

@ -415,6 +415,10 @@ static inline int mg_mkdir(const char *path, mode_t mode) {
#if MG_ARCH == MG_ARCH_WIN32
#ifndef _CRT_RAND_S
#define _CRT_RAND_S
#endif
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
@ -470,12 +474,6 @@ 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)
#pragma comment(lib, "bcrypt.lib")
#endif
#endif
// Protect from calls like std::snprintf in app code

View File

@ -2,6 +2,10 @@
#if MG_ARCH == MG_ARCH_WIN32
#ifndef _CRT_RAND_S
#define _CRT_RAND_S
#endif
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
@ -57,12 +61,6 @@ 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)
#pragma comment(lib, "bcrypt.lib")
#endif
#endif
// Protect from calls like std::snprintf in app code

View File

@ -30,7 +30,7 @@ bool mg_random(void *buf, size_t len) {
if (initialised == true) {
success = CryptGenRandom(hProv, len, p);
}
#elif defined(_CRT_RAND_S)
#else
size_t i;
for (i = 0; i < len; i++) {
unsigned int rand_v;
@ -41,16 +41,6 @@ bool mg_random(void *buf, size_t len) {
}
}
success = (i == len);
#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;
}
#endif
#elif MG_ARCH == MG_ARCH_UNIX

View File

@ -11,7 +11,6 @@ ENV ?= -e Tmp=. -e WINEDEBUG=-all
DOCKER_BIN ?= docker
DOCKER ?= $(DOCKER_BIN) run --platform linux/amd64 --rm $(ENV) -v $(ROOT_DIR):$(ROOT_DIR) -w $(CWD)
VCFLAGS = /nologo /W3 /O2 /MD /I. $(DEFS) $(TFLAGS)
VCRANDFLAG = /D_CRT_RAND_S
IPV6 ?= 1
ASAN ?= -fsanitize=address,undefined,alignment -fno-sanitize-recover=all -fno-omit-frame-pointer -fno-common
ASAN_OPTIONS ?= detect_leaks=1
@ -172,11 +171,11 @@ vc98: Makefile mongoose.h $(SRCS)
$(DOCKER) mdashnet/vc98 wine $@.exe
vc17: Makefile mongoose.h $(SRCS)
$(DOCKER) mdashnet/vc17 wine64 cl $(SRCS) $(VCRANDFLAG) $(VCFLAGS) /Fe$@.exe
$(DOCKER) mdashnet/vc17 wine64 cl $(SRCS) $(VCFLAGS) /Fe$@.exe
$(DOCKER) mdashnet/vc17 wine64 $@.exe
vc22: Makefile mongoose.h $(SRCS)
$(DOCKER) mdashnet/vc22 wine64 cl $(SRCS) $(VCRANDFLAG) $(VCFLAGS) /Fe$@.exe
$(DOCKER) mdashnet/vc22 wine64 cl $(SRCS) $(VCFLAGS) /Fe$@.exe
$(DOCKER) mdashnet/vc22 wine64 $@.exe
mingw: Makefile mongoose.h $(SRCS)