xref: /freebsd/secure/lib/libpkgecc/pkg_libecc_rand.c (revision b196276c20b577b364372f1aa1a646b9ce34bf5c)
1 /* SPDX-License-Identifier: Unlicense */
2 #include <sys/types.h>
3 #include <stdlib.h>
4 
5 #include <libecc/external_deps/rand.h>
6 
7 int
8 get_random(unsigned char *buf, uint16_t len)
9 {
10 
11 	/*
12 	 * We need random numbers even in a sandbox, so we can't use
13 	 * /dev/urandom as the external_deps version of get_random() does on
14 	 * FreeBSD.  arc4random_buf() is a better choice because it uses the
15 	 * underlying getrandom(2) instead of needing to open a device handle.
16 	 *
17 	 * We don't have any guarantees that this won't open a device on other
18 	 * platforms, but we also don't do any sandboxing on those platforms.
19 	 */
20 	arc4random_buf(buf, len);
21 	return 0;
22 }
23