Make DSA_METHOD opaque
[openssl.git] / crypto / dsa / dsa_meth.c
1 /* ====================================================================
2  * Copyright (c) 2016 The OpenSSL Project.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in
13  *    the documentation and/or other materials provided with the
14  *    distribution.
15  *
16  * 3. All advertising materials mentioning features or use of this
17  *    software must display the following acknowledgment:
18  *    "This product includes software developed by the OpenSSL Project
19  *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20  *
21  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22  *    endorse or promote products derived from this software without
23  *    prior written permission. For written permission, please contact
24  *    openssl-core@OpenSSL.org.
25  *
26  * 5. Products derived from this software may not be called "OpenSSL"
27  *    nor may "OpenSSL" appear in their names without prior written
28  *    permission of the OpenSSL Project.
29  *
30  * 6. Redistributions of any form whatsoever must retain the following
31  *    acknowledgment:
32  *    "This product includes software developed by the OpenSSL Project
33  *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34  *
35  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
39  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46  * OF THE POSSIBILITY OF SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This product includes cryptographic software written by Eric Young
50  * (eay@cryptsoft.com).  This product includes software written by Tim
51  * Hudson (tjh@cryptsoft.com).
52  *
53  */
54
55 #include "dsa_locl.h"
56 #include <string.h>
57
58 DSA_METHOD *DSA_meth_new(const char *name, int flags)
59 {
60     DSA_METHOD *dsam = OPENSSL_zalloc(sizeof(DSA_METHOD));
61
62     if (dsam != NULL) {
63         dsam->name = OPENSSL_strdup(name);
64         dsam->flags = flags;
65     }
66
67     return dsam;
68 }
69
70 void DSA_meth_free(DSA_METHOD *dsam)
71 {
72     if (dsam != NULL) {
73         if (dsam->name != NULL)
74             OPENSSL_free(dsam->name);
75         OPENSSL_free(dsam);
76     }
77 }
78
79 DSA_METHOD *DSA_meth_dup(const DSA_METHOD *meth)
80 {
81     DSA_METHOD *ret;
82
83     ret = OPENSSL_malloc(sizeof(DSA_METHOD));
84
85     if (ret != NULL) {
86         memcpy(ret, meth, sizeof(*meth));
87         ret->name = OPENSSL_strdup(meth->name);
88     }
89
90     return ret;
91 }
92
93 const char *DSA_meth_get_name(const DSA_METHOD *dsam)
94 {
95     return dsam->name;
96 }
97
98 int DSA_meth_set_name(DSA_METHOD *dsam, const char *name)
99 {
100     OPENSSL_free(dsam->name);
101     dsam->name = OPENSSL_strdup(name);
102
103     return dsam->name != NULL;
104 }
105
106 int DSA_meth_get_flags(DSA_METHOD *dsam)
107 {
108     return dsam->flags;
109 }
110
111 int DSA_meth_set_flags(DSA_METHOD *dsam, int flags)
112 {
113     dsam->flags = flags;
114     return 1;
115 }
116
117 void *DSA_meth_get_app_data(const DSA_METHOD *dsam)
118 {
119     return dsam->app_data;
120 }
121
122 int DSA_meth_set_app_data(DSA_METHOD *dsam, void *app_data)
123 {
124     dsam->app_data = app_data;
125     return 1;
126 }
127
128 DSA_SIG *(*DSA_meth_get_sign(const DSA_METHOD *dsam))
129         (const unsigned char *, int, DSA *)
130 {
131     return dsam->dsa_do_sign;
132 }
133
134 int DSA_meth_set_sign(DSA_METHOD *dsam,
135                        DSA_SIG *(*sign) (const unsigned char *, int, DSA *))
136 {
137     dsam->dsa_do_sign = sign;
138     return 1;
139 }
140
141 int (*DSA_meth_get_sign_setup(const DSA_METHOD *dsam))
142         (DSA *, BN_CTX *, BIGNUM **, BIGNUM **)
143 {
144     return dsam->dsa_sign_setup;
145 }
146
147 int DSA_meth_set_sign_setup(DSA_METHOD *dsam,
148         int (*sign_setup) (DSA *, BN_CTX *, BIGNUM **, BIGNUM **))
149 {
150     dsam->dsa_sign_setup = sign_setup;
151     return 1;
152 }
153
154 int (*DSA_meth_get_verify(const DSA_METHOD *dsam))
155         (const unsigned char *, int , DSA_SIG *, DSA *)
156 {
157     return dsam->dsa_do_verify;
158 }
159
160 int DSA_meth_set_verify(DSA_METHOD *dsam,
161     int (*verify) (const unsigned char *, int, DSA_SIG *, DSA *))
162 {
163     dsam->dsa_do_verify = verify;
164     return 1;
165 }
166
167 int (*DSA_meth_get_mod_exp(const DSA_METHOD *dsam))
168         (DSA *, BIGNUM *, BIGNUM *, BIGNUM *, BIGNUM *, BIGNUM *, BIGNUM *,
169          BN_CTX *, BN_MONT_CTX *)
170 {
171     return dsam->dsa_mod_exp;
172 }
173
174 int DSA_meth_set_mod_exp(DSA_METHOD *dsam,
175     int (*mod_exp) (DSA *, BIGNUM *, BIGNUM *, BIGNUM *, BIGNUM *, BIGNUM *,
176                     BIGNUM *, BN_CTX *, BN_MONT_CTX *))
177 {
178     dsam->dsa_mod_exp = mod_exp;
179     return 1;
180 }
181
182 int (*DSA_meth_get_bn_mod_exp(const DSA_METHOD *dsam))
183     (DSA *, BIGNUM *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *,
184      BN_MONT_CTX *)
185 {
186     return dsam->bn_mod_exp;
187 }
188
189 int DSA_meth_set_bn_mod_exp(DSA_METHOD *dsam,
190     int (*bn_mod_exp) (DSA *, BIGNUM *, BIGNUM *, const BIGNUM *,
191                        const BIGNUM *, BN_CTX *, BN_MONT_CTX *))
192 {
193     dsam->bn_mod_exp = bn_mod_exp;
194     return 1;
195 }
196
197 int (*DSA_meth_get_init(const DSA_METHOD *dsam))(DSA *)
198 {
199     return dsam->init;
200 }
201
202 int DSA_meth_set_init(DSA_METHOD *dsam, int (*init)(DSA *))
203 {
204     dsam->init = init;
205     return 1;
206 }
207
208 int (*DSA_meth_get_finish(const DSA_METHOD *dsam)) (DSA *)
209 {
210     return dsam->finish;
211 }
212
213 int DSA_meth_set_finish(DSA_METHOD *dsam, int (*finish) (DSA *))
214 {
215     dsam->finish = finish;
216     return 1;
217 }
218
219 int (*DSA_meth_get_paramgen(const DSA_METHOD *dsam))
220         (DSA *, int, const unsigned char *, int, int *, unsigned long *,
221          BN_GENCB *)
222 {
223     return dsam->dsa_paramgen;
224 }
225
226 int DSA_meth_set_paramgen(DSA_METHOD *dsam,
227         int (*paramgen) (DSA *, int, const unsigned char *, int, int *,
228                          unsigned long *, BN_GENCB *))
229 {
230     dsam->dsa_paramgen = paramgen;
231     return 1;
232 }
233
234 int (*DSA_meth_get_keygen(const DSA_METHOD *dsam)) (DSA *)
235 {
236     return dsam->dsa_keygen;
237 }
238
239 int DSA_meth_set_keygen(DSA_METHOD *dsam, int (*keygen) (DSA *))
240 {
241     dsam->dsa_keygen = keygen;
242     return 1;
243 }