add win32 (msvc) support
This commit is contained in:
30
core/sys/windows/random.c
Normal file
30
core/sys/windows/random.c
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <fcntl.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
#include <wincrypt.h>
|
||||
|
||||
uint64_t z__b_platform_random_seed_secure(void)
|
||||
{
|
||||
BOOL status;
|
||||
HCRYPTPROV hCryptProv;
|
||||
status = CryptAcquireContext(
|
||||
&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
|
||||
|
||||
if (status == FALSE) {
|
||||
return (uint64_t)-1;
|
||||
}
|
||||
|
||||
uint64_t v = 0;
|
||||
status = CryptGenRandom(hCryptProv, sizeof v, (BYTE *)&v);
|
||||
|
||||
CryptReleaseContext(hCryptProv, 0);
|
||||
|
||||
return status == TRUE ? v : (uint64_t)-1;
|
||||
}
|
||||
|
||||
uint64_t z__b_platform_random_seed(void)
|
||||
{
|
||||
return z__b_platform_random_seed_secure();
|
||||
}
|
||||
Reference in New Issue
Block a user