Fix grammar in srp_verifier.txt
[openssl.git] / crypto / dsa / dsa_meth.c
1 /*
2  * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 /*
11  * Licensed under the Apache License 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  * https://www.openssl.org/source/license.html
15  * or in the file LICENSE in the source distribution.
16  */
17
18 #include "dsa_local.h"
19 #include <string.h>
20 #include <openssl/err.h>
21
22 #ifndef OPENSSL_NO_DEPRECATED_3_0
23 DSA_METHOD *DSA_meth_new(const char *name, int flags)
24 {
25     DSA_METHOD *dsam = OPENSSL_zalloc(sizeof(*dsam));
26
27     if (dsam != NULL) {
28         dsam->flags = flags;
29
30         dsam->name = OPENSSL_strdup(name);
31         if (dsam->name != NULL)
32             return dsam;
33
34         OPENSSL_free(dsam);
35     }
36
37     DSAerr(DSA_F_DSA_METH_NEW, ERR_R_MALLOC_FAILURE);
38     return NULL;
39 }
40
41 void DSA_meth_free(DSA_METHOD *dsam)
42 {
43     if (dsam != NULL) {
44         OPENSSL_free(dsam->name);
45         OPENSSL_free(dsam);
46     }
47 }
48
49 DSA_METHOD *DSA_meth_dup(const DSA_METHOD *dsam)
50 {
51     DSA_METHOD *ret = OPENSSL_malloc(sizeof(*ret));
52
53     if (ret != NULL) {
54         memcpy(ret, dsam, sizeof(*dsam));
55
56         ret->name = OPENSSL_strdup(dsam->name);
57         if (ret->name != NULL)
58             return ret;
59
60         OPENSSL_free(ret);
61     }
62
63     DSAerr(DSA_F_DSA_METH_DUP, ERR_R_MALLOC_FAILURE);
64     return NULL;
65 }
66
67 const char *DSA_meth_get0_name(const DSA_METHOD *dsam)
68 {
69     return dsam->name;
70 }
71
72 int DSA_meth_set1_name(DSA_METHOD *dsam, const char *name)
73 {
74     char *tmpname = OPENSSL_strdup(name);
75
76     if (tmpname == NULL) {
77         DSAerr(DSA_F_DSA_METH_SET1_NAME, ERR_R_MALLOC_FAILURE);
78         return 0;
79     }
80
81     OPENSSL_free(dsam->name);
82     dsam->name = tmpname;
83
84     return 1;
85 }
86
87 int DSA_meth_get_flags(const DSA_METHOD *dsam)
88 {
89     return dsam->flags;
90 }
91
92 int DSA_meth_set_flags(DSA_METHOD *dsam, int flags)
93 {
94     dsam->flags = flags;
95     return 1;
96 }
97
98 void *DSA_meth_get0_app_data(const DSA_METHOD *dsam)
99 {
100     return dsam->app_data;
101 }
102
103 int DSA_meth_set0_app_data(DSA_METHOD *dsam, void *app_data)
104 {
105     dsam->app_data = app_data;
106     return 1;
107 }
108
109 DSA_SIG *(*DSA_meth_get_sign(const DSA_METHOD *dsam))
110         (const unsigned char *, int, DSA *)
111 {
112     return dsam->dsa_do_sign;
113 }
114
115 int DSA_meth_set_sign(DSA_METHOD *dsam,
116                        DSA_SIG *(*sign) (const unsigned char *, int, DSA *))
117 {
118     dsam->dsa_do_sign = sign;
119     return 1;
120 }
121
122 int (*DSA_meth_get_sign_setup(const DSA_METHOD *dsam))
123         (DSA *, BN_CTX *, BIGNUM **, BIGNUM **)
124 {
125     return dsam->dsa_sign_setup;
126 }
127
128 int DSA_meth_set_sign_setup(DSA_METHOD *dsam,
129         int (*sign_setup) (DSA *, BN_CTX *, BIGNUM **, BIGNUM **))
130 {
131     dsam->dsa_sign_setup = sign_setup;
132     return 1;
133 }
134
135 int (*DSA_meth_get_verify(const DSA_METHOD *dsam))
136         (const unsigned char *, int, DSA_SIG *, DSA *)
137 {
138     return dsam->dsa_do_verify;
139 }
140
141 int DSA_meth_set_verify(DSA_METHOD *dsam,
142     int (*verify) (const unsigned char *, int, DSA_SIG *, DSA *))
143 {
144     dsam->dsa_do_verify = verify;
145     return 1;
146 }
147
148 int (*DSA_meth_get_mod_exp(const DSA_METHOD *dsam))
149         (DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *,
150          const BIGNUM *, const BIGNUM *, BN_CTX *, BN_MONT_CTX *)
151 {
152     return dsam->dsa_mod_exp;
153 }
154
155 int DSA_meth_set_mod_exp(DSA_METHOD *dsam,
156     int (*mod_exp) (DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *,
157                     const BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *,
158                     BN_MONT_CTX *))
159 {
160     dsam->dsa_mod_exp = mod_exp;
161     return 1;
162 }
163
164 int (*DSA_meth_get_bn_mod_exp(const DSA_METHOD *dsam))
165     (DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *,
166      BN_MONT_CTX *)
167 {
168     return dsam->bn_mod_exp;
169 }
170
171 int DSA_meth_set_bn_mod_exp(DSA_METHOD *dsam,
172     int (*bn_mod_exp) (DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *,
173                        const BIGNUM *, BN_CTX *, BN_MONT_CTX *))
174 {
175     dsam->bn_mod_exp = bn_mod_exp;
176     return 1;
177 }
178
179 int (*DSA_meth_get_init(const DSA_METHOD *dsam))(DSA *)
180 {
181     return dsam->init;
182 }
183
184 int DSA_meth_set_init(DSA_METHOD *dsam, int (*init)(DSA *))
185 {
186     dsam->init = init;
187     return 1;
188 }
189
190 int (*DSA_meth_get_finish(const DSA_METHOD *dsam)) (DSA *)
191 {
192     return dsam->finish;
193 }
194
195 int DSA_meth_set_finish(DSA_METHOD *dsam, int (*finish) (DSA *))
196 {
197     dsam->finish = finish;
198     return 1;
199 }
200
201 int (*DSA_meth_get_paramgen(const DSA_METHOD *dsam))
202         (DSA *, int, const unsigned char *, int, int *, unsigned long *,
203          BN_GENCB *)
204 {
205     return dsam->dsa_paramgen;
206 }
207
208 int DSA_meth_set_paramgen(DSA_METHOD *dsam,
209         int (*paramgen) (DSA *, int, const unsigned char *, int, int *,
210                          unsigned long *, BN_GENCB *))
211 {
212     dsam->dsa_paramgen = paramgen;
213     return 1;
214 }
215
216 int (*DSA_meth_get_keygen(const DSA_METHOD *dsam)) (DSA *)
217 {
218     return dsam->dsa_keygen;
219 }
220
221 int DSA_meth_set_keygen(DSA_METHOD *dsam, int (*keygen) (DSA *))
222 {
223     dsam->dsa_keygen = keygen;
224     return 1;
225 }
226 #endif