When strict SCT fails record verification failure
[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         if (dsam->name != NULL)
43             OPENSSL_free(dsam->name);
44         OPENSSL_free(dsam);
45     }
46 }
47
48 DSA_METHOD *DSA_meth_dup(const DSA_METHOD *dsam)
49 {
50     DSA_METHOD *ret;
51
52     ret = OPENSSL_malloc(sizeof(DSA_METHOD));
53
54     if (ret != NULL) {
55         memcpy(ret, dsam, sizeof(*dsam));
56         ret->name = OPENSSL_strdup(dsam->name);
57         if (ret->name == NULL) {
58             OPENSSL_free(ret);
59             DSAerr(DSA_F_DSA_METH_DUP, ERR_R_MALLOC_FAILURE);
60             return NULL;
61         }
62     }
63
64     return ret;
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;
75
76     tmpname = OPENSSL_strdup(name);
77     if (tmpname == NULL) {
78         DSAerr(DSA_F_DSA_METH_SET1_NAME, ERR_R_MALLOC_FAILURE);
79         return 0;
80     }
81
82     OPENSSL_free(dsam->name);
83     dsam->name = tmpname;
84
85     return 1;
86 }
87
88 int DSA_meth_get_flags(DSA_METHOD *dsam)
89 {
90     return dsam->flags;
91 }
92
93 int DSA_meth_set_flags(DSA_METHOD *dsam, int flags)
94 {
95     dsam->flags = flags;
96     return 1;
97 }
98
99 void *DSA_meth_get0_app_data(const DSA_METHOD *dsam)
100 {
101     return dsam->app_data;
102 }
103
104 int DSA_meth_set0_app_data(DSA_METHOD *dsam, void *app_data)
105 {
106     dsam->app_data = app_data;
107     return 1;
108 }
109
110 DSA_SIG *(*DSA_meth_get_sign(const DSA_METHOD *dsam))
111         (const unsigned char *, int, DSA *)
112 {
113     return dsam->dsa_do_sign;
114 }
115
116 int DSA_meth_set_sign(DSA_METHOD *dsam,
117                        DSA_SIG *(*sign) (const unsigned char *, int, DSA *))
118 {
119     dsam->dsa_do_sign = sign;
120     return 1;
121 }
122
123 int (*DSA_meth_get_sign_setup(const DSA_METHOD *dsam))
124         (DSA *, BN_CTX *, BIGNUM **, BIGNUM **)
125 {
126     return dsam->dsa_sign_setup;
127 }
128
129 int DSA_meth_set_sign_setup(DSA_METHOD *dsam,
130         int (*sign_setup) (DSA *, BN_CTX *, BIGNUM **, BIGNUM **))
131 {
132     dsam->dsa_sign_setup = sign_setup;
133     return 1;
134 }
135
136 int (*DSA_meth_get_verify(const DSA_METHOD *dsam))
137         (const unsigned char *, int , DSA_SIG *, DSA *)
138 {
139     return dsam->dsa_do_verify;
140 }
141
142 int DSA_meth_set_verify(DSA_METHOD *dsam,
143     int (*verify) (const unsigned char *, int, DSA_SIG *, DSA *))
144 {
145     dsam->dsa_do_verify = verify;
146     return 1;
147 }
148
149 int (*DSA_meth_get_mod_exp(const DSA_METHOD *dsam))
150         (DSA *, BIGNUM *, BIGNUM *, BIGNUM *, BIGNUM *, BIGNUM *, BIGNUM *,
151          BN_CTX *, BN_MONT_CTX *)
152 {
153     return dsam->dsa_mod_exp;
154 }
155
156 int DSA_meth_set_mod_exp(DSA_METHOD *dsam,
157     int (*mod_exp) (DSA *, BIGNUM *, BIGNUM *, BIGNUM *, BIGNUM *, BIGNUM *,
158                     BIGNUM *, BN_CTX *, 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 *, 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 *, 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 }