opnsense-src/secure/lib/libpkgecc/pkg_libecc_rand.c
Kyle Evans 05427f4639 secure: hook up libecc as libpkgecc
libecc is not intended to be general use, other applications should
really be using openssl.  pkg(7) uses libecc to align with the pkg(8)
project and its goals.  This will be used in the upcoming support for
ECC in pkg(7).

Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D48117
2025-01-01 15:11:22 -06:00

22 lines
647 B
C

/* SPDX-License-Identifier: Unlicense */
#include <sys/types.h>
#include <stdlib.h>
#include <libecc/external_deps/rand.h>
int
get_random(unsigned char *buf, uint16_t len)
{
/*
* We need random numbers even in a sandbox, so we can't use
* /dev/urandom as the external_deps version of get_random() does on
* FreeBSD. arc4random_buf() is a better choice because it uses the
* underlying getrandom(2) instead of needing to open a device handle.
*
* We don't have any guarantees that this won't open a device on other
* platforms, but we also don't do any sandboxing on those platforms.
*/
arc4random_buf(buf, len);
return 0;
}