2 * include/linux/random.h
4 * Include file for the random number generator.
6 #ifndef _LINUX_RANDOM_H
7 #define _LINUX_RANDOM_H
10 #include <sys/syscall.h>
11 #include <linux/bug.h>
14 static inline int getrandom(void *buf, size_t buflen, unsigned int flags)
16 return syscall(SYS_getrandom, buf, buflen, flags);
19 extern int urandom_fd;
21 static inline int getrandom(void *buf, size_t buflen, unsigned int flags)
23 return read(urandom_fd, buf, buflen);
27 static inline void get_random_bytes(void *buf, int nbytes)
29 BUG_ON(getrandom(buf, nbytes, 0) != nbytes);
32 #define get_random_type(type) \
33 static inline type get_random_##type(void) \
37 get_random_bytes(&v, sizeof(v)); \
42 get_random_type(long);
46 #endif /* _LINUX_RANDOM_H */