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

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

<h1>RAND_egd(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="#NOTES">NOTES</A>
	<LI><A HREF="#RETURN_VALUE">RETURN VALUE</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_egd, RAND_egd_bytes, RAND_query_egd_bytes - query entropy gathering
daemon

</P>
<P>
<HR>
<H1><A NAME="SYNOPSIS">SYNOPSIS</A></H1>
<PRE> #include &lt;openssl/rand.h&gt;
</PRE>
<PRE> int RAND_egd(const char *path);
 int RAND_egd_bytes(const char *path, int bytes);
</PRE>
<PRE> int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes);
</PRE>
<P>
<HR>
<H1><A NAME="DESCRIPTION">DESCRIPTION</A></H1>
<P>
<CODE>RAND_egd()</CODE> queries the entropy gathering daemon EGD on socket <STRONG>path</STRONG>. It queries 255 bytes and uses <A HREF="../crypto/RAND_add.html#">RAND_add(3)</A> to seed the OpenSSL built-in PRNG. <CODE>RAND_egd(path)</CODE> is a wrapper
for <CODE>RAND_egd_bytes(path,</CODE> 255);

</P>
<P>
<CODE>RAND_egd_bytes()</CODE> queries the entropy gathering daemon EGD on
socket <STRONG>path</STRONG>. It queries <STRONG>bytes</STRONG> bytes and uses <A HREF="../crypto/RAND_add.html#">RAND_add(3)</A> to seed the OpenSSL built-in PRNG. This function is more flexible than
<CODE>RAND_egd().</CODE> When only one secret key must be generated, it is
not necessary to request the full amount 255 bytes from the EGD socket.
This can be advantageous, since the amount of entropy that can be retrieved
from EGD over time is limited.

</P>
<P>
<CODE>RAND_query_egd_bytes()</CODE> performs the actual query of the EGD
daemon on socket
<STRONG>path</STRONG>. If <STRONG>buf</STRONG> is given, <STRONG>bytes</STRONG> bytes are queried and written into
<STRONG>buf</STRONG>. If <STRONG>buf</STRONG> is NULL, <STRONG>bytes</STRONG> bytes are queried and used to seed the OpenSSL built-in PRNG using <A HREF="../crypto/RAND_add.html#">RAND_add(3)</A>.

</P>
<P>
<HR>
<H1><A NAME="NOTES">NOTES</A></H1>
<P>
On systems without /dev/*random devices providing entropy from the kernel,
the EGD entropy gathering daemon can be used to collect entropy. It
provides a socket interface through which entropy can be gathered in chunks
up to 255 bytes. Several chunks can be queried during one connection.

</P>
<P>
EGD is available from <A
HREF="http://www.lothar.com/tech/crypto/">http://www.lothar.com/tech/crypto/</A>
(<CODE>perl
Makefile.PL; make; make install</CODE> to install). It is run as <STRONG>egd</STRONG>

<EM>path</EM>, where <EM>path</EM> is an absolute path designating a socket. When <CODE>RAND_egd()</CODE> is
called with that path as an argument, it tries to read random bytes that
EGD has collected. <CODE>RAND_egd()</CODE> retrieves entropy from the
daemon using the daemon's ``non-blocking read'' command which shall be
answered immediately by the daemon without waiting for additional entropy
to be collected. The write and read socket operations in the communication
are blocking.

</P>
<P>
Alternatively, the EGD-interface compatible daemon PRNGD can be used. It is
available from <A
HREF="http://prngd.sourceforge.net/">http://prngd.sourceforge.net/</A> .
PRNGD does employ an internal PRNG itself and can therefore never run out
of entropy.

</P>
<P>
OpenSSL automatically queries EGD when entropy is requested via
<CODE>RAND_bytes()</CODE> or the status is checked via
<CODE>RAND_status()</CODE> for the first time, if the socket is located at
/var/run/egd-pool, /dev/egd-pool or /etc/egd-pool.

</P>
<P>
<HR>
<H1><A NAME="RETURN_VALUE">RETURN VALUE</A></H1>
<P>
<CODE>RAND_egd()</CODE> and <CODE>RAND_egd_bytes()</CODE> return the number
of bytes read from the daemon on success, and -1 if the connection failed
or the daemon did not return enough data to fully seed the PRNG.

</P>
<P>
<CODE>RAND_query_egd_bytes()</CODE> returns the number of bytes read from
the daemon on success, and -1 if the connection failed. The PRNG state is
not considered.

</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_add.html#">RAND_add(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_egd()</CODE> is available since OpenSSL 0.9.5.

</P>
<P>
<CODE>RAND_egd_bytes()</CODE> is available since OpenSSL 0.9.6.

</P>
<P>
<CODE>RAND_query_egd_bytes()</CODE> is available since OpenSSL 0.9.7.

</P>
<P>
The automatic query of /var/run/egd-pool et al was added in OpenSSL 0.9.7.

</P>
:}

