xref: /netbsd-src/crypto/external/bsd/openssl.old/dist/doc/man3/RAND_bytes.pod (revision 4724848cf0da353df257f730694b7882798e5daf)
1*4724848cSchristos=pod
2*4724848cSchristos
3*4724848cSchristos=head1 NAME
4*4724848cSchristos
5*4724848cSchristosRAND_bytes, RAND_priv_bytes, RAND_pseudo_bytes - generate random data
6*4724848cSchristos
7*4724848cSchristos=head1 SYNOPSIS
8*4724848cSchristos
9*4724848cSchristos #include <openssl/rand.h>
10*4724848cSchristos
11*4724848cSchristos int RAND_bytes(unsigned char *buf, int num);
12*4724848cSchristos int RAND_priv_bytes(unsigned char *buf, int num);
13*4724848cSchristos
14*4724848cSchristosDeprecated:
15*4724848cSchristos
16*4724848cSchristos #if OPENSSL_API_COMPAT < 0x10100000L
17*4724848cSchristos int RAND_pseudo_bytes(unsigned char *buf, int num);
18*4724848cSchristos #endif
19*4724848cSchristos
20*4724848cSchristos=head1 DESCRIPTION
21*4724848cSchristos
22*4724848cSchristosRAND_bytes() generates B<num> random bytes using a cryptographically
23*4724848cSchristossecure pseudo random generator (CSPRNG) and stores them in B<buf>.
24*4724848cSchristos
25*4724848cSchristosRAND_priv_bytes() has the same semantics as RAND_bytes().  It is intended to
26*4724848cSchristosbe used for generating values that should remain private. If using the
27*4724848cSchristosdefault RAND_METHOD, this function uses a separate "private" PRNG
28*4724848cSchristosinstance so that a compromise of the "public" PRNG instance will not
29*4724848cSchristosaffect the secrecy of these private values, as described in L<RAND(7)>
30*4724848cSchristosand L<RAND_DRBG(7)>.
31*4724848cSchristos
32*4724848cSchristos=head1 NOTES
33*4724848cSchristos
34*4724848cSchristosBy default, the OpenSSL CSPRNG supports a security level of 256 bits, provided it
35*4724848cSchristoswas able to seed itself from a trusted entropy source.
36*4724848cSchristosOn all major platforms supported by OpenSSL (including the Unix-like platforms
37*4724848cSchristosand Windows), OpenSSL is configured to automatically seed the CSPRNG on first use
38*4724848cSchristosusing the operating systems's random generator.
39*4724848cSchristos
40*4724848cSchristosIf the entropy source fails or is not available, the CSPRNG will enter an
41*4724848cSchristoserror state and refuse to generate random bytes. For that reason, it is important
42*4724848cSchristosto always check the error return value of RAND_bytes() and RAND_priv_bytes() and
43*4724848cSchristosnot take randomness for granted.
44*4724848cSchristos
45*4724848cSchristosOn other platforms, there might not be a trusted entropy source available
46*4724848cSchristosor OpenSSL might have been explicitly configured to use different entropy sources.
47*4724848cSchristosIf you are in doubt about the quality of the entropy source, don't hesitate to ask
48*4724848cSchristosyour operating system vendor or post a question on GitHub or the openssl-users
49*4724848cSchristosmailing list.
50*4724848cSchristos
51*4724848cSchristos=head1 RETURN VALUES
52*4724848cSchristos
53*4724848cSchristosRAND_bytes() and RAND_priv_bytes()
54*4724848cSchristosreturn 1 on success, -1 if not supported by the current
55*4724848cSchristosRAND method, or 0 on other failure. The error code can be
56*4724848cSchristosobtained by L<ERR_get_error(3)>.
57*4724848cSchristos
58*4724848cSchristos=head1 SEE ALSO
59*4724848cSchristos
60*4724848cSchristosL<RAND_add(3)>,
61*4724848cSchristosL<RAND_bytes(3)>,
62*4724848cSchristosL<RAND_priv_bytes(3)>,
63*4724848cSchristosL<ERR_get_error(3)>,
64*4724848cSchristosL<RAND(7)>,
65*4724848cSchristosL<RAND_DRBG(7)>
66*4724848cSchristos
67*4724848cSchristos=head1 HISTORY
68*4724848cSchristos
69*4724848cSchristos=over 2
70*4724848cSchristos
71*4724848cSchristos=item *
72*4724848cSchristos
73*4724848cSchristosRAND_pseudo_bytes() was deprecated in OpenSSL 1.1.0; use RAND_bytes() instead.
74*4724848cSchristos
75*4724848cSchristos=item *
76*4724848cSchristos
77*4724848cSchristosThe RAND_priv_bytes() function was added in OpenSSL 1.1.1.
78*4724848cSchristos
79*4724848cSchristos=back
80*4724848cSchristos
81*4724848cSchristos=head1 COPYRIGHT
82*4724848cSchristos
83*4724848cSchristosCopyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved.
84*4724848cSchristos
85*4724848cSchristosLicensed under the OpenSSL license (the "License").  You may not use
86*4724848cSchristosthis file except in compliance with the License.  You can obtain a copy
87*4724848cSchristosin the file LICENSE in the source distribution or at
88*4724848cSchristosL<https://www.openssl.org/source/license.html>.
89*4724848cSchristos
90*4724848cSchristos=cut
91