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

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

<h1>RAND_add(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_add, RAND_seed, RAND_status, RAND_event, RAND_screen - add entropy to
the PRNG

</P>
<P>
<HR>
<H1><A NAME="SYNOPSIS">SYNOPSIS</A></H1>
<PRE> #include &lt;openssl/rand.h&gt;
</PRE>
<PRE> void RAND_seed(const void *buf, int num);
</PRE>
<PRE> void RAND_add(const void *buf, int num, double entropy);
</PRE>
<PRE> int  RAND_status(void);
</PRE>
<PRE> int  RAND_event(UINT iMsg, WPARAM wParam, LPARAM lParam);
 void RAND_screen(void);
</PRE>
<P>
<HR>
<H1><A NAME="DESCRIPTION">DESCRIPTION</A></H1>
<P>
<CODE>RAND_add()</CODE> mixes the <STRONG>num</STRONG> bytes at <STRONG>buf</STRONG> into the PRNG state. Thus, if the data at <STRONG>buf</STRONG> are unpredictable to an adversary, this increases the uncertainty about the
state and makes the PRNG output less predictable. Suitable input comes from
user interaction (random key presses, mouse movements) and certain hardware
events. The
<STRONG>entropy</STRONG> argument is (the lower bound of) an estimate of how much randomness is
contained in <STRONG>buf</STRONG>, measured in bytes. Details about sources of randomness and how to
estimate their entropy can be found in the literature, e.g. RFC 1750.

</P>
<P>
<CODE>RAND_add()</CODE> may be called with sensitive data such as user
entered passwords. The seed values cannot be recovered from the PRNG
output.

</P>
<P>
OpenSSL makes sure that the PRNG state is unique for each thread. On
systems that provide <CODE>/dev/urandom</CODE>, the randomness device is used to seed the PRNG transparently. However, on
all other systems, the application is responsible for seeding the PRNG by
calling <CODE>RAND_add(),</CODE>
<A HREF="../crypto/RAND_egd.html#">RAND_egd(3)</A>
or <A HREF="../crypto/RAND_load_file.html#">RAND_load_file(3)</A>.

</P>
<P>
<CODE>RAND_seed()</CODE> is equivalent to <CODE>RAND_add()</CODE> when <STRONG>num == entropy</STRONG>.

</P>
<P>
<CODE>RAND_event()</CODE> collects the entropy from Windows events such as
mouse movements and other user interaction. It should be called with the
<STRONG>iMsg</STRONG>, <STRONG>wParam</STRONG> and <STRONG>lParam</STRONG> arguments of <EM>all</EM> messages sent to the window procedure. It will estimate the entropy
contained in the event message (if any), and add it to the PRNG. The
program can then process the messages as usual.

</P>
<P>
The <CODE>RAND_screen()</CODE> function is available for the convenience of
Windows programmers. It adds the current contents of the screen to the
PRNG. For applications that can catch Windows events, seeding the PRNG by
calling <CODE>RAND_event()</CODE> is a significantly better source of
randomness. It should be noted that both methods cannot be used on servers
that run without user interaction.

</P>
<P>
<HR>
<H1><A NAME="RETURN_VALUES">RETURN VALUES</A></H1>
<P>
<CODE>RAND_status()</CODE> and <CODE>RAND_event()</CODE> return 1 if the
PRNG has been seeded with enough data, 0 otherwise.

</P>
<P>
The other functions do not return values.

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



</P>
<P>
<HR>
<H1><A NAME="HISTORY">HISTORY</A></H1>
<P>
<CODE>RAND_seed()</CODE> and <CODE>RAND_screen()</CODE> are available in
all versions of SSLeay and OpenSSL. <CODE>RAND_add()</CODE> and
<CODE>RAND_status()</CODE> have been added in OpenSSL 0.9.5,
<CODE>RAND_event()</CODE> in OpenSSL 0.9.5a.

</P>
:}


