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

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

<h1>DSA_set_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_DSA_METHOD_STRUCTURE">THE DSA_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>
DSA_set_default_method, DSA_get_default_method, DSA_set_method,
DSA_new_method, DSA_OpenSSL - select DSA method

</P>
<P>
<HR>
<H1><A NAME="SYNOPSIS">SYNOPSIS</A></H1>
<PRE> #include &lt;openssl/dsa.h&gt;
 \#include &lt;openssl/engine.h&gt;
</PRE>
<PRE> void DSA_set_default_method(const DSA_METHOD *meth);
</PRE>
<PRE> const DSA_METHOD *DSA_get_default_method(void);
</PRE>
<PRE> int DSA_set_method(DSA *dsa, const DSA_METHOD *meth);
</PRE>
<PRE> DSA *DSA_new_method(ENGINE *engine);
</PRE>
<PRE> DSA_METHOD *DSA_OpenSSL(void);
</PRE>
<P>
<HR>
<H1><A NAME="DESCRIPTION">DESCRIPTION</A></H1>
<P>
A <STRONG>DSA_METHOD</STRONG> specifies the functions that OpenSSL uses for DSA operations. By modifying
the method, alternative implementations such as hardware accelerators may
be used. IMPORTANT: See the NOTES section for important information about
how these DSA API functions are affected by the use of <STRONG>ENGINE</STRONG> API calls.

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

</P>
<P>
<CODE>DSA_set_default_method()</CODE> makes <STRONG>meth</STRONG> the default method for all DSA structures created later. <STRONG>NB</STRONG>: This is true only whilst no ENGINE has been set as a default for DSA, so
this function is no longer recommended.

</P>
<P>
<CODE>DSA_get_default_method()</CODE> returns a pointer to the current
default DSA_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>
<CODE>DSA_set_method()</CODE> selects <STRONG>meth</STRONG> to perform all operations using the key
<STRONG>rsa</STRONG>. This will replace the DSA_METHOD used by the DSA key and if the previous
method was supplied by an ENGINE, the handle to that ENGINE will be
released during the change. It is possible to have DSA keys that only work
with certain DSA_METHOD implementations (eg. from an ENGINE module that
supports embedded hardware-protected keys), and in such cases attempting to
change the DSA_METHOD for the key can have unexpected results.

</P>
<P>
<CODE>DSA_new_method()</CODE> allocates and initializes a DSA structure so
that <STRONG>engine</STRONG>
will be used for the DSA operations. If <STRONG>engine</STRONG> is NULL, the default engine for DSA operations is used, and if no default
ENGINE is set, the DSA_METHOD controlled by
<CODE>DSA_set_default_method()</CODE> is used.

</P>
<P>
<HR>
<H1><A NAME="THE_DSA_METHOD_STRUCTURE">THE DSA_METHOD STRUCTURE</A></H1>
<P>
struct { /* name of the implementation */ const char *name;

</P>
<PRE>     /* sign */
        DSA_SIG *(*dsa_do_sign)(const unsigned char *dgst, int dlen,
                                 DSA *dsa);
</PRE>
<PRE>     /* pre-compute k^-1 and r */
        int (*dsa_sign_setup)(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp,
                                 BIGNUM **rp);
</PRE>
<PRE>     /* verify */
        int (*dsa_do_verify)(const unsigned char *dgst, int dgst_len,
                                 DSA_SIG *sig, DSA *dsa);
</PRE>
<PRE>     /* compute rr = a1^p1 * a2^p2 mod m (May be NULL for some
                                          implementations) */
        int (*dsa_mod_exp)(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
                                 BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
                                 BN_CTX *ctx, BN_MONT_CTX *in_mont);
</PRE>
<PRE>     /* compute r = a ^ p mod m (May be NULL for some implementations) */
        int (*bn_mod_exp)(DSA *dsa, BIGNUM *r, BIGNUM *a,
                                 const BIGNUM *p, const BIGNUM *m,
                                 BN_CTX *ctx, BN_MONT_CTX *m_ctx);
</PRE>
<PRE>     /* called at DSA_new */
        int (*init)(DSA *DSA);
</PRE>
<PRE>     /* called at DSA_free */
        int (*finish)(DSA *DSA);
</PRE>
<PRE>        int flags;
</PRE>
<PRE>        char *app_data; /* ?? */
</PRE>
<PRE> } DSA_METHOD;
</PRE>
<P>
<HR>
<H1><A NAME="RETURN_VALUES">RETURN VALUES</A></H1>
<P>
<CODE>DSA_OpenSSL()</CODE> and <CODE>DSA_get_default_method()</CODE> return
pointers to the respective
<STRONG>DSA_METHOD</STRONG>s.

</P>
<P>
<CODE>DSA_set_default_method()</CODE> returns no value.

</P>
<P>
<CODE>DSA_set_method()</CODE> returns non-zero if the provided <STRONG>meth</STRONG> was successfully set as the method for <STRONG>dsa</STRONG> (including unloading the ENGINE handle if the previous method was supplied
by an ENGINE).

</P>
<P>
<CODE>DSA_new_method()</CODE> returns NULL and sets an error code that can
be obtained by <A HREF="../crypto/ERR_get_error.html#">ERR_get_error(3)</A> if the allocation fails. Otherwise it returns a pointer to the newly
allocated structure.

</P>
<P>
<HR>
<H1><A NAME="NOTES">NOTES</A></H1>
<P>
As of version 0.9.7, DSA_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 DSA functionality using an
ENGINE API function, that will override any DSA defaults set using the DSA
API (ie. <CODE>DSA_set_default_method()).</CODE> For this reason, the
ENGINE API is the recommended way to control default implementations for
use in DSA and other cryptographic algorithms.

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



</P>
<P>
<HR>
<H1><A NAME="HISTORY">HISTORY</A></H1>
<P>
<CODE>DSA_set_default_method(),</CODE>
<CODE>DSA_get_default_method(),</CODE> <CODE>DSA_set_method(),</CODE>
<CODE>DSA_new_method()</CODE> and <CODE>DSA_OpenSSL()</CODE> were added in
OpenSSL 0.9.4.

</P>
<P>
<CODE>DSA_set_default_openssl_method()</CODE> and
<CODE>DSA_get_default_openssl_method()</CODE> replaced
<CODE>DSA_set_default_method()</CODE> and
<CODE>DSA_get_default_method()</CODE> respectively, and
<CODE>DSA_set_method()</CODE> and <CODE>DSA_new_method()</CODE> were
altered to use <STRONG>ENGINE</STRONG>s rather than
<STRONG>DSA_METHOD</STRONG>s during development of the engine version of OpenSSL 0.9.6. For 0.9.7, the
handling of defaults in the ENGINE API was restructured so that this change
was reversed, and behaviour of the other functions resembled more closely
the previous behaviour. The behaviour of defaults in the ENGINE API now
transparently overrides the behaviour of defaults in the DSA API without
requiring changing these function prototypes.

</P>
:}


