mirror of
https://github.com/opnsense/src.git
synced 2026-05-28 04:12:45 -04:00
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
This commit is contained in:
parent
27f0f2ec5f
commit
bf4e2e5be1
1 changed files with 22 additions and 2 deletions
|
|
@ -28,7 +28,8 @@
|
|||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#ifndef _LINUX_RANDOM_H_
|
||||
|
||||
#ifndef _LINUX_RANDOM_H_
|
||||
#define _LINUX_RANDOM_H_
|
||||
|
||||
#include <sys/random.h>
|
||||
|
|
@ -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_ */
|
||||
|
|
|
|||
Loading…
Reference in a new issue