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

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

<h1>RAND_set_rand_method(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="#THE_RAND_METHOD_STRUCTURE">THE RAND_METHOD STRUCTURE</A>
	<LI><A HREF="#RETURN_VALUES">RETURN VALUES</A>
	<LI><A HREF="#NOTES">NOTES</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_set_rand_method, RAND_get_rand_method, RAND_SSLeay - select RAND
method

</P>
<P>
<HR>
<H1><A NAME="SYNOPSIS">SYNOPSIS</A></H1>
<PRE> #include &lt;openssl/rand.h&gt;
</PRE>
<PRE> void RAND_set_rand_method(const RAND_METHOD *meth);
</PRE>
<PRE> const RAND_METHOD *RAND_get_rand_method(void);
</PRE>
<PRE> RAND_METHOD *RAND_SSLeay(void);
</PRE>
<P>
<HR>
<H1><A NAME="DESCRIPTION">DESCRIPTION</A></H1>
<P>
A <STRONG>RAND_METHOD</STRONG> specifies the functions that OpenSSL uses for random number generation. By
modifying the method, alternative implementations such as hardware RNGs may
be used. IMPORTANT: See the NOTES section for important information about
how these RAND API functions are affected by the use of
<STRONG>ENGINE</STRONG> API calls.

</P>
<P>
Initially, the default RAND_METHOD is the OpenSSL internal implementation,
as returned by <CODE>RAND_SSLeay().</CODE>

</P>
<P>
<CODE>RAND_set_default_method()</CODE> makes <STRONG>meth</STRONG> the method for PRNG use. <STRONG>NB</STRONG>: This is true only whilst no ENGINE has been set as a default for RAND, so
this function is no longer recommended.

</P>
<P>
<CODE>RAND_get_default_method()</CODE> returns a pointer to the current
RAND_METHOD. However, the meaningfulness of this result is dependent on
whether the ENGINE API is being used, so this function is no longer
recommended.

</P>
<P>
<HR>
<H1><A NAME="THE_RAND_METHOD_STRUCTURE">THE RAND_METHOD STRUCTURE</A></H1>
<PRE> typedef struct rand_meth_st
 {
        void (*seed)(const void *buf, int num);
        int (*bytes)(unsigned char *buf, int num);
        void (*cleanup)(void);
        void (*add)(const void *buf, int num, int entropy);
        int (*pseudorand)(unsigned char *buf, int num);
        int (*status)(void);
 } RAND_METHOD;
</PRE>
<P>
The components point to the implementation of <CODE>RAND_seed(),</CODE>
<CODE>RAND_bytes(),</CODE> <CODE>RAND_cleanup(),</CODE>
<CODE>RAND_add(),</CODE> <CODE>RAND_pseudo_rand()</CODE> and
<CODE>RAND_status().</CODE> Each component may be NULL if the function is
not implemented.

</P>
<P>
<HR>
<H1><A NAME="RETURN_VALUES">RETURN VALUES</A></H1>
<P>
<CODE>RAND_set_rand_method()</CODE> returns no value.
<CODE>RAND_get_rand_method()</CODE> and <CODE>RAND_SSLeay()</CODE> return
pointers to the respective methods.

</P>
<P>
<HR>
<H1><A NAME="NOTES">NOTES</A></H1>
<P>
As of version 0.9.7, RAND_METHOD implementations are grouped together with
other algorithmic APIs (eg. RSA_METHOD, EVP_CIPHER, etc) in <STRONG>ENGINE</STRONG> modules. If a default ENGINE is specified for RAND functionality using an
ENGINE API function, that will override any RAND defaults set using the
RAND API (ie. <CODE>RAND_set_rand_method()).</CODE> For this reason, the
ENGINE API is the recommended way to control default implementations for
use in RAND and other cryptographic algorithms.

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



</P>
<P>
<HR>
<H1><A NAME="HISTORY">HISTORY</A></H1>
<P>
<CODE>RAND_set_rand_method(),</CODE> <CODE>RAND_get_rand_method()</CODE>
and <CODE>RAND_SSLeay()</CODE> are available in all versions of OpenSSL.

</P>
<P>
In the engine version of version 0.9.6, <CODE>RAND_set_rand_method()</CODE>
was altered to take an ENGINE pointer as its argument. As of version 0.9.7,
that has been reverted as the ENGINE API transparently overrides RAND
defaults if used, otherwise RAND API functions work as before.
<CODE>RAND_set_rand_engine()</CODE> was also introduced in version 0.9.7.

</P>
:}


