From e0898f87bf6d1a73d254ddacbf25d21a8700f725 Mon Sep 17 00:00:00 2001 From: Loganaden Velvindron Date: Fri, 6 Dec 2024 10:29:49 +0400 Subject: [PATCH] Add support for NetBSD getrandom interface. (Based on work done by University of Mauritius Resilient and Innovative Computing Research Group) Signed-off-by: Loganaden Velvindron Signed-off-by: Jaykishan Mutkawoa --- ref/randombytes.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ref/randombytes.c b/ref/randombytes.c index 7f4b857..8a12a42 100644 --- a/ref/randombytes.c +++ b/ref/randombytes.c @@ -13,6 +13,8 @@ #define _GNU_SOURCE #include #include +#elif __NetBSD__ +#include #else #include #endif @@ -53,6 +55,21 @@ void randombytes(uint8_t *out, size_t outlen) { outlen -= ret; } } +#elif defined(__NetBSD__) +void randombytes(uint8_t *out, size_t outlen) { + ssize_t ret; + + while(outlen > 0) { + ret = getrandom(out, outlen, 0); + if(ret == -1 && errno == EINTR) + continue; + else if(ret == -1) + abort(); + + out += ret; + outlen -= ret; + } +} #else void randombytes(uint8_t *out, size_t outlen) { static int fd = -1;