text
stringlengths
0
234
unlike
.ir /dev/random
and
.ir /dev/urandom ,
.br getrandom ()
does not involve the use of pathnames or file descriptors.
thus,
.br getrandom ()
can be useful in cases where
.br chroot (2)
makes
.i /dev
pathnames invisible,
and where an application (e.g., a daemon during start-up)
closes a file descriptor for one of these files
that was opened by a library.
.\"
.ss maximum number of bytes returned
as of linux 3.19 the following limits apply:
.ip * 3
when reading from the
.ir urandom
source, a maximum of 33554431 bytes is returned by a single call to
.br getrandom ()
on systems where
.i int
has a size of 32 bits.
.ip *
when reading from the
.ir random
source, a maximum of 512 bytes is returned.
.ss interruption by a signal handler
when reading from the
.i urandom
source
.rb ( grnd_random
is not set),
.br getrandom ()
will block until the entropy pool has been initialized
(unless the
.br grnd_nonblock
flag was specified).
if a request is made to read a large number of bytes (more than 256),
.br getrandom ()
will block until those bytes have been generated and transferred
from kernel memory to
.ir buf .
when reading from the
.i random
source
.rb ( grnd_random
is set),
.br getrandom ()
will block until some random bytes become available
(unless the
.br grnd_nonblock
flag was specified).
.pp
the behavior when a call to
.br getrandom ()
that is blocked while reading from the
.i urandom
source is interrupted by a signal handler
depends on the initialization state of the entropy buffer
and on the request size,
.ir buflen .
if the entropy is not yet initialized, then the call fails with the
.b eintr
error.
if the entropy pool has been initialized
and the request size is large
.ri ( buflen "\ >\ 256),"
the call either succeeds, returning a partially filled buffer,
or fails with the error
.br eintr .
if the entropy pool has been initialized and the request size is small
.ri ( buflen "\ <=\ 256),"
then
.br getrandom ()
will not fail with
.br eintr .
instead, it will return all of the bytes that have been requested.
.pp
when reading from the
.ir random
source, blocking requests of any size can be interrupted by a signal handler
(the call fails with the error
.br eintr ).
.pp
using
.br getrandom ()
to read small buffers (<=\ 256 bytes) from the
.i urandom
source is the preferred mode of usage.
.pp
the special treatment of small values of
.i buflen
was designed for compatibility with
openbsd's
.br getentropy (3),