From bf4e2e5be1a12941d215072acac470ff25c847f6 Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Wed, 4 Oct 2017 17:29:08 +0000 Subject: [PATCH] Add get_random_{int,long} to the LinuxKPI. Fix some whitespace bugs while here. Reviewed by: hselasky MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D12588 --- .../linuxkpi/common/include/linux/random.h | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/random.h b/sys/compat/linuxkpi/common/include/linux/random.h index 28475ed2275..04729319aaa 100644 --- a/sys/compat/linuxkpi/common/include/linux/random.h +++ b/sys/compat/linuxkpi/common/include/linux/random.h @@ -28,7 +28,8 @@ * * $FreeBSD$ */ -#ifndef _LINUX_RANDOM_H_ + +#ifndef _LINUX_RANDOM_H_ #define _LINUX_RANDOM_H_ #include @@ -37,8 +38,27 @@ static inline void get_random_bytes(void *buf, int nbytes) { + if (read_random(buf, nbytes) == 0) arc4rand(buf, nbytes, 0); } -#endif /* _LINUX_RANDOM_H_ */ +static inline u_int +get_random_int(void) +{ + u_int val; + + get_random_bytes(&val, sizeof(val)); + return (val); +} + +static inline u_long +get_random_long(void) +{ + u_long val; + + get_random_bytes(&val, sizeof(val)); + return (val); +} + +#endif /* _LINUX_RANDOM_H_ */