2024-10-27 15:36:14 +00:00
|
|
|
#include <fcntl.h>
|
2024-10-24 21:33:05 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
2024-10-27 15:36:14 +00:00
|
|
|
uint64_t z__b_platform_random_seed()
|
2024-10-24 21:33:05 +01:00
|
|
|
{
|
|
|
|
|
int fd = open("/dev/urandom", O_RDONLY);
|
|
|
|
|
if (fd == -1) {
|
|
|
|
|
return (uint64_t)-1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint64_t v = 0;
|
|
|
|
|
if (read(fd, &v, sizeof v) != sizeof v) {
|
|
|
|
|
close(fd);
|
|
|
|
|
return (uint64_t)-1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return v;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-27 15:36:14 +00:00
|
|
|
uint64_t z__b_platform_random_seed_secure()
|
2024-10-24 21:33:05 +01:00
|
|
|
{
|
|
|
|
|
int fd = open("/dev/random", O_RDONLY);
|
|
|
|
|
if (fd == -1) {
|
|
|
|
|
return (uint64_t)-1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint64_t v = 0;
|
|
|
|
|
if (read(fd, &v, sizeof v) != sizeof v) {
|
|
|
|
|
close(fd);
|
|
|
|
|
return (uint64_t)-1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return v;
|
|
|
|
|
}
|