2023-10-03 14:45:12 +02:00
|
|
|
/**************************************************************
|
|
|
|
_ __ _ _
|
|
|
|
_ __ ___| |_ _ __ ___ / _| ___ _ __| |_| |__
|
|
|
|
| '__/ _ \ __| '__/ _ \| |_ / _ \| '__| __| '_ \
|
|
|
|
| | | __/ |_| | | (_) | _| (_) | | | |_| | | |
|
|
|
|
|_| \___|\__|_| \___/|_| \___/|_| \__|_| |_|
|
|
|
|
for nga
|
2023-03-29 02:42:45 +02:00
|
|
|
|
2023-10-03 14:45:12 +02:00
|
|
|
(c) Charles Childers, Luke Parrish, Marc Simpsonn,
|
|
|
|
Jay Skeer, Kenneth Keating
|
2023-03-29 02:42:45 +02:00
|
|
|
|
2023-10-03 14:45:12 +02:00
|
|
|
**************************************************************/
|
2023-03-29 02:42:45 +02:00
|
|
|
|
|
|
|
#ifdef ENABLE_RNG
|
|
|
|
void io_rng(NgaState *vm) {
|
|
|
|
int64_t r = 0;
|
|
|
|
char buffer[8];
|
|
|
|
int i;
|
|
|
|
ssize_t ignore;
|
|
|
|
int fd = open("/dev/urandom", O_RDONLY);
|
|
|
|
ignore = read(fd, buffer, 8);
|
|
|
|
close(fd);
|
|
|
|
for(i = 0; i < 8; ++i) {
|
|
|
|
r = r << 8;
|
|
|
|
r += ((int64_t)buffer[i] & 0xFF);
|
|
|
|
}
|
|
|
|
#ifndef BIT64
|
|
|
|
stack_push(vm, (CELL)abs((CELL)r));
|
|
|
|
#else
|
|
|
|
stack_push(vm, (CELL)llabs((CELL)r));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void query_rng(NgaState *vm) {
|
|
|
|
stack_push(vm, 0);
|
2023-12-09 19:15:54 +01:00
|
|
|
stack_push(vm, DEVICE_RNG);
|
2023-03-29 02:42:45 +02:00
|
|
|
}
|
|
|
|
#endif
|