|
Packit |
7cfc04 |
.\" Copyright (C) 2017, Michael Kerrisk <mtk.manpages@gmail.com>
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" %%%LICENSE_START(VERBATIM)
|
|
Packit |
7cfc04 |
.\" Permission is granted to make and distribute verbatim copies of this
|
|
Packit |
7cfc04 |
.\" manual provided the copyright notice and this permission notice are
|
|
Packit |
7cfc04 |
.\" preserved on all copies.
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" Permission is granted to copy and distribute modified versions of
|
|
Packit |
7cfc04 |
.\" this manual under the conditions for verbatim copying, provided that
|
|
Packit |
7cfc04 |
.\" the entire resulting derived work is distributed under the terms of
|
|
Packit |
7cfc04 |
.\" a permission notice identical to this one.
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" Since the Linux kernel and libraries are constantly changing, this
|
|
Packit |
7cfc04 |
.\" manual page may be incorrect or out-of-date. The author(s) assume.
|
|
Packit |
7cfc04 |
.\" no responsibility for errors or omissions, or for damages resulting.
|
|
Packit |
7cfc04 |
.\" from the use of the information contained herein. The author(s) may.
|
|
Packit |
7cfc04 |
.\" not have taken the same level of care in the production of this.
|
|
Packit |
7cfc04 |
.\" manual, which is licensed free of charge, as they might when working.
|
|
Packit |
7cfc04 |
.\" professionally.
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" Formatted or processed versions of this manual, if unaccompanied by
|
|
Packit |
7cfc04 |
.\" the source, must acknowledge the copyright and authors of this work.
|
|
Packit |
7cfc04 |
.\" %%%LICENSE_END
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.TH GETENTROPY 3 2017-09-15 "Linux" "Linux Programmer's Manual"
|
|
Packit |
7cfc04 |
.SH NAME
|
|
Packit |
7cfc04 |
getentropy \- fill a buffer with random bytes
|
|
Packit |
7cfc04 |
.SH SYNOPSIS
|
|
Packit |
7cfc04 |
.B #include <unistd.h>
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.BI "int getentropy(void *" buffer ", size_t " length );
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.in -4n
|
|
Packit |
7cfc04 |
Feature Test Macro Requirements for glibc (see
|
|
Packit |
7cfc04 |
.BR feature_test_macros (7)):
|
|
Packit |
7cfc04 |
.in
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.BR getentropy ():
|
|
Packit |
7cfc04 |
.br
|
|
Packit |
7cfc04 |
.RS 4
|
|
Packit |
7cfc04 |
.ad l
|
|
Packit |
7cfc04 |
_DEFAULT_SOURCE
|
|
Packit |
7cfc04 |
.RE
|
|
Packit |
7cfc04 |
.ad
|
|
Packit |
7cfc04 |
.SH DESCRIPTION
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
.BR getentropy ()
|
|
Packit |
7cfc04 |
function writes
|
|
Packit |
7cfc04 |
.I length
|
|
Packit |
7cfc04 |
bytes of high-quality random data to the buffer starting
|
|
Packit |
7cfc04 |
at the location pointed to by
|
|
Packit |
7cfc04 |
.IR buffer .
|
|
Packit |
7cfc04 |
The maximum permitted value for the
|
|
Packit |
7cfc04 |
.I length
|
|
Packit |
7cfc04 |
argument is 256.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
A successful call to
|
|
Packit |
7cfc04 |
.BR getentropy ()
|
|
Packit |
7cfc04 |
always provides the requested number of bytes of entropy.
|
|
Packit |
7cfc04 |
.SH RETURN VALUE
|
|
Packit |
7cfc04 |
On success, this function returns zero.
|
|
Packit |
7cfc04 |
On error, \-1 is returned, and
|
|
Packit |
7cfc04 |
.I errno
|
|
Packit |
7cfc04 |
is set appropriately.
|
|
Packit |
7cfc04 |
.SH ERRORS
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B EFAULT
|
|
Packit |
7cfc04 |
Part or all of the buffer specified by
|
|
Packit |
7cfc04 |
.I buffer
|
|
Packit |
7cfc04 |
and
|
|
Packit |
7cfc04 |
.I length
|
|
Packit |
7cfc04 |
is not in valid addressable memory.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B EIO
|
|
Packit |
7cfc04 |
.I length
|
|
Packit |
7cfc04 |
is greater than 256.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B EIO
|
|
Packit |
7cfc04 |
An unspecified error occurred while trying to overwrite
|
|
Packit |
7cfc04 |
.I buffer
|
|
Packit |
7cfc04 |
with random data.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B ENOSYS
|
|
Packit |
7cfc04 |
This kernel version does not implement the
|
|
Packit |
7cfc04 |
.BR getrandom (2)
|
|
Packit |
7cfc04 |
system call required to implement this function.
|
|
Packit |
7cfc04 |
.SH VERSIONS
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
.BR getentropy ()
|
|
Packit |
7cfc04 |
function first appeared in glibc 2.25.
|
|
Packit |
7cfc04 |
.SH CONFORMING TO
|
|
Packit |
7cfc04 |
This function is nonstandard.
|
|
Packit |
7cfc04 |
It is also present on OpenBSD.
|
|
Packit |
7cfc04 |
.SH NOTES
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
.BR getentropy ()
|
|
Packit |
7cfc04 |
function is implemented using
|
|
Packit |
7cfc04 |
.BR getrandom (2).
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
Whereas the glibc wrapper makes
|
|
Packit |
7cfc04 |
.BR getrandom (2)
|
|
Packit |
7cfc04 |
a cancellation point,
|
|
Packit |
7cfc04 |
.BR getentropy ()
|
|
Packit |
7cfc04 |
is not a cancellation point.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.BR getentropy ()
|
|
Packit |
7cfc04 |
is also declared in
|
|
Packit |
7cfc04 |
.BR <sys/random.h> .
|
|
Packit |
7cfc04 |
(No feature test macro need be defined to obtain the declaration from
|
|
Packit |
7cfc04 |
that header file.)
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
A call to
|
|
Packit |
7cfc04 |
.BR getentropy ()
|
|
Packit |
7cfc04 |
may block if the system has just booted and the kernel has
|
|
Packit |
7cfc04 |
not yet collected enough randomness to initialize the entropy pool.
|
|
Packit |
7cfc04 |
In this case,
|
|
Packit |
7cfc04 |
.BR getentropy ()
|
|
Packit |
7cfc04 |
will keep blocking even if a signal is handled,
|
|
Packit |
7cfc04 |
and will return only once the entropy pool has been initialized.
|
|
Packit |
7cfc04 |
.SH SEE ALSO
|
|
Packit |
7cfc04 |
.BR getrandom (2),
|
|
Packit |
7cfc04 |
.BR urandom (4),
|
|
Packit |
7cfc04 |
.BR random (7)
|
|
Packit |
7cfc04 |
.SH COLOPHON
|
|
Packit |
7cfc04 |
This page is part of release 4.15 of the Linux
|
|
Packit |
7cfc04 |
.I man-pages
|
|
Packit |
7cfc04 |
project.
|
|
Packit |
7cfc04 |
A description of the project,
|
|
Packit |
7cfc04 |
information about reporting bugs,
|
|
Packit |
7cfc04 |
and the latest version of this page,
|
|
Packit |
7cfc04 |
can be found at
|
|
Packit |
7cfc04 |
\%https://www.kernel.org/doc/man\-pages/.
|