Remove useless NULL checks
[openssl.git] / crypto / dsa / dsa_meth.c
1 /*
2  * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the OpenSSL license (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 OpenSSL licenses, (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_locl.h"
19 #include <string.h>
20 #include <openssl/err.h>
21
22 DSA_METHOD *DSA_meth_new(const char *name, int flags)
23 {
24     DSA_METHOD *dsam = OPENSSL_zalloc(sizeof(DSA_METHOD));
25
26     if (dsam != NULL) {
27         dsam->name = OPENSSL_strdup(name);
28         if (dsam->name == NULL) {
29             OPENSSL_free(dsam);
30             DSAerr(DSA_F_DSA_METH_NEW, ERR_R_MALLOC_FAILURE);
31             return NULL;
32         }
33         dsam->flags = flags;
34     }
35
36     return dsam;
37 }
38
39 void DSA_meth_free(DSA_METHOD *dsam)
40 {
41     if (dsam != NULL) {
42         OPENSSL_free(dsam->name);
43         OPENSSL_free(dsam);
44     }
45 }
46
47 DSA_METHOD *DSA_meth_dup(const DSA_METHOD *dsam)
48 {
49     DSA_METHOD *ret;
50
51     ret = OPENSSL_malloc(sizeof(DSA_METHOD));
52
53     if (ret != NULL) {
54         memcpy(ret, dsam, sizeof(*dsam));
55         ret->name = OPENSSL_strdup(dsam->name);
56         if (ret->name == NULL) {
57             OPENSSL_free(ret);
58             DSAerr(DSA_F_DSA_METH_DUP, ERR_R_MALLOC_FAILURE);
59             return NULL;
60         }
61     }
62
63     return ret;
64 }
65
66 const char *DSA_meth_get0_name(const DSA_METHOD *dsam)
67 {
68     return dsam->name;
69 }
70
71 int DSA_meth_set1_name(DSA_METHOD *dsam, const char *name)
72 {
73     char *tmpname;
74
75     tmpname = OPENSSL_strdup(name);
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(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 *, BIGNUM *, BIGNUM *, BIGNUM *, BIGNUM *, BIGNUM *,
150          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 *, BIGNUM *, BIGNUM *, BIGNUM *, BIGNUM *,
157                     BIGNUM *, BN_CTX *, BN_MONT_CTX *))
158 {
159     dsam->dsa_mod_exp = mod_exp;
160     return 1;
161 }
162
163 int (*DSA_meth_get_bn_mod_exp(const DSA_METHOD *dsam))
164     (DSA *, BIGNUM *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *,
165      BN_MONT_CTX *)
166 {
167     return dsam->bn_mod_exp;
168 }
169
170 int DSA_meth_set_bn_mod_exp(DSA_METHOD *dsam,
171     int (*bn_mod_exp) (DSA *, BIGNUM *, BIGNUM *, const BIGNUM *,
172                        const BIGNUM *, BN_CTX *, BN_MONT_CTX *))
173 {
174     dsam->bn_mod_exp = bn_mod_exp;
175     return 1;
176 }
177
178 int (*DSA_meth_get_init(const DSA_METHOD *dsam))(DSA *)
179 {
180     return dsam->init;
181 }
182
183 int DSA_meth_set_init(DSA_METHOD *dsam, int (*init)(DSA *))
184 {
185     dsam->init = init;
186     return 1;
187 }
188
189 int (*DSA_meth_get_finish(const DSA_METHOD *dsam)) (DSA *)
190 {
191     return dsam->finish;
192 }
193
194 int DSA_meth_set_finish(DSA_METHOD *dsam, int (*finish) (DSA *))
195 {
196     dsam->finish = finish;
197     return 1;
198 }
199
200 int (*DSA_meth_get_paramgen(const DSA_METHOD *dsam))
201         (DSA *, int, const unsigned char *, int, int *, unsigned long *,
202          BN_GENCB *)
203 {
204     return dsam->dsa_paramgen;
205 }
206
207 int DSA_meth_set_paramgen(DSA_METHOD *dsam,
208         int (*paramgen) (DSA *, int, const unsigned char *, int, int *,
209                          unsigned long *, BN_GENCB *))
210 {
211     dsam->dsa_paramgen = paramgen;
212     return 1;
213 }
214
215 int (*DSA_meth_get_keygen(const DSA_METHOD *dsam)) (DSA *)
216 {
217     return dsam->dsa_keygen;
218 }
219
220 int DSA_meth_set_keygen(DSA_METHOD *dsam, int (*keygen) (DSA *))
221 {
222     dsam->dsa_keygen = keygen;
223     return 1;
224 }