Files
fx/core/sys/windows/random.c

30 lines
600 B
C
Raw Normal View History

2024-11-14 16:56:12 +00:00
#include <fcntl.h>
#include <stdint.h>
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <wincrypt.h>
2026-03-16 10:35:43 +00:00
uint64_t z__fx_platform_random_seed_secure(void)
2024-11-14 16:56:12 +00:00
{
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;
}
2026-03-16 10:35:43 +00:00
uint64_t z__fx_platform_random_seed(void)
2024-11-14 16:56:12 +00:00
{
2026-03-16 10:35:43 +00:00
return z__fx_platform_random_seed_secure();
2024-11-14 16:56:12 +00:00
}