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

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

<h1>DH_generate_parameters(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="#NOTES">NOTES</A>
	<LI><A HREF="#BUGS">BUGS</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>
DH_generate_parameters, DH_check - generate and check Diffie-Hellman
parameters

</P>
<P>
<HR>
<H1><A NAME="SYNOPSIS">SYNOPSIS</A></H1>
<PRE> #include &lt;openssl/dh.h&gt;
</PRE>
<PRE> DH *DH_generate_parameters(int prime_len, int generator,
     void (*callback)(int, int, void *), void *cb_arg);
</PRE>
<PRE> int DH_check(DH *dh, int *codes);
</PRE>
<P>
<HR>
<H1><A NAME="DESCRIPTION">DESCRIPTION</A></H1>
<P>
<CODE>DH_generate_parameters()</CODE> generates Diffie-Hellman parameters
that can be shared among a group of users, and returns them in a newly
allocated <STRONG>DH</STRONG> structure. The pseudo-random number generator must be seeded prior to
calling <CODE>DH_generate_parameters().</CODE>

</P>
<P>
<STRONG>prime_len</STRONG> is the length in bits of the safe prime to be generated.
<STRONG>generator</STRONG> is a small number &gt; 1, typically 2 or 5. 

</P>
<P>
A callback function may be used to provide feedback about the progress of
the key generation. If <STRONG>callback</STRONG> is not <STRONG>NULL</STRONG>, it will be called as described in <A HREF="../crypto/BN_generate_prime.html#">BN_generate_prime(3)</A> while a random prime number is generated, and when a prime has been found, <STRONG>callback(3,
0, cb_arg)</STRONG> is called.

</P>
<P>
<CODE>DH_check()</CODE> validates Diffie-Hellman parameters. It checks that <STRONG>p</STRONG> is a safe prime, and that <STRONG>g</STRONG> is a suitable generator. In the case of an error, the bit flags
DH_CHECK_P_NOT_SAFE_PRIME or DH_NOT_SUITABLE_GENERATOR are set in <STRONG>*codes</STRONG>. DH_UNABLE_TO_CHECK_GENERATOR is set if the generator cannot be checked,
i.e. it does not equal 2 or 5.

</P>
<P>
<HR>
<H1><A NAME="RETURN_VALUES">RETURN VALUES</A></H1>
<P>
<CODE>DH_generate_parameters()</CODE> returns a pointer to the DH
structure, or NULL if the parameter generation fails. The error codes can
be obtained by <A HREF="../crypto/ERR_get_error.html#">ERR_get_error(3)</A>.

</P>
<P>
<CODE>DH_check()</CODE> returns 1 if the check could be performed, 0
otherwise.

</P>
<P>
<HR>
<H1><A NAME="NOTES">NOTES</A></H1>
<P>
<CODE>DH_generate_parameters()</CODE> may run for several hours before
finding a suitable prime.

</P>
<P>
The parameters generated by <CODE>DH_generate_parameters()</CODE> are not
to be used in signature schemes.

</P>
<P>
<HR>
<H1><A NAME="BUGS">BUGS</A></H1>
<P>
If <STRONG>generator</STRONG> is not 2 or 5, <STRONG>dh-&gt;g</STRONG>=<STRONG>generator</STRONG> is not a usable generator.

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



</P>
<P>
<HR>
<H1><A NAME="HISTORY">HISTORY</A></H1>
<P>
<CODE>DH_check()</CODE> is available in all versions of SSLeay and OpenSSL.
The <STRONG>cb_arg</STRONG> argument to <CODE>DH_generate_parameters()</CODE> was added in SSLeay
0.9.0.

</P>
<P>
In versions before OpenSSL 0.9.5, DH_CHECK_P_NOT_STRONG_PRIME is used
instead of DH_CHECK_P_NOT_SAFE_PRIME.

</P>
:}


