summaryrefslogtreecommitdiff
path: root/include/linux/random.h
blob: bd3dc61b598a6dc5dde792a1c4488ea71d3fbf11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
 * include/linux/random.h
 *
 * Include file for the random number generator.
 */
#ifndef _LINUX_RANDOM_H
#define _LINUX_RANDOM_H

#include <unistd.h>
#include <sys/syscall.h>
#include <linux/bug.h>

static inline int getrandom(void *buf, size_t buflen, unsigned int flags)
{
	 return syscall(SYS_getrandom, buf, buflen, flags);
}

static inline void get_random_bytes(void *buf, int nbytes)
{
	BUG_ON(getrandom(buf, nbytes, 0) != nbytes);
}

static inline int get_random_int(void)
{
	int v;

	get_random_bytes(&v, sizeof(v));
	return v;
}

#endif /* _LINUX_RANDOM_H */