diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-03-12 19:32:04 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-03-12 19:32:04 -0400 |
| commit | bae83f17cf0cf57ee056ab8d55b390ebe666c408 (patch) | |
| tree | 601de65574e779ded77f45d866868fb063ee29e8 | |
| parent | a3c4e0a82d5b56e280cbf72af2ecf5a990b1f577 (diff) | |
Simplify RNG seeding
| -rw-r--r-- | stdlib/stdlib.c | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/stdlib/stdlib.c b/stdlib/stdlib.c index 28174d6c..7d13fcbd 100644 --- a/stdlib/stdlib.c +++ b/stdlib/stdlib.c @@ -52,13 +52,9 @@ public void tomo_init(void) setlocale(LC_ALL, ""); getrandom(TOMO_HASH_KEY, sizeof(TOMO_HASH_KEY), 0); - int rng_fd = open("/dev/urandom", O_RDONLY); - if (rng_fd < 0) - fail("Couldn't read from /dev/urandom"); - uint8_t *random_bytes = GC_MALLOC_ATOMIC(40); - if (read(rng_fd, (void*)random_bytes, 40) < 40) - fail("Couldn't read from /dev/urandom"); - Array_t rng_seed = {.length=40, .data=random_bytes, .stride=1, .atomic=1}; + uint8_t *random_bytes[40] = {}; + getrandom(random_bytes, sizeof(random_bytes), 0); + Array_t rng_seed = {.length=sizeof(random_bytes), .data=random_bytes, .stride=1, .atomic=1}; RNG$set_seed(default_rng, rng_seed); if (register_printf_specifier('k', printf_text, printf_text_size)) |
