/src/openssl33/providers/implementations/signature/dsa_sig.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2019-2023 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 <string.h> |
17 | | |
18 | | #include <openssl/crypto.h> |
19 | | #include <openssl/core_dispatch.h> |
20 | | #include <openssl/core_names.h> |
21 | | #include <openssl/err.h> |
22 | | #include <openssl/dsa.h> |
23 | | #include <openssl/params.h> |
24 | | #include <openssl/evp.h> |
25 | | #include <openssl/proverr.h> |
26 | | #include "internal/nelem.h" |
27 | | #include "internal/sizes.h" |
28 | | #include "internal/cryptlib.h" |
29 | | #include "prov/providercommon.h" |
30 | | #include "prov/implementations.h" |
31 | | #include "prov/provider_ctx.h" |
32 | | #include "prov/securitycheck.h" |
33 | | #include "crypto/dsa.h" |
34 | | #include "prov/der_dsa.h" |
35 | | |
36 | | static OSSL_FUNC_signature_newctx_fn dsa_newctx; |
37 | | static OSSL_FUNC_signature_sign_init_fn dsa_sign_init; |
38 | | static OSSL_FUNC_signature_verify_init_fn dsa_verify_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_sign_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_verify_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; |
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 { |
65 | | OSSL_LIB_CTX *libctx; |
66 | | char *propq; |
67 | | DSA *dsa; |
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 | | |
77 | | /* If this is set to 1 then the generated k is not random */ |
78 | | unsigned int nonce_type; |
79 | | |
80 | | char mdname[OSSL_MAX_NAME_SIZE]; |
81 | | |
82 | | /* The Algorithm Identifier of the combined signature algorithm */ |
83 | | unsigned char aid_buf[OSSL_MAX_ALGORITHM_ID_SIZE]; |
84 | | unsigned char *aid; |
85 | | size_t aid_len; |
86 | | |
87 | | /* main digest */ |
88 | | EVP_MD *md; |
89 | | EVP_MD_CTX *mdctx; |
90 | | int operation; |
91 | | } PROV_DSA_CTX; |
92 | | |
93 | | static size_t dsa_get_md_size(const PROV_DSA_CTX *pdsactx) |
94 | 793 | { |
95 | 793 | if (pdsactx->md != NULL) |
96 | 793 | return EVP_MD_get_size(pdsactx->md); |
97 | 0 | return 0; |
98 | 793 | } |
99 | | |
100 | | static void *dsa_newctx(void *provctx, const char *propq) |
101 | 3.26k | { |
102 | 3.26k | PROV_DSA_CTX *pdsactx; |
103 | | |
104 | 3.26k | if (!ossl_prov_is_running()) |
105 | 0 | return NULL; |
106 | | |
107 | 3.26k | pdsactx = OPENSSL_zalloc(sizeof(PROV_DSA_CTX)); |
108 | 3.26k | if (pdsactx == NULL) |
109 | 0 | return NULL; |
110 | | |
111 | 3.26k | pdsactx->libctx = PROV_LIBCTX_OF(provctx); |
112 | 3.26k | pdsactx->flag_allow_md = 1; |
113 | 3.26k | if (propq != NULL && (pdsactx->propq = OPENSSL_strdup(propq)) == NULL) { |
114 | 0 | OPENSSL_free(pdsactx); |
115 | 0 | pdsactx = NULL; |
116 | 0 | } |
117 | 3.26k | return pdsactx; |
118 | 3.26k | } |
119 | | |
120 | | static int dsa_setup_md(PROV_DSA_CTX *ctx, |
121 | | const char *mdname, const char *mdprops) |
122 | 793 | { |
123 | 793 | if (mdprops == NULL) |
124 | 793 | mdprops = ctx->propq; |
125 | | |
126 | 793 | if (mdname != NULL) { |
127 | 793 | int sha1_allowed = (ctx->operation != EVP_PKEY_OP_SIGN); |
128 | 793 | WPACKET pkt; |
129 | 793 | EVP_MD *md = EVP_MD_fetch(ctx->libctx, mdname, mdprops); |
130 | 793 | int md_nid = ossl_digest_get_approved_nid_with_sha1(ctx->libctx, md, |
131 | 793 | sha1_allowed); |
132 | 793 | size_t mdname_len = strlen(mdname); |
133 | | |
134 | 793 | if (md == NULL || md_nid < 0) { |
135 | 0 | if (md == NULL) |
136 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_DIGEST, |
137 | 0 | "%s could not be fetched", mdname); |
138 | 0 | if (md_nid < 0) |
139 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_DIGEST_NOT_ALLOWED, |
140 | 0 | "digest=%s", mdname); |
141 | 0 | if (mdname_len >= sizeof(ctx->mdname)) |
142 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_DIGEST, |
143 | 0 | "%s exceeds name buffer length", mdname); |
144 | 0 | EVP_MD_free(md); |
145 | 0 | return 0; |
146 | 0 | } |
147 | | |
148 | 793 | if (!ctx->flag_allow_md) { |
149 | 0 | if (ctx->mdname[0] != '\0' && !EVP_MD_is_a(md, ctx->mdname)) { |
150 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_DIGEST_NOT_ALLOWED, |
151 | 0 | "digest %s != %s", mdname, ctx->mdname); |
152 | 0 | EVP_MD_free(md); |
153 | 0 | return 0; |
154 | 0 | } |
155 | 0 | EVP_MD_free(md); |
156 | 0 | return 1; |
157 | 0 | } |
158 | | |
159 | 793 | EVP_MD_CTX_free(ctx->mdctx); |
160 | 793 | EVP_MD_free(ctx->md); |
161 | | |
162 | | /* |
163 | | * We do not care about DER writing errors. |
164 | | * All it really means is that for some reason, there's no |
165 | | * AlgorithmIdentifier to be had, but the operation itself is |
166 | | * still valid, just as long as it's not used to construct |
167 | | * anything that needs an AlgorithmIdentifier. |
168 | | */ |
169 | 793 | ctx->aid_len = 0; |
170 | 793 | if (WPACKET_init_der(&pkt, ctx->aid_buf, sizeof(ctx->aid_buf)) |
171 | 793 | && ossl_DER_w_algorithmIdentifier_DSA_with_MD(&pkt, -1, ctx->dsa, |
172 | 793 | md_nid) |
173 | 793 | && WPACKET_finish(&pkt)) { |
174 | 793 | WPACKET_get_total_written(&pkt, &ctx->aid_len); |
175 | 793 | ctx->aid = WPACKET_get_curr(&pkt); |
176 | 793 | } |
177 | 793 | WPACKET_cleanup(&pkt); |
178 | | |
179 | 793 | ctx->mdctx = NULL; |
180 | 793 | ctx->md = md; |
181 | 793 | OPENSSL_strlcpy(ctx->mdname, mdname, sizeof(ctx->mdname)); |
182 | 793 | } |
183 | 793 | return 1; |
184 | 793 | } |
185 | | |
186 | | static int dsa_signverify_init(void *vpdsactx, void *vdsa, |
187 | | const OSSL_PARAM params[], int operation) |
188 | 793 | { |
189 | 793 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
190 | | |
191 | 793 | if (!ossl_prov_is_running() |
192 | 793 | || pdsactx == NULL) |
193 | 0 | return 0; |
194 | | |
195 | 793 | if (vdsa == NULL && pdsactx->dsa == NULL) { |
196 | 0 | ERR_raise(ERR_LIB_PROV, PROV_R_NO_KEY_SET); |
197 | 0 | return 0; |
198 | 0 | } |
199 | | |
200 | 793 | if (vdsa != NULL) { |
201 | 793 | if (!ossl_dsa_check_key(pdsactx->libctx, vdsa, |
202 | 793 | operation == EVP_PKEY_OP_SIGN)) { |
203 | 0 | ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH); |
204 | 0 | return 0; |
205 | 0 | } |
206 | 793 | if (!DSA_up_ref(vdsa)) |
207 | 0 | return 0; |
208 | 793 | DSA_free(pdsactx->dsa); |
209 | 793 | pdsactx->dsa = vdsa; |
210 | 793 | } |
211 | | |
212 | 793 | pdsactx->operation = operation; |
213 | | |
214 | 793 | if (!dsa_set_ctx_params(pdsactx, params)) |
215 | 0 | return 0; |
216 | | |
217 | 793 | return 1; |
218 | 793 | } |
219 | | |
220 | | static int dsa_sign_init(void *vpdsactx, void *vdsa, const OSSL_PARAM params[]) |
221 | 0 | { |
222 | 0 | return dsa_signverify_init(vpdsactx, vdsa, params, EVP_PKEY_OP_SIGN); |
223 | 0 | } |
224 | | |
225 | | static int dsa_verify_init(void *vpdsactx, void *vdsa, |
226 | | const OSSL_PARAM params[]) |
227 | 0 | { |
228 | 0 | return dsa_signverify_init(vpdsactx, vdsa, params, EVP_PKEY_OP_VERIFY); |
229 | 0 | } |
230 | | |
231 | | static int dsa_sign(void *vpdsactx, unsigned char *sig, size_t *siglen, |
232 | | size_t sigsize, const unsigned char *tbs, size_t tbslen) |
233 | 0 | { |
234 | 0 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
235 | 0 | int ret; |
236 | 0 | unsigned int sltmp; |
237 | 0 | size_t dsasize = DSA_size(pdsactx->dsa); |
238 | 0 | size_t mdsize = dsa_get_md_size(pdsactx); |
239 | |
|
240 | 0 | if (!ossl_prov_is_running()) |
241 | 0 | return 0; |
242 | | |
243 | 0 | if (sig == NULL) { |
244 | 0 | *siglen = dsasize; |
245 | 0 | return 1; |
246 | 0 | } |
247 | | |
248 | 0 | if (sigsize < (size_t)dsasize) |
249 | 0 | return 0; |
250 | | |
251 | 0 | if (mdsize != 0 && tbslen != mdsize) |
252 | 0 | return 0; |
253 | | |
254 | 0 | ret = ossl_dsa_sign_int(0, tbs, tbslen, sig, &sltmp, pdsactx->dsa, |
255 | 0 | pdsactx->nonce_type, pdsactx->mdname, |
256 | 0 | pdsactx->libctx, pdsactx->propq); |
257 | 0 | if (ret <= 0) |
258 | 0 | return 0; |
259 | | |
260 | 0 | *siglen = sltmp; |
261 | 0 | return 1; |
262 | 0 | } |
263 | | |
264 | | static int dsa_verify(void *vpdsactx, const unsigned char *sig, size_t siglen, |
265 | | const unsigned char *tbs, size_t tbslen) |
266 | 793 | { |
267 | 793 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
268 | 793 | size_t mdsize = dsa_get_md_size(pdsactx); |
269 | | |
270 | 793 | if (!ossl_prov_is_running() || (mdsize != 0 && tbslen != mdsize)) |
271 | 0 | return 0; |
272 | | |
273 | 793 | return DSA_verify(0, tbs, tbslen, sig, siglen, pdsactx->dsa); |
274 | 793 | } |
275 | | |
276 | | static int dsa_digest_signverify_init(void *vpdsactx, const char *mdname, |
277 | | void *vdsa, const OSSL_PARAM params[], |
278 | | int operation) |
279 | 793 | { |
280 | 793 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
281 | | |
282 | 793 | if (!ossl_prov_is_running()) |
283 | 0 | return 0; |
284 | | |
285 | 793 | if (!dsa_signverify_init(vpdsactx, vdsa, params, operation)) |
286 | 0 | return 0; |
287 | | |
288 | 793 | if (!dsa_setup_md(pdsactx, mdname, NULL)) |
289 | 0 | return 0; |
290 | | |
291 | 793 | pdsactx->flag_allow_md = 0; |
292 | | |
293 | 793 | if (pdsactx->mdctx == NULL) { |
294 | 793 | pdsactx->mdctx = EVP_MD_CTX_new(); |
295 | 793 | if (pdsactx->mdctx == NULL) |
296 | 0 | goto error; |
297 | 793 | } |
298 | | |
299 | 793 | if (!EVP_DigestInit_ex2(pdsactx->mdctx, pdsactx->md, params)) |
300 | 0 | goto error; |
301 | | |
302 | 793 | return 1; |
303 | | |
304 | 0 | error: |
305 | 0 | EVP_MD_CTX_free(pdsactx->mdctx); |
306 | 0 | pdsactx->mdctx = NULL; |
307 | 0 | return 0; |
308 | 793 | } |
309 | | |
310 | | static int dsa_digest_sign_init(void *vpdsactx, const char *mdname, |
311 | | void *vdsa, const OSSL_PARAM params[]) |
312 | 0 | { |
313 | 0 | return dsa_digest_signverify_init(vpdsactx, mdname, vdsa, params, |
314 | 0 | EVP_PKEY_OP_SIGN); |
315 | 0 | } |
316 | | |
317 | | static int dsa_digest_verify_init(void *vpdsactx, const char *mdname, |
318 | | void *vdsa, const OSSL_PARAM params[]) |
319 | 3.26k | { |
320 | 3.26k | return dsa_digest_signverify_init(vpdsactx, mdname, vdsa, params, |
321 | 3.26k | EVP_PKEY_OP_VERIFY); |
322 | 3.26k | } |
323 | | |
324 | | int dsa_digest_signverify_update(void *vpdsactx, const unsigned char *data, |
325 | | size_t datalen) |
326 | 793 | { |
327 | 793 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
328 | | |
329 | 793 | if (pdsactx == NULL || pdsactx->mdctx == NULL) |
330 | 0 | return 0; |
331 | | |
332 | 793 | return EVP_DigestUpdate(pdsactx->mdctx, data, datalen); |
333 | 793 | } |
334 | | |
335 | | int dsa_digest_sign_final(void *vpdsactx, unsigned char *sig, size_t *siglen, |
336 | | size_t sigsize) |
337 | 0 | { |
338 | 0 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
339 | 0 | unsigned char digest[EVP_MAX_MD_SIZE]; |
340 | 0 | unsigned int dlen = 0; |
341 | |
|
342 | 0 | if (!ossl_prov_is_running() || pdsactx == NULL || pdsactx->mdctx == NULL) |
343 | 0 | return 0; |
344 | | |
345 | | /* |
346 | | * If sig is NULL then we're just finding out the sig size. Other fields |
347 | | * are ignored. Defer to dsa_sign. |
348 | | */ |
349 | 0 | if (sig != NULL) { |
350 | | /* |
351 | | * There is the possibility that some externally provided |
352 | | * digests exceed EVP_MAX_MD_SIZE. We should probably handle that somehow - |
353 | | * but that problem is much larger than just in DSA. |
354 | | */ |
355 | 0 | if (!EVP_DigestFinal_ex(pdsactx->mdctx, digest, &dlen)) |
356 | 0 | return 0; |
357 | 0 | } |
358 | | |
359 | 0 | pdsactx->flag_allow_md = 1; |
360 | |
|
361 | 0 | return dsa_sign(vpdsactx, sig, siglen, sigsize, digest, (size_t)dlen); |
362 | 0 | } |
363 | | |
364 | | int dsa_digest_verify_final(void *vpdsactx, const unsigned char *sig, |
365 | | size_t siglen) |
366 | 793 | { |
367 | 793 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
368 | 793 | unsigned char digest[EVP_MAX_MD_SIZE]; |
369 | 793 | unsigned int dlen = 0; |
370 | | |
371 | 793 | if (!ossl_prov_is_running() || pdsactx == NULL || pdsactx->mdctx == NULL) |
372 | 0 | return 0; |
373 | | |
374 | | /* |
375 | | * There is the possibility that some externally provided |
376 | | * digests exceed EVP_MAX_MD_SIZE. We should probably handle that somehow - |
377 | | * but that problem is much larger than just in DSA. |
378 | | */ |
379 | 793 | if (!EVP_DigestFinal_ex(pdsactx->mdctx, digest, &dlen)) |
380 | 0 | return 0; |
381 | | |
382 | 793 | pdsactx->flag_allow_md = 1; |
383 | | |
384 | 793 | return dsa_verify(vpdsactx, sig, siglen, digest, (size_t)dlen); |
385 | 793 | } |
386 | | |
387 | | static void dsa_freectx(void *vpdsactx) |
388 | 6.53k | { |
389 | 6.53k | PROV_DSA_CTX *ctx = (PROV_DSA_CTX *)vpdsactx; |
390 | | |
391 | 6.53k | OPENSSL_free(ctx->propq); |
392 | 6.53k | EVP_MD_CTX_free(ctx->mdctx); |
393 | 6.53k | EVP_MD_free(ctx->md); |
394 | 6.53k | ctx->propq = NULL; |
395 | 6.53k | ctx->mdctx = NULL; |
396 | 6.53k | ctx->md = NULL; |
397 | 6.53k | DSA_free(ctx->dsa); |
398 | 6.53k | OPENSSL_free(ctx); |
399 | 6.53k | } |
400 | | |
401 | | static void *dsa_dupctx(void *vpdsactx) |
402 | 3.26k | { |
403 | 3.26k | PROV_DSA_CTX *srcctx = (PROV_DSA_CTX *)vpdsactx; |
404 | 3.26k | PROV_DSA_CTX *dstctx; |
405 | | |
406 | 3.26k | if (!ossl_prov_is_running()) |
407 | 0 | return NULL; |
408 | | |
409 | 3.26k | dstctx = OPENSSL_zalloc(sizeof(*srcctx)); |
410 | 3.26k | if (dstctx == NULL) |
411 | 0 | return NULL; |
412 | | |
413 | 3.26k | *dstctx = *srcctx; |
414 | 3.26k | dstctx->dsa = NULL; |
415 | 3.26k | dstctx->md = NULL; |
416 | 3.26k | dstctx->mdctx = NULL; |
417 | 3.26k | dstctx->propq = NULL; |
418 | | |
419 | 3.26k | if (srcctx->dsa != NULL && !DSA_up_ref(srcctx->dsa)) |
420 | 0 | goto err; |
421 | 3.26k | dstctx->dsa = srcctx->dsa; |
422 | | |
423 | 3.26k | if (srcctx->md != NULL && !EVP_MD_up_ref(srcctx->md)) |
424 | 0 | goto err; |
425 | 3.26k | dstctx->md = srcctx->md; |
426 | | |
427 | 3.26k | if (srcctx->mdctx != NULL) { |
428 | 3.26k | dstctx->mdctx = EVP_MD_CTX_new(); |
429 | 3.26k | if (dstctx->mdctx == NULL |
430 | 3.26k | || !EVP_MD_CTX_copy_ex(dstctx->mdctx, srcctx->mdctx)) |
431 | 0 | goto err; |
432 | 3.26k | } |
433 | 3.26k | if (srcctx->propq != NULL) { |
434 | 0 | dstctx->propq = OPENSSL_strdup(srcctx->propq); |
435 | 0 | if (dstctx->propq == NULL) |
436 | 0 | goto err; |
437 | 0 | } |
438 | | |
439 | 3.26k | return dstctx; |
440 | 0 | err: |
441 | 0 | dsa_freectx(dstctx); |
442 | 0 | return NULL; |
443 | 3.26k | } |
444 | | |
445 | | static int dsa_get_ctx_params(void *vpdsactx, OSSL_PARAM *params) |
446 | 0 | { |
447 | 0 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
448 | 0 | OSSL_PARAM *p; |
449 | |
|
450 | 0 | if (pdsactx == NULL) |
451 | 0 | return 0; |
452 | | |
453 | 0 | p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_ALGORITHM_ID); |
454 | 0 | if (p != NULL |
455 | 0 | && !OSSL_PARAM_set_octet_string(p, pdsactx->aid, pdsactx->aid_len)) |
456 | 0 | return 0; |
457 | | |
458 | 0 | p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_DIGEST); |
459 | 0 | if (p != NULL && !OSSL_PARAM_set_utf8_string(p, pdsactx->mdname)) |
460 | 0 | return 0; |
461 | | |
462 | 0 | p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_NONCE_TYPE); |
463 | 0 | if (p != NULL && !OSSL_PARAM_set_uint(p, pdsactx->nonce_type)) |
464 | 0 | return 0; |
465 | | |
466 | 0 | return 1; |
467 | 0 | } |
468 | | |
469 | | static const OSSL_PARAM known_gettable_ctx_params[] = { |
470 | | OSSL_PARAM_octet_string(OSSL_SIGNATURE_PARAM_ALGORITHM_ID, NULL, 0), |
471 | | OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, NULL, 0), |
472 | | OSSL_PARAM_uint(OSSL_SIGNATURE_PARAM_NONCE_TYPE, NULL), |
473 | | OSSL_PARAM_END |
474 | | }; |
475 | | |
476 | | static const OSSL_PARAM *dsa_gettable_ctx_params(ossl_unused void *ctx, |
477 | | ossl_unused void *provctx) |
478 | 0 | { |
479 | 0 | return known_gettable_ctx_params; |
480 | 0 | } |
481 | | |
482 | | static int dsa_set_ctx_params(void *vpdsactx, const OSSL_PARAM params[]) |
483 | 431 | { |
484 | 431 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
485 | 431 | const OSSL_PARAM *p; |
486 | | |
487 | 431 | if (pdsactx == NULL) |
488 | 0 | return 0; |
489 | 431 | if (params == NULL) |
490 | 431 | return 1; |
491 | | |
492 | 0 | p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_DIGEST); |
493 | 0 | if (p != NULL) { |
494 | 0 | char mdname[OSSL_MAX_NAME_SIZE] = "", *pmdname = mdname; |
495 | 0 | char mdprops[OSSL_MAX_PROPQUERY_SIZE] = "", *pmdprops = mdprops; |
496 | 0 | const OSSL_PARAM *propsp = OSSL_PARAM_locate_const(params, |
497 | 0 | OSSL_SIGNATURE_PARAM_PROPERTIES); |
498 | |
|
499 | 0 | if (!OSSL_PARAM_get_utf8_string(p, &pmdname, sizeof(mdname))) |
500 | 0 | return 0; |
501 | 0 | if (propsp != NULL |
502 | 0 | && !OSSL_PARAM_get_utf8_string(propsp, &pmdprops, sizeof(mdprops))) |
503 | 0 | return 0; |
504 | 0 | if (!dsa_setup_md(pdsactx, mdname, mdprops)) |
505 | 0 | return 0; |
506 | 0 | } |
507 | 0 | p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_NONCE_TYPE); |
508 | 0 | if (p != NULL |
509 | 0 | && !OSSL_PARAM_get_uint(p, &pdsactx->nonce_type)) |
510 | 0 | return 0; |
511 | | |
512 | 0 | return 1; |
513 | 0 | } |
514 | | |
515 | | static const OSSL_PARAM settable_ctx_params[] = { |
516 | | OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, NULL, 0), |
517 | | OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_PROPERTIES, NULL, 0), |
518 | | OSSL_PARAM_uint(OSSL_SIGNATURE_PARAM_NONCE_TYPE, NULL), |
519 | | OSSL_PARAM_END |
520 | | }; |
521 | | |
522 | | static const OSSL_PARAM settable_ctx_params_no_digest[] = { |
523 | | OSSL_PARAM_END |
524 | | }; |
525 | | |
526 | | static const OSSL_PARAM *dsa_settable_ctx_params(void *vpdsactx, |
527 | | ossl_unused void *provctx) |
528 | 7 | { |
529 | 7 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
530 | | |
531 | 7 | if (pdsactx != NULL && !pdsactx->flag_allow_md) |
532 | 0 | return settable_ctx_params_no_digest; |
533 | 7 | return settable_ctx_params; |
534 | 7 | } |
535 | | |
536 | | static int dsa_get_ctx_md_params(void *vpdsactx, OSSL_PARAM *params) |
537 | 0 | { |
538 | 0 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
539 | |
|
540 | 0 | if (pdsactx->mdctx == NULL) |
541 | 0 | return 0; |
542 | | |
543 | 0 | return EVP_MD_CTX_get_params(pdsactx->mdctx, params); |
544 | 0 | } |
545 | | |
546 | | static const OSSL_PARAM *dsa_gettable_ctx_md_params(void *vpdsactx) |
547 | 0 | { |
548 | 0 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
549 | |
|
550 | 0 | if (pdsactx->md == NULL) |
551 | 0 | return 0; |
552 | | |
553 | 0 | return EVP_MD_gettable_ctx_params(pdsactx->md); |
554 | 0 | } |
555 | | |
556 | | static int dsa_set_ctx_md_params(void *vpdsactx, const OSSL_PARAM params[]) |
557 | 0 | { |
558 | 0 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
559 | |
|
560 | 0 | if (pdsactx->mdctx == NULL) |
561 | 0 | return 0; |
562 | | |
563 | 0 | return EVP_MD_CTX_set_params(pdsactx->mdctx, params); |
564 | 0 | } |
565 | | |
566 | | static const OSSL_PARAM *dsa_settable_ctx_md_params(void *vpdsactx) |
567 | 0 | { |
568 | 0 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
569 | |
|
570 | 0 | if (pdsactx->md == NULL) |
571 | 0 | return 0; |
572 | | |
573 | 0 | return EVP_MD_settable_ctx_params(pdsactx->md); |
574 | 0 | } |
575 | | |
576 | | const OSSL_DISPATCH ossl_dsa_signature_functions[] = { |
577 | | { OSSL_FUNC_SIGNATURE_NEWCTX, (void (*)(void))dsa_newctx }, |
578 | | { OSSL_FUNC_SIGNATURE_SIGN_INIT, (void (*)(void))dsa_sign_init }, |
579 | | { OSSL_FUNC_SIGNATURE_SIGN, (void (*)(void))dsa_sign }, |
580 | | { OSSL_FUNC_SIGNATURE_VERIFY_INIT, (void (*)(void))dsa_verify_init }, |
581 | | { OSSL_FUNC_SIGNATURE_VERIFY, (void (*)(void))dsa_verify }, |
582 | | { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT, |
583 | | (void (*)(void))dsa_digest_sign_init }, |
584 | | { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_UPDATE, |
585 | | (void (*)(void))dsa_digest_signverify_update }, |
586 | | { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_FINAL, |
587 | | (void (*)(void))dsa_digest_sign_final }, |
588 | | { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT, |
589 | | (void (*)(void))dsa_digest_verify_init }, |
590 | | { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_UPDATE, |
591 | | (void (*)(void))dsa_digest_signverify_update }, |
592 | | { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_FINAL, |
593 | | (void (*)(void))dsa_digest_verify_final }, |
594 | | { OSSL_FUNC_SIGNATURE_FREECTX, (void (*)(void))dsa_freectx }, |
595 | | { OSSL_FUNC_SIGNATURE_DUPCTX, (void (*)(void))dsa_dupctx }, |
596 | | { OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS, (void (*)(void))dsa_get_ctx_params }, |
597 | | { OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS, |
598 | | (void (*)(void))dsa_gettable_ctx_params }, |
599 | | { OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS, (void (*)(void))dsa_set_ctx_params }, |
600 | | { OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS, |
601 | | (void (*)(void))dsa_settable_ctx_params }, |
602 | | { OSSL_FUNC_SIGNATURE_GET_CTX_MD_PARAMS, |
603 | | (void (*)(void))dsa_get_ctx_md_params }, |
604 | | { OSSL_FUNC_SIGNATURE_GETTABLE_CTX_MD_PARAMS, |
605 | | (void (*)(void))dsa_gettable_ctx_md_params }, |
606 | | { OSSL_FUNC_SIGNATURE_SET_CTX_MD_PARAMS, |
607 | | (void (*)(void))dsa_set_ctx_md_params }, |
608 | | { OSSL_FUNC_SIGNATURE_SETTABLE_CTX_MD_PARAMS, |
609 | | (void (*)(void))dsa_settable_ctx_md_params }, |
610 | | OSSL_DISPATCH_END |
611 | | }; |