xref: /openssl/crypto/dsa/dsa_meth.c (revision e077455e)
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  * DSA low level APIs are deprecated for public use, but still ok for
12  * internal use.
13  */
14 #include "internal/deprecated.h"
15 
16 #include "dsa_local.h"
17 #include <string.h>
18 #include <openssl/err.h>
19 
20 #ifndef OPENSSL_NO_DEPRECATED_3_0
DSA_meth_new(const char * name,int flags)21 DSA_METHOD *DSA_meth_new(const char *name, int flags)
22 {
23     DSA_METHOD *dsam = OPENSSL_zalloc(sizeof(*dsam));
24 
25     if (dsam != NULL) {
26         dsam->flags = flags;
27 
28         dsam->name = OPENSSL_strdup(name);
29         if (dsam->name != NULL)
30             return dsam;
31 
32         OPENSSL_free(dsam);
33     }
34 
35     return NULL;
36 }
37 
DSA_meth_free(DSA_METHOD * dsam)38 void DSA_meth_free(DSA_METHOD *dsam)
39 {
40     if (dsam != NULL) {
41         OPENSSL_free(dsam->name);
42         OPENSSL_free(dsam);
43     }
44 }
45 
DSA_meth_dup(const DSA_METHOD * dsam)46 DSA_METHOD *DSA_meth_dup(const DSA_METHOD *dsam)
47 {
48     DSA_METHOD *ret = OPENSSL_malloc(sizeof(*ret));
49 
50     if (ret != NULL) {
51         memcpy(ret, dsam, sizeof(*dsam));
52 
53         ret->name = OPENSSL_strdup(dsam->name);
54         if (ret->name != NULL)
55             return ret;
56 
57         OPENSSL_free(ret);
58     }
59 
60     return NULL;
61 }
62 
DSA_meth_get0_name(const DSA_METHOD * dsam)63 const char *DSA_meth_get0_name(const DSA_METHOD *dsam)
64 {
65     return dsam->name;
66 }
67 
DSA_meth_set1_name(DSA_METHOD * dsam,const char * name)68 int DSA_meth_set1_name(DSA_METHOD *dsam, const char *name)
69 {
70     char *tmpname = OPENSSL_strdup(name);
71 
72     if (tmpname == NULL)
73         return 0;
74 
75     OPENSSL_free(dsam->name);
76     dsam->name = tmpname;
77 
78     return 1;
79 }
80 
DSA_meth_get_flags(const DSA_METHOD * dsam)81 int DSA_meth_get_flags(const DSA_METHOD *dsam)
82 {
83     return dsam->flags;
84 }
85 
DSA_meth_set_flags(DSA_METHOD * dsam,int flags)86 int DSA_meth_set_flags(DSA_METHOD *dsam, int flags)
87 {
88     dsam->flags = flags;
89     return 1;
90 }
91 
DSA_meth_get0_app_data(const DSA_METHOD * dsam)92 void *DSA_meth_get0_app_data(const DSA_METHOD *dsam)
93 {
94     return dsam->app_data;
95 }
96 
DSA_meth_set0_app_data(DSA_METHOD * dsam,void * app_data)97 int DSA_meth_set0_app_data(DSA_METHOD *dsam, void *app_data)
98 {
99     dsam->app_data = app_data;
100     return 1;
101 }
102 
DSA_meth_get_sign(const DSA_METHOD * dsam)103 DSA_SIG *(*DSA_meth_get_sign(const DSA_METHOD *dsam))
104         (const unsigned char *, int, DSA *)
105 {
106     return dsam->dsa_do_sign;
107 }
108 
DSA_meth_set_sign(DSA_METHOD * dsam,DSA_SIG * (* sign)(const unsigned char *,int,DSA *))109 int DSA_meth_set_sign(DSA_METHOD *dsam,
110                        DSA_SIG *(*sign) (const unsigned char *, int, DSA *))
111 {
112     dsam->dsa_do_sign = sign;
113     return 1;
114 }
115 
DSA_meth_get_sign_setup(const DSA_METHOD * dsam)116 int (*DSA_meth_get_sign_setup(const DSA_METHOD *dsam))
117         (DSA *, BN_CTX *, BIGNUM **, BIGNUM **)
118 {
119     return dsam->dsa_sign_setup;
120 }
121 
DSA_meth_set_sign_setup(DSA_METHOD * dsam,int (* sign_setup)(DSA *,BN_CTX *,BIGNUM **,BIGNUM **))122 int DSA_meth_set_sign_setup(DSA_METHOD *dsam,
123         int (*sign_setup) (DSA *, BN_CTX *, BIGNUM **, BIGNUM **))
124 {
125     dsam->dsa_sign_setup = sign_setup;
126     return 1;
127 }
128 
DSA_meth_get_verify(const DSA_METHOD * dsam)129 int (*DSA_meth_get_verify(const DSA_METHOD *dsam))
130         (const unsigned char *, int, DSA_SIG *, DSA *)
131 {
132     return dsam->dsa_do_verify;
133 }
134 
DSA_meth_set_verify(DSA_METHOD * dsam,int (* verify)(const unsigned char *,int,DSA_SIG *,DSA *))135 int DSA_meth_set_verify(DSA_METHOD *dsam,
136     int (*verify) (const unsigned char *, int, DSA_SIG *, DSA *))
137 {
138     dsam->dsa_do_verify = verify;
139     return 1;
140 }
141 
DSA_meth_get_mod_exp(const DSA_METHOD * dsam)142 int (*DSA_meth_get_mod_exp(const DSA_METHOD *dsam))
143         (DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *,
144          const BIGNUM *, const BIGNUM *, BN_CTX *, BN_MONT_CTX *)
145 {
146     return dsam->dsa_mod_exp;
147 }
148 
DSA_meth_set_mod_exp(DSA_METHOD * dsam,int (* mod_exp)(DSA *,BIGNUM *,const BIGNUM *,const BIGNUM *,const BIGNUM *,const BIGNUM *,const BIGNUM *,BN_CTX *,BN_MONT_CTX *))149 int DSA_meth_set_mod_exp(DSA_METHOD *dsam,
150     int (*mod_exp) (DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *,
151                     const BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *,
152                     BN_MONT_CTX *))
153 {
154     dsam->dsa_mod_exp = mod_exp;
155     return 1;
156 }
157 
DSA_meth_get_bn_mod_exp(const DSA_METHOD * dsam)158 int (*DSA_meth_get_bn_mod_exp(const DSA_METHOD *dsam))
159     (DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *,
160      BN_MONT_CTX *)
161 {
162     return dsam->bn_mod_exp;
163 }
164 
DSA_meth_set_bn_mod_exp(DSA_METHOD * dsam,int (* bn_mod_exp)(DSA *,BIGNUM *,const BIGNUM *,const BIGNUM *,const BIGNUM *,BN_CTX *,BN_MONT_CTX *))165 int DSA_meth_set_bn_mod_exp(DSA_METHOD *dsam,
166     int (*bn_mod_exp) (DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *,
167                        const BIGNUM *, BN_CTX *, BN_MONT_CTX *))
168 {
169     dsam->bn_mod_exp = bn_mod_exp;
170     return 1;
171 }
172 
DSA_meth_get_init(const DSA_METHOD * dsam)173 int (*DSA_meth_get_init(const DSA_METHOD *dsam))(DSA *)
174 {
175     return dsam->init;
176 }
177 
DSA_meth_set_init(DSA_METHOD * dsam,int (* init)(DSA *))178 int DSA_meth_set_init(DSA_METHOD *dsam, int (*init)(DSA *))
179 {
180     dsam->init = init;
181     return 1;
182 }
183 
DSA_meth_get_finish(const DSA_METHOD * dsam)184 int (*DSA_meth_get_finish(const DSA_METHOD *dsam)) (DSA *)
185 {
186     return dsam->finish;
187 }
188 
DSA_meth_set_finish(DSA_METHOD * dsam,int (* finish)(DSA *))189 int DSA_meth_set_finish(DSA_METHOD *dsam, int (*finish) (DSA *))
190 {
191     dsam->finish = finish;
192     return 1;
193 }
194 
DSA_meth_get_paramgen(const DSA_METHOD * dsam)195 int (*DSA_meth_get_paramgen(const DSA_METHOD *dsam))
196         (DSA *, int, const unsigned char *, int, int *, unsigned long *,
197          BN_GENCB *)
198 {
199     return dsam->dsa_paramgen;
200 }
201 
DSA_meth_set_paramgen(DSA_METHOD * dsam,int (* paramgen)(DSA *,int,const unsigned char *,int,int *,unsigned long *,BN_GENCB *))202 int DSA_meth_set_paramgen(DSA_METHOD *dsam,
203         int (*paramgen) (DSA *, int, const unsigned char *, int, int *,
204                          unsigned long *, BN_GENCB *))
205 {
206     dsam->dsa_paramgen = paramgen;
207     return 1;
208 }
209 
DSA_meth_get_keygen(const DSA_METHOD * dsam)210 int (*DSA_meth_get_keygen(const DSA_METHOD *dsam)) (DSA *)
211 {
212     return dsam->dsa_keygen;
213 }
214 
DSA_meth_set_keygen(DSA_METHOD * dsam,int (* keygen)(DSA *))215 int DSA_meth_set_keygen(DSA_METHOD *dsam, int (*keygen) (DSA *))
216 {
217     dsam->dsa_keygen = keygen;
218     return 1;
219 }
220 #endif
221