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