openssl-prebuild/linux_amd64/share/doc/openssl/html/man3/BN_rand.html
2020-03-02 16:50:34 +00:00

154 lines
6.0 KiB
HTML
Executable File

<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>BN_rand</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:root@localhost" />
</head>
<body style="background-color: white">
<!-- INDEX BEGIN -->
<div name="index">
<p><a name="__index__"></a></p>
<ul>
<li><a href="#name">NAME</a></li>
<li><a href="#synopsis">SYNOPSIS</a></li>
<li><a href="#description">DESCRIPTION</a></li>
<li><a href="#notes">NOTES</a></li>
<li><a href="#return_values">RETURN VALUES</a></li>
<li><a href="#see_also">SEE ALSO</a></li>
<li><a href="#history">HISTORY</a></li>
<li><a href="#copyright">COPYRIGHT</a></li>
</ul>
<hr name="index" />
</div>
<!-- INDEX END -->
<p>
</p>
<hr />
<h1><a name="name">NAME</a></h1>
<p>BN_rand_ex, BN_rand, BN_priv_rand_ex, BN_priv_rand, BN_pseudo_rand,
BN_rand_range_ex, BN_rand_range, BN_priv_rand_range_ex, BN_priv_rand_range,
BN_pseudo_rand_range
- generate pseudo-random number</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
#include &lt;openssl/bn.h&gt;</pre>
<pre>
int BN_rand_ex(BIGNUM *rnd, int bits, int top, int bottom, BN_CTX *ctx);
int BN_rand(BIGNUM *rnd, int bits, int top, int bottom);</pre>
<pre>
int BN_priv_rand_ex(BIGNUM *rnd, int bits, int top, int bottom, BN_CTX *ctx);
int BN_priv_rand(BIGNUM *rnd, int bits, int top, int bottom);</pre>
<pre>
int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom);</pre>
<pre>
int BN_rand_range_ex(BIGNUM *rnd, BIGNUM *range, BN_CTX *ctx);
int BN_rand_range(BIGNUM *rnd, BIGNUM *range);</pre>
<pre>
int BN_priv_rand_range_ex(BIGNUM *rnd, BIGNUM *range, BN_CTX *ctx);
int BN_priv_rand_range(BIGNUM *rnd, BIGNUM *range);</pre>
<pre>
int BN_pseudo_rand_range(BIGNUM *rnd, BIGNUM *range);</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p><code>BN_rand_ex()</code> generate a cryptographically strong pseudo-random
number of <strong>bits</strong> in length and stores it in <strong>rnd</strong> using the random number
generator for the library context associated with <strong>ctx</strong>. The parameter <strong>ctx</strong>
may be NULL in which case the default library context is used.
If <strong>bits</strong> is less than zero, or too small to
accommodate the requirements specified by the <strong>top</strong> and <strong>bottom</strong>
parameters, an error is returned.
The <strong>top</strong> parameters specifies
requirements on the most significant bit of the generated number.
If it is <strong>BN_RAND_TOP_ANY</strong>, there is no constraint.
If it is <strong>BN_RAND_TOP_ONE</strong>, the top bit must be one.
If it is <strong>BN_RAND_TOP_TWO</strong>, the two most significant bits of
the number will be set to 1, so that the product of two such random
numbers will always have 2*<strong>bits</strong> length.
If <strong>bottom</strong> is <strong>BN_RAND_BOTTOM_ODD</strong>, the number will be odd; if it
is <strong>BN_RAND_BOTTOM_ANY</strong> it can be odd or even.
If <strong>bits</strong> is 1 then <strong>top</strong> cannot also be <strong>BN_RAND_FLG_TOPTWO</strong>.</p>
<p><code>BN_rand()</code> is the same as <code>BN_rand_ex()</code> except that the default library context
is always used.</p>
<p><code>BN_rand_range_ex()</code> generates a cryptographically strong pseudo-random
number <strong>rnd</strong> in the range 0 &lt;= <strong>rnd</strong> &lt; <strong>range</strong> using the random number
generator for the library context associated with <strong>ctx</strong>. The parameter <strong>ctx</strong>
may be NULL in which case the default library context is used.</p>
<p><code>BN_rand_range()</code> is the same as <code>BN_rand_range_ex()</code> except that the default
library context is always used.</p>
<p><code>BN_priv_rand_ex()</code>, <code>BN_priv_rand()</code>, <code>BN_priv_rand_rand_ex()</code> and
<code>BN_priv_rand_range()</code> have the same semantics as <code>BN_rand_ex()</code>, <code>BN_rand()</code>,
<code>BN_rand_range_ex()</code> and <code>BN_rand_range()</code> respectively. They are intended to be
used for generating values that should remain private, and mirror the
same difference between <em>RAND_bytes(3)</em> and <em>RAND_priv_bytes(3)</em>.</p>
<p>
</p>
<hr />
<h1><a name="notes">NOTES</a></h1>
<p>Always check the error return value of these functions and do not take
randomness for granted: an error occurs if the CSPRNG has not been
seeded with enough randomness to ensure an unpredictable byte sequence.</p>
<p>
</p>
<hr />
<h1><a name="return_values">RETURN VALUES</a></h1>
<p>The functions return 1 on success, 0 on error.
The error codes can be obtained by <em>ERR_get_error(3)</em>.</p>
<p>
</p>
<hr />
<h1><a name="see_also">SEE ALSO</a></h1>
<p><em>ERR_get_error(3)</em>,
<em>RAND_add(3)</em>,
<em>RAND_bytes(3)</em>,
<em>RAND_priv_bytes(3)</em>,
<em>RAND(7)</em>,
<em>RAND_DRBG(7)</em></p>
<p>
</p>
<hr />
<h1><a name="history">HISTORY</a></h1>
<ul>
<li>
<p>Starting with OpenSSL release 1.1.0, <code>BN_pseudo_rand()</code> has been identical
to <code>BN_rand()</code> and <code>BN_pseudo_rand_range()</code> has been identical to
<code>BN_rand_range()</code>.
The &quot;pseudo&quot; functions should not be used and may be deprecated in
a future release.</p>
</li>
<li>
<p>The
<code>BN_priv_rand()</code> and <code>BN_priv_rand_range()</code> functions were added in OpenSSL 1.1.1.</p>
</li>
<li>
<p>The <code>BN_rand_ex()</code>, <code>BN_priv_rand_ex()</code>, <code>BN_rand_range_ex()</code> and
<code>BN_priv_rand_range_ex()</code> functions were added in OpenSSL 3.0.</p>
</li>
</ul>
<p>
</p>
<hr />
<h1><a name="copyright">COPYRIGHT</a></h1>
<p>Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved.</p>
<p>Licensed under the Apache License 2.0 (the &quot;License&quot;). You may not use
this file except in compliance with the License. You can obtain a copy
in the file LICENSE in the source distribution or at
<a href="https://www.openssl.org/source/license.html">https://www.openssl.org/source/license.html</a>.</p>
</body>
</html>