Main index | Section 9 | Options |
#include <sys/libkern.h>
#include <sys/random.h>
#include <sys/libkern.h>
The arc4rand() CSPRNG is seeded from the random(4) kernel abstract entropy device. Automatic reseeding happens at unspecified time and bytes (of output) intervals. A reseed can be forced by passing a non-zero reseed value.
The read_random() function is used to read entropy directly from the kernel abstract entropy device. read_random() blocks if and until the entropy device is seeded. The provided buffer is filled with no more than count bytes. It is strongly advised that read_random() is not used directly; instead, use the arc4rand() family of functions.
The is_random_seeded() function can be used to check in advance if read_random() will block. (If random is seeded, it will not block.)
The read_random_uio() function behaves identically to read(2) on /dev/random. The uio argument points to a buffer where random data should be stored. If nonblock is true and the random device is not seeded, this function does not return any data. Otherwise, this function may block interruptibly until the random device is seeded. If the function is interrupted before the random device is seeded, no data is returned.
The deprecated random() function will return a 31-bit value. It is obsolete and scheduled to be removed in FreeBSD 14.0 . Consider prng(9) instead and see SECURITY CONSIDERATIONS.
The read_random() function returns the number of bytes placed in buffer.
read_random_uio() returns zero when successful, otherwise an error code is returned.
random() returns numbers in the range from 0 to 231-1.
[EFAULT] | |
uio points to an invalid memory region. | |
[EWOULDBLOCK] | |
The random device is unseeded and nonblock is true. | |
It is important to remember that the random() function is entirely predictable. It is easy for attackers to predict future output of random() by recording some generated values. We cannot emphasize strongly enough that random() must not be used to generate values that are intended to be unpredictable.
RANDOM (9) | March 22, 2021 |
Main index | Section 9 | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.
“ | Hang in there, people suffering from natural disasters and deadly diseases - we're putting ribbons on our cars as fast as we can | ” |
— Artur Bagyants |