Upgrade less(1). 1/2
[dragonfly.git] / lib / libc / sys / getrandom.2
1 .\" Copyright 2020, 2018 Conrad Meyer <cem@FreeBSD.org>.  All rights reserved.
2 .\"
3 .\" Redistribution and use in source and binary forms, with or without
4 .\" modification, are permitted provided that the following conditions
5 .\" are met:
6 .\" 1. Redistributions of source code must retain the above copyright
7 .\"    notice, this list of conditions and the following disclaimer.
8 .\" 2. Redistributions in binary form must reproduce the above copyright
9 .\"    notice, this list of conditions and the following disclaimer in the
10 .\"    documentation and/or other materials provided with the distribution.
11 .\"
12 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
13 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
16 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22 .\" SUCH DAMAGE.
23 .\"
24 .\" $FreeBSD$
25 .\"
26 .Dd February 1, 2020
27 .Dt GETRANDOM 2
28 .Os
29 .Sh NAME
30 .Nm getrandom
31 .Nd get random data
32 .Sh LIBRARY
33 .Lb libc
34 .Sh SYNOPSIS
35 .In sys/random.h
36 .Ft ssize_t
37 .Fn getrandom "void *buf" "size_t buflen" "unsigned int flags"
38 .Sh DESCRIPTION
39 .Fn getrandom
40 fills
41 .Fa buf
42 with up to
43 .Fa buflen
44 bytes of random data.
45 .Pp
46 The
47 .Fa flags
48 argument may include zero or more of the following:
49 .Bl -tag -width _GRND_NONBLOCK_
50 .It Dv GRND_NONBLOCK
51 Return
52 .Er EAGAIN
53 instead of blocking, if the
54 .Xr random 4
55 device has not yet been seeded.
56 By default,
57 .Fn getrandom
58 will block until the device is seeded.
59 .It Dv GRND_RANDOM
60 This flag does nothing on
61 .Dx .
62 .Pa /dev/random
63 and
64 .Pa /dev/urandom
65 are identical.
66 .It Dv GRND_INSECURE
67 This flag is treated as an alternative name for
68 .Dv GRND_NONBLOCK .
69 It is provided solely for API compatibility with Linux.
70 .El
71 .Pp
72 If the
73 .Xr random 4
74 device has been seeded, reads of up to 256 bytes will always return as many
75 bytes as requested and will not be interrupted by signals.
76 .Sh RETURN VALUES
77 Upon successful completion, the number of bytes which were actually read is
78 returned.
79 For requests larger than 256 bytes, this can be fewer bytes than were
80 requested.
81 Otherwise, -1 is returned and the global variable
82 .Va errno
83 is set to indicate the error.
84 .Sh ERRORS
85 The
86 .Fn getrandom
87 operation returns the following errors:
88 .Bl -tag -width Er
89 .It Bq Er EAGAIN
90 The
91 .Dv GRND_NONBLOCK
92 (or
93 .Dv GRND_INSECURE )
94 flag was set and the
95 .Xr random 4
96 device was not yet seeded.
97 .It Bq Er EFAULT
98 The
99 .Fa buf
100 parameter points to an invalid address.
101 .It Bq Er EINTR
102 The sleep was interrupted by a signal.
103 .It Bq Er EINVAL
104 An invalid
105 .Fa flags
106 was specified.
107 .It Bq Er EINVAL
108 The requested
109 .Fa buflen
110 is invalid (typically if negative).
111 .Dx
112 does not impose a limit on the buffer size.
113 .El
114 .Sh SEE ALSO
115 .Xr arc4random 3 ,
116 .\".Xr getentropy 3 ,
117 .Xr random 4
118 .Sh STANDARDS
119 .Fn getrandom
120 is non-standard.
121 It is present in Linux.
122 .Sh HISTORY
123 The
124 .Fn getrandom
125 system call first appeared in
126 .Dx 5.7 .
127 .Sh CAVEATS
128 Unlike Linux, the
129 .Dv GRND_INSECURE
130 flag on
131 .Dx
132 does not produce any output before the
133 .Xr random 4
134 device is seeded.