summaryrefslogtreecommitdiffstats
path: root/arch/sandbox/board/dev-random.c
blob: b62e8cc0d7cce0acc20bf9aeb87b3b620b136fb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// SPDX-License-Identifier: GPL-2.0-only

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