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