]>
Commit | Line | Data |
---|---|---|
4889dadc | 1 | /* |
33388b44 | 2 | * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved. |
4889dadc MC |
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 | ||
f41ac0ee P |
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 | ||
505b41fc RL |
16 | #include <string.h> |
17 | ||
4889dadc | 18 | #include <openssl/crypto.h> |
23c48d94 | 19 | #include <openssl/core_dispatch.h> |
4889dadc | 20 | #include <openssl/core_names.h> |
505b41fc | 21 | #include <openssl/err.h> |
4889dadc MC |
22 | #include <openssl/dsa.h> |
23 | #include <openssl/params.h> | |
45a845e4 | 24 | #include <openssl/evp.h> |
8bee6512 | 25 | #include <openssl/err.h> |
505b41fc | 26 | #include "internal/nelem.h" |
c24937d5 | 27 | #include "internal/sizes.h" |
8c555803 | 28 | #include "internal/cryptlib.h" |
f590a5ea | 29 | #include "prov/providercommon.h" |
af3e7e1b | 30 | #include "prov/implementations.h" |
8bee6512 | 31 | #include "prov/providercommonerr.h" |
ddd21319 | 32 | #include "prov/provider_ctx.h" |
e683582b | 33 | #include "crypto/dsa.h" |
8c555803 | 34 | #include "prov/der_dsa.h" |
4889dadc | 35 | |
363b1e5d DMSP |
36 | static OSSL_FUNC_signature_newctx_fn dsa_newctx; |
37 | static OSSL_FUNC_signature_sign_init_fn dsa_signature_init; | |
38 | static OSSL_FUNC_signature_verify_init_fn dsa_signature_init; | |
39 | static OSSL_FUNC_signature_sign_fn dsa_sign; | |
40 | static OSSL_FUNC_signature_verify_fn dsa_verify; | |
41 | static OSSL_FUNC_signature_digest_sign_init_fn dsa_digest_signverify_init; | |
42 | static OSSL_FUNC_signature_digest_sign_update_fn dsa_digest_signverify_update; | |
43 | static OSSL_FUNC_signature_digest_sign_final_fn dsa_digest_sign_final; | |
44 | static OSSL_FUNC_signature_digest_verify_init_fn dsa_digest_signverify_init; | |
45 | static OSSL_FUNC_signature_digest_verify_update_fn dsa_digest_signverify_update; | |
46 | static OSSL_FUNC_signature_digest_verify_final_fn dsa_digest_verify_final; | |
47 | static OSSL_FUNC_signature_freectx_fn dsa_freectx; | |
48 | static OSSL_FUNC_signature_dupctx_fn dsa_dupctx; | |
49 | static OSSL_FUNC_signature_get_ctx_params_fn dsa_get_ctx_params; | |
50 | static OSSL_FUNC_signature_gettable_ctx_params_fn dsa_gettable_ctx_params; | |
51 | static OSSL_FUNC_signature_set_ctx_params_fn dsa_set_ctx_params; | |
52 | static OSSL_FUNC_signature_settable_ctx_params_fn dsa_settable_ctx_params; | |
53 | static OSSL_FUNC_signature_get_ctx_md_params_fn dsa_get_ctx_md_params; | |
54 | static OSSL_FUNC_signature_gettable_ctx_md_params_fn dsa_gettable_ctx_md_params; | |
55 | static OSSL_FUNC_signature_set_ctx_md_params_fn dsa_set_ctx_md_params; | |
56 | static OSSL_FUNC_signature_settable_ctx_md_params_fn dsa_settable_ctx_md_params; | |
4889dadc MC |
57 | |
58 | /* | |
59 | * What's passed as an actual key is defined by the KEYMGMT interface. | |
60 | * We happen to know that our KEYMGMT simply passes DSA structures, so | |
61 | * we use that here too. | |
62 | */ | |
63 | ||
64 | typedef struct { | |
45a845e4 | 65 | OPENSSL_CTX *libctx; |
2c6094ba | 66 | char *propq; |
4889dadc | 67 | DSA *dsa; |
8bee6512 RL |
68 | |
69 | /* | |
70 | * Flag to determine if the hash function can be changed (1) or not (0) | |
71 | * Because it's dangerous to change during a DigestSign or DigestVerify | |
72 | * operation, this flag is cleared by their Init function, and set again | |
73 | * by their Final function. | |
74 | */ | |
75 | unsigned int flag_allow_md : 1; | |
76 | ||
c24937d5 | 77 | char mdname[OSSL_MAX_NAME_SIZE]; |
505b41fc | 78 | |
edd3b7a3 | 79 | /* The Algorithm Identifier of the combined signature algorithm */ |
8c555803 RL |
80 | unsigned char aid_buf[OSSL_MAX_ALGORITHM_ID_SIZE]; |
81 | unsigned char *aid; | |
505b41fc RL |
82 | size_t aid_len; |
83 | ||
84 | /* main digest */ | |
45a845e4 MC |
85 | EVP_MD *md; |
86 | EVP_MD_CTX *mdctx; | |
8bee6512 | 87 | size_t mdsize; |
4889dadc MC |
88 | } PROV_DSA_CTX; |
89 | ||
8bee6512 RL |
90 | static size_t dsa_get_md_size(const PROV_DSA_CTX *pdsactx) |
91 | { | |
92 | if (pdsactx->md != NULL) | |
93 | return EVP_MD_size(pdsactx->md); | |
94 | return 0; | |
95 | } | |
96 | ||
97 | static int dsa_get_md_nid(const EVP_MD *md) | |
98 | { | |
99 | /* | |
100 | * Because the DSA library deals with NIDs, we need to translate. | |
101 | * We do so using EVP_MD_is_a(), and therefore need a name to NID | |
102 | * map. | |
103 | */ | |
104 | static const OSSL_ITEM name_to_nid[] = { | |
105 | { NID_sha1, OSSL_DIGEST_NAME_SHA1 }, | |
106 | { NID_sha224, OSSL_DIGEST_NAME_SHA2_224 }, | |
107 | { NID_sha256, OSSL_DIGEST_NAME_SHA2_256 }, | |
108 | { NID_sha384, OSSL_DIGEST_NAME_SHA2_384 }, | |
109 | { NID_sha512, OSSL_DIGEST_NAME_SHA2_512 }, | |
110 | { NID_sha3_224, OSSL_DIGEST_NAME_SHA3_224 }, | |
111 | { NID_sha3_256, OSSL_DIGEST_NAME_SHA3_256 }, | |
112 | { NID_sha3_384, OSSL_DIGEST_NAME_SHA3_384 }, | |
113 | { NID_sha3_512, OSSL_DIGEST_NAME_SHA3_512 }, | |
114 | }; | |
115 | size_t i; | |
116 | int mdnid = NID_undef; | |
117 | ||
118 | if (md == NULL) | |
119 | goto end; | |
120 | ||
121 | for (i = 0; i < OSSL_NELEM(name_to_nid); i++) { | |
122 | if (EVP_MD_is_a(md, name_to_nid[i].ptr)) { | |
123 | mdnid = (int)name_to_nid[i].id; | |
124 | break; | |
125 | } | |
126 | } | |
127 | ||
128 | if (mdnid == NID_undef) | |
129 | ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_DIGEST); | |
130 | ||
131 | end: | |
132 | return mdnid; | |
133 | } | |
134 | ||
2c6094ba | 135 | static void *dsa_newctx(void *provctx, const char *propq) |
4889dadc | 136 | { |
f590a5ea P |
137 | PROV_DSA_CTX *pdsactx; |
138 | ||
139 | if (!ossl_prov_is_running()) | |
140 | return NULL; | |
45a845e4 | 141 | |
f590a5ea | 142 | pdsactx = OPENSSL_zalloc(sizeof(PROV_DSA_CTX)); |
45a845e4 MC |
143 | if (pdsactx == NULL) |
144 | return NULL; | |
145 | ||
146 | pdsactx->libctx = PROV_LIBRARY_CONTEXT_OF(provctx); | |
8bee6512 | 147 | pdsactx->flag_allow_md = 1; |
2c6094ba RL |
148 | if (propq != NULL && (pdsactx->propq = OPENSSL_strdup(propq)) == NULL) { |
149 | OPENSSL_free(pdsactx); | |
150 | pdsactx = NULL; | |
151 | ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE); | |
152 | } | |
45a845e4 | 153 | return pdsactx; |
4889dadc MC |
154 | } |
155 | ||
8bee6512 RL |
156 | static int dsa_setup_md(PROV_DSA_CTX *ctx, |
157 | const char *mdname, const char *mdprops) | |
158 | { | |
2c6094ba RL |
159 | if (mdprops == NULL) |
160 | mdprops = ctx->propq; | |
161 | ||
8bee6512 RL |
162 | if (mdname != NULL) { |
163 | EVP_MD *md = EVP_MD_fetch(ctx->libctx, mdname, mdprops); | |
164 | int md_nid = dsa_get_md_nid(md); | |
8c555803 | 165 | WPACKET pkt; |
8bee6512 | 166 | |
8c555803 | 167 | if (md == NULL || md_nid == NID_undef) { |
8bee6512 RL |
168 | EVP_MD_free(md); |
169 | return 0; | |
170 | } | |
171 | ||
8c555803 RL |
172 | EVP_MD_CTX_free(ctx->mdctx); |
173 | EVP_MD_free(ctx->md); | |
174 | ||
175 | /* | |
176 | * TODO(3.0) Should we care about DER writing errors? | |
177 | * All it really means is that for some reason, there's no | |
178 | * AlgorithmIdentifier to be had, but the operation itself is | |
179 | * still valid, just as long as it's not used to construct | |
180 | * anything that needs an AlgorithmIdentifier. | |
181 | */ | |
182 | ctx->aid_len = 0; | |
183 | if (WPACKET_init_der(&pkt, ctx->aid_buf, sizeof(ctx->aid_buf)) | |
a30027b6 RL |
184 | && DER_w_algorithmIdentifier_DSA_with_MD(&pkt, -1, ctx->dsa, |
185 | md_nid) | |
8c555803 RL |
186 | && WPACKET_finish(&pkt)) { |
187 | WPACKET_get_total_written(&pkt, &ctx->aid_len); | |
188 | ctx->aid = WPACKET_get_curr(&pkt); | |
189 | } | |
190 | WPACKET_cleanup(&pkt); | |
191 | ||
192 | ctx->mdctx = NULL; | |
8bee6512 RL |
193 | ctx->md = md; |
194 | OPENSSL_strlcpy(ctx->mdname, mdname, sizeof(ctx->mdname)); | |
195 | } | |
196 | return 1; | |
197 | } | |
198 | ||
390acbeb | 199 | static int dsa_signature_init(void *vpdsactx, void *vdsa) |
4889dadc MC |
200 | { |
201 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; | |
202 | ||
f590a5ea P |
203 | if (!ossl_prov_is_running() |
204 | || pdsactx == NULL | |
205 | || vdsa == NULL | |
206 | || !DSA_up_ref(vdsa)) | |
4889dadc MC |
207 | return 0; |
208 | DSA_free(pdsactx->dsa); | |
209 | pdsactx->dsa = vdsa; | |
210 | return 1; | |
211 | } | |
212 | ||
213 | static int dsa_sign(void *vpdsactx, unsigned char *sig, size_t *siglen, | |
214 | size_t sigsize, const unsigned char *tbs, size_t tbslen) | |
215 | { | |
216 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; | |
217 | int ret; | |
218 | unsigned int sltmp; | |
219 | size_t dsasize = DSA_size(pdsactx->dsa); | |
8bee6512 | 220 | size_t mdsize = dsa_get_md_size(pdsactx); |
4889dadc | 221 | |
f590a5ea P |
222 | if (!ossl_prov_is_running()) |
223 | return 0; | |
224 | ||
4889dadc MC |
225 | if (sig == NULL) { |
226 | *siglen = dsasize; | |
227 | return 1; | |
228 | } | |
229 | ||
230 | if (sigsize < (size_t)dsasize) | |
231 | return 0; | |
232 | ||
8bee6512 | 233 | if (mdsize != 0 && tbslen != mdsize) |
4889dadc MC |
234 | return 0; |
235 | ||
8083fd3a | 236 | ret = dsa_sign_int(0, tbs, tbslen, sig, &sltmp, pdsactx->dsa); |
4889dadc MC |
237 | if (ret <= 0) |
238 | return 0; | |
239 | ||
240 | *siglen = sltmp; | |
241 | return 1; | |
242 | } | |
243 | ||
390acbeb MC |
244 | static int dsa_verify(void *vpdsactx, const unsigned char *sig, size_t siglen, |
245 | const unsigned char *tbs, size_t tbslen) | |
246 | { | |
247 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; | |
8bee6512 | 248 | size_t mdsize = dsa_get_md_size(pdsactx); |
390acbeb | 249 | |
f590a5ea | 250 | if (!ossl_prov_is_running() || (mdsize != 0 && tbslen != mdsize)) |
390acbeb MC |
251 | return 0; |
252 | ||
253 | return DSA_verify(0, tbs, tbslen, sig, siglen, pdsactx->dsa); | |
254 | } | |
255 | ||
45a845e4 | 256 | static int dsa_digest_signverify_init(void *vpdsactx, const char *mdname, |
2c6094ba | 257 | void *vdsa) |
45a845e4 MC |
258 | { |
259 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; | |
45a845e4 | 260 | |
f590a5ea P |
261 | if (!ossl_prov_is_running()) |
262 | return 0; | |
263 | ||
8bee6512 | 264 | pdsactx->flag_allow_md = 0; |
45a845e4 MC |
265 | if (!dsa_signature_init(vpdsactx, vdsa)) |
266 | return 0; | |
267 | ||
2c6094ba | 268 | if (!dsa_setup_md(pdsactx, mdname, NULL)) |
8bee6512 | 269 | return 0; |
505b41fc | 270 | |
45a845e4 MC |
271 | pdsactx->mdctx = EVP_MD_CTX_new(); |
272 | if (pdsactx->mdctx == NULL) | |
505b41fc | 273 | goto error; |
45a845e4 | 274 | |
505b41fc RL |
275 | if (!EVP_DigestInit_ex(pdsactx->mdctx, pdsactx->md, NULL)) |
276 | goto error; | |
45a845e4 MC |
277 | |
278 | return 1; | |
505b41fc RL |
279 | |
280 | error: | |
281 | EVP_MD_CTX_free(pdsactx->mdctx); | |
282 | EVP_MD_free(pdsactx->md); | |
283 | pdsactx->mdctx = NULL; | |
505b41fc RL |
284 | pdsactx->md = NULL; |
285 | return 0; | |
45a845e4 MC |
286 | } |
287 | ||
288 | int dsa_digest_signverify_update(void *vpdsactx, const unsigned char *data, | |
289 | size_t datalen) | |
290 | { | |
291 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; | |
292 | ||
293 | if (pdsactx == NULL || pdsactx->mdctx == NULL) | |
294 | return 0; | |
295 | ||
296 | return EVP_DigestUpdate(pdsactx->mdctx, data, datalen); | |
297 | } | |
298 | ||
299 | int dsa_digest_sign_final(void *vpdsactx, unsigned char *sig, size_t *siglen, | |
300 | size_t sigsize) | |
301 | { | |
302 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; | |
303 | unsigned char digest[EVP_MAX_MD_SIZE]; | |
304 | unsigned int dlen = 0; | |
305 | ||
f590a5ea | 306 | if (!ossl_prov_is_running() || pdsactx == NULL || pdsactx->mdctx == NULL) |
45a845e4 MC |
307 | return 0; |
308 | ||
309 | /* | |
310 | * If sig is NULL then we're just finding out the sig size. Other fields | |
311 | * are ignored. Defer to dsa_sign. | |
312 | */ | |
313 | if (sig != NULL) { | |
314 | /* | |
315 | * TODO(3.0): There is the possibility that some externally provided | |
316 | * digests exceed EVP_MAX_MD_SIZE. We should probably handle that somehow - | |
317 | * but that problem is much larger than just in DSA. | |
318 | */ | |
319 | if (!EVP_DigestFinal_ex(pdsactx->mdctx, digest, &dlen)) | |
320 | return 0; | |
321 | } | |
322 | ||
8bee6512 RL |
323 | pdsactx->flag_allow_md = 1; |
324 | ||
45a845e4 MC |
325 | return dsa_sign(vpdsactx, sig, siglen, sigsize, digest, (size_t)dlen); |
326 | } | |
327 | ||
328 | ||
329 | int dsa_digest_verify_final(void *vpdsactx, const unsigned char *sig, | |
330 | size_t siglen) | |
331 | { | |
332 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; | |
333 | unsigned char digest[EVP_MAX_MD_SIZE]; | |
334 | unsigned int dlen = 0; | |
335 | ||
f590a5ea | 336 | if (!ossl_prov_is_running() || pdsactx == NULL || pdsactx->mdctx == NULL) |
45a845e4 MC |
337 | return 0; |
338 | ||
339 | /* | |
340 | * TODO(3.0): There is the possibility that some externally provided | |
341 | * digests exceed EVP_MAX_MD_SIZE. We should probably handle that somehow - | |
342 | * but that problem is much larger than just in DSA. | |
343 | */ | |
344 | if (!EVP_DigestFinal_ex(pdsactx->mdctx, digest, &dlen)) | |
345 | return 0; | |
346 | ||
8bee6512 RL |
347 | pdsactx->flag_allow_md = 1; |
348 | ||
45a845e4 MC |
349 | return dsa_verify(vpdsactx, sig, siglen, digest, (size_t)dlen); |
350 | } | |
390acbeb | 351 | |
4889dadc MC |
352 | static void dsa_freectx(void *vpdsactx) |
353 | { | |
4f2271d5 SL |
354 | PROV_DSA_CTX *ctx = (PROV_DSA_CTX *)vpdsactx; |
355 | ||
356 | OPENSSL_free(ctx->propq); | |
357 | EVP_MD_CTX_free(ctx->mdctx); | |
358 | EVP_MD_free(ctx->md); | |
359 | ctx->propq = NULL; | |
360 | ctx->mdctx = NULL; | |
361 | ctx->md = NULL; | |
362 | ctx->mdsize = 0; | |
363 | DSA_free(ctx->dsa); | |
364 | OPENSSL_free(ctx); | |
4889dadc MC |
365 | } |
366 | ||
367 | static void *dsa_dupctx(void *vpdsactx) | |
368 | { | |
369 | PROV_DSA_CTX *srcctx = (PROV_DSA_CTX *)vpdsactx; | |
370 | PROV_DSA_CTX *dstctx; | |
371 | ||
f590a5ea P |
372 | if (!ossl_prov_is_running()) |
373 | return NULL; | |
374 | ||
4889dadc MC |
375 | dstctx = OPENSSL_zalloc(sizeof(*srcctx)); |
376 | if (dstctx == NULL) | |
377 | return NULL; | |
378 | ||
379 | *dstctx = *srcctx; | |
45a845e4 MC |
380 | dstctx->dsa = NULL; |
381 | dstctx->md = NULL; | |
382 | dstctx->mdctx = NULL; | |
383 | ||
384 | if (srcctx->dsa != NULL && !DSA_up_ref(srcctx->dsa)) | |
385 | goto err; | |
386 | dstctx->dsa = srcctx->dsa; | |
387 | ||
388 | if (srcctx->md != NULL && !EVP_MD_up_ref(srcctx->md)) | |
389 | goto err; | |
390 | dstctx->md = srcctx->md; | |
391 | ||
392 | if (srcctx->mdctx != NULL) { | |
393 | dstctx->mdctx = EVP_MD_CTX_new(); | |
394 | if (dstctx->mdctx == NULL | |
395 | || !EVP_MD_CTX_copy_ex(dstctx->mdctx, srcctx->mdctx)) | |
396 | goto err; | |
4889dadc MC |
397 | } |
398 | ||
399 | return dstctx; | |
45a845e4 MC |
400 | err: |
401 | dsa_freectx(dstctx); | |
402 | return NULL; | |
4889dadc MC |
403 | } |
404 | ||
9c45222d MC |
405 | static int dsa_get_ctx_params(void *vpdsactx, OSSL_PARAM *params) |
406 | { | |
407 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; | |
408 | OSSL_PARAM *p; | |
409 | ||
410 | if (pdsactx == NULL || params == NULL) | |
411 | return 0; | |
412 | ||
505b41fc RL |
413 | p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_ALGORITHM_ID); |
414 | if (p != NULL | |
415 | && !OSSL_PARAM_set_octet_string(p, pdsactx->aid, pdsactx->aid_len)) | |
416 | return 0; | |
417 | ||
9c45222d | 418 | p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_DIGEST); |
8bee6512 | 419 | if (p != NULL && !OSSL_PARAM_set_utf8_string(p, pdsactx->mdname)) |
9c45222d MC |
420 | return 0; |
421 | ||
422 | return 1; | |
423 | } | |
424 | ||
425 | static const OSSL_PARAM known_gettable_ctx_params[] = { | |
505b41fc | 426 | OSSL_PARAM_octet_string(OSSL_SIGNATURE_PARAM_ALGORITHM_ID, NULL, 0), |
9c45222d MC |
427 | OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, NULL, 0), |
428 | OSSL_PARAM_END | |
429 | }; | |
430 | ||
1017ab21 | 431 | static const OSSL_PARAM *dsa_gettable_ctx_params(ossl_unused void *provctx) |
9c45222d MC |
432 | { |
433 | return known_gettable_ctx_params; | |
434 | } | |
435 | ||
436 | static int dsa_set_ctx_params(void *vpdsactx, const OSSL_PARAM params[]) | |
4889dadc MC |
437 | { |
438 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; | |
439 | const OSSL_PARAM *p; | |
4889dadc MC |
440 | |
441 | if (pdsactx == NULL || params == NULL) | |
442 | return 0; | |
443 | ||
9c45222d | 444 | p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_DIGEST); |
8bee6512 RL |
445 | /* Not allowed during certain operations */ |
446 | if (p != NULL && !pdsactx->flag_allow_md) | |
9c45222d | 447 | return 0; |
8bee6512 RL |
448 | if (p != NULL) { |
449 | char mdname[OSSL_MAX_NAME_SIZE] = "", *pmdname = mdname; | |
450 | char mdprops[OSSL_MAX_PROPQUERY_SIZE] = "", *pmdprops = mdprops; | |
451 | const OSSL_PARAM *propsp = | |
452 | OSSL_PARAM_locate_const(params, | |
453 | OSSL_SIGNATURE_PARAM_PROPERTIES); | |
454 | ||
455 | if (!OSSL_PARAM_get_utf8_string(p, &pmdname, sizeof(mdname))) | |
456 | return 0; | |
457 | if (propsp != NULL | |
458 | && !OSSL_PARAM_get_utf8_string(propsp, &pmdprops, sizeof(mdprops))) | |
459 | return 0; | |
460 | if (!dsa_setup_md(pdsactx, mdname, mdprops)) | |
461 | return 0; | |
462 | } | |
4889dadc MC |
463 | |
464 | return 1; | |
465 | } | |
466 | ||
9c45222d | 467 | static const OSSL_PARAM known_settable_ctx_params[] = { |
9c45222d | 468 | OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, NULL, 0), |
b8086652 | 469 | OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_PROPERTIES, NULL, 0), |
9c45222d MC |
470 | OSSL_PARAM_END |
471 | }; | |
472 | ||
1017ab21 | 473 | static const OSSL_PARAM *dsa_settable_ctx_params(ossl_unused void *provctx) |
9c45222d | 474 | { |
45a845e4 MC |
475 | /* |
476 | * TODO(3.0): Should this function return a different set of settable ctx | |
477 | * params if the ctx is being used for a DigestSign/DigestVerify? In that | |
478 | * case it is not allowed to set the digest size/digest name because the | |
479 | * digest is explicitly set as part of the init. | |
480 | */ | |
9c45222d MC |
481 | return known_settable_ctx_params; |
482 | } | |
483 | ||
45a845e4 MC |
484 | static int dsa_get_ctx_md_params(void *vpdsactx, OSSL_PARAM *params) |
485 | { | |
486 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; | |
487 | ||
488 | if (pdsactx->mdctx == NULL) | |
489 | return 0; | |
490 | ||
491 | return EVP_MD_CTX_get_params(pdsactx->mdctx, params); | |
492 | } | |
493 | ||
494 | static const OSSL_PARAM *dsa_gettable_ctx_md_params(void *vpdsactx) | |
495 | { | |
496 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; | |
497 | ||
498 | if (pdsactx->md == NULL) | |
499 | return 0; | |
500 | ||
501 | return EVP_MD_gettable_ctx_params(pdsactx->md); | |
502 | } | |
503 | ||
504 | static int dsa_set_ctx_md_params(void *vpdsactx, const OSSL_PARAM params[]) | |
505 | { | |
506 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; | |
507 | ||
508 | if (pdsactx->mdctx == NULL) | |
509 | return 0; | |
510 | ||
511 | return EVP_MD_CTX_set_params(pdsactx->mdctx, params); | |
512 | } | |
513 | ||
514 | static const OSSL_PARAM *dsa_settable_ctx_md_params(void *vpdsactx) | |
515 | { | |
516 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; | |
517 | ||
518 | if (pdsactx->md == NULL) | |
519 | return 0; | |
520 | ||
521 | return EVP_MD_settable_ctx_params(pdsactx->md); | |
522 | } | |
523 | ||
4889dadc MC |
524 | const OSSL_DISPATCH dsa_signature_functions[] = { |
525 | { OSSL_FUNC_SIGNATURE_NEWCTX, (void (*)(void))dsa_newctx }, | |
390acbeb | 526 | { OSSL_FUNC_SIGNATURE_SIGN_INIT, (void (*)(void))dsa_signature_init }, |
4889dadc | 527 | { OSSL_FUNC_SIGNATURE_SIGN, (void (*)(void))dsa_sign }, |
390acbeb MC |
528 | { OSSL_FUNC_SIGNATURE_VERIFY_INIT, (void (*)(void))dsa_signature_init }, |
529 | { OSSL_FUNC_SIGNATURE_VERIFY, (void (*)(void))dsa_verify }, | |
45a845e4 MC |
530 | { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT, |
531 | (void (*)(void))dsa_digest_signverify_init }, | |
532 | { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_UPDATE, | |
533 | (void (*)(void))dsa_digest_signverify_update }, | |
534 | { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_FINAL, | |
535 | (void (*)(void))dsa_digest_sign_final }, | |
536 | { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT, | |
537 | (void (*)(void))dsa_digest_signverify_init }, | |
538 | { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_UPDATE, | |
539 | (void (*)(void))dsa_digest_signverify_update }, | |
540 | { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_FINAL, | |
541 | (void (*)(void))dsa_digest_verify_final }, | |
4889dadc MC |
542 | { OSSL_FUNC_SIGNATURE_FREECTX, (void (*)(void))dsa_freectx }, |
543 | { OSSL_FUNC_SIGNATURE_DUPCTX, (void (*)(void))dsa_dupctx }, | |
9c45222d MC |
544 | { OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS, (void (*)(void))dsa_get_ctx_params }, |
545 | { OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS, | |
546 | (void (*)(void))dsa_gettable_ctx_params }, | |
547 | { OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS, (void (*)(void))dsa_set_ctx_params }, | |
548 | { OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS, | |
549 | (void (*)(void))dsa_settable_ctx_params }, | |
45a845e4 MC |
550 | { OSSL_FUNC_SIGNATURE_GET_CTX_MD_PARAMS, |
551 | (void (*)(void))dsa_get_ctx_md_params }, | |
552 | { OSSL_FUNC_SIGNATURE_GETTABLE_CTX_MD_PARAMS, | |
553 | (void (*)(void))dsa_gettable_ctx_md_params }, | |
554 | { OSSL_FUNC_SIGNATURE_SET_CTX_MD_PARAMS, | |
555 | (void (*)(void))dsa_set_ctx_md_params }, | |
556 | { OSSL_FUNC_SIGNATURE_SETTABLE_CTX_MD_PARAMS, | |
557 | (void (*)(void))dsa_settable_ctx_md_params }, | |
4889dadc MC |
558 | { 0, NULL } |
559 | }; |