And for Windows too

This commit is contained in:
UnknownShadow200 2024-12-17 21:01:20 +11:00
parent 9467c8951a
commit 0e1fba3d1e
3 changed files with 21 additions and 57 deletions

View file

@ -1081,8 +1081,23 @@ cc_result Platform_Decrypt(const void* data, int len, cc_string* dst) {
return 0;
}
static BOOL (WINAPI *_RtlGenRandom)(PVOID data, ULONG len);
cc_result Platform_GetEntropy(void* data, int len) {
return ERR_NOT_SUPPORTED;
static const struct DynamicLibSym funcs[] = {
DynamicLib_Sym2("SystemFunction036", RtlGenRandom)
};
if (!_RtlGenRandom) {
static const cc_string kernel32 = String_FromConst("ADVAPI32.DLL");
void* lib;
DynamicLib_LoadAll(&kernel32, funcs, Array_Elems(funcs), &lib);
if (!_RtlGenRandom) return ERR_NOT_SUPPORTED;
}
if (!_RtlGenRandom(data, len)) return GetLastError();
return 0;
}

View file

@ -42,6 +42,11 @@
#undef _WIN32
#endif
/* Rely on ClassiCube's implementation for RNG */
#define BR_USE_WIN32_RAND 0
#define BR_USE_URANDOM 0
#define BR_USE_GETENTROPY 0
/*
* When BR_64 is enabled, 64-bit integer types are assumed to be
* efficient (i.e. the architecture has 64-bit registers and can

View file

@ -24,62 +24,6 @@
#include "inner.h"
#if 0
/* obsolete */
/*
* If BR_USE_URANDOM is not defined, then try to autodetect its presence
* through compiler macros.
*/
#ifndef BR_USE_URANDOM
/*
* Macro values documented on:
* https://sourceforge.net/p/predef/wiki/OperatingSystems/
*
* Only the most common systems have been included here for now. This
* should be enriched later on.
*/
#if defined _AIX \
|| defined __ANDROID__ \
|| defined __FreeBSD__ \
|| defined __NetBSD__ \
|| defined __OpenBSD__ \
|| defined __DragonFly__ \
|| defined __linux__ \
|| (defined __sun && (defined __SVR4 || defined __svr4__)) \
|| (defined __APPLE__ && defined __MACH__)
#define BR_USE_URANDOM 1
#endif
#endif
/*
* If BR_USE_WIN32_RAND is not defined, perform autodetection here.
*/
#ifndef BR_USE_WIN32_RAND
#if defined _WIN32 || defined _WIN64
#define BR_USE_WIN32_RAND 1
#endif
#endif
#if BR_USE_URANDOM
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#endif
#if BR_USE_WIN32_RAND
#include <windows.h>
#include <wincrypt.h>
#pragma comment(lib, "advapi32")
#endif
#endif
/* ==================================================================== */
/*
* This part of the file does the low-level record management.