diff --git a/include/kore/kore.h b/include/kore/kore.h index f6b7c1b..317bb18 100644 --- 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 index 8799504..2505694 100644 --- 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 index e9a9894..587fa6f 100644 --- a/src/linux.c +++ b/src/linux.c @@ -15,6 +15,7 @@ */ #include +#include #include #include #include @@ -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); +}