30 lines
597 B
C
30 lines
597 B
C
#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();
|
|
} |