]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/getentropy.3
Many pages: Use correct letter case in page titles (TH)
[thirdparty/man-pages.git] / man3 / getentropy.3
CommitLineData
b0265728
MK
1.\" Copyright (C) 2017, Michael Kerrisk <mtk.manpages@gmail.com>
2.\"
5fbde956 3.\" SPDX-License-Identifier: Linux-man-pages-copyleft
b0265728 4.\"
4c1c5274 5.TH getentropy 3 (date) "Linux man-pages (unreleased)"
b0265728
MK
6.SH NAME
7getentropy \- fill a buffer with random bytes
42009080
AC
8.SH LIBRARY
9Standard C library
10.RI ( libc ", " \-lc )
b0265728 11.SH SYNOPSIS
c7db92b9 12.nf
9cf011f9 13.B #include <unistd.h>
68e4db0a 14.PP
d75c6df9 15.BI "int getentropy(void *" buffer ", size_t " length );
c7db92b9 16.fi
68e4db0a 17.PP
d39ad78f 18.RS -4
f0ed9710
MK
19Feature Test Macro Requirements for glibc (see
20.BR feature_test_macros (7)):
d39ad78f 21.RE
68e4db0a 22.PP
f0ed9710 23.BR getentropy ():
9d2adbae
MK
24.nf
25 _DEFAULT_SOURCE
26.fi
b0265728
MK
27.SH DESCRIPTION
28The
29.BR getentropy ()
30function writes
31.I length
32bytes of high-quality random data to the buffer starting
33at the location pointed to by
34.IR buffer .
35The maximum permitted value for the
36.I length
37argument is 256.
847e0d88 38.PP
b0265728
MK
39A successful call to
40.BR getentropy ()
419ba7b3 41always provides the requested number of bytes of entropy.
b0265728 42.SH RETURN VALUE
78cba5ac 43On success, this function returns zero.
b0265728
MK
44On error, \-1 is returned, and
45.I errno
f6a4078b 46is set to indicate the error.
b0265728
MK
47.SH ERRORS
48.TP
49.B EFAULT
50Part or all of the buffer specified by
51.I buffer
52and
53.I length
54is not in valid addressable memory.
55.TP
56.B EIO
57.I length
58is greater than 256.
59.TP
60.B EIO
61An unspecified error occurred while trying to overwrite
62.I buffer
63with random data.
64.TP
65.B ENOSYS
66This kernel version does not implement the
67.BR getrandom (2)
68system call required to implement this function.
69.SH VERSIONS
70The
71.BR getentropy ()
72function first appeared in glibc 2.25.
3113c7f3 73.SH STANDARDS
b0265728
MK
74This function is nonstandard.
75It is also present on OpenBSD.
76.SH NOTES
77The
78.BR getentropy ()
79function is implemented using
80.BR getrandom (2).
847e0d88 81.PP
b0265728
MK
82Whereas the glibc wrapper makes
83.BR getrandom (2)
1f08fc80 84a cancelation point,
b0265728 85.BR getentropy ()
1f08fc80 86is not a cancelation point.
847e0d88 87.PP
f0ed9710
MK
88.BR getentropy ()
89is also declared in
90.BR <sys/random.h> .
91(No feature test macro need be defined to obtain the declaration from
92that header file.)
847e0d88 93.PP
b0265728
MK
94A call to
95.BR getentropy ()
96may block if the system has just booted and the kernel has
97not yet collected enough randomness to initialize the entropy pool.
98In this case,
99.BR getentropy ()
100will keep blocking even if a signal is handled,
101and will return only once the entropy pool has been initialized.
102.SH SEE ALSO
103.BR getrandom (2),
104.BR urandom (4),
105.BR random (7)