24#define WIN32_NO_STATUS
29#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__)
30#include <sys/random.h>
31#elif defined(__OpenBSD__)
34#error "Couldn't identify the OS"
45 NTSTATUS res = BCryptGenRandom(NULL,
data, size, BCRYPT_USE_SYSTEM_PREFERRED_RNG);
46 if (res != STATUS_SUCCESS || size > ULONG_MAX) {
51#elif defined(__linux__) || defined(__FreeBSD__)
53 ssize_t res = getrandom(
data, size, 0);
54 if (res < 0 || (
size_t)res != size ) {
59#elif defined(__APPLE__) || defined(__OpenBSD__)
62 int res = getentropy(
data, size);
75 for (i = 0; i < size; i++) {
89 SecureZeroMemory(ptr, len);
90#elif defined(__GNUC__)
103 __asm__ __volatile__(
"" : :
"r"(ptr) :
"memory");
105 void *(*
volatile const volatile_memset)(
void *,
int,
size_t) = memset;
106 volatile_memset(ptr, 0, len);
static int fill_random(unsigned char *data, size_t size)
static void secure_erase(void *ptr, size_t len)
static void print_hex(unsigned char *data, size_t size)