/src/openssl36/providers/implementations/signature/dsa_sig.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2019-2025 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 | | /* clang-format off */ |
10 | | |
11 | | /* clang-format on */ |
12 | | |
13 | | /* |
14 | | * DSA low level APIs are deprecated for public use, but still ok for |
15 | | * internal use. |
16 | | */ |
17 | | #include "internal/deprecated.h" |
18 | | |
19 | | #include <string.h> |
20 | | |
21 | | #include <openssl/crypto.h> |
22 | | #include <openssl/core_dispatch.h> |
23 | | #include <openssl/core_names.h> |
24 | | #include <openssl/err.h> |
25 | | #include <openssl/dsa.h> |
26 | | #include <openssl/params.h> |
27 | | #include <openssl/evp.h> |
28 | | #include <openssl/proverr.h> |
29 | | #include "internal/nelem.h" |
30 | | #include "internal/sizes.h" |
31 | | #include "internal/cryptlib.h" |
32 | | #include "prov/providercommon.h" |
33 | | #include "prov/implementations.h" |
34 | | #include "prov/provider_ctx.h" |
35 | | #include "prov/securitycheck.h" |
36 | | #include "prov/der_dsa.h" |
37 | | #include "crypto/dsa.h" |
38 | | |
39 | | static OSSL_FUNC_signature_newctx_fn dsa_newctx; |
40 | | static OSSL_FUNC_signature_sign_init_fn dsa_sign_init; |
41 | | static OSSL_FUNC_signature_verify_init_fn dsa_verify_init; |
42 | | static OSSL_FUNC_signature_sign_fn dsa_sign; |
43 | | static OSSL_FUNC_signature_sign_message_update_fn dsa_signverify_message_update; |
44 | | static OSSL_FUNC_signature_sign_message_final_fn dsa_sign_message_final; |
45 | | static OSSL_FUNC_signature_verify_fn dsa_verify; |
46 | | static OSSL_FUNC_signature_verify_message_update_fn dsa_signverify_message_update; |
47 | | static OSSL_FUNC_signature_verify_message_final_fn dsa_verify_message_final; |
48 | | static OSSL_FUNC_signature_digest_sign_init_fn dsa_digest_sign_init; |
49 | | static OSSL_FUNC_signature_digest_sign_update_fn dsa_digest_signverify_update; |
50 | | static OSSL_FUNC_signature_digest_sign_final_fn dsa_digest_sign_final; |
51 | | static OSSL_FUNC_signature_digest_verify_init_fn dsa_digest_verify_init; |
52 | | static OSSL_FUNC_signature_digest_verify_update_fn dsa_digest_signverify_update; |
53 | | static OSSL_FUNC_signature_digest_verify_final_fn dsa_digest_verify_final; |
54 | | static OSSL_FUNC_signature_freectx_fn dsa_freectx; |
55 | | static OSSL_FUNC_signature_dupctx_fn dsa_dupctx; |
56 | | static OSSL_FUNC_signature_query_key_types_fn dsa_sigalg_query_key_types; |
57 | | static OSSL_FUNC_signature_get_ctx_params_fn dsa_get_ctx_params; |
58 | | static OSSL_FUNC_signature_gettable_ctx_params_fn dsa_gettable_ctx_params; |
59 | | static OSSL_FUNC_signature_set_ctx_params_fn dsa_set_ctx_params; |
60 | | static OSSL_FUNC_signature_settable_ctx_params_fn dsa_settable_ctx_params; |
61 | | static OSSL_FUNC_signature_get_ctx_md_params_fn dsa_get_ctx_md_params; |
62 | | static OSSL_FUNC_signature_gettable_ctx_md_params_fn dsa_gettable_ctx_md_params; |
63 | | static OSSL_FUNC_signature_set_ctx_md_params_fn dsa_set_ctx_md_params; |
64 | | static OSSL_FUNC_signature_settable_ctx_md_params_fn dsa_settable_ctx_md_params; |
65 | | static OSSL_FUNC_signature_set_ctx_params_fn dsa_sigalg_set_ctx_params; |
66 | | static OSSL_FUNC_signature_settable_ctx_params_fn dsa_sigalg_settable_ctx_params; |
67 | | |
68 | | /* |
69 | | * What's passed as an actual key is defined by the KEYMGMT interface. |
70 | | * We happen to know that our KEYMGMT simply passes DSA structures, so |
71 | | * we use that here too. |
72 | | */ |
73 | | |
74 | | typedef struct { |
75 | | OSSL_LIB_CTX *libctx; |
76 | | char *propq; |
77 | | DSA *dsa; |
78 | | /* |operation| reuses EVP's operation bitfield */ |
79 | | int operation; |
80 | | |
81 | | /* |
82 | | * Flag to determine if a full sigalg is run (1) or if a composable |
83 | | * signature algorithm is run (0). |
84 | | * |
85 | | * When a full sigalg is run (1), this currently affects the following |
86 | | * other flags, which are to remain untouched after their initialization: |
87 | | * |
88 | | * - flag_allow_md (initialized to 0) |
89 | | */ |
90 | | unsigned int flag_sigalg : 1; |
91 | | /* |
92 | | * Flag to determine if the hash function can be changed (1) or not (0) |
93 | | * Because it's dangerous to change during a DigestSign or DigestVerify |
94 | | * operation, this flag is cleared by their Init function, and set again |
95 | | * by their Final function. |
96 | | */ |
97 | | unsigned int flag_allow_md : 1; |
98 | | |
99 | | /* If this is set to 1 then the generated k is not random */ |
100 | | unsigned int nonce_type; |
101 | | |
102 | | /* The Algorithm Identifier of the combined signature algorithm */ |
103 | | unsigned char aid_buf[OSSL_MAX_ALGORITHM_ID_SIZE]; |
104 | | size_t aid_len; |
105 | | |
106 | | /* main digest */ |
107 | | char mdname[OSSL_MAX_NAME_SIZE]; |
108 | | EVP_MD *md; |
109 | | EVP_MD_CTX *mdctx; |
110 | | |
111 | | /* Signature, for verification */ |
112 | | unsigned char *sig; |
113 | | size_t siglen; |
114 | | |
115 | | OSSL_FIPS_IND_DECLARE |
116 | | } PROV_DSA_CTX; |
117 | | |
118 | | static size_t dsa_get_md_size(const PROV_DSA_CTX *pdsactx) |
119 | 2.47k | { |
120 | 2.47k | int md_size; |
121 | | |
122 | 2.47k | if (pdsactx->md != NULL) { |
123 | 2.47k | md_size = EVP_MD_get_size(pdsactx->md); |
124 | 2.47k | if (md_size <= 0) |
125 | 0 | return 0; |
126 | 2.47k | return (size_t)md_size; |
127 | 2.47k | } |
128 | 0 | return 0; |
129 | 2.47k | } |
130 | | |
131 | | static void *dsa_newctx(void *provctx, const char *propq) |
132 | 3.26k | { |
133 | 3.26k | PROV_DSA_CTX *pdsactx; |
134 | | |
135 | 3.26k | if (!ossl_prov_is_running()) |
136 | 0 | return NULL; |
137 | | |
138 | 3.26k | pdsactx = OPENSSL_zalloc(sizeof(PROV_DSA_CTX)); |
139 | 3.26k | if (pdsactx == NULL) |
140 | 0 | return NULL; |
141 | | |
142 | 3.26k | pdsactx->libctx = PROV_LIBCTX_OF(provctx); |
143 | 3.26k | pdsactx->flag_allow_md = 1; |
144 | 3.26k | OSSL_FIPS_IND_INIT(pdsactx) |
145 | 3.26k | if (propq != NULL && (pdsactx->propq = OPENSSL_strdup(propq)) == NULL) { |
146 | 0 | OPENSSL_free(pdsactx); |
147 | 0 | pdsactx = NULL; |
148 | 0 | } |
149 | 3.26k | return pdsactx; |
150 | 3.26k | } |
151 | | |
152 | | static int dsa_setup_md(PROV_DSA_CTX *ctx, |
153 | | const char *mdname, const char *mdprops, |
154 | | const char *desc) |
155 | 2.47k | { |
156 | 2.47k | EVP_MD *md = NULL; |
157 | | |
158 | 2.47k | if (mdprops == NULL) |
159 | 2.47k | mdprops = ctx->propq; |
160 | | |
161 | 2.47k | if (mdname != NULL) { |
162 | 2.47k | WPACKET pkt; |
163 | 2.47k | int md_nid; |
164 | 2.47k | size_t mdname_len = strlen(mdname); |
165 | 2.47k | unsigned char *aid = NULL; |
166 | | |
167 | 2.47k | md = EVP_MD_fetch(ctx->libctx, mdname, mdprops); |
168 | 2.47k | md_nid = ossl_digest_get_approved_nid(md); |
169 | | |
170 | 2.47k | if (md == NULL) { |
171 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_DIGEST, |
172 | 0 | "%s could not be fetched", mdname); |
173 | 0 | goto err; |
174 | 0 | } |
175 | 2.47k | if (md_nid == NID_undef) { |
176 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_DIGEST_NOT_ALLOWED, |
177 | 0 | "digest=%s", mdname); |
178 | 0 | goto err; |
179 | 0 | } |
180 | 2.47k | if (mdname_len >= sizeof(ctx->mdname)) { |
181 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_DIGEST, |
182 | 0 | "%s exceeds name buffer length", mdname); |
183 | 0 | goto err; |
184 | 0 | } |
185 | | /* XOF digests don't work */ |
186 | 2.47k | if (EVP_MD_xof(md)) { |
187 | 0 | ERR_raise(ERR_LIB_PROV, PROV_R_XOF_DIGESTS_NOT_ALLOWED); |
188 | 0 | goto err; |
189 | 0 | } |
190 | | #ifdef FIPS_MODULE |
191 | | { |
192 | | int sha1_allowed |
193 | | = ((ctx->operation |
194 | | & (EVP_PKEY_OP_SIGN | EVP_PKEY_OP_SIGNMSG)) |
195 | | == 0); |
196 | | |
197 | | if (!ossl_fips_ind_digest_sign_check(OSSL_FIPS_IND_GET(ctx), |
198 | | OSSL_FIPS_IND_SETTABLE1, |
199 | | ctx->libctx, |
200 | | md_nid, sha1_allowed, 0, desc, |
201 | | ossl_fips_config_signature_digest_check)) |
202 | | goto err; |
203 | | } |
204 | | #endif |
205 | | |
206 | 2.47k | if (!ctx->flag_allow_md) { |
207 | 0 | if (ctx->mdname[0] != '\0' |
208 | 0 | && !EVP_MD_is_a(md, ctx->mdname)) { |
209 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_DIGEST_NOT_ALLOWED, |
210 | 0 | "digest %s != %s", mdname, ctx->mdname); |
211 | 0 | goto err; |
212 | 0 | } |
213 | 0 | EVP_MD_free(md); |
214 | 0 | return 1; |
215 | 0 | } |
216 | | |
217 | 2.47k | EVP_MD_CTX_free(ctx->mdctx); |
218 | 2.47k | EVP_MD_free(ctx->md); |
219 | | |
220 | | /* |
221 | | * We do not care about DER writing errors. |
222 | | * All it really means is that for some reason, there's no |
223 | | * AlgorithmIdentifier to be had, but the operation itself is |
224 | | * still valid, just as long as it's not used to construct |
225 | | * anything that needs an AlgorithmIdentifier. |
226 | | */ |
227 | 2.47k | ctx->aid_len = 0; |
228 | 2.47k | if (WPACKET_init_der(&pkt, ctx->aid_buf, sizeof(ctx->aid_buf)) |
229 | 2.47k | && ossl_DER_w_algorithmIdentifier_DSA_with_MD(&pkt, -1, ctx->dsa, |
230 | 2.47k | md_nid) |
231 | 2.47k | && WPACKET_finish(&pkt)) { |
232 | 2.47k | WPACKET_get_total_written(&pkt, &ctx->aid_len); |
233 | 2.47k | aid = WPACKET_get_curr(&pkt); |
234 | 2.47k | } |
235 | 2.47k | WPACKET_cleanup(&pkt); |
236 | 2.47k | if (aid != NULL && ctx->aid_len != 0) |
237 | 2.47k | memmove(ctx->aid_buf, aid, ctx->aid_len); |
238 | | |
239 | 2.47k | ctx->mdctx = NULL; |
240 | 2.47k | ctx->md = md; |
241 | 2.47k | OPENSSL_strlcpy(ctx->mdname, mdname, sizeof(ctx->mdname)); |
242 | 2.47k | } |
243 | | |
244 | 2.47k | return 1; |
245 | 0 | err: |
246 | 0 | EVP_MD_free(md); |
247 | 0 | return 0; |
248 | 2.47k | } |
249 | | |
250 | | #ifdef FIPS_MODULE |
251 | | |
252 | | static int dsa_sign_check_approved(PROV_DSA_CTX *ctx, int signing, |
253 | | const char *desc) |
254 | | { |
255 | | /* DSA Signing is not approved in FIPS 140-3 */ |
256 | | if (signing |
257 | | && !OSSL_FIPS_IND_ON_UNAPPROVED(ctx, OSSL_FIPS_IND_SETTABLE2, |
258 | | ctx->libctx, desc, "DSA", |
259 | | ossl_fips_config_dsa_sign_disallowed)) |
260 | | return 0; |
261 | | return 1; |
262 | | } |
263 | | |
264 | | static int dsa_check_key(PROV_DSA_CTX *ctx, int sign, const char *desc) |
265 | | { |
266 | | int approved = ossl_dsa_check_key(ctx->dsa, sign); |
267 | | |
268 | | if (!approved) { |
269 | | if (!OSSL_FIPS_IND_ON_UNAPPROVED(ctx, OSSL_FIPS_IND_SETTABLE0, |
270 | | ctx->libctx, desc, "DSA Key", |
271 | | ossl_fips_config_signature_digest_check)) { |
272 | | ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH); |
273 | | return 0; |
274 | | } |
275 | | } |
276 | | return 1; |
277 | | } |
278 | | #endif |
279 | | |
280 | | static int |
281 | | dsa_signverify_init(void *vpdsactx, void *vdsa, |
282 | | OSSL_FUNC_signature_set_ctx_params_fn *set_ctx_params, |
283 | | const OSSL_PARAM params[], int operation, |
284 | | const char *desc) |
285 | 2.47k | { |
286 | 2.47k | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
287 | | |
288 | 2.47k | if (!ossl_prov_is_running() |
289 | 2.47k | || pdsactx == NULL) |
290 | 0 | return 0; |
291 | | |
292 | 2.47k | if (vdsa == NULL && pdsactx->dsa == NULL) { |
293 | 0 | ERR_raise(ERR_LIB_PROV, PROV_R_NO_KEY_SET); |
294 | 0 | return 0; |
295 | 0 | } |
296 | | |
297 | 2.47k | if (vdsa != NULL) { |
298 | 2.47k | if (!DSA_up_ref(vdsa)) |
299 | 0 | return 0; |
300 | 2.47k | DSA_free(pdsactx->dsa); |
301 | 2.47k | pdsactx->dsa = vdsa; |
302 | 2.47k | } |
303 | | |
304 | 2.47k | pdsactx->operation = operation; |
305 | | |
306 | 2.47k | OSSL_FIPS_IND_SET_APPROVED(pdsactx) |
307 | 2.47k | if (!set_ctx_params(pdsactx, params)) |
308 | 0 | return 0; |
309 | | #ifdef FIPS_MODULE |
310 | | { |
311 | | int operation_is_sign |
312 | | = (operation & (EVP_PKEY_OP_SIGN | EVP_PKEY_OP_SIGNMSG)) != 0; |
313 | | |
314 | | if (!dsa_sign_check_approved(pdsactx, operation_is_sign, desc)) |
315 | | return 0; |
316 | | if (!dsa_check_key(pdsactx, operation_is_sign, desc)) |
317 | | return 0; |
318 | | } |
319 | | #endif |
320 | 2.47k | return 1; |
321 | 2.47k | } |
322 | | |
323 | | static int dsa_sign_init(void *vpdsactx, void *vdsa, const OSSL_PARAM params[]) |
324 | 0 | { |
325 | 0 | return dsa_signverify_init(vpdsactx, vdsa, dsa_set_ctx_params, params, |
326 | 0 | EVP_PKEY_OP_SIGN, "DSA Sign Init"); |
327 | 0 | } |
328 | | |
329 | | /* |
330 | | * Sign tbs without digesting it first. This is suitable for "primitive" |
331 | | * signing and signing the digest of a message, i.e. should be used with |
332 | | * implementations of the keytype related algorithms. |
333 | | */ |
334 | | static int dsa_sign_directly(void *vpdsactx, |
335 | | unsigned char *sig, size_t *siglen, size_t sigsize, |
336 | | const unsigned char *tbs, size_t tbslen) |
337 | 0 | { |
338 | 0 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
339 | 0 | int ret; |
340 | 0 | unsigned int sltmp; |
341 | 0 | size_t dsasize = DSA_size(pdsactx->dsa); |
342 | 0 | size_t mdsize = dsa_get_md_size(pdsactx); |
343 | |
|
344 | 0 | if (!ossl_prov_is_running()) |
345 | 0 | return 0; |
346 | | |
347 | | #ifdef FIPS_MODULE |
348 | | if (!dsa_sign_check_approved(pdsactx, 1, "Sign")) |
349 | | return 0; |
350 | | #endif |
351 | | |
352 | 0 | if (sig == NULL) { |
353 | 0 | *siglen = dsasize; |
354 | 0 | return 1; |
355 | 0 | } |
356 | | |
357 | 0 | if (sigsize < dsasize) |
358 | 0 | return 0; |
359 | | |
360 | 0 | if (mdsize != 0 && tbslen != mdsize) |
361 | 0 | return 0; |
362 | | |
363 | 0 | ret = ossl_dsa_sign_int(0, tbs, (int)tbslen, sig, &sltmp, pdsactx->dsa, |
364 | 0 | pdsactx->nonce_type, pdsactx->mdname, |
365 | 0 | pdsactx->libctx, pdsactx->propq); |
366 | 0 | if (ret <= 0) |
367 | 0 | return 0; |
368 | | |
369 | 0 | *siglen = sltmp; |
370 | 0 | return 1; |
371 | 0 | } |
372 | | |
373 | | static int dsa_signverify_message_update(void *vpdsactx, |
374 | | const unsigned char *data, |
375 | | size_t datalen) |
376 | 2.47k | { |
377 | 2.47k | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
378 | | |
379 | 2.47k | if (pdsactx == NULL) |
380 | 0 | return 0; |
381 | | |
382 | 2.47k | return EVP_DigestUpdate(pdsactx->mdctx, data, datalen); |
383 | 2.47k | } |
384 | | |
385 | | static int dsa_sign_message_final(void *vpdsactx, unsigned char *sig, |
386 | | size_t *siglen, size_t sigsize) |
387 | 0 | { |
388 | 0 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
389 | 0 | unsigned char digest[EVP_MAX_MD_SIZE]; |
390 | 0 | unsigned int dlen = 0; |
391 | |
|
392 | 0 | if (!ossl_prov_is_running() || pdsactx == NULL || pdsactx->mdctx == NULL) |
393 | 0 | return 0; |
394 | | /* |
395 | | * If sig is NULL then we're just finding out the sig size. Other fields |
396 | | * are ignored. Defer to dsa_sign. |
397 | | */ |
398 | 0 | if (sig != NULL) { |
399 | | /* |
400 | | * When this function is used through dsa_digest_sign_final(), |
401 | | * there is the possibility that some externally provided digests |
402 | | * exceed EVP_MAX_MD_SIZE. We should probably handle that |
403 | | * somehow but that problem is much larger than just in DSA. |
404 | | */ |
405 | 0 | if (!EVP_DigestFinal_ex(pdsactx->mdctx, digest, &dlen)) |
406 | 0 | return 0; |
407 | 0 | } |
408 | | |
409 | 0 | return dsa_sign_directly(vpdsactx, sig, siglen, sigsize, digest, dlen); |
410 | 0 | } |
411 | | |
412 | | /* |
413 | | * If signing a message, digest tbs and sign the result. |
414 | | * Otherwise, sign tbs directly. |
415 | | */ |
416 | | static int dsa_sign(void *vpdsactx, unsigned char *sig, size_t *siglen, |
417 | | size_t sigsize, const unsigned char *tbs, size_t tbslen) |
418 | 0 | { |
419 | 0 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
420 | |
|
421 | 0 | if (pdsactx->operation == EVP_PKEY_OP_SIGNMSG) { |
422 | | /* |
423 | | * If |sig| is NULL, the caller is only looking for the sig length. |
424 | | * DO NOT update the input in this case. |
425 | | */ |
426 | 0 | if (sig == NULL) |
427 | 0 | return dsa_sign_message_final(pdsactx, sig, siglen, sigsize); |
428 | | |
429 | 0 | if (dsa_signverify_message_update(pdsactx, tbs, tbslen) <= 0) |
430 | 0 | return 0; |
431 | 0 | return dsa_sign_message_final(pdsactx, sig, siglen, sigsize); |
432 | 0 | } |
433 | 0 | return dsa_sign_directly(pdsactx, sig, siglen, sigsize, tbs, tbslen); |
434 | 0 | } |
435 | | |
436 | | static int dsa_verify_init(void *vpdsactx, void *vdsa, |
437 | | const OSSL_PARAM params[]) |
438 | 0 | { |
439 | 0 | return dsa_signverify_init(vpdsactx, vdsa, dsa_set_ctx_params, params, |
440 | 0 | EVP_PKEY_OP_VERIFY, "DSA Verify Init"); |
441 | 0 | } |
442 | | |
443 | | static int dsa_verify_directly(void *vpdsactx, |
444 | | const unsigned char *sig, size_t siglen, |
445 | | const unsigned char *tbs, size_t tbslen) |
446 | 2.47k | { |
447 | 2.47k | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
448 | 2.47k | size_t mdsize = dsa_get_md_size(pdsactx); |
449 | | |
450 | 2.47k | if (!ossl_prov_is_running() || (mdsize != 0 && tbslen != mdsize)) |
451 | 0 | return 0; |
452 | | |
453 | 2.47k | return DSA_verify(0, tbs, (int)tbslen, sig, (int)siglen, pdsactx->dsa); |
454 | 2.47k | } |
455 | | |
456 | | static int dsa_verify_set_sig(void *vpdsactx, |
457 | | const unsigned char *sig, size_t siglen) |
458 | 2.47k | { |
459 | 2.47k | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
460 | 2.47k | OSSL_PARAM params[2]; |
461 | | |
462 | 2.47k | params[0] = OSSL_PARAM_construct_octet_string(OSSL_SIGNATURE_PARAM_SIGNATURE, |
463 | 2.47k | (unsigned char *)sig, siglen); |
464 | 2.47k | params[1] = OSSL_PARAM_construct_end(); |
465 | 2.47k | return dsa_sigalg_set_ctx_params(pdsactx, params); |
466 | 2.47k | } |
467 | | |
468 | | static int dsa_verify_message_final(void *vpdsactx) |
469 | 2.47k | { |
470 | 2.47k | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
471 | 2.47k | unsigned char digest[EVP_MAX_MD_SIZE]; |
472 | 2.47k | unsigned int dlen = 0; |
473 | | |
474 | 2.47k | if (!ossl_prov_is_running()) |
475 | 0 | return 0; |
476 | | |
477 | 2.47k | if (pdsactx == NULL || pdsactx->mdctx == NULL) |
478 | 0 | return 0; |
479 | | |
480 | | /* |
481 | | * The digests used here are all known (see dsa_get_md_nid()), so they |
482 | | * should not exceed the internal buffer size of EVP_MAX_MD_SIZE. |
483 | | */ |
484 | 2.47k | if (!EVP_DigestFinal_ex(pdsactx->mdctx, digest, &dlen)) |
485 | 0 | return 0; |
486 | | |
487 | 2.47k | return dsa_verify_directly(vpdsactx, pdsactx->sig, pdsactx->siglen, |
488 | 2.47k | digest, dlen); |
489 | 2.47k | } |
490 | | |
491 | | /* |
492 | | * If verifying a message, digest tbs and verify the result. |
493 | | * Otherwise, verify tbs directly. |
494 | | */ |
495 | | static int dsa_verify(void *vpdsactx, |
496 | | const unsigned char *sig, size_t siglen, |
497 | | const unsigned char *tbs, size_t tbslen) |
498 | 0 | { |
499 | 0 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
500 | |
|
501 | 0 | if (pdsactx->operation == EVP_PKEY_OP_VERIFYMSG) { |
502 | 0 | if (dsa_verify_set_sig(pdsactx, sig, siglen) <= 0) |
503 | 0 | return 0; |
504 | 0 | if (dsa_signverify_message_update(pdsactx, tbs, tbslen) <= 0) |
505 | 0 | return 0; |
506 | 0 | return dsa_verify_message_final(pdsactx); |
507 | 0 | } |
508 | 0 | return dsa_verify_directly(pdsactx, sig, siglen, tbs, tbslen); |
509 | 0 | } |
510 | | |
511 | | /* DigestSign/DigestVerify wrappers */ |
512 | | |
513 | | static int dsa_digest_signverify_init(void *vpdsactx, const char *mdname, |
514 | | void *vdsa, const OSSL_PARAM params[], |
515 | | int operation, const char *desc) |
516 | 2.47k | { |
517 | 2.47k | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
518 | | |
519 | 2.47k | if (!ossl_prov_is_running()) |
520 | 0 | return 0; |
521 | | |
522 | 2.47k | if (!dsa_signverify_init(vpdsactx, vdsa, dsa_set_ctx_params, params, |
523 | 2.47k | operation, desc)) |
524 | 0 | return 0; |
525 | | |
526 | 2.47k | if (mdname != NULL |
527 | | /* was dsa_setup_md already called in dsa_signverify_init()? */ |
528 | 2.47k | && (mdname[0] == '\0' || OPENSSL_strcasecmp(pdsactx->mdname, mdname) != 0) |
529 | 2.47k | && !dsa_setup_md(pdsactx, mdname, NULL, desc)) |
530 | 0 | return 0; |
531 | | |
532 | 2.47k | pdsactx->flag_allow_md = 0; |
533 | | |
534 | 2.47k | if (pdsactx->mdctx == NULL) { |
535 | 2.47k | pdsactx->mdctx = EVP_MD_CTX_new(); |
536 | 2.47k | if (pdsactx->mdctx == NULL) |
537 | 0 | goto error; |
538 | 2.47k | } |
539 | | |
540 | 2.47k | if (!EVP_DigestInit_ex2(pdsactx->mdctx, pdsactx->md, params)) |
541 | 0 | goto error; |
542 | | |
543 | 2.47k | return 1; |
544 | | |
545 | 0 | error: |
546 | 0 | EVP_MD_CTX_free(pdsactx->mdctx); |
547 | 0 | pdsactx->mdctx = NULL; |
548 | 0 | return 0; |
549 | 2.47k | } |
550 | | |
551 | | static int dsa_digest_sign_init(void *vpdsactx, const char *mdname, |
552 | | void *vdsa, const OSSL_PARAM params[]) |
553 | 0 | { |
554 | 0 | return dsa_digest_signverify_init(vpdsactx, mdname, vdsa, params, |
555 | 0 | EVP_PKEY_OP_SIGNMSG, |
556 | 0 | "DSA Digest Sign Init"); |
557 | 0 | } |
558 | | |
559 | | static int dsa_digest_signverify_update(void *vpdsactx, const unsigned char *data, |
560 | | size_t datalen) |
561 | 2.47k | { |
562 | 2.47k | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
563 | | |
564 | 2.47k | if (pdsactx == NULL) |
565 | 0 | return 0; |
566 | | /* Sigalg implementations shouldn't do digest_sign */ |
567 | 2.47k | if (pdsactx->flag_sigalg) |
568 | 0 | return 0; |
569 | | |
570 | 2.47k | return dsa_signverify_message_update(vpdsactx, data, datalen); |
571 | 2.47k | } |
572 | | |
573 | | static int dsa_digest_sign_final(void *vpdsactx, unsigned char *sig, |
574 | | size_t *siglen, size_t sigsize) |
575 | 0 | { |
576 | 0 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
577 | 0 | int ok = 0; |
578 | |
|
579 | 0 | if (pdsactx == NULL) |
580 | 0 | return 0; |
581 | | /* Sigalg implementations shouldn't do digest_sign */ |
582 | 0 | if (pdsactx->flag_sigalg) |
583 | 0 | return 0; |
584 | | |
585 | 0 | ok = dsa_sign_message_final(pdsactx, sig, siglen, sigsize); |
586 | |
|
587 | 0 | pdsactx->flag_allow_md = 1; |
588 | |
|
589 | 0 | return ok; |
590 | 0 | } |
591 | | |
592 | | static int dsa_digest_verify_init(void *vpdsactx, const char *mdname, |
593 | | void *vdsa, const OSSL_PARAM params[]) |
594 | 3.26k | { |
595 | 3.26k | return dsa_digest_signverify_init(vpdsactx, mdname, vdsa, params, |
596 | 3.26k | EVP_PKEY_OP_VERIFYMSG, |
597 | 3.26k | "DSA Digest Verify Init"); |
598 | 3.26k | } |
599 | | |
600 | | int dsa_digest_verify_final(void *vpdsactx, const unsigned char *sig, |
601 | | size_t siglen) |
602 | 2.47k | { |
603 | 2.47k | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
604 | 2.47k | int ok = 0; |
605 | | |
606 | 2.47k | if (pdsactx == NULL) |
607 | 0 | return 0; |
608 | | /* Sigalg implementations shouldn't do digest_verify */ |
609 | 2.47k | if (pdsactx->flag_sigalg) |
610 | 0 | return 0; |
611 | | |
612 | 2.47k | if (dsa_verify_set_sig(pdsactx, sig, siglen)) |
613 | 2.47k | ok = dsa_verify_message_final(vpdsactx); |
614 | | |
615 | 2.47k | pdsactx->flag_allow_md = 1; |
616 | | |
617 | 2.47k | return ok; |
618 | 2.47k | } |
619 | | |
620 | | static void dsa_freectx(void *vpdsactx) |
621 | 6.53k | { |
622 | 6.53k | PROV_DSA_CTX *ctx = (PROV_DSA_CTX *)vpdsactx; |
623 | | |
624 | 6.53k | EVP_MD_CTX_free(ctx->mdctx); |
625 | 6.53k | EVP_MD_free(ctx->md); |
626 | 6.53k | OPENSSL_free(ctx->sig); |
627 | 6.53k | OPENSSL_free(ctx->propq); |
628 | 6.53k | DSA_free(ctx->dsa); |
629 | 6.53k | OPENSSL_free(ctx); |
630 | 6.53k | } |
631 | | |
632 | | static void *dsa_dupctx(void *vpdsactx) |
633 | 3.26k | { |
634 | 3.26k | PROV_DSA_CTX *srcctx = (PROV_DSA_CTX *)vpdsactx; |
635 | 3.26k | PROV_DSA_CTX *dstctx; |
636 | | |
637 | 3.26k | if (!ossl_prov_is_running()) |
638 | 0 | return NULL; |
639 | | |
640 | 3.26k | dstctx = OPENSSL_zalloc(sizeof(*srcctx)); |
641 | 3.26k | if (dstctx == NULL) |
642 | 0 | return NULL; |
643 | | |
644 | 3.26k | *dstctx = *srcctx; |
645 | 3.26k | dstctx->dsa = NULL; |
646 | 3.26k | dstctx->propq = NULL; |
647 | | |
648 | 3.26k | if (srcctx->dsa != NULL && !DSA_up_ref(srcctx->dsa)) |
649 | 0 | goto err; |
650 | 3.26k | dstctx->dsa = srcctx->dsa; |
651 | | |
652 | 3.26k | if (srcctx->md != NULL && !EVP_MD_up_ref(srcctx->md)) |
653 | 0 | goto err; |
654 | 3.26k | dstctx->md = srcctx->md; |
655 | | |
656 | 3.26k | if (srcctx->mdctx != NULL) { |
657 | 3.26k | dstctx->mdctx = EVP_MD_CTX_new(); |
658 | 3.26k | if (dstctx->mdctx == NULL |
659 | 3.26k | || !EVP_MD_CTX_copy_ex(dstctx->mdctx, srcctx->mdctx)) |
660 | 0 | goto err; |
661 | 3.26k | } |
662 | | |
663 | 3.26k | if (srcctx->propq != NULL) { |
664 | 0 | dstctx->propq = OPENSSL_strdup(srcctx->propq); |
665 | 0 | if (dstctx->propq == NULL) |
666 | 0 | goto err; |
667 | 0 | } |
668 | | |
669 | 3.26k | return dstctx; |
670 | 0 | err: |
671 | 0 | dsa_freectx(dstctx); |
672 | 0 | return NULL; |
673 | 3.26k | } |
674 | | |
675 | | /* clang-format off */ |
676 | | /* Machine generated by util/perl/OpenSSL/paramnames.pm */ |
677 | | #ifndef dsa_get_ctx_params_list |
678 | | static const OSSL_PARAM dsa_get_ctx_params_list[] = { |
679 | | OSSL_PARAM_octet_string(OSSL_SIGNATURE_PARAM_ALGORITHM_ID, NULL, 0), |
680 | | OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, NULL, 0), |
681 | | OSSL_PARAM_uint(OSSL_SIGNATURE_PARAM_NONCE_TYPE, NULL), |
682 | | # if defined(FIPS_MODULE) |
683 | | OSSL_PARAM_int(OSSL_SIGNATURE_PARAM_FIPS_APPROVED_INDICATOR, NULL), |
684 | | # endif |
685 | | OSSL_PARAM_END |
686 | | }; |
687 | | #endif |
688 | | |
689 | | #ifndef dsa_get_ctx_params_st |
690 | | struct dsa_get_ctx_params_st { |
691 | | OSSL_PARAM *algid; |
692 | | OSSL_PARAM *digest; |
693 | | # if defined(FIPS_MODULE) |
694 | | OSSL_PARAM *ind; |
695 | | # endif |
696 | | OSSL_PARAM *nonce; |
697 | | }; |
698 | | #endif |
699 | | |
700 | | #ifndef dsa_get_ctx_params_decoder |
701 | | static int dsa_get_ctx_params_decoder |
702 | | (const OSSL_PARAM *p, struct dsa_get_ctx_params_st *r) |
703 | 0 | { |
704 | 0 | const char *s; |
705 | |
|
706 | 0 | memset(r, 0, sizeof(*r)); |
707 | 0 | if (p != NULL) |
708 | 0 | for (; (s = p->key) != NULL; p++) |
709 | 0 | switch(s[0]) { |
710 | 0 | default: |
711 | 0 | break; |
712 | 0 | case 'a': |
713 | 0 | if (ossl_likely(strcmp("lgorithm-id", s + 1) == 0)) { |
714 | | /* OSSL_SIGNATURE_PARAM_ALGORITHM_ID */ |
715 | 0 | if (ossl_unlikely(r->algid != NULL)) { |
716 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
717 | 0 | "param %s is repeated", s); |
718 | 0 | return 0; |
719 | 0 | } |
720 | 0 | r->algid = (OSSL_PARAM *)p; |
721 | 0 | } |
722 | 0 | break; |
723 | 0 | case 'd': |
724 | 0 | if (ossl_likely(strcmp("igest", s + 1) == 0)) { |
725 | | /* OSSL_SIGNATURE_PARAM_DIGEST */ |
726 | 0 | if (ossl_unlikely(r->digest != NULL)) { |
727 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
728 | 0 | "param %s is repeated", s); |
729 | 0 | return 0; |
730 | 0 | } |
731 | 0 | r->digest = (OSSL_PARAM *)p; |
732 | 0 | } |
733 | 0 | break; |
734 | 0 | case 'f': |
735 | | # if defined(FIPS_MODULE) |
736 | | if (ossl_likely(strcmp("ips-indicator", s + 1) == 0)) { |
737 | | /* OSSL_SIGNATURE_PARAM_FIPS_APPROVED_INDICATOR */ |
738 | | if (ossl_unlikely(r->ind != NULL)) { |
739 | | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
740 | | "param %s is repeated", s); |
741 | | return 0; |
742 | | } |
743 | | r->ind = (OSSL_PARAM *)p; |
744 | | } |
745 | | # endif |
746 | 0 | break; |
747 | 0 | case 'n': |
748 | 0 | if (ossl_likely(strcmp("once-type", s + 1) == 0)) { |
749 | | /* OSSL_SIGNATURE_PARAM_NONCE_TYPE */ |
750 | 0 | if (ossl_unlikely(r->nonce != NULL)) { |
751 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
752 | 0 | "param %s is repeated", s); |
753 | 0 | return 0; |
754 | 0 | } |
755 | 0 | r->nonce = (OSSL_PARAM *)p; |
756 | 0 | } |
757 | 0 | } |
758 | 0 | return 1; |
759 | 0 | } |
760 | | #endif |
761 | | /* End of machine generated */ |
762 | | /* clang-format on */ |
763 | | |
764 | | static int dsa_get_ctx_params(void *vpdsactx, OSSL_PARAM *params) |
765 | 0 | { |
766 | 0 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
767 | 0 | struct dsa_get_ctx_params_st p; |
768 | |
|
769 | 0 | if (pdsactx == NULL || !dsa_get_ctx_params_decoder(params, &p)) |
770 | 0 | return 0; |
771 | | |
772 | 0 | if (p.algid != NULL |
773 | 0 | && !OSSL_PARAM_set_octet_string(p.algid, |
774 | 0 | pdsactx->aid_len == 0 ? NULL : pdsactx->aid_buf, |
775 | 0 | pdsactx->aid_len)) |
776 | 0 | return 0; |
777 | | |
778 | 0 | if (p.digest != NULL && !OSSL_PARAM_set_utf8_string(p.digest, pdsactx->mdname)) |
779 | 0 | return 0; |
780 | | |
781 | 0 | if (p.nonce != NULL && !OSSL_PARAM_set_uint(p.nonce, pdsactx->nonce_type)) |
782 | 0 | return 0; |
783 | | |
784 | 0 | if (!OSSL_FIPS_IND_GET_CTX_FROM_PARAM(pdsactx, p.ind)) |
785 | 0 | return 0; |
786 | | |
787 | 0 | return 1; |
788 | 0 | } |
789 | | |
790 | | static const OSSL_PARAM *dsa_gettable_ctx_params(ossl_unused void *ctx, |
791 | | ossl_unused void *provctx) |
792 | 0 | { |
793 | 0 | return dsa_get_ctx_params_list; |
794 | 0 | } |
795 | | |
796 | | struct dsa_all_set_ctx_params_st { |
797 | | OSSL_PARAM *digest; /* dsa_set_ctx_params */ |
798 | | OSSL_PARAM *propq; /* dsa_set_ctx_params */ |
799 | | #ifdef FIPS_MODULE |
800 | | OSSL_PARAM *ind_d; |
801 | | OSSL_PARAM *ind_k; |
802 | | OSSL_PARAM *ind_sign; |
803 | | #endif |
804 | | OSSL_PARAM *nonce; |
805 | | OSSL_PARAM *sig; /* dsa_sigalg_set_ctx_params */ |
806 | | }; |
807 | | |
808 | | /** |
809 | | * @brief Setup common params for dsa_set_ctx_params and dsa_sigalg_set_ctx_params |
810 | | * The caller is responsible for checking |vpdsactx| is not NULL and |params| |
811 | | * is not empty. |
812 | | */ |
813 | | static int dsa_common_set_ctx_params(PROV_DSA_CTX *pdsactx, |
814 | | const struct dsa_all_set_ctx_params_st *p) |
815 | 2.79k | { |
816 | 2.79k | if (!OSSL_FIPS_IND_SET_CTX_FROM_PARAM(pdsactx, OSSL_FIPS_IND_SETTABLE0, |
817 | 2.79k | p->ind_k)) |
818 | 0 | return 0; |
819 | 2.79k | if (!OSSL_FIPS_IND_SET_CTX_FROM_PARAM(pdsactx, OSSL_FIPS_IND_SETTABLE1, |
820 | 2.79k | p->ind_d)) |
821 | 0 | return 0; |
822 | 2.79k | if (!OSSL_FIPS_IND_SET_CTX_FROM_PARAM(pdsactx, OSSL_FIPS_IND_SETTABLE2, |
823 | 2.79k | p->ind_sign)) |
824 | 0 | return 0; |
825 | | |
826 | 2.79k | if (p->nonce != NULL |
827 | 0 | && !OSSL_PARAM_get_uint(p->nonce, &pdsactx->nonce_type)) |
828 | 0 | return 0; |
829 | 2.79k | return 1; |
830 | 2.79k | } |
831 | | |
832 | | #define dsa_set_ctx_params_st dsa_all_set_ctx_params_st |
833 | | |
834 | | /* clang-format off */ |
835 | | /* Machine generated by util/perl/OpenSSL/paramnames.pm */ |
836 | | #ifndef dsa_set_ctx_params_list |
837 | | static const OSSL_PARAM dsa_set_ctx_params_list[] = { |
838 | | OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, NULL, 0), |
839 | | OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_PROPERTIES, NULL, 0), |
840 | | OSSL_PARAM_uint(OSSL_SIGNATURE_PARAM_NONCE_TYPE, NULL), |
841 | | # if defined(FIPS_MODULE) |
842 | | OSSL_PARAM_int(OSSL_SIGNATURE_PARAM_FIPS_KEY_CHECK, NULL), |
843 | | # endif |
844 | | # if defined(FIPS_MODULE) |
845 | | OSSL_PARAM_int(OSSL_SIGNATURE_PARAM_FIPS_DIGEST_CHECK, NULL), |
846 | | # endif |
847 | | # if defined(FIPS_MODULE) |
848 | | OSSL_PARAM_int(OSSL_SIGNATURE_PARAM_FIPS_SIGN_CHECK, NULL), |
849 | | # endif |
850 | | OSSL_PARAM_END |
851 | | }; |
852 | | #endif |
853 | | |
854 | | #ifndef dsa_set_ctx_params_st |
855 | | struct dsa_set_ctx_params_st { |
856 | | OSSL_PARAM *digest; |
857 | | # if defined(FIPS_MODULE) |
858 | | OSSL_PARAM *ind_d; |
859 | | # endif |
860 | | # if defined(FIPS_MODULE) |
861 | | OSSL_PARAM *ind_k; |
862 | | # endif |
863 | | # if defined(FIPS_MODULE) |
864 | | OSSL_PARAM *ind_sign; |
865 | | # endif |
866 | | OSSL_PARAM *nonce; |
867 | | OSSL_PARAM *propq; |
868 | | }; |
869 | | #endif |
870 | | |
871 | | #ifndef dsa_set_ctx_params_decoder |
872 | | static int dsa_set_ctx_params_decoder |
873 | | (const OSSL_PARAM *p, struct dsa_set_ctx_params_st *r) |
874 | 757 | { |
875 | 757 | const char *s; |
876 | | |
877 | 757 | memset(r, 0, sizeof(*r)); |
878 | 757 | if (p != NULL) |
879 | 0 | for (; (s = p->key) != NULL; p++) |
880 | 0 | switch(s[0]) { |
881 | 0 | default: |
882 | 0 | break; |
883 | 0 | case 'd': |
884 | 0 | switch(s[1]) { |
885 | 0 | default: |
886 | 0 | break; |
887 | 0 | case 'i': |
888 | 0 | switch(s[2]) { |
889 | 0 | default: |
890 | 0 | break; |
891 | 0 | case 'g': |
892 | 0 | switch(s[3]) { |
893 | 0 | default: |
894 | 0 | break; |
895 | 0 | case 'e': |
896 | 0 | switch(s[4]) { |
897 | 0 | default: |
898 | 0 | break; |
899 | 0 | case 's': |
900 | 0 | switch(s[5]) { |
901 | 0 | default: |
902 | 0 | break; |
903 | 0 | case 't': |
904 | 0 | switch(s[6]) { |
905 | 0 | default: |
906 | 0 | break; |
907 | 0 | case '-': |
908 | | # if defined(FIPS_MODULE) |
909 | | if (ossl_likely(strcmp("check", s + 7) == 0)) { |
910 | | /* OSSL_SIGNATURE_PARAM_FIPS_DIGEST_CHECK */ |
911 | | if (ossl_unlikely(r->ind_d != NULL)) { |
912 | | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
913 | | "param %s is repeated", s); |
914 | | return 0; |
915 | | } |
916 | | r->ind_d = (OSSL_PARAM *)p; |
917 | | } |
918 | | # endif |
919 | 0 | break; |
920 | 0 | case '\0': |
921 | 0 | if (ossl_unlikely(r->digest != NULL)) { |
922 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
923 | 0 | "param %s is repeated", s); |
924 | 0 | return 0; |
925 | 0 | } |
926 | 0 | r->digest = (OSSL_PARAM *)p; |
927 | 0 | } |
928 | 0 | } |
929 | 0 | } |
930 | 0 | } |
931 | 0 | } |
932 | 0 | } |
933 | 0 | break; |
934 | 0 | case 'k': |
935 | | # if defined(FIPS_MODULE) |
936 | | if (ossl_likely(strcmp("ey-check", s + 1) == 0)) { |
937 | | /* OSSL_SIGNATURE_PARAM_FIPS_KEY_CHECK */ |
938 | | if (ossl_unlikely(r->ind_k != NULL)) { |
939 | | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
940 | | "param %s is repeated", s); |
941 | | return 0; |
942 | | } |
943 | | r->ind_k = (OSSL_PARAM *)p; |
944 | | } |
945 | | # endif |
946 | 0 | break; |
947 | 0 | case 'n': |
948 | 0 | if (ossl_likely(strcmp("once-type", s + 1) == 0)) { |
949 | | /* OSSL_SIGNATURE_PARAM_NONCE_TYPE */ |
950 | 0 | if (ossl_unlikely(r->nonce != NULL)) { |
951 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
952 | 0 | "param %s is repeated", s); |
953 | 0 | return 0; |
954 | 0 | } |
955 | 0 | r->nonce = (OSSL_PARAM *)p; |
956 | 0 | } |
957 | 0 | break; |
958 | 0 | case 'p': |
959 | 0 | if (ossl_likely(strcmp("roperties", s + 1) == 0)) { |
960 | | /* OSSL_SIGNATURE_PARAM_PROPERTIES */ |
961 | 0 | if (ossl_unlikely(r->propq != NULL)) { |
962 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
963 | 0 | "param %s is repeated", s); |
964 | 0 | return 0; |
965 | 0 | } |
966 | 0 | r->propq = (OSSL_PARAM *)p; |
967 | 0 | } |
968 | 0 | break; |
969 | 0 | case 's': |
970 | | # if defined(FIPS_MODULE) |
971 | | if (ossl_likely(strcmp("ign-check", s + 1) == 0)) { |
972 | | /* OSSL_SIGNATURE_PARAM_FIPS_SIGN_CHECK */ |
973 | | if (ossl_unlikely(r->ind_sign != NULL)) { |
974 | | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
975 | | "param %s is repeated", s); |
976 | | return 0; |
977 | | } |
978 | | r->ind_sign = (OSSL_PARAM *)p; |
979 | | } |
980 | | # endif |
981 | 0 | break; |
982 | 0 | } |
983 | 757 | return 1; |
984 | 757 | } |
985 | | #endif |
986 | | /* End of machine generated */ |
987 | | /* clang-format on */ |
988 | | |
989 | | static int dsa_set_ctx_params(void *vpdsactx, const OSSL_PARAM params[]) |
990 | 757 | { |
991 | 757 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
992 | 757 | struct dsa_all_set_ctx_params_st p; |
993 | 757 | int ret; |
994 | | |
995 | 757 | if (pdsactx == NULL || !dsa_set_ctx_params_decoder(params, &p)) |
996 | 0 | return 0; |
997 | | |
998 | 757 | if ((ret = dsa_common_set_ctx_params(pdsactx, &p)) <= 0) |
999 | 0 | return ret; |
1000 | | |
1001 | 757 | if (p.digest != NULL) { |
1002 | 0 | char mdname[OSSL_MAX_NAME_SIZE] = "", *pmdname = mdname; |
1003 | 0 | char mdprops[OSSL_MAX_PROPQUERY_SIZE] = "", *pmdprops = mdprops; |
1004 | |
|
1005 | 0 | if (!OSSL_PARAM_get_utf8_string(p.digest, &pmdname, sizeof(mdname))) |
1006 | 0 | return 0; |
1007 | 0 | if (p.propq != NULL |
1008 | 0 | && !OSSL_PARAM_get_utf8_string(p.propq, &pmdprops, sizeof(mdprops))) |
1009 | 0 | return 0; |
1010 | 0 | if (!dsa_setup_md(pdsactx, mdname, mdprops, "DSA Set Ctx")) |
1011 | 0 | return 0; |
1012 | 0 | } |
1013 | 757 | return 1; |
1014 | 757 | } |
1015 | | |
1016 | | static const OSSL_PARAM settable_ctx_params_no_digest[] = { |
1017 | | OSSL_PARAM_END |
1018 | | }; |
1019 | | |
1020 | | static const OSSL_PARAM *dsa_settable_ctx_params(void *vpdsactx, |
1021 | | ossl_unused void *provctx) |
1022 | 7 | { |
1023 | 7 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
1024 | | |
1025 | 7 | if (pdsactx != NULL && !pdsactx->flag_allow_md) |
1026 | 0 | return settable_ctx_params_no_digest; |
1027 | 7 | return dsa_set_ctx_params_list; |
1028 | 7 | } |
1029 | | |
1030 | | static int dsa_get_ctx_md_params(void *vpdsactx, OSSL_PARAM *params) |
1031 | 0 | { |
1032 | 0 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
1033 | |
|
1034 | 0 | if (pdsactx->mdctx == NULL) |
1035 | 0 | return 0; |
1036 | | |
1037 | 0 | return EVP_MD_CTX_get_params(pdsactx->mdctx, params); |
1038 | 0 | } |
1039 | | |
1040 | | static const OSSL_PARAM *dsa_gettable_ctx_md_params(void *vpdsactx) |
1041 | 0 | { |
1042 | 0 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
1043 | |
|
1044 | 0 | if (pdsactx->md == NULL) |
1045 | 0 | return 0; |
1046 | | |
1047 | 0 | return EVP_MD_gettable_ctx_params(pdsactx->md); |
1048 | 0 | } |
1049 | | |
1050 | | static int dsa_set_ctx_md_params(void *vpdsactx, const OSSL_PARAM params[]) |
1051 | 0 | { |
1052 | 0 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
1053 | |
|
1054 | 0 | if (pdsactx->mdctx == NULL) |
1055 | 0 | return 0; |
1056 | | |
1057 | 0 | return EVP_MD_CTX_set_params(pdsactx->mdctx, params); |
1058 | 0 | } |
1059 | | |
1060 | | static const OSSL_PARAM *dsa_settable_ctx_md_params(void *vpdsactx) |
1061 | 0 | { |
1062 | 0 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
1063 | |
|
1064 | 0 | if (pdsactx->md == NULL) |
1065 | 0 | return 0; |
1066 | | |
1067 | 0 | return EVP_MD_settable_ctx_params(pdsactx->md); |
1068 | 0 | } |
1069 | | |
1070 | | const OSSL_DISPATCH ossl_dsa_signature_functions[] = { |
1071 | | { OSSL_FUNC_SIGNATURE_NEWCTX, (void (*)(void))dsa_newctx }, |
1072 | | { OSSL_FUNC_SIGNATURE_SIGN_INIT, (void (*)(void))dsa_sign_init }, |
1073 | | { OSSL_FUNC_SIGNATURE_SIGN, (void (*)(void))dsa_sign }, |
1074 | | { OSSL_FUNC_SIGNATURE_VERIFY_INIT, (void (*)(void))dsa_verify_init }, |
1075 | | { OSSL_FUNC_SIGNATURE_VERIFY, (void (*)(void))dsa_verify }, |
1076 | | { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT, |
1077 | | (void (*)(void))dsa_digest_sign_init }, |
1078 | | { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_UPDATE, |
1079 | | (void (*)(void))dsa_digest_signverify_update }, |
1080 | | { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_FINAL, |
1081 | | (void (*)(void))dsa_digest_sign_final }, |
1082 | | { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT, |
1083 | | (void (*)(void))dsa_digest_verify_init }, |
1084 | | { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_UPDATE, |
1085 | | (void (*)(void))dsa_digest_signverify_update }, |
1086 | | { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_FINAL, |
1087 | | (void (*)(void))dsa_digest_verify_final }, |
1088 | | { OSSL_FUNC_SIGNATURE_FREECTX, (void (*)(void))dsa_freectx }, |
1089 | | { OSSL_FUNC_SIGNATURE_DUPCTX, (void (*)(void))dsa_dupctx }, |
1090 | | { OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS, (void (*)(void))dsa_get_ctx_params }, |
1091 | | { OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS, |
1092 | | (void (*)(void))dsa_gettable_ctx_params }, |
1093 | | { OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS, (void (*)(void))dsa_set_ctx_params }, |
1094 | | { OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS, |
1095 | | (void (*)(void))dsa_settable_ctx_params }, |
1096 | | { OSSL_FUNC_SIGNATURE_GET_CTX_MD_PARAMS, |
1097 | | (void (*)(void))dsa_get_ctx_md_params }, |
1098 | | { OSSL_FUNC_SIGNATURE_GETTABLE_CTX_MD_PARAMS, |
1099 | | (void (*)(void))dsa_gettable_ctx_md_params }, |
1100 | | { OSSL_FUNC_SIGNATURE_SET_CTX_MD_PARAMS, |
1101 | | (void (*)(void))dsa_set_ctx_md_params }, |
1102 | | { OSSL_FUNC_SIGNATURE_SETTABLE_CTX_MD_PARAMS, |
1103 | | (void (*)(void))dsa_settable_ctx_md_params }, |
1104 | | OSSL_DISPATCH_END |
1105 | | }; |
1106 | | |
1107 | | /* ------------------------------------------------------------------ */ |
1108 | | |
1109 | | /* |
1110 | | * So called sigalgs (composite DSA+hash) implemented below. They |
1111 | | * are pretty much hard coded. |
1112 | | */ |
1113 | | |
1114 | | static OSSL_FUNC_signature_query_key_types_fn dsa_sigalg_query_key_types; |
1115 | | static OSSL_FUNC_signature_settable_ctx_params_fn dsa_sigalg_settable_ctx_params; |
1116 | | static OSSL_FUNC_signature_set_ctx_params_fn dsa_sigalg_set_ctx_params; |
1117 | | |
1118 | | /* |
1119 | | * dsa_sigalg_signverify_init() is almost like dsa_digest_signverify_init(), |
1120 | | * just doesn't allow fetching an MD from whatever the user chooses. |
1121 | | */ |
1122 | | static int dsa_sigalg_signverify_init(void *vpdsactx, void *vdsa, |
1123 | | OSSL_FUNC_signature_set_ctx_params_fn *set_ctx_params, |
1124 | | const OSSL_PARAM params[], |
1125 | | const char *mdname, |
1126 | | int operation, const char *desc) |
1127 | 0 | { |
1128 | 0 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
1129 | |
|
1130 | 0 | if (!ossl_prov_is_running()) |
1131 | 0 | return 0; |
1132 | | |
1133 | 0 | if (!dsa_signverify_init(vpdsactx, vdsa, set_ctx_params, params, operation, |
1134 | 0 | desc)) |
1135 | 0 | return 0; |
1136 | | |
1137 | 0 | if (!dsa_setup_md(pdsactx, mdname, NULL, desc)) |
1138 | 0 | return 0; |
1139 | | |
1140 | 0 | pdsactx->flag_sigalg = 1; |
1141 | 0 | pdsactx->flag_allow_md = 0; |
1142 | |
|
1143 | 0 | if (pdsactx->mdctx == NULL) { |
1144 | 0 | pdsactx->mdctx = EVP_MD_CTX_new(); |
1145 | 0 | if (pdsactx->mdctx == NULL) |
1146 | 0 | goto error; |
1147 | 0 | } |
1148 | | |
1149 | 0 | if (!EVP_DigestInit_ex2(pdsactx->mdctx, pdsactx->md, params)) |
1150 | 0 | goto error; |
1151 | | |
1152 | 0 | return 1; |
1153 | | |
1154 | 0 | error: |
1155 | 0 | EVP_MD_CTX_free(pdsactx->mdctx); |
1156 | 0 | pdsactx->mdctx = NULL; |
1157 | 0 | return 0; |
1158 | 0 | } |
1159 | | |
1160 | | static const char **dsa_sigalg_query_key_types(void) |
1161 | 0 | { |
1162 | 0 | static const char *keytypes[] = { "DSA", NULL }; |
1163 | |
|
1164 | 0 | return keytypes; |
1165 | 0 | } |
1166 | | |
1167 | | #define dsa_sigalg_set_ctx_params_st dsa_all_set_ctx_params_st |
1168 | | |
1169 | | /* clang-format off */ |
1170 | | /* Machine generated by util/perl/OpenSSL/paramnames.pm */ |
1171 | | #ifndef dsa_sigalg_set_ctx_params_list |
1172 | | static const OSSL_PARAM dsa_sigalg_set_ctx_params_list[] = { |
1173 | | OSSL_PARAM_octet_string(OSSL_SIGNATURE_PARAM_SIGNATURE, NULL, 0), |
1174 | | OSSL_PARAM_uint(OSSL_SIGNATURE_PARAM_NONCE_TYPE, NULL), |
1175 | | # if defined(FIPS_MODULE) |
1176 | | OSSL_PARAM_int(OSSL_SIGNATURE_PARAM_FIPS_KEY_CHECK, NULL), |
1177 | | # endif |
1178 | | # if defined(FIPS_MODULE) |
1179 | | OSSL_PARAM_int(OSSL_SIGNATURE_PARAM_FIPS_DIGEST_CHECK, NULL), |
1180 | | # endif |
1181 | | # if defined(FIPS_MODULE) |
1182 | | OSSL_PARAM_int(OSSL_SIGNATURE_PARAM_FIPS_SIGN_CHECK, NULL), |
1183 | | # endif |
1184 | | OSSL_PARAM_END |
1185 | | }; |
1186 | | #endif |
1187 | | |
1188 | | #ifndef dsa_sigalg_set_ctx_params_st |
1189 | | struct dsa_sigalg_set_ctx_params_st { |
1190 | | # if defined(FIPS_MODULE) |
1191 | | OSSL_PARAM *ind_d; |
1192 | | # endif |
1193 | | # if defined(FIPS_MODULE) |
1194 | | OSSL_PARAM *ind_k; |
1195 | | # endif |
1196 | | # if defined(FIPS_MODULE) |
1197 | | OSSL_PARAM *ind_sign; |
1198 | | # endif |
1199 | | OSSL_PARAM *nonce; |
1200 | | OSSL_PARAM *sig; |
1201 | | }; |
1202 | | #endif |
1203 | | |
1204 | | #ifndef dsa_sigalg_set_ctx_params_decoder |
1205 | | static int dsa_sigalg_set_ctx_params_decoder |
1206 | | (const OSSL_PARAM *p, struct dsa_sigalg_set_ctx_params_st *r) |
1207 | 757 | { |
1208 | 757 | const char *s; |
1209 | | |
1210 | 757 | memset(r, 0, sizeof(*r)); |
1211 | 757 | if (p != NULL) |
1212 | 1.51k | for (; (s = p->key) != NULL; p++) |
1213 | 757 | switch(s[0]) { |
1214 | 0 | default: |
1215 | 0 | break; |
1216 | 0 | case 'd': |
1217 | | # if defined(FIPS_MODULE) |
1218 | | if (ossl_likely(strcmp("igest-check", s + 1) == 0)) { |
1219 | | /* OSSL_SIGNATURE_PARAM_FIPS_DIGEST_CHECK */ |
1220 | | if (ossl_unlikely(r->ind_d != NULL)) { |
1221 | | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
1222 | | "param %s is repeated", s); |
1223 | | return 0; |
1224 | | } |
1225 | | r->ind_d = (OSSL_PARAM *)p; |
1226 | | } |
1227 | | # endif |
1228 | 0 | break; |
1229 | 0 | case 'k': |
1230 | | # if defined(FIPS_MODULE) |
1231 | | if (ossl_likely(strcmp("ey-check", s + 1) == 0)) { |
1232 | | /* OSSL_SIGNATURE_PARAM_FIPS_KEY_CHECK */ |
1233 | | if (ossl_unlikely(r->ind_k != NULL)) { |
1234 | | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
1235 | | "param %s is repeated", s); |
1236 | | return 0; |
1237 | | } |
1238 | | r->ind_k = (OSSL_PARAM *)p; |
1239 | | } |
1240 | | # endif |
1241 | 0 | break; |
1242 | 0 | case 'n': |
1243 | 0 | if (ossl_likely(strcmp("once-type", s + 1) == 0)) { |
1244 | | /* OSSL_SIGNATURE_PARAM_NONCE_TYPE */ |
1245 | 0 | if (ossl_unlikely(r->nonce != NULL)) { |
1246 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
1247 | 0 | "param %s is repeated", s); |
1248 | 0 | return 0; |
1249 | 0 | } |
1250 | 0 | r->nonce = (OSSL_PARAM *)p; |
1251 | 0 | } |
1252 | 0 | break; |
1253 | 757 | case 's': |
1254 | 757 | switch(s[1]) { |
1255 | 0 | default: |
1256 | 0 | break; |
1257 | 757 | case 'i': |
1258 | 757 | switch(s[2]) { |
1259 | 0 | default: |
1260 | 0 | break; |
1261 | 757 | case 'g': |
1262 | 757 | switch(s[3]) { |
1263 | 0 | default: |
1264 | 0 | break; |
1265 | 757 | case 'n': |
1266 | 757 | switch(s[4]) { |
1267 | 0 | default: |
1268 | 0 | break; |
1269 | 0 | case '-': |
1270 | | # if defined(FIPS_MODULE) |
1271 | | if (ossl_likely(strcmp("check", s + 5) == 0)) { |
1272 | | /* OSSL_SIGNATURE_PARAM_FIPS_SIGN_CHECK */ |
1273 | | if (ossl_unlikely(r->ind_sign != NULL)) { |
1274 | | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
1275 | | "param %s is repeated", s); |
1276 | | return 0; |
1277 | | } |
1278 | | r->ind_sign = (OSSL_PARAM *)p; |
1279 | | } |
1280 | | # endif |
1281 | 0 | break; |
1282 | 757 | case 'a': |
1283 | 757 | if (ossl_likely(strcmp("ture", s + 5) == 0)) { |
1284 | | /* OSSL_SIGNATURE_PARAM_SIGNATURE */ |
1285 | 757 | if (ossl_unlikely(r->sig != NULL)) { |
1286 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_REPEATED_PARAMETER, |
1287 | 0 | "param %s is repeated", s); |
1288 | 0 | return 0; |
1289 | 0 | } |
1290 | 757 | r->sig = (OSSL_PARAM *)p; |
1291 | 757 | } |
1292 | 757 | } |
1293 | 757 | } |
1294 | 757 | } |
1295 | 757 | } |
1296 | 757 | } |
1297 | 757 | return 1; |
1298 | 757 | } |
1299 | | #endif |
1300 | | /* End of machine generated */ |
1301 | | /* clang-format on */ |
1302 | | |
1303 | | static const OSSL_PARAM *dsa_sigalg_settable_ctx_params(void *vpdsactx, |
1304 | | ossl_unused void *provctx) |
1305 | 4 | { |
1306 | 4 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
1307 | | |
1308 | 4 | if (pdsactx != NULL && pdsactx->operation == EVP_PKEY_OP_VERIFYMSG) |
1309 | 0 | return dsa_sigalg_set_ctx_params_list; |
1310 | 4 | return NULL; |
1311 | 4 | } |
1312 | | |
1313 | | static int dsa_sigalg_set_ctx_params(void *vpdsactx, const OSSL_PARAM params[]) |
1314 | 757 | { |
1315 | 757 | PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; |
1316 | 757 | struct dsa_all_set_ctx_params_st p; |
1317 | 757 | int ret; |
1318 | | |
1319 | 757 | if (pdsactx == NULL || !dsa_sigalg_set_ctx_params_decoder(params, &p)) |
1320 | 0 | return 0; |
1321 | | |
1322 | 757 | if ((ret = dsa_common_set_ctx_params(pdsactx, &p)) <= 0) |
1323 | 0 | return ret; |
1324 | | |
1325 | 757 | if (pdsactx->operation == EVP_PKEY_OP_VERIFYMSG) { |
1326 | 757 | if (p.sig != NULL) { |
1327 | 757 | OPENSSL_free(pdsactx->sig); |
1328 | 757 | pdsactx->sig = NULL; |
1329 | 757 | pdsactx->siglen = 0; |
1330 | 757 | if (!OSSL_PARAM_get_octet_string(p.sig, (void **)&pdsactx->sig, |
1331 | 757 | 0, &pdsactx->siglen)) |
1332 | 0 | return 0; |
1333 | 757 | } |
1334 | 757 | } |
1335 | 757 | return 1; |
1336 | 757 | } |
1337 | | |
1338 | | #define IMPL_DSA_SIGALG(md, MD) \ |
1339 | | static OSSL_FUNC_signature_sign_init_fn dsa_##md##_sign_init; \ |
1340 | | static OSSL_FUNC_signature_sign_message_init_fn \ |
1341 | | dsa_##md##_sign_message_init; \ |
1342 | | static OSSL_FUNC_signature_verify_init_fn dsa_##md##_verify_init; \ |
1343 | | static OSSL_FUNC_signature_verify_message_init_fn \ |
1344 | | dsa_##md##_verify_message_init; \ |
1345 | | \ |
1346 | | static int \ |
1347 | | dsa_##md##_sign_init(void *vpdsactx, void *vdsa, \ |
1348 | | const OSSL_PARAM params[]) \ |
1349 | 0 | { \ |
1350 | 0 | static const char desc[] = "DSA-" MD " Sign Init"; \ |
1351 | 0 | \ |
1352 | 0 | return dsa_sigalg_signverify_init(vpdsactx, vdsa, \ |
1353 | 0 | dsa_sigalg_set_ctx_params, \ |
1354 | 0 | params, MD, \ |
1355 | 0 | EVP_PKEY_OP_SIGN, \ |
1356 | 0 | desc); \ |
1357 | 0 | } \ Unexecuted instantiation: dsa_sig.c:dsa_sha1_sign_init Unexecuted instantiation: dsa_sig.c:dsa_sha224_sign_init Unexecuted instantiation: dsa_sig.c:dsa_sha256_sign_init Unexecuted instantiation: dsa_sig.c:dsa_sha384_sign_init Unexecuted instantiation: dsa_sig.c:dsa_sha512_sign_init Unexecuted instantiation: dsa_sig.c:dsa_sha3_224_sign_init Unexecuted instantiation: dsa_sig.c:dsa_sha3_256_sign_init Unexecuted instantiation: dsa_sig.c:dsa_sha3_384_sign_init Unexecuted instantiation: dsa_sig.c:dsa_sha3_512_sign_init |
1358 | | \ |
1359 | | static int \ |
1360 | | dsa_##md##_sign_message_init(void *vpdsactx, void *vdsa, \ |
1361 | | const OSSL_PARAM params[]) \ |
1362 | 0 | { \ |
1363 | 0 | static const char desc[] = "DSA-" MD " Sign Message Init"; \ |
1364 | 0 | \ |
1365 | 0 | return dsa_sigalg_signverify_init(vpdsactx, vdsa, \ |
1366 | 0 | dsa_sigalg_set_ctx_params, \ |
1367 | 0 | params, MD, \ |
1368 | 0 | EVP_PKEY_OP_SIGNMSG, \ |
1369 | 0 | desc); \ |
1370 | 0 | } \ Unexecuted instantiation: dsa_sig.c:dsa_sha1_sign_message_init Unexecuted instantiation: dsa_sig.c:dsa_sha224_sign_message_init Unexecuted instantiation: dsa_sig.c:dsa_sha256_sign_message_init Unexecuted instantiation: dsa_sig.c:dsa_sha384_sign_message_init Unexecuted instantiation: dsa_sig.c:dsa_sha512_sign_message_init Unexecuted instantiation: dsa_sig.c:dsa_sha3_224_sign_message_init Unexecuted instantiation: dsa_sig.c:dsa_sha3_256_sign_message_init Unexecuted instantiation: dsa_sig.c:dsa_sha3_384_sign_message_init Unexecuted instantiation: dsa_sig.c:dsa_sha3_512_sign_message_init |
1371 | | \ |
1372 | | static int \ |
1373 | | dsa_##md##_verify_init(void *vpdsactx, void *vdsa, \ |
1374 | | const OSSL_PARAM params[]) \ |
1375 | 0 | { \ |
1376 | 0 | static const char desc[] = "DSA-" MD " Verify Init"; \ |
1377 | 0 | \ |
1378 | 0 | return dsa_sigalg_signverify_init(vpdsactx, vdsa, \ |
1379 | 0 | dsa_sigalg_set_ctx_params, \ |
1380 | 0 | params, MD, \ |
1381 | 0 | EVP_PKEY_OP_VERIFY, \ |
1382 | 0 | desc); \ |
1383 | 0 | } \ Unexecuted instantiation: dsa_sig.c:dsa_sha1_verify_init Unexecuted instantiation: dsa_sig.c:dsa_sha224_verify_init Unexecuted instantiation: dsa_sig.c:dsa_sha256_verify_init Unexecuted instantiation: dsa_sig.c:dsa_sha384_verify_init Unexecuted instantiation: dsa_sig.c:dsa_sha512_verify_init Unexecuted instantiation: dsa_sig.c:dsa_sha3_224_verify_init Unexecuted instantiation: dsa_sig.c:dsa_sha3_256_verify_init Unexecuted instantiation: dsa_sig.c:dsa_sha3_384_verify_init Unexecuted instantiation: dsa_sig.c:dsa_sha3_512_verify_init |
1384 | | \ |
1385 | | static int \ |
1386 | | dsa_##md##_verify_message_init(void *vpdsactx, void *vdsa, \ |
1387 | | const OSSL_PARAM params[]) \ |
1388 | 0 | { \ |
1389 | 0 | static const char desc[] = "DSA-" MD " Verify Message Init"; \ |
1390 | 0 | \ |
1391 | 0 | return dsa_sigalg_signverify_init(vpdsactx, vdsa, \ |
1392 | 0 | dsa_sigalg_set_ctx_params, \ |
1393 | 0 | params, MD, \ |
1394 | 0 | EVP_PKEY_OP_VERIFYMSG, \ |
1395 | 0 | desc); \ |
1396 | 0 | } \ Unexecuted instantiation: dsa_sig.c:dsa_sha1_verify_message_init Unexecuted instantiation: dsa_sig.c:dsa_sha224_verify_message_init Unexecuted instantiation: dsa_sig.c:dsa_sha256_verify_message_init Unexecuted instantiation: dsa_sig.c:dsa_sha384_verify_message_init Unexecuted instantiation: dsa_sig.c:dsa_sha512_verify_message_init Unexecuted instantiation: dsa_sig.c:dsa_sha3_224_verify_message_init Unexecuted instantiation: dsa_sig.c:dsa_sha3_256_verify_message_init Unexecuted instantiation: dsa_sig.c:dsa_sha3_384_verify_message_init Unexecuted instantiation: dsa_sig.c:dsa_sha3_512_verify_message_init |
1397 | | \ |
1398 | | const OSSL_DISPATCH ossl_dsa_##md##_signature_functions[] = { \ |
1399 | | { OSSL_FUNC_SIGNATURE_NEWCTX, (void (*)(void))dsa_newctx }, \ |
1400 | | { OSSL_FUNC_SIGNATURE_SIGN_INIT, \ |
1401 | | (void (*)(void))dsa_##md##_sign_init }, \ |
1402 | | { OSSL_FUNC_SIGNATURE_SIGN, (void (*)(void))dsa_sign }, \ |
1403 | | { OSSL_FUNC_SIGNATURE_SIGN_MESSAGE_INIT, \ |
1404 | | (void (*)(void))dsa_##md##_sign_message_init }, \ |
1405 | | { OSSL_FUNC_SIGNATURE_SIGN_MESSAGE_UPDATE, \ |
1406 | | (void (*)(void))dsa_signverify_message_update }, \ |
1407 | | { OSSL_FUNC_SIGNATURE_SIGN_MESSAGE_FINAL, \ |
1408 | | (void (*)(void))dsa_sign_message_final }, \ |
1409 | | { OSSL_FUNC_SIGNATURE_VERIFY_INIT, \ |
1410 | | (void (*)(void))dsa_##md##_verify_init }, \ |
1411 | | { OSSL_FUNC_SIGNATURE_VERIFY, \ |
1412 | | (void (*)(void))dsa_verify }, \ |
1413 | | { OSSL_FUNC_SIGNATURE_VERIFY_MESSAGE_INIT, \ |
1414 | | (void (*)(void))dsa_##md##_verify_message_init }, \ |
1415 | | { OSSL_FUNC_SIGNATURE_VERIFY_MESSAGE_UPDATE, \ |
1416 | | (void (*)(void))dsa_signverify_message_update }, \ |
1417 | | { OSSL_FUNC_SIGNATURE_VERIFY_MESSAGE_FINAL, \ |
1418 | | (void (*)(void))dsa_verify_message_final }, \ |
1419 | | { OSSL_FUNC_SIGNATURE_FREECTX, (void (*)(void))dsa_freectx }, \ |
1420 | | { OSSL_FUNC_SIGNATURE_DUPCTX, (void (*)(void))dsa_dupctx }, \ |
1421 | | { OSSL_FUNC_SIGNATURE_QUERY_KEY_TYPES, \ |
1422 | | (void (*)(void))dsa_sigalg_query_key_types }, \ |
1423 | | { OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS, \ |
1424 | | (void (*)(void))dsa_get_ctx_params }, \ |
1425 | | { OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS, \ |
1426 | | (void (*)(void))dsa_gettable_ctx_params }, \ |
1427 | | { OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS, \ |
1428 | | (void (*)(void))dsa_sigalg_set_ctx_params }, \ |
1429 | | { OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS, \ |
1430 | | (void (*)(void))dsa_sigalg_settable_ctx_params }, \ |
1431 | | OSSL_DISPATCH_END \ |
1432 | | } |
1433 | | |
1434 | | IMPL_DSA_SIGALG(sha1, "SHA1"); |
1435 | | IMPL_DSA_SIGALG(sha224, "SHA2-224"); |
1436 | | IMPL_DSA_SIGALG(sha256, "SHA2-256"); |
1437 | | IMPL_DSA_SIGALG(sha384, "SHA2-384"); |
1438 | | IMPL_DSA_SIGALG(sha512, "SHA2-512"); |
1439 | | IMPL_DSA_SIGALG(sha3_224, "SHA3-224"); |
1440 | | IMPL_DSA_SIGALG(sha3_256, "SHA3-256"); |
1441 | | IMPL_DSA_SIGALG(sha3_384, "SHA3-384"); |
1442 | | IMPL_DSA_SIGALG(sha3_512, "SHA3-512"); |