xref: /freebsd/crypto/openssl/crypto/dsa/dsa_meth.c (revision f25b8c9fb4f58cf61adb47d7570abe7caa6d385d)
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))(const unsigned char *, int, DSA *)
104 {
105     return dsam->dsa_do_sign;
106 }
107 
DSA_meth_set_sign(DSA_METHOD * dsam,DSA_SIG * (* sign)(const unsigned char *,int,DSA *))108 int DSA_meth_set_sign(DSA_METHOD *dsam,
109     DSA_SIG *(*sign)(const unsigned char *, int, DSA *))
110 {
111     dsam->dsa_do_sign = sign;
112     return 1;
113 }
114 
DSA_meth_get_sign_setup(const DSA_METHOD * dsam)115 int (*DSA_meth_get_sign_setup(const DSA_METHOD *dsam))(DSA *, BN_CTX *, BIGNUM **, BIGNUM **)
116 {
117     return dsam->dsa_sign_setup;
118 }
119 
DSA_meth_set_sign_setup(DSA_METHOD * dsam,int (* sign_setup)(DSA *,BN_CTX *,BIGNUM **,BIGNUM **))120 int DSA_meth_set_sign_setup(DSA_METHOD *dsam,
121     int (*sign_setup)(DSA *, BN_CTX *, BIGNUM **, BIGNUM **))
122 {
123     dsam->dsa_sign_setup = sign_setup;
124     return 1;
125 }
126 
DSA_meth_get_verify(const DSA_METHOD * dsam)127 int (*DSA_meth_get_verify(const DSA_METHOD *dsam))(const unsigned char *, int, DSA_SIG *, DSA *)
128 {
129     return dsam->dsa_do_verify;
130 }
131 
DSA_meth_set_verify(DSA_METHOD * dsam,int (* verify)(const unsigned char *,int,DSA_SIG *,DSA *))132 int DSA_meth_set_verify(DSA_METHOD *dsam,
133     int (*verify)(const unsigned char *, int, DSA_SIG *, DSA *))
134 {
135     dsam->dsa_do_verify = verify;
136     return 1;
137 }
138 
DSA_meth_get_mod_exp(const DSA_METHOD * dsam)139 int (*DSA_meth_get_mod_exp(const DSA_METHOD *dsam))(DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *,
140     const BIGNUM *, const BIGNUM *, BN_CTX *, BN_MONT_CTX *)
141 {
142     return dsam->dsa_mod_exp;
143 }
144 
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 *))145 int DSA_meth_set_mod_exp(DSA_METHOD *dsam,
146     int (*mod_exp)(DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *,
147         const BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *,
148         BN_MONT_CTX *))
149 {
150     dsam->dsa_mod_exp = mod_exp;
151     return 1;
152 }
153 
DSA_meth_get_bn_mod_exp(const DSA_METHOD * dsam)154 int (*DSA_meth_get_bn_mod_exp(const DSA_METHOD *dsam))(DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *,
155     BN_MONT_CTX *)
156 {
157     return dsam->bn_mod_exp;
158 }
159 
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 *))160 int DSA_meth_set_bn_mod_exp(DSA_METHOD *dsam,
161     int (*bn_mod_exp)(DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *,
162         const BIGNUM *, BN_CTX *, BN_MONT_CTX *))
163 {
164     dsam->bn_mod_exp = bn_mod_exp;
165     return 1;
166 }
167 
DSA_meth_get_init(const DSA_METHOD * dsam)168 int (*DSA_meth_get_init(const DSA_METHOD *dsam))(DSA *)
169 {
170     return dsam->init;
171 }
172 
DSA_meth_set_init(DSA_METHOD * dsam,int (* init)(DSA *))173 int DSA_meth_set_init(DSA_METHOD *dsam, int (*init)(DSA *))
174 {
175     dsam->init = init;
176     return 1;
177 }
178 
DSA_meth_get_finish(const DSA_METHOD * dsam)179 int (*DSA_meth_get_finish(const DSA_METHOD *dsam))(DSA *)
180 {
181     return dsam->finish;
182 }
183 
DSA_meth_set_finish(DSA_METHOD * dsam,int (* finish)(DSA *))184 int DSA_meth_set_finish(DSA_METHOD *dsam, int (*finish)(DSA *))
185 {
186     dsam->finish = finish;
187     return 1;
188 }
189 
DSA_meth_get_paramgen(const DSA_METHOD * dsam)190 int (*DSA_meth_get_paramgen(const DSA_METHOD *dsam))(DSA *, int, const unsigned char *, int, int *, unsigned long *,
191     BN_GENCB *)
192 {
193     return dsam->dsa_paramgen;
194 }
195 
DSA_meth_set_paramgen(DSA_METHOD * dsam,int (* paramgen)(DSA *,int,const unsigned char *,int,int *,unsigned long *,BN_GENCB *))196 int DSA_meth_set_paramgen(DSA_METHOD *dsam,
197     int (*paramgen)(DSA *, int, const unsigned char *, int, int *,
198         unsigned long *, BN_GENCB *))
199 {
200     dsam->dsa_paramgen = paramgen;
201     return 1;
202 }
203 
DSA_meth_get_keygen(const DSA_METHOD * dsam)204 int (*DSA_meth_get_keygen(const DSA_METHOD *dsam))(DSA *)
205 {
206     return dsam->dsa_keygen;
207 }
208 
DSA_meth_set_keygen(DSA_METHOD * dsam,int (* keygen)(DSA *))209 int DSA_meth_set_keygen(DSA_METHOD *dsam, int (*keygen)(DSA *))
210 {
211     dsam->dsa_keygen = keygen;
212     return 1;
213 }
214 #endif
215