mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-26 22:41:03 +08:00
Windows: added alternative to bcrypt lib
This commit is contained in:
parent
8a8ff2aef0
commit
5ec26a5015
11
mongoose.c
11
mongoose.c
@ -16385,6 +16385,17 @@ bool mg_random(void *buf, size_t len) {
|
|||||||
if (initialised == true) {
|
if (initialised == true) {
|
||||||
success = CryptGenRandom(hProv, len, p);
|
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
|
#else
|
||||||
// BCrypt is a "new generation" strong crypto API, so try it first
|
// BCrypt is a "new generation" strong crypto API, so try it first
|
||||||
static BCRYPT_ALG_HANDLE hProv;
|
static BCRYPT_ALG_HANDLE hProv;
|
||||||
|
@ -470,6 +470,7 @@ typedef enum { false = 0, true = 1 } bool;
|
|||||||
#endif
|
#endif
|
||||||
#include <wincrypt.h>
|
#include <wincrypt.h>
|
||||||
#pragma comment(lib, "advapi32.lib")
|
#pragma comment(lib, "advapi32.lib")
|
||||||
|
#elif defined(_CRT_RAND_S)
|
||||||
#else
|
#else
|
||||||
#include <bcrypt.h>
|
#include <bcrypt.h>
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
|
@ -57,6 +57,7 @@ typedef enum { false = 0, true = 1 } bool;
|
|||||||
#endif
|
#endif
|
||||||
#include <wincrypt.h>
|
#include <wincrypt.h>
|
||||||
#pragma comment(lib, "advapi32.lib")
|
#pragma comment(lib, "advapi32.lib")
|
||||||
|
#elif defined(_CRT_RAND_S)
|
||||||
#else
|
#else
|
||||||
#include <bcrypt.h>
|
#include <bcrypt.h>
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
|
11
src/util.c
11
src/util.c
@ -30,6 +30,17 @@ bool mg_random(void *buf, size_t len) {
|
|||||||
if (initialised == true) {
|
if (initialised == true) {
|
||||||
success = CryptGenRandom(hProv, len, p);
|
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
|
#else
|
||||||
// BCrypt is a "new generation" strong crypto API, so try it first
|
// BCrypt is a "new generation" strong crypto API, so try it first
|
||||||
static BCRYPT_ALG_HANDLE hProv;
|
static BCRYPT_ALG_HANDLE hProv;
|
||||||
|
@ -11,6 +11,7 @@ ENV ?= -e Tmp=. -e WINEDEBUG=-all
|
|||||||
DOCKER_BIN ?= docker
|
DOCKER_BIN ?= docker
|
||||||
DOCKER ?= $(DOCKER_BIN) run --platform linux/amd64 --rm $(ENV) -v $(ROOT_DIR):$(ROOT_DIR) -w $(CWD)
|
DOCKER ?= $(DOCKER_BIN) run --platform linux/amd64 --rm $(ENV) -v $(ROOT_DIR):$(ROOT_DIR) -w $(CWD)
|
||||||
VCFLAGS = /nologo /W3 /O2 /MD /I. $(DEFS) $(TFLAGS)
|
VCFLAGS = /nologo /W3 /O2 /MD /I. $(DEFS) $(TFLAGS)
|
||||||
|
VCRANDFLAG = /D_CRT_RAND_S
|
||||||
IPV6 ?= 1
|
IPV6 ?= 1
|
||||||
ASAN ?= -fsanitize=address,undefined,alignment -fno-sanitize-recover=all -fno-omit-frame-pointer -fno-common
|
ASAN ?= -fsanitize=address,undefined,alignment -fno-sanitize-recover=all -fno-omit-frame-pointer -fno-common
|
||||||
ASAN_OPTIONS ?= detect_leaks=1
|
ASAN_OPTIONS ?= detect_leaks=1
|
||||||
@ -171,11 +172,11 @@ vc98: Makefile mongoose.h $(SRCS)
|
|||||||
$(DOCKER) mdashnet/vc98 wine $@.exe
|
$(DOCKER) mdashnet/vc98 wine $@.exe
|
||||||
|
|
||||||
vc17: Makefile mongoose.h $(SRCS)
|
vc17: Makefile mongoose.h $(SRCS)
|
||||||
$(DOCKER) mdashnet/vc17 wine64 cl $(SRCS) $(VCFLAGS) /Fe$@.exe
|
$(DOCKER) mdashnet/vc17 wine64 cl $(SRCS) $(VCRANDFLAG) $(VCFLAGS) /Fe$@.exe
|
||||||
$(DOCKER) mdashnet/vc17 wine64 $@.exe
|
$(DOCKER) mdashnet/vc17 wine64 $@.exe
|
||||||
|
|
||||||
vc22: Makefile mongoose.h $(SRCS)
|
vc22: Makefile mongoose.h $(SRCS)
|
||||||
$(DOCKER) mdashnet/vc22 wine64 cl $(SRCS) $(VCFLAGS) /Fe$@.exe
|
$(DOCKER) mdashnet/vc22 wine64 cl $(SRCS) $(VCRANDFLAG) $(VCFLAGS) /Fe$@.exe
|
||||||
$(DOCKER) mdashnet/vc22 wine64 $@.exe
|
$(DOCKER) mdashnet/vc22 wine64 $@.exe
|
||||||
|
|
||||||
mingw: Makefile mongoose.h $(SRCS)
|
mingw: Makefile mongoose.h $(SRCS)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user