summaryrefslogtreecommitdiffstats
path: root/arch/sandbox/board/dev-random.c
blob: 60295e9fced2dc6954c7d18e7a57af64069cd939 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <common.h>
#include <mach/linux.h>

devrandom_t *devrandom_init(void) {
	devrandom_t *fds = xzalloc(sizeof(*fds));

	fds->urandomfd = linux_open("/dev/urandom", false);
	if (fds->urandomfd < 0)
		return ERR_PTR(-EPERM);

	return fds;
}

int devrandom_read(devrandom_t *devrandom, void *buf, size_t len, int wait)
{
	(void)wait; /* /dev/urandom won't block */

	return linux_read(devrandom->urandomfd, buf, len);
}