A small detail: since 0.9.7, DH_new_method() and DSA_new_method()
[openssl.git] / doc / crypto / DSA_set_method.pod
1 =pod
2
3 =head1 NAME
4
5 DSA_set_default_method, DSA_get_default_method,
6 DSA_set_method, DSA_new_method, DSA_OpenSSL - select DSA method
7
8 =head1 SYNOPSIS
9
10  #include <openssl/dsa.h>
11
12  void DSA_set_default_method(const DSA_METHOD *meth);
13
14  const DSA_METHOD *DSA_get_default_method(void);
15
16  int DSA_set_method(DSA *dsa, const DSA_METHOD *meth);
17
18  DSA *DSA_new_method(DSA_METHOD *meth);
19
20  DSA_METHOD *DSA_OpenSSL(void);
21
22 =head1 DESCRIPTION
23
24 A B<DSA_METHOD> specifies the functions that OpenSSL uses for DSA
25 operations. By modifying the method, alternative implementations
26 such as hardware accelerators may be used. IMPORTANT: See the NOTES section for
27 important information about how these DSA API functions are affected by the use
28 of B<ENGINE> API calls.
29
30 Initially, the default DSA_METHOD is the OpenSSL internal implementation,
31 as returned by DSA_OpenSSL().
32
33 DSA_set_default_method() makes B<meth> the default method for all DSA
34 structures created later. B<NB>: This is true only whilst no ENGINE has
35 been set as a default for DSA, so this function is no longer recommended.
36
37 DSA_get_default_method() returns a pointer to the current default
38 DSA_METHOD. However, the meaningfulness of this result is dependant on
39 whether the ENGINE API is being used, so this function is no longer 
40 recommended.
41
42 DSA_set_method() selects B<meth> to perform all operations using the key
43 B<rsa>. This will replace the DSA_METHOD used by the DSA key and if the
44 previous method was supplied by an ENGINE, the handle to that ENGINE will
45 be released during the change. It is possible to have DSA keys that only
46 work with certain DSA_METHOD implementations (eg. from an ENGINE module
47 that supports embedded hardware-protected keys), and in such cases
48 attempting to change the DSA_METHOD for the key can have unexpected
49 results.
50
51 DSA_new_method() allocates and initializes a DSA structure so that B<engine>
52 will be used for the DSA operations. If B<engine> is NULL, the default engine
53 for DSA operations is used, and if no default ENGINE is set, the DSA_METHOD
54 controlled by DSA_set_default_method() is used.
55
56 =head1 THE DSA_METHOD STRUCTURE
57
58 struct
59  {
60      /* name of the implementation */
61         const char *name;
62
63      /* sign */
64         DSA_SIG *(*dsa_do_sign)(const unsigned char *dgst, int dlen,
65                                  DSA *dsa);
66
67      /* pre-compute k^-1 and r */
68         int (*dsa_sign_setup)(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp,
69                                  BIGNUM **rp);
70
71      /* verify */
72         int (*dsa_do_verify)(const unsigned char *dgst, int dgst_len,
73                                  DSA_SIG *sig, DSA *dsa);
74
75      /* compute rr = a1^p1 * a2^p2 mod m (May be NULL for some
76                                           implementations) */
77         int (*dsa_mod_exp)(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
78                                  BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
79                                  BN_CTX *ctx, BN_MONT_CTX *in_mont);
80
81      /* compute r = a ^ p mod m (May be NULL for some implementations) */
82         int (*bn_mod_exp)(DSA *dsa, BIGNUM *r, BIGNUM *a,
83                                  const BIGNUM *p, const BIGNUM *m,
84                                  BN_CTX *ctx, BN_MONT_CTX *m_ctx);
85
86      /* called at DSA_new */
87         int (*init)(DSA *DSA);
88
89      /* called at DSA_free */
90         int (*finish)(DSA *DSA);
91
92         int flags;
93
94         char *app_data; /* ?? */
95
96  } DSA_METHOD;
97
98 =head1 RETURN VALUES
99
100 DSA_OpenSSL() and DSA_get_default_method() return pointers to the respective
101 B<DSA_METHOD>s.
102
103 DSA_set_default_method() returns no value.
104
105 DSA_set_method() returns non-zero if the provided B<meth> was successfully set as
106 the method for B<dsa> (including unloading the ENGINE handle if the previous
107 method was supplied by an ENGINE).
108
109 DSA_new_method() returns NULL and sets an error code that can be
110 obtained by L<ERR_get_error(3)|ERR_get_error(3)> if the allocation
111 fails. Otherwise it returns a pointer to the newly allocated structure.
112
113 =head1 NOTES
114
115 As of version 0.9.7, DSA_METHOD implementations are grouped together with other
116 algorithmic APIs (eg. RSA_METHOD, EVP_CIPHER, etc) in B<ENGINE> modules. If a
117 default ENGINE is specified for DSA functionality using an ENGINE API function,
118 that will override any DSA defaults set using the DSA API (ie.
119 DSA_set_default_method()). For this reason, the ENGINE API is the recommended way
120 to control default implementations for use in DSA and other cryptographic
121 algorithms.
122
123 =head1 SEE ALSO
124
125 L<dsa(3)|dsa(3)>, L<DSA_new(3)|DSA_new(3)>
126
127 =head1 HISTORY
128
129 DSA_set_default_method(), DSA_get_default_method(), DSA_set_method(),
130 DSA_new_method() and DSA_OpenSSL() were added in OpenSSL 0.9.4.
131
132 DSA_set_default_openssl_method() and DSA_get_default_openssl_method() replaced
133 DSA_set_default_method() and DSA_get_default_method() respectively, and
134 DSA_set_method() and DSA_new_method() were altered to use B<ENGINE>s rather than
135 B<DSA_METHOD>s during development of the engine version of OpenSSL 0.9.6. For
136 0.9.7, the handling of defaults in the ENGINE API was restructured so that this
137 change was reversed, and behaviour of the other functions resembled more closely
138 the previous behaviour. The behaviour of defaults in the ENGINE API now
139 transparently overrides the behaviour of defaults in the DSA API without
140 requiring changing these function prototypes.
141
142 =cut