2 * Copyright 2006-2024 The OpenSSL Project Authors. All Rights Reserved.
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
12 #include <openssl/objects.h>
13 #include <openssl/evp.h>
14 #include "internal/numbers.h" /* includes SIZE_MAX */
15 #include "internal/cryptlib.h"
16 #include "internal/provider.h"
17 #include "internal/core.h"
18 #include "crypto/evp.h"
19 #include "evp_local.h"
21 static EVP_SIGNATURE
*evp_signature_new(OSSL_PROVIDER
*prov
)
23 EVP_SIGNATURE
*signature
= OPENSSL_zalloc(sizeof(EVP_SIGNATURE
));
25 if (signature
== NULL
)
28 if (!CRYPTO_NEW_REF(&signature
->refcnt
, 1)) {
29 OPENSSL_free(signature
);
33 signature
->prov
= prov
;
34 ossl_provider_up_ref(prov
);
39 static void *evp_signature_from_algorithm(int name_id
,
40 const OSSL_ALGORITHM
*algodef
,
43 const OSSL_DISPATCH
*fns
= algodef
->implementation
;
44 EVP_SIGNATURE
*signature
= NULL
;
45 int ctxfncnt
= 0, signfncnt
= 0, verifyfncnt
= 0, verifyrecfncnt
= 0;
46 int digsignfncnt
= 0, digverifyfncnt
= 0;
47 int gparamfncnt
= 0, sparamfncnt
= 0, gmdparamfncnt
= 0, smdparamfncnt
= 0;
49 if ((signature
= evp_signature_new(prov
)) == NULL
) {
50 ERR_raise(ERR_LIB_EVP
, ERR_R_EVP_LIB
);
54 signature
->name_id
= name_id
;
55 if ((signature
->type_name
= ossl_algorithm_get1_first_name(algodef
)) == NULL
)
57 signature
->description
= algodef
->algorithm_description
;
59 for (; fns
->function_id
!= 0; fns
++) {
60 switch (fns
->function_id
) {
61 case OSSL_FUNC_SIGNATURE_NEWCTX
:
62 if (signature
->newctx
!= NULL
)
64 signature
->newctx
= OSSL_FUNC_signature_newctx(fns
);
67 case OSSL_FUNC_SIGNATURE_SIGN_INIT
:
68 if (signature
->sign_init
!= NULL
)
70 signature
->sign_init
= OSSL_FUNC_signature_sign_init(fns
);
73 case OSSL_FUNC_SIGNATURE_SIGN
:
74 if (signature
->sign
!= NULL
)
76 signature
->sign
= OSSL_FUNC_signature_sign(fns
);
79 case OSSL_FUNC_SIGNATURE_VERIFY_INIT
:
80 if (signature
->verify_init
!= NULL
)
82 signature
->verify_init
= OSSL_FUNC_signature_verify_init(fns
);
85 case OSSL_FUNC_SIGNATURE_VERIFY
:
86 if (signature
->verify
!= NULL
)
88 signature
->verify
= OSSL_FUNC_signature_verify(fns
);
91 case OSSL_FUNC_SIGNATURE_VERIFY_RECOVER_INIT
:
92 if (signature
->verify_recover_init
!= NULL
)
94 signature
->verify_recover_init
95 = OSSL_FUNC_signature_verify_recover_init(fns
);
98 case OSSL_FUNC_SIGNATURE_VERIFY_RECOVER
:
99 if (signature
->verify_recover
!= NULL
)
101 signature
->verify_recover
102 = OSSL_FUNC_signature_verify_recover(fns
);
105 case OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT
:
106 if (signature
->digest_sign_init
!= NULL
)
108 signature
->digest_sign_init
109 = OSSL_FUNC_signature_digest_sign_init(fns
);
111 case OSSL_FUNC_SIGNATURE_DIGEST_SIGN_UPDATE
:
112 if (signature
->digest_sign_update
!= NULL
)
114 signature
->digest_sign_update
115 = OSSL_FUNC_signature_digest_sign_update(fns
);
118 case OSSL_FUNC_SIGNATURE_DIGEST_SIGN_FINAL
:
119 if (signature
->digest_sign_final
!= NULL
)
121 signature
->digest_sign_final
122 = OSSL_FUNC_signature_digest_sign_final(fns
);
125 case OSSL_FUNC_SIGNATURE_DIGEST_SIGN
:
126 if (signature
->digest_sign
!= NULL
)
128 signature
->digest_sign
129 = OSSL_FUNC_signature_digest_sign(fns
);
131 case OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT
:
132 if (signature
->digest_verify_init
!= NULL
)
134 signature
->digest_verify_init
135 = OSSL_FUNC_signature_digest_verify_init(fns
);
137 case OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_UPDATE
:
138 if (signature
->digest_verify_update
!= NULL
)
140 signature
->digest_verify_update
141 = OSSL_FUNC_signature_digest_verify_update(fns
);
144 case OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_FINAL
:
145 if (signature
->digest_verify_final
!= NULL
)
147 signature
->digest_verify_final
148 = OSSL_FUNC_signature_digest_verify_final(fns
);
151 case OSSL_FUNC_SIGNATURE_DIGEST_VERIFY
:
152 if (signature
->digest_verify
!= NULL
)
154 signature
->digest_verify
155 = OSSL_FUNC_signature_digest_verify(fns
);
157 case OSSL_FUNC_SIGNATURE_FREECTX
:
158 if (signature
->freectx
!= NULL
)
160 signature
->freectx
= OSSL_FUNC_signature_freectx(fns
);
163 case OSSL_FUNC_SIGNATURE_DUPCTX
:
164 if (signature
->dupctx
!= NULL
)
166 signature
->dupctx
= OSSL_FUNC_signature_dupctx(fns
);
168 case OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS
:
169 if (signature
->get_ctx_params
!= NULL
)
171 signature
->get_ctx_params
172 = OSSL_FUNC_signature_get_ctx_params(fns
);
175 case OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS
:
176 if (signature
->gettable_ctx_params
!= NULL
)
178 signature
->gettable_ctx_params
179 = OSSL_FUNC_signature_gettable_ctx_params(fns
);
182 case OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS
:
183 if (signature
->set_ctx_params
!= NULL
)
185 signature
->set_ctx_params
186 = OSSL_FUNC_signature_set_ctx_params(fns
);
189 case OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS
:
190 if (signature
->settable_ctx_params
!= NULL
)
192 signature
->settable_ctx_params
193 = OSSL_FUNC_signature_settable_ctx_params(fns
);
196 case OSSL_FUNC_SIGNATURE_GET_CTX_MD_PARAMS
:
197 if (signature
->get_ctx_md_params
!= NULL
)
199 signature
->get_ctx_md_params
200 = OSSL_FUNC_signature_get_ctx_md_params(fns
);
203 case OSSL_FUNC_SIGNATURE_GETTABLE_CTX_MD_PARAMS
:
204 if (signature
->gettable_ctx_md_params
!= NULL
)
206 signature
->gettable_ctx_md_params
207 = OSSL_FUNC_signature_gettable_ctx_md_params(fns
);
210 case OSSL_FUNC_SIGNATURE_SET_CTX_MD_PARAMS
:
211 if (signature
->set_ctx_md_params
!= NULL
)
213 signature
->set_ctx_md_params
214 = OSSL_FUNC_signature_set_ctx_md_params(fns
);
217 case OSSL_FUNC_SIGNATURE_SETTABLE_CTX_MD_PARAMS
:
218 if (signature
->settable_ctx_md_params
!= NULL
)
220 signature
->settable_ctx_md_params
221 = OSSL_FUNC_signature_settable_ctx_md_params(fns
);
229 && verifyrecfncnt
== 0
231 && digverifyfncnt
== 0
232 && signature
->digest_sign
== NULL
233 && signature
->digest_verify
== NULL
)
234 || (signfncnt
!= 0 && signfncnt
!= 2)
235 || (verifyfncnt
!= 0 && verifyfncnt
!= 2)
236 || (verifyrecfncnt
!= 0 && verifyrecfncnt
!= 2)
237 || (digsignfncnt
!= 0 && digsignfncnt
!= 2)
238 || (digsignfncnt
== 2 && signature
->digest_sign_init
== NULL
)
239 || (digverifyfncnt
!= 0 && digverifyfncnt
!= 2)
240 || (digverifyfncnt
== 2 && signature
->digest_verify_init
== NULL
)
241 || (signature
->digest_sign
!= NULL
242 && signature
->digest_sign_init
== NULL
)
243 || (signature
->digest_verify
!= NULL
244 && signature
->digest_verify_init
== NULL
)
245 || (gparamfncnt
!= 0 && gparamfncnt
!= 2)
246 || (sparamfncnt
!= 0 && sparamfncnt
!= 2)
247 || (gmdparamfncnt
!= 0 && gmdparamfncnt
!= 2)
248 || (smdparamfncnt
!= 0 && smdparamfncnt
!= 2)) {
250 * In order to be a consistent set of functions we must have at least
251 * a set of context functions (newctx and freectx) as well as a set of
252 * "signature" functions:
253 * (sign_init, sign) or
254 * (verify_init verify) or
255 * (verify_recover_init, verify_recover) or
256 * (digest_sign_init, digest_sign_update, digest_sign_final) or
257 * (digest_verify_init, digest_verify_update, digest_verify_final) or
258 * (digest_sign_init, digest_sign) or
259 * (digest_verify_init, digest_verify).
261 * set_ctx_params and settable_ctx_params are optional, but if one of
262 * them is present then the other one must also be present. The same
263 * applies to get_ctx_params and gettable_ctx_params. The same rules
264 * apply to the "md_params" functions. The dupctx function is optional.
266 ERR_raise(ERR_LIB_EVP
, EVP_R_INVALID_PROVIDER_FUNCTIONS
);
272 EVP_SIGNATURE_free(signature
);
276 void EVP_SIGNATURE_free(EVP_SIGNATURE
*signature
)
280 if (signature
== NULL
)
282 CRYPTO_DOWN_REF(&signature
->refcnt
, &i
);
285 OPENSSL_free(signature
->type_name
);
286 ossl_provider_free(signature
->prov
);
287 CRYPTO_FREE_REF(&signature
->refcnt
);
288 OPENSSL_free(signature
);
291 int EVP_SIGNATURE_up_ref(EVP_SIGNATURE
*signature
)
295 CRYPTO_UP_REF(&signature
->refcnt
, &ref
);
299 OSSL_PROVIDER
*EVP_SIGNATURE_get0_provider(const EVP_SIGNATURE
*signature
)
301 return signature
->prov
;
304 EVP_SIGNATURE
*EVP_SIGNATURE_fetch(OSSL_LIB_CTX
*ctx
, const char *algorithm
,
305 const char *properties
)
307 return evp_generic_fetch(ctx
, OSSL_OP_SIGNATURE
, algorithm
, properties
,
308 evp_signature_from_algorithm
,
309 (int (*)(void *))EVP_SIGNATURE_up_ref
,
310 (void (*)(void *))EVP_SIGNATURE_free
);
313 EVP_SIGNATURE
*evp_signature_fetch_from_prov(OSSL_PROVIDER
*prov
,
314 const char *algorithm
,
315 const char *properties
)
317 return evp_generic_fetch_from_prov(prov
, OSSL_OP_SIGNATURE
,
318 algorithm
, properties
,
319 evp_signature_from_algorithm
,
320 (int (*)(void *))EVP_SIGNATURE_up_ref
,
321 (void (*)(void *))EVP_SIGNATURE_free
);
324 int EVP_SIGNATURE_is_a(const EVP_SIGNATURE
*signature
, const char *name
)
326 return signature
!= NULL
327 && evp_is_a(signature
->prov
, signature
->name_id
, NULL
, name
);
330 int evp_signature_get_number(const EVP_SIGNATURE
*signature
)
332 return signature
->name_id
;
335 const char *EVP_SIGNATURE_get0_name(const EVP_SIGNATURE
*signature
)
337 return signature
->type_name
;
340 const char *EVP_SIGNATURE_get0_description(const EVP_SIGNATURE
*signature
)
342 return signature
->description
;
345 void EVP_SIGNATURE_do_all_provided(OSSL_LIB_CTX
*libctx
,
346 void (*fn
)(EVP_SIGNATURE
*signature
,
350 evp_generic_do_all(libctx
, OSSL_OP_SIGNATURE
,
351 (void (*)(void *, void *))fn
, arg
,
352 evp_signature_from_algorithm
,
353 (int (*)(void *))EVP_SIGNATURE_up_ref
,
354 (void (*)(void *))EVP_SIGNATURE_free
);
358 int EVP_SIGNATURE_names_do_all(const EVP_SIGNATURE
*signature
,
359 void (*fn
)(const char *name
, void *data
),
362 if (signature
->prov
!= NULL
)
363 return evp_names_do_all(signature
->prov
, signature
->name_id
, fn
, data
);
368 const OSSL_PARAM
*EVP_SIGNATURE_gettable_ctx_params(const EVP_SIGNATURE
*sig
)
372 if (sig
== NULL
|| sig
->gettable_ctx_params
== NULL
)
375 provctx
= ossl_provider_ctx(EVP_SIGNATURE_get0_provider(sig
));
376 return sig
->gettable_ctx_params(NULL
, provctx
);
379 const OSSL_PARAM
*EVP_SIGNATURE_settable_ctx_params(const EVP_SIGNATURE
*sig
)
383 if (sig
== NULL
|| sig
->settable_ctx_params
== NULL
)
386 provctx
= ossl_provider_ctx(EVP_SIGNATURE_get0_provider(sig
));
387 return sig
->settable_ctx_params(NULL
, provctx
);
390 static int evp_pkey_signature_init(EVP_PKEY_CTX
*ctx
, int operation
,
391 const OSSL_PARAM params
[])
394 void *provkey
= NULL
;
395 EVP_SIGNATURE
*signature
= NULL
;
396 EVP_KEYMGMT
*tmp_keymgmt
= NULL
;
397 const OSSL_PROVIDER
*tmp_prov
= NULL
;
398 const char *supported_sig
= NULL
;
402 ERR_raise(ERR_LIB_EVP
, ERR_R_PASSED_NULL_PARAMETER
);
406 evp_pkey_ctx_free_old_ops(ctx
);
407 ctx
->operation
= operation
;
411 if (evp_pkey_ctx_is_legacy(ctx
))
414 if (ctx
->pkey
== NULL
) {
415 ERR_clear_last_mark();
416 ERR_raise(ERR_LIB_EVP
, EVP_R_NO_KEY_SET
);
421 * Try to derive the supported signature from |ctx->keymgmt|.
423 if (!ossl_assert(ctx
->pkey
->keymgmt
== NULL
424 || ctx
->pkey
->keymgmt
== ctx
->keymgmt
)) {
425 ERR_clear_last_mark();
426 ERR_raise(ERR_LIB_EVP
, ERR_R_INTERNAL_ERROR
);
429 supported_sig
= evp_keymgmt_util_query_operation_name(ctx
->keymgmt
,
431 if (supported_sig
== NULL
) {
432 ERR_clear_last_mark();
433 ERR_raise(ERR_LIB_EVP
, EVP_R_INITIALIZATION_ERROR
);
438 * We perform two iterations:
440 * 1. Do the normal signature fetch, using the fetching data given by
442 * 2. Do the provider specific signature fetch, from the same provider
445 * We then try to fetch the keymgmt from the same provider as the
446 * signature, and try to export |ctx->pkey| to that keymgmt (when
447 * this keymgmt happens to be the same as |ctx->keymgmt|, the export
448 * is a no-op, but we call it anyway to not complicate the code even
450 * If the export call succeeds (returns a non-NULL provider key pointer),
451 * we're done and can perform the operation itself. If not, we perform
452 * the second iteration, or jump to legacy.
454 for (iter
= 1; iter
< 3 && provkey
== NULL
; iter
++) {
455 EVP_KEYMGMT
*tmp_keymgmt_tofree
= NULL
;
458 * If we're on the second iteration, free the results from the first.
459 * They are NULL on the first iteration, so no need to check what
460 * iteration we're on.
462 EVP_SIGNATURE_free(signature
);
463 EVP_KEYMGMT_free(tmp_keymgmt
);
468 EVP_SIGNATURE_fetch(ctx
->libctx
, supported_sig
, ctx
->propquery
);
469 if (signature
!= NULL
)
470 tmp_prov
= EVP_SIGNATURE_get0_provider(signature
);
473 tmp_prov
= EVP_KEYMGMT_get0_provider(ctx
->keymgmt
);
475 evp_signature_fetch_from_prov((OSSL_PROVIDER
*)tmp_prov
,
476 supported_sig
, ctx
->propquery
);
477 if (signature
== NULL
)
481 if (signature
== NULL
)
485 * Ensure that the key is provided, either natively, or as a cached
486 * export. We start by fetching the keymgmt with the same name as
487 * |ctx->pkey|, but from the provider of the signature method, using
488 * the same property query as when fetching the signature method.
489 * With the keymgmt we found (if we did), we try to export |ctx->pkey|
490 * to it (evp_pkey_export_to_provider() is smart enough to only actually
492 * export it if |tmp_keymgmt| is different from |ctx->pkey|'s keymgmt)
494 tmp_keymgmt_tofree
= tmp_keymgmt
=
495 evp_keymgmt_fetch_from_prov((OSSL_PROVIDER
*)tmp_prov
,
496 EVP_KEYMGMT_get0_name(ctx
->keymgmt
),
498 if (tmp_keymgmt
!= NULL
)
499 provkey
= evp_pkey_export_to_provider(ctx
->pkey
, ctx
->libctx
,
500 &tmp_keymgmt
, ctx
->propquery
);
501 if (tmp_keymgmt
== NULL
)
502 EVP_KEYMGMT_free(tmp_keymgmt_tofree
);
505 if (provkey
== NULL
) {
506 EVP_SIGNATURE_free(signature
);
512 /* No more legacy from here down to legacy: */
514 ctx
->op
.sig
.signature
= signature
;
516 signature
->newctx(ossl_provider_ctx(signature
->prov
), ctx
->propquery
);
517 if (ctx
->op
.sig
.algctx
== NULL
) {
518 /* The provider key can stay in the cache */
519 ERR_raise(ERR_LIB_EVP
, EVP_R_INITIALIZATION_ERROR
);
524 case EVP_PKEY_OP_SIGN
:
525 if (signature
->sign_init
== NULL
) {
526 ERR_raise(ERR_LIB_EVP
, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE
);
530 ret
= signature
->sign_init(ctx
->op
.sig
.algctx
, provkey
, params
);
532 case EVP_PKEY_OP_VERIFY
:
533 if (signature
->verify_init
== NULL
) {
534 ERR_raise(ERR_LIB_EVP
, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE
);
538 ret
= signature
->verify_init(ctx
->op
.sig
.algctx
, provkey
, params
);
540 case EVP_PKEY_OP_VERIFYRECOVER
:
541 if (signature
->verify_recover_init
== NULL
) {
542 ERR_raise(ERR_LIB_EVP
, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE
);
546 ret
= signature
->verify_recover_init(ctx
->op
.sig
.algctx
, provkey
,
550 ERR_raise(ERR_LIB_EVP
, EVP_R_INITIALIZATION_ERROR
);
555 signature
->freectx(ctx
->op
.sig
.algctx
);
556 ctx
->op
.sig
.algctx
= NULL
;
563 * If we don't have the full support we need with provided methods,
564 * let's go see if legacy does.
567 EVP_KEYMGMT_free(tmp_keymgmt
);
570 if (ctx
->pmeth
== NULL
571 || (operation
== EVP_PKEY_OP_SIGN
&& ctx
->pmeth
->sign
== NULL
)
572 || (operation
== EVP_PKEY_OP_VERIFY
&& ctx
->pmeth
->verify
== NULL
)
573 || (operation
== EVP_PKEY_OP_VERIFYRECOVER
574 && ctx
->pmeth
->verify_recover
== NULL
)) {
575 ERR_raise(ERR_LIB_EVP
, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE
);
580 case EVP_PKEY_OP_SIGN
:
581 if (ctx
->pmeth
->sign_init
== NULL
)
583 ret
= ctx
->pmeth
->sign_init(ctx
);
585 case EVP_PKEY_OP_VERIFY
:
586 if (ctx
->pmeth
->verify_init
== NULL
)
588 ret
= ctx
->pmeth
->verify_init(ctx
);
590 case EVP_PKEY_OP_VERIFYRECOVER
:
591 if (ctx
->pmeth
->verify_recover_init
== NULL
)
593 ret
= ctx
->pmeth
->verify_recover_init(ctx
);
596 ERR_raise(ERR_LIB_EVP
, EVP_R_INITIALIZATION_ERROR
);
604 ret
= evp_pkey_ctx_use_cached_data(ctx
);
607 EVP_KEYMGMT_free(tmp_keymgmt
);
610 evp_pkey_ctx_free_old_ops(ctx
);
611 ctx
->operation
= EVP_PKEY_OP_UNDEFINED
;
612 EVP_KEYMGMT_free(tmp_keymgmt
);
616 int EVP_PKEY_sign_init(EVP_PKEY_CTX
*ctx
)
618 return evp_pkey_signature_init(ctx
, EVP_PKEY_OP_SIGN
, NULL
);
621 int EVP_PKEY_sign_init_ex(EVP_PKEY_CTX
*ctx
, const OSSL_PARAM params
[])
623 return evp_pkey_signature_init(ctx
, EVP_PKEY_OP_SIGN
, params
);
626 int EVP_PKEY_sign(EVP_PKEY_CTX
*ctx
,
627 unsigned char *sig
, size_t *siglen
,
628 const unsigned char *tbs
, size_t tbslen
)
633 ERR_raise(ERR_LIB_EVP
, ERR_R_PASSED_NULL_PARAMETER
);
637 if (ctx
->operation
!= EVP_PKEY_OP_SIGN
) {
638 ERR_raise(ERR_LIB_EVP
, EVP_R_OPERATION_NOT_INITIALIZED
);
642 if (ctx
->op
.sig
.algctx
== NULL
)
645 if (ctx
->op
.sig
.signature
->sign
== NULL
) {
646 ERR_raise(ERR_LIB_EVP
, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE
);
650 ret
= ctx
->op
.sig
.signature
->sign(ctx
->op
.sig
.algctx
, sig
, siglen
,
651 (sig
== NULL
) ? 0 : *siglen
, tbs
, tbslen
);
656 if (ctx
->pmeth
== NULL
|| ctx
->pmeth
->sign
== NULL
) {
657 ERR_raise(ERR_LIB_EVP
, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE
);
661 M_check_autoarg(ctx
, sig
, siglen
, EVP_F_EVP_PKEY_SIGN
)
662 return ctx
->pmeth
->sign(ctx
, sig
, siglen
, tbs
, tbslen
);
665 int EVP_PKEY_verify_init(EVP_PKEY_CTX
*ctx
)
667 return evp_pkey_signature_init(ctx
, EVP_PKEY_OP_VERIFY
, NULL
);
670 int EVP_PKEY_verify_init_ex(EVP_PKEY_CTX
*ctx
, const OSSL_PARAM params
[])
672 return evp_pkey_signature_init(ctx
, EVP_PKEY_OP_VERIFY
, params
);
675 int EVP_PKEY_verify(EVP_PKEY_CTX
*ctx
,
676 const unsigned char *sig
, size_t siglen
,
677 const unsigned char *tbs
, size_t tbslen
)
682 ERR_raise(ERR_LIB_EVP
, ERR_R_PASSED_NULL_PARAMETER
);
686 if (ctx
->operation
!= EVP_PKEY_OP_VERIFY
) {
687 ERR_raise(ERR_LIB_EVP
, EVP_R_OPERATION_NOT_INITIALIZED
);
691 if (ctx
->op
.sig
.algctx
== NULL
)
694 if (ctx
->op
.sig
.signature
->verify
== NULL
) {
695 ERR_raise(ERR_LIB_EVP
, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE
);
699 ret
= ctx
->op
.sig
.signature
->verify(ctx
->op
.sig
.algctx
, sig
, siglen
,
704 if (ctx
->pmeth
== NULL
|| ctx
->pmeth
->verify
== NULL
) {
705 ERR_raise(ERR_LIB_EVP
, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE
);
709 return ctx
->pmeth
->verify(ctx
, sig
, siglen
, tbs
, tbslen
);
712 int EVP_PKEY_verify_recover_init(EVP_PKEY_CTX
*ctx
)
714 return evp_pkey_signature_init(ctx
, EVP_PKEY_OP_VERIFYRECOVER
, NULL
);
717 int EVP_PKEY_verify_recover_init_ex(EVP_PKEY_CTX
*ctx
,
718 const OSSL_PARAM params
[])
720 return evp_pkey_signature_init(ctx
, EVP_PKEY_OP_VERIFYRECOVER
, params
);
723 int EVP_PKEY_verify_recover(EVP_PKEY_CTX
*ctx
,
724 unsigned char *rout
, size_t *routlen
,
725 const unsigned char *sig
, size_t siglen
)
730 ERR_raise(ERR_LIB_EVP
, ERR_R_PASSED_NULL_PARAMETER
);
734 if (ctx
->operation
!= EVP_PKEY_OP_VERIFYRECOVER
) {
735 ERR_raise(ERR_LIB_EVP
, EVP_R_OPERATION_NOT_INITIALIZED
);
739 if (ctx
->op
.sig
.algctx
== NULL
)
742 if (ctx
->op
.sig
.signature
->verify_recover
== NULL
) {
743 ERR_raise(ERR_LIB_EVP
, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE
);
747 ret
= ctx
->op
.sig
.signature
->verify_recover(ctx
->op
.sig
.algctx
, rout
,
749 (rout
== NULL
? 0 : *routlen
),
753 if (ctx
->pmeth
== NULL
|| ctx
->pmeth
->verify_recover
== NULL
) {
754 ERR_raise(ERR_LIB_EVP
, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE
);
757 M_check_autoarg(ctx
, rout
, routlen
, EVP_F_EVP_PKEY_VERIFY_RECOVER
)
758 return ctx
->pmeth
->verify_recover(ctx
, rout
, routlen
, sig
, siglen
);