kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 4ecd6d5603dd6803c206ed28f27616c41bf35ea7
parent 7b48959c32f6194b28edf28b20be6f625aedafea
Author: Joris Vink <joris@coders.se>
Date:   Wed,  4 Jan 2023 11:48:19 +0100

Add kore_platform_random_uint32().

Diffstat:
include/kore/kore.h | 1+
src/bsd.c | 6++++++
src/linux.c | 16++++++++++++++++
3 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/include/kore/kore.h b/include/kore/kore.h @@ -803,6 +803,7 @@ void kore_platform_schedule_read(int, void *); void kore_platform_schedule_write(int, void *); void kore_platform_event_schedule(int, int, int, void *); void kore_platform_worker_setcpu(struct kore_worker *); +u_int32_t kore_platform_random_uint32(void); #if defined(KORE_USE_PLATFORM_SENDFILE) int kore_platform_sendfile(struct connection *, struct netbuf *); diff --git a/src/bsd.c b/src/bsd.c @@ -298,6 +298,12 @@ kore_platform_sandbox(void) #endif } +u_int32_t +kore_platform_random_uint32(void) +{ + return (arc4random()); +} + #if defined(KORE_USE_PLATFORM_PLEDGE) void kore_platform_pledge(void) diff --git a/src/linux.c b/src/linux.c @@ -15,6 +15,7 @@ */ #include <sys/param.h> +#include <sys/random.h> #include <sys/epoll.h> #include <sys/sendfile.h> #include <sys/syscall.h> @@ -262,3 +263,18 @@ kore_platform_sandbox(void) { kore_seccomp_enable(); } + +u_int32_t +kore_platform_random_uint32(void) +{ + ssize_t ret; + u_int32_t val; + + if ((ret = getrandom(&val, sizeof(val), 0)) == -1) + fatalx("getrandom(): %s", errno_s); + + if ((size_t)ret != sizeof(val)) + fatalx("getrandom() %zd != %zu", ret, sizeof(val)); + + return (val); +}