man-pages/man7/RAND.7ssl.html
2021-03-31 01:06:50 +01:00

120 lines
5.3 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of RAND</TITLE>
</HEAD><BODY>
<H1>RAND</H1>
Section: OpenSSL (7SSL)<BR>Updated: 2021-03-22<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
RAND - the OpenSSL random generator
<A NAME="lbAC">&nbsp;</A>
<H2>DESCRIPTION</H2>
Random numbers are a vital part of cryptography, they are needed to provide
unpredictability for tasks like key generation, creating salts, and many more.
Software-based generators must be seeded with external randomness before they
can be used as a cryptographically-secure pseudo-random number generator
(<FONT SIZE="-1">CSPRNG</FONT>).
The availability of common hardware with special instructions and
modern operating systems, which may use items such as interrupt jitter
and network packet timings, can be reasonable sources of seeding material.
<P>
OpenSSL comes with a default implementation of the <FONT SIZE="-1">RAND API</FONT> which is based on
the deterministic random bit generator (<FONT SIZE="-1">DRBG</FONT>) model as described in
[<FONT SIZE="-1">NIST SP 800-90A</FONT> Rev. 1]. The default random generator will initialize
automatically on first use and will be fully functional without having
to be initialized ('seeded') explicitly.
It seeds and reseeds itself automatically using trusted random sources
provided by the operating system.
<P>
As a normal application developer, you do not have to worry about any details,
just use <B><A HREF="/cgi-bin/man/man2html?3+RAND_bytes">RAND_bytes</A></B>(3) to obtain random data.
Having said that, there is one important rule to obey: Always check the error
return value of <B><A HREF="/cgi-bin/man/man2html?3+RAND_bytes">RAND_bytes</A></B>(3) and do not take randomness for granted.
Although (re-)seeding is automatic, it can fail because no trusted random source
is available or the trusted source(s) temporarily fail to provide sufficient
random seed material.
In this case the <FONT SIZE="-1">CSPRNG</FONT> enters an error state and ceases to provide output,
until it is able to recover from the error by reseeding itself.
For more details on reseeding and error recovery, see <FONT SIZE="-1"><B><A HREF="/cgi-bin/man/man2html?7+RAND_DRBG">RAND_DRBG</A></B></FONT><B></B>(7).
<P>
For values that should remain secret, you can use <B><A HREF="/cgi-bin/man/man2html?3+RAND_priv_bytes">RAND_priv_bytes</A></B>(3)
instead.
This method does not provide 'better' randomness, it uses the same type of <FONT SIZE="-1">CSPRNG.</FONT>
The intention behind using a dedicated <FONT SIZE="-1">CSPRNG</FONT> exclusively for private
values is that none of its output should be visible to an attacker (e.g.,
used as salt value), in order to reveal as little information as
possible about its internal state, and that a compromise of the ``public''
<FONT SIZE="-1">CSPRNG</FONT> instance will not affect the secrecy of these private values.
<P>
In the rare case where the default implementation does not satisfy your special
requirements, there are two options:
<DL COMPACT>
<DT id="1">&bull;<DD>
Replace the default <FONT SIZE="-1">RAND</FONT> method by your own <FONT SIZE="-1">RAND</FONT> method using
<B><A HREF="/cgi-bin/man/man2html?3+RAND_set_rand_method">RAND_set_rand_method</A></B>(3).
<DT id="2">&bull;<DD>
Modify the default settings of the OpenSSL <FONT SIZE="-1">RAND</FONT> method by modifying the security
parameters of the underlying <FONT SIZE="-1">DRBG,</FONT> which is described in detail in <FONT SIZE="-1"><B><A HREF="/cgi-bin/man/man2html?7+RAND_DRBG">RAND_DRBG</A></B></FONT><B></B>(7).
</DL>
<P>
Changing the default random generator or its default parameters should be necessary
only in exceptional cases and is not recommended, unless you have a profound knowledge
of cryptographic principles and understand the implications of your changes.
<A NAME="lbAD">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?3+RAND_add">RAND_add</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+RAND_bytes">RAND_bytes</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+RAND_priv_bytes">RAND_priv_bytes</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+RAND_get_rand_method">RAND_get_rand_method</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+RAND_set_rand_method">RAND_set_rand_method</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+RAND_OpenSSL">RAND_OpenSSL</A></B>(3),
<FONT SIZE="-1"><B><A HREF="/cgi-bin/man/man2html?7+RAND_DRBG">RAND_DRBG</A></B></FONT><B></B>(7)
<A NAME="lbAE">&nbsp;</A>
<H2>COPYRIGHT</H2>
Copyright 2018-2019 The OpenSSL Project Authors. All Rights Reserved.
<P>
Licensed under the OpenSSL license (the ``License''). You may not use
this file except in compliance with the License. You can obtain a copy
in the file <FONT SIZE="-1">LICENSE</FONT> in the source distribution or at
&lt;<A HREF="https://www.openssl.org/source/license.html">https://www.openssl.org/source/license.html</A>&gt;.
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="3"><A HREF="#lbAB">NAME</A><DD>
<DT id="4"><A HREF="#lbAC">DESCRIPTION</A><DD>
<DT id="5"><A HREF="#lbAD">SEE ALSO</A><DD>
<DT id="6"><A HREF="#lbAE">COPYRIGHT</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:06:09 GMT, March 31, 2021
</BODY>
</HTML>