Add kore_platform_random_uint32().

This commit is contained in:
Joris Vink 2023-01-04 11:48:19 +01:00
parent 7b48959c32
commit 4ecd6d5603
3 changed files with 23 additions and 0 deletions

View File

@ -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 *);

View File

@ -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)

View File

@ -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);
}