
#use wml::openssl-macros area=docs page=RAND_bytes

<title>Documents, RAND_bytes(3)</title>

<h1>RAND_bytes(3)</h1>

#use wml::imp::generic

{:
## What's this? [[s|(<STRONG>[^<].+?)</A>(</STRONG><DD>)|$1$2|sg]]
[[s|<P>\s+<P>|<P>|sg]]
[[s|<P>\s+</|</|sg]]
[[s|<DD>\s*<DT>|<DD>&nbsp;<DT>|sg]]
[[s|<DD>\s*</DL>|<DD>&nbsp;</DL>|sg]]
[[s|\[|&#91;|sg]]
[[s|\]|&#93;|sg]]

<!-- INDEX BEGIN -->

<UL>

	<LI><A HREF="#NAME">NAME</A>
	<LI><A HREF="#SYNOPSIS">SYNOPSIS</A>
	<LI><A HREF="#DESCRIPTION">DESCRIPTION</A>
	<LI><A HREF="#RETURN_VALUES">RETURN VALUES</A>
	<LI><A HREF="#SEE_ALSO">SEE ALSO</A>
	<LI><A HREF="#HISTORY">HISTORY</A>
</UL>
<!-- INDEX END -->

<HR>
<P>
<HR>
<H1><A NAME="NAME">NAME</A></H1>
<P>
RAND_bytes, RAND_pseudo_bytes - generate random data

</P>
<P>
<HR>
<H1><A NAME="SYNOPSIS">SYNOPSIS</A></H1>
<PRE> #include &lt;openssl/rand.h&gt;
</PRE>
<PRE> int RAND_bytes(unsigned char *buf, int num);
</PRE>
<PRE> int RAND_pseudo_bytes(unsigned char *buf, int num);
</PRE>
<P>
<HR>
<H1><A NAME="DESCRIPTION">DESCRIPTION</A></H1>
<P>
<CODE>RAND_bytes()</CODE> puts <STRONG>num</STRONG> cryptographically strong pseudo-random bytes into <STRONG>buf</STRONG>. An error occurs if the PRNG has not been seeded with enough randomness to
ensure an unpredictable byte sequence.

</P>
<P>
<CODE>RAND_pseudo_bytes()</CODE> puts <STRONG>num</STRONG> pseudo-random bytes into <STRONG>buf</STRONG>. Pseudo-random byte sequences generated by
<CODE>RAND_pseudo_bytes()</CODE> will be unique if they are of sufficient
length, but are not necessarily unpredictable. They can be used for
non-cryptographic purposes and for certain purposes in cryptographic
protocols, but usually not for key generation etc.

</P>
<P>
The contents of <STRONG>buf</STRONG> is mixed into the entropy pool before retrieving the new pseudo-random
bytes unless disabled at compile time (see FAQ).

</P>
<P>
<HR>
<H1><A NAME="RETURN_VALUES">RETURN VALUES</A></H1>
<P>
<CODE>RAND_bytes()</CODE> returns 1 on success, 0 otherwise. The error code
can be obtained by <A HREF="../crypto/ERR_get_error.html#">ERR_get_error(3)</A>. <CODE>RAND_pseudo_bytes()</CODE> returns 1 if the bytes generated are
cryptographically strong, 0 otherwise. Both functions return -1 if they are
not supported by the current RAND method.

</P>
<P>
<HR>
<H1><A NAME="SEE_ALSO">SEE ALSO</A></H1>
<P>
<A HREF="../crypto/rand.html#">rand(3)</A>, <A HREF="../crypto/ERR_get_error.html#">ERR_get_error(3)</A>,
<A HREF="../crypto/RAND_add.html#">RAND_add(3)</A>



</P>
<P>
<HR>
<H1><A NAME="HISTORY">HISTORY</A></H1>
<P>
<CODE>RAND_bytes()</CODE> is available in all versions of SSLeay and
OpenSSL. It has a return value since OpenSSL 0.9.5.
<CODE>RAND_pseudo_bytes()</CODE> was added in OpenSSL 0.9.5.

</P>
:}


