2 * Copyright 2006-2018 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/engine.h>
13 #include <openssl/evp.h>
14 #include <openssl/x509v3.h>
15 #include <openssl/core_names.h>
16 #include <openssl/dh.h>
17 #include "internal/cryptlib.h"
18 #include "internal/asn1_int.h"
19 #include "internal/evp_int.h"
20 #include "internal/numbers.h"
23 typedef int sk_cmp_fn_type(const char *const *a
, const char *const *b
);
25 static STACK_OF(EVP_PKEY_METHOD
) *app_pkey_methods
= NULL
;
27 /* This array needs to be in order of NIDs */
28 static const EVP_PKEY_METHOD
*standard_methods
[] = {
29 #ifndef OPENSSL_NO_RSA
35 #ifndef OPENSSL_NO_DSA
42 #ifndef OPENSSL_NO_CMAC
45 #ifndef OPENSSL_NO_RSA
51 #ifndef OPENSSL_NO_SCRYPT
60 #ifndef OPENSSL_NO_POLY1305
63 #ifndef OPENSSL_NO_SIPHASH
70 #ifndef OPENSSL_NO_SM2
75 DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD
*, const EVP_PKEY_METHOD
*,
78 static int pmeth_cmp(const EVP_PKEY_METHOD
*const *a
,
79 const EVP_PKEY_METHOD
*const *b
)
81 return ((*a
)->pkey_id
- (*b
)->pkey_id
);
84 IMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD
*, const EVP_PKEY_METHOD
*,
87 const EVP_PKEY_METHOD
*EVP_PKEY_meth_find(int type
)
90 const EVP_PKEY_METHOD
*t
= &tmp
, **ret
;
92 if (app_pkey_methods
) {
94 idx
= sk_EVP_PKEY_METHOD_find(app_pkey_methods
, &tmp
);
96 return sk_EVP_PKEY_METHOD_value(app_pkey_methods
, idx
);
98 ret
= OBJ_bsearch_pmeth(&t
, standard_methods
,
99 sizeof(standard_methods
) /
100 sizeof(EVP_PKEY_METHOD
*));
106 static EVP_PKEY_CTX
*int_ctx_new(EVP_PKEY
*pkey
, ENGINE
*e
, int id
)
109 const EVP_PKEY_METHOD
*pmeth
;
116 #ifndef OPENSSL_NO_ENGINE
117 if (e
== NULL
&& pkey
!= NULL
)
118 e
= pkey
->pmeth_engine
!= NULL
? pkey
->pmeth_engine
: pkey
->engine
;
119 /* Try to find an ENGINE which implements this method */
121 if (!ENGINE_init(e
)) {
122 EVPerr(EVP_F_INT_CTX_NEW
, ERR_R_ENGINE_LIB
);
126 e
= ENGINE_get_pkey_meth_engine(id
);
130 * If an ENGINE handled this method look it up. Otherwise use internal
134 pmeth
= ENGINE_get_pkey_meth(e
, id
);
137 pmeth
= EVP_PKEY_meth_find(id
);
140 #ifndef OPENSSL_NO_ENGINE
143 EVPerr(EVP_F_INT_CTX_NEW
, EVP_R_UNSUPPORTED_ALGORITHM
);
147 ret
= OPENSSL_zalloc(sizeof(*ret
));
149 #ifndef OPENSSL_NO_ENGINE
152 EVPerr(EVP_F_INT_CTX_NEW
, ERR_R_MALLOC_FAILURE
);
157 ret
->operation
= EVP_PKEY_OP_UNDEFINED
;
160 EVP_PKEY_up_ref(pkey
);
163 if (pmeth
->init(ret
) <= 0) {
165 EVP_PKEY_CTX_free(ret
);
173 EVP_PKEY_METHOD
*EVP_PKEY_meth_new(int id
, int flags
)
175 EVP_PKEY_METHOD
*pmeth
;
177 pmeth
= OPENSSL_zalloc(sizeof(*pmeth
));
179 EVPerr(EVP_F_EVP_PKEY_METH_NEW
, ERR_R_MALLOC_FAILURE
);
184 pmeth
->flags
= flags
| EVP_PKEY_FLAG_DYNAMIC
;
188 void EVP_PKEY_meth_get0_info(int *ppkey_id
, int *pflags
,
189 const EVP_PKEY_METHOD
*meth
)
192 *ppkey_id
= meth
->pkey_id
;
194 *pflags
= meth
->flags
;
197 void EVP_PKEY_meth_copy(EVP_PKEY_METHOD
*dst
, const EVP_PKEY_METHOD
*src
)
200 dst
->init
= src
->init
;
201 dst
->copy
= src
->copy
;
202 dst
->cleanup
= src
->cleanup
;
204 dst
->paramgen_init
= src
->paramgen_init
;
205 dst
->paramgen
= src
->paramgen
;
207 dst
->keygen_init
= src
->keygen_init
;
208 dst
->keygen
= src
->keygen
;
210 dst
->sign_init
= src
->sign_init
;
211 dst
->sign
= src
->sign
;
213 dst
->verify_init
= src
->verify_init
;
214 dst
->verify
= src
->verify
;
216 dst
->verify_recover_init
= src
->verify_recover_init
;
217 dst
->verify_recover
= src
->verify_recover
;
219 dst
->signctx_init
= src
->signctx_init
;
220 dst
->signctx
= src
->signctx
;
222 dst
->verifyctx_init
= src
->verifyctx_init
;
223 dst
->verifyctx
= src
->verifyctx
;
225 dst
->encrypt_init
= src
->encrypt_init
;
226 dst
->encrypt
= src
->encrypt
;
228 dst
->decrypt_init
= src
->decrypt_init
;
229 dst
->decrypt
= src
->decrypt
;
231 dst
->derive_init
= src
->derive_init
;
232 dst
->derive
= src
->derive
;
234 dst
->ctrl
= src
->ctrl
;
235 dst
->ctrl_str
= src
->ctrl_str
;
237 dst
->check
= src
->check
;
240 void EVP_PKEY_meth_free(EVP_PKEY_METHOD
*pmeth
)
242 if (pmeth
&& (pmeth
->flags
& EVP_PKEY_FLAG_DYNAMIC
))
246 EVP_PKEY_CTX
*EVP_PKEY_CTX_new(EVP_PKEY
*pkey
, ENGINE
*e
)
248 return int_ctx_new(pkey
, e
, -1);
251 EVP_PKEY_CTX
*EVP_PKEY_CTX_new_id(int id
, ENGINE
*e
)
253 return int_ctx_new(NULL
, e
, id
);
256 EVP_PKEY_CTX
*EVP_PKEY_CTX_dup(const EVP_PKEY_CTX
*pctx
)
260 if (((pctx
->pmeth
== NULL
) || (pctx
->pmeth
->copy
== NULL
))
261 && pctx
->exchprovctx
== NULL
)
263 #ifndef OPENSSL_NO_ENGINE
264 /* Make sure it's safe to copy a pkey context using an ENGINE */
265 if (pctx
->engine
&& !ENGINE_init(pctx
->engine
)) {
266 EVPerr(EVP_F_EVP_PKEY_CTX_DUP
, ERR_R_ENGINE_LIB
);
270 rctx
= OPENSSL_zalloc(sizeof(*rctx
));
272 EVPerr(EVP_F_EVP_PKEY_CTX_DUP
, ERR_R_MALLOC_FAILURE
);
276 if (pctx
->pkey
!= NULL
)
277 EVP_PKEY_up_ref(pctx
->pkey
);
278 rctx
->pkey
= pctx
->pkey
;
279 rctx
->operation
= pctx
->operation
;
281 if (pctx
->exchprovctx
!= NULL
) {
282 if (!ossl_assert(pctx
->exchange
!= NULL
))
284 rctx
->exchange
= pctx
->exchange
;
285 if (!EVP_KEYEXCH_up_ref(rctx
->exchange
)) {
289 rctx
->exchprovctx
= pctx
->exchange
->dupctx(pctx
->exchprovctx
);
290 if (rctx
->exchprovctx
== NULL
) {
291 EVP_KEYEXCH_free(rctx
->exchange
);
298 rctx
->pmeth
= pctx
->pmeth
;
299 #ifndef OPENSSL_NO_ENGINE
300 rctx
->engine
= pctx
->engine
;
304 EVP_PKEY_up_ref(pctx
->peerkey
);
305 rctx
->peerkey
= pctx
->peerkey
;
307 if (pctx
->pmeth
->copy(rctx
, pctx
) > 0)
311 EVP_PKEY_CTX_free(rctx
);
316 int EVP_PKEY_meth_add0(const EVP_PKEY_METHOD
*pmeth
)
318 if (app_pkey_methods
== NULL
) {
319 app_pkey_methods
= sk_EVP_PKEY_METHOD_new(pmeth_cmp
);
320 if (app_pkey_methods
== NULL
){
321 EVPerr(EVP_F_EVP_PKEY_METH_ADD0
, ERR_R_MALLOC_FAILURE
);
325 if (!sk_EVP_PKEY_METHOD_push(app_pkey_methods
, pmeth
)) {
326 EVPerr(EVP_F_EVP_PKEY_METH_ADD0
, ERR_R_MALLOC_FAILURE
);
329 sk_EVP_PKEY_METHOD_sort(app_pkey_methods
);
333 void evp_app_cleanup_int(void)
335 if (app_pkey_methods
!= NULL
)
336 sk_EVP_PKEY_METHOD_pop_free(app_pkey_methods
, EVP_PKEY_meth_free
);
339 int EVP_PKEY_meth_remove(const EVP_PKEY_METHOD
*pmeth
)
341 const EVP_PKEY_METHOD
*ret
;
343 ret
= sk_EVP_PKEY_METHOD_delete_ptr(app_pkey_methods
, pmeth
);
345 return ret
== NULL
? 0 : 1;
348 size_t EVP_PKEY_meth_get_count(void)
350 size_t rv
= OSSL_NELEM(standard_methods
);
352 if (app_pkey_methods
)
353 rv
+= sk_EVP_PKEY_METHOD_num(app_pkey_methods
);
357 const EVP_PKEY_METHOD
*EVP_PKEY_meth_get0(size_t idx
)
359 if (idx
< OSSL_NELEM(standard_methods
))
360 return standard_methods
[idx
];
361 if (app_pkey_methods
== NULL
)
363 idx
-= OSSL_NELEM(standard_methods
);
364 if (idx
>= (size_t)sk_EVP_PKEY_METHOD_num(app_pkey_methods
))
366 return sk_EVP_PKEY_METHOD_value(app_pkey_methods
, idx
);
369 void EVP_PKEY_CTX_free(EVP_PKEY_CTX
*ctx
)
373 if (ctx
->pmeth
&& ctx
->pmeth
->cleanup
)
374 ctx
->pmeth
->cleanup(ctx
);
376 if (ctx
->exchprovctx
!= NULL
&& ctx
->exchange
!= NULL
)
377 ctx
->exchange
->freectx(ctx
->exchprovctx
);
379 EVP_KEYEXCH_free(ctx
->exchange
);
381 EVP_PKEY_free(ctx
->pkey
);
382 EVP_PKEY_free(ctx
->peerkey
);
383 #ifndef OPENSSL_NO_ENGINE
384 ENGINE_finish(ctx
->engine
);
389 int EVP_PKEY_CTX_set_params(EVP_PKEY_CTX
*ctx
, OSSL_PARAM
*params
)
391 if (ctx
->exchprovctx
!= NULL
&& ctx
->exchange
!= NULL
)
392 return ctx
->exchange
->set_params(ctx
->exchprovctx
, params
);
396 #ifndef OPENSSL_NO_DH
397 int EVP_PKEY_CTX_set_dh_pad(EVP_PKEY_CTX
*ctx
, int pad
)
399 OSSL_PARAM dh_pad_params
[2];
401 /* TODO(3.0): Remove this eventually when no more legacy */
402 if (ctx
->exchprovctx
== NULL
)
403 return EVP_PKEY_CTX_ctrl(ctx
, EVP_PKEY_DH
, EVP_PKEY_OP_DERIVE
,
404 EVP_PKEY_CTRL_DH_PAD
, pad
, NULL
);
406 dh_pad_params
[0] = OSSL_PARAM_construct_int(OSSL_EXCHANGE_PARAM_PAD
, &pad
);
407 dh_pad_params
[1] = OSSL_PARAM_construct_end();
409 return EVP_PKEY_CTX_set_params(ctx
, dh_pad_params
);
413 static int legacy_ctrl_to_param(EVP_PKEY_CTX
*ctx
, int keytype
, int optype
,
414 int cmd
, int p1
, void *p2
)
417 #ifndef OPENSSL_NO_DH
418 case EVP_PKEY_CTRL_DH_PAD
:
419 return EVP_PKEY_CTX_set_dh_pad(ctx
, p1
);
425 int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX
*ctx
, int keytype
, int optype
,
426 int cmd
, int p1
, void *p2
)
431 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL
, EVP_R_COMMAND_NOT_SUPPORTED
);
435 if (ctx
->exchprovctx
!= NULL
)
436 return legacy_ctrl_to_param(ctx
, keytype
, optype
, cmd
, p1
, p2
);
438 if (ctx
->pmeth
== NULL
|| ctx
->pmeth
->ctrl
== NULL
) {
439 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL
, EVP_R_COMMAND_NOT_SUPPORTED
);
442 if ((keytype
!= -1) && (ctx
->pmeth
->pkey_id
!= keytype
))
445 /* Skip the operation checks since this is called in a very early stage */
446 if (ctx
->pmeth
->digest_custom
!= NULL
)
449 if (ctx
->operation
== EVP_PKEY_OP_UNDEFINED
) {
450 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL
, EVP_R_NO_OPERATION_SET
);
454 if ((optype
!= -1) && !(ctx
->operation
& optype
)) {
455 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL
, EVP_R_INVALID_OPERATION
);
460 ret
= ctx
->pmeth
->ctrl(ctx
, cmd
, p1
, p2
);
463 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL
, EVP_R_COMMAND_NOT_SUPPORTED
);
468 int EVP_PKEY_CTX_ctrl_uint64(EVP_PKEY_CTX
*ctx
, int keytype
, int optype
,
469 int cmd
, uint64_t value
)
471 return EVP_PKEY_CTX_ctrl(ctx
, keytype
, optype
, cmd
, 0, &value
);
474 static int legacy_ctrl_str_to_param(EVP_PKEY_CTX
*ctx
, const char *name
,
477 #ifndef OPENSSL_NO_DH
478 if (strcmp(name
, "dh_pad") == 0) {
482 return EVP_PKEY_CTX_set_dh_pad(ctx
, pad
);
488 int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX
*ctx
,
489 const char *name
, const char *value
)
492 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR
, EVP_R_COMMAND_NOT_SUPPORTED
);
496 if (ctx
->exchprovctx
!= NULL
)
497 return legacy_ctrl_str_to_param(ctx
, name
, value
);
499 if (!ctx
|| !ctx
->pmeth
|| !ctx
->pmeth
->ctrl_str
) {
500 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR
, EVP_R_COMMAND_NOT_SUPPORTED
);
503 if (strcmp(name
, "digest") == 0)
504 return EVP_PKEY_CTX_md(ctx
, EVP_PKEY_OP_TYPE_SIG
, EVP_PKEY_CTRL_MD
,
506 return ctx
->pmeth
->ctrl_str(ctx
, name
, value
);
509 /* Utility functions to send a string of hex string to a ctrl */
511 int EVP_PKEY_CTX_str2ctrl(EVP_PKEY_CTX
*ctx
, int cmd
, const char *str
)
518 return ctx
->pmeth
->ctrl(ctx
, cmd
, len
, (void *)str
);
521 int EVP_PKEY_CTX_hex2ctrl(EVP_PKEY_CTX
*ctx
, int cmd
, const char *hex
)
527 bin
= OPENSSL_hexstr2buf(hex
, &binlen
);
530 if (binlen
<= INT_MAX
)
531 rv
= ctx
->pmeth
->ctrl(ctx
, cmd
, binlen
, bin
);
536 /* Pass a message digest to a ctrl */
537 int EVP_PKEY_CTX_md(EVP_PKEY_CTX
*ctx
, int optype
, int cmd
, const char *md
)
541 if (md
== NULL
|| (m
= EVP_get_digestbyname(md
)) == NULL
) {
542 EVPerr(EVP_F_EVP_PKEY_CTX_MD
, EVP_R_INVALID_DIGEST
);
545 return EVP_PKEY_CTX_ctrl(ctx
, -1, optype
, cmd
, 0, (void *)m
);
548 int EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX
*ctx
)
550 return ctx
->operation
;
553 void EVP_PKEY_CTX_set0_keygen_info(EVP_PKEY_CTX
*ctx
, int *dat
, int datlen
)
555 ctx
->keygen_info
= dat
;
556 ctx
->keygen_info_count
= datlen
;
559 void EVP_PKEY_CTX_set_data(EVP_PKEY_CTX
*ctx
, void *data
)
564 void *EVP_PKEY_CTX_get_data(const EVP_PKEY_CTX
*ctx
)
569 EVP_PKEY
*EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX
*ctx
)
574 EVP_PKEY
*EVP_PKEY_CTX_get0_peerkey(EVP_PKEY_CTX
*ctx
)
579 void EVP_PKEY_CTX_set_app_data(EVP_PKEY_CTX
*ctx
, void *data
)
581 ctx
->app_data
= data
;
584 void *EVP_PKEY_CTX_get_app_data(EVP_PKEY_CTX
*ctx
)
586 return ctx
->app_data
;
589 void EVP_PKEY_meth_set_init(EVP_PKEY_METHOD
*pmeth
,
590 int (*init
) (EVP_PKEY_CTX
*ctx
))
595 void EVP_PKEY_meth_set_copy(EVP_PKEY_METHOD
*pmeth
,
596 int (*copy
) (EVP_PKEY_CTX
*dst
,
597 const EVP_PKEY_CTX
*src
))
602 void EVP_PKEY_meth_set_cleanup(EVP_PKEY_METHOD
*pmeth
,
603 void (*cleanup
) (EVP_PKEY_CTX
*ctx
))
605 pmeth
->cleanup
= cleanup
;
608 void EVP_PKEY_meth_set_paramgen(EVP_PKEY_METHOD
*pmeth
,
609 int (*paramgen_init
) (EVP_PKEY_CTX
*ctx
),
610 int (*paramgen
) (EVP_PKEY_CTX
*ctx
,
613 pmeth
->paramgen_init
= paramgen_init
;
614 pmeth
->paramgen
= paramgen
;
617 void EVP_PKEY_meth_set_keygen(EVP_PKEY_METHOD
*pmeth
,
618 int (*keygen_init
) (EVP_PKEY_CTX
*ctx
),
619 int (*keygen
) (EVP_PKEY_CTX
*ctx
,
622 pmeth
->keygen_init
= keygen_init
;
623 pmeth
->keygen
= keygen
;
626 void EVP_PKEY_meth_set_sign(EVP_PKEY_METHOD
*pmeth
,
627 int (*sign_init
) (EVP_PKEY_CTX
*ctx
),
628 int (*sign
) (EVP_PKEY_CTX
*ctx
,
629 unsigned char *sig
, size_t *siglen
,
630 const unsigned char *tbs
,
633 pmeth
->sign_init
= sign_init
;
637 void EVP_PKEY_meth_set_verify(EVP_PKEY_METHOD
*pmeth
,
638 int (*verify_init
) (EVP_PKEY_CTX
*ctx
),
639 int (*verify
) (EVP_PKEY_CTX
*ctx
,
640 const unsigned char *sig
,
642 const unsigned char *tbs
,
645 pmeth
->verify_init
= verify_init
;
646 pmeth
->verify
= verify
;
649 void EVP_PKEY_meth_set_verify_recover(EVP_PKEY_METHOD
*pmeth
,
650 int (*verify_recover_init
) (EVP_PKEY_CTX
652 int (*verify_recover
) (EVP_PKEY_CTX
661 pmeth
->verify_recover_init
= verify_recover_init
;
662 pmeth
->verify_recover
= verify_recover
;
665 void EVP_PKEY_meth_set_signctx(EVP_PKEY_METHOD
*pmeth
,
666 int (*signctx_init
) (EVP_PKEY_CTX
*ctx
,
668 int (*signctx
) (EVP_PKEY_CTX
*ctx
,
673 pmeth
->signctx_init
= signctx_init
;
674 pmeth
->signctx
= signctx
;
677 void EVP_PKEY_meth_set_verifyctx(EVP_PKEY_METHOD
*pmeth
,
678 int (*verifyctx_init
) (EVP_PKEY_CTX
*ctx
,
680 int (*verifyctx
) (EVP_PKEY_CTX
*ctx
,
681 const unsigned char *sig
,
685 pmeth
->verifyctx_init
= verifyctx_init
;
686 pmeth
->verifyctx
= verifyctx
;
689 void EVP_PKEY_meth_set_encrypt(EVP_PKEY_METHOD
*pmeth
,
690 int (*encrypt_init
) (EVP_PKEY_CTX
*ctx
),
691 int (*encryptfn
) (EVP_PKEY_CTX
*ctx
,
694 const unsigned char *in
,
697 pmeth
->encrypt_init
= encrypt_init
;
698 pmeth
->encrypt
= encryptfn
;
701 void EVP_PKEY_meth_set_decrypt(EVP_PKEY_METHOD
*pmeth
,
702 int (*decrypt_init
) (EVP_PKEY_CTX
*ctx
),
703 int (*decrypt
) (EVP_PKEY_CTX
*ctx
,
706 const unsigned char *in
,
709 pmeth
->decrypt_init
= decrypt_init
;
710 pmeth
->decrypt
= decrypt
;
713 void EVP_PKEY_meth_set_derive(EVP_PKEY_METHOD
*pmeth
,
714 int (*derive_init
) (EVP_PKEY_CTX
*ctx
),
715 int (*derive
) (EVP_PKEY_CTX
*ctx
,
719 pmeth
->derive_init
= derive_init
;
720 pmeth
->derive
= derive
;
723 void EVP_PKEY_meth_set_ctrl(EVP_PKEY_METHOD
*pmeth
,
724 int (*ctrl
) (EVP_PKEY_CTX
*ctx
, int type
, int p1
,
726 int (*ctrl_str
) (EVP_PKEY_CTX
*ctx
,
731 pmeth
->ctrl_str
= ctrl_str
;
734 void EVP_PKEY_meth_set_check(EVP_PKEY_METHOD
*pmeth
,
735 int (*check
) (EVP_PKEY
*pkey
))
737 pmeth
->check
= check
;
740 void EVP_PKEY_meth_set_public_check(EVP_PKEY_METHOD
*pmeth
,
741 int (*check
) (EVP_PKEY
*pkey
))
743 pmeth
->public_check
= check
;
746 void EVP_PKEY_meth_set_param_check(EVP_PKEY_METHOD
*pmeth
,
747 int (*check
) (EVP_PKEY
*pkey
))
749 pmeth
->param_check
= check
;
752 void EVP_PKEY_meth_set_digest_custom(EVP_PKEY_METHOD
*pmeth
,
753 int (*digest_custom
) (EVP_PKEY_CTX
*ctx
,
756 pmeth
->digest_custom
= digest_custom
;
759 void EVP_PKEY_meth_get_init(const EVP_PKEY_METHOD
*pmeth
,
760 int (**pinit
) (EVP_PKEY_CTX
*ctx
))
762 *pinit
= pmeth
->init
;
765 void EVP_PKEY_meth_get_copy(const EVP_PKEY_METHOD
*pmeth
,
766 int (**pcopy
) (EVP_PKEY_CTX
*dst
,
767 const EVP_PKEY_CTX
*src
))
769 *pcopy
= pmeth
->copy
;
772 void EVP_PKEY_meth_get_cleanup(const EVP_PKEY_METHOD
*pmeth
,
773 void (**pcleanup
) (EVP_PKEY_CTX
*ctx
))
775 *pcleanup
= pmeth
->cleanup
;
778 void EVP_PKEY_meth_get_paramgen(const EVP_PKEY_METHOD
*pmeth
,
779 int (**pparamgen_init
) (EVP_PKEY_CTX
*ctx
),
780 int (**pparamgen
) (EVP_PKEY_CTX
*ctx
,
784 *pparamgen_init
= pmeth
->paramgen_init
;
786 *pparamgen
= pmeth
->paramgen
;
789 void EVP_PKEY_meth_get_keygen(const EVP_PKEY_METHOD
*pmeth
,
790 int (**pkeygen_init
) (EVP_PKEY_CTX
*ctx
),
791 int (**pkeygen
) (EVP_PKEY_CTX
*ctx
,
795 *pkeygen_init
= pmeth
->keygen_init
;
797 *pkeygen
= pmeth
->keygen
;
800 void EVP_PKEY_meth_get_sign(const EVP_PKEY_METHOD
*pmeth
,
801 int (**psign_init
) (EVP_PKEY_CTX
*ctx
),
802 int (**psign
) (EVP_PKEY_CTX
*ctx
,
803 unsigned char *sig
, size_t *siglen
,
804 const unsigned char *tbs
,
808 *psign_init
= pmeth
->sign_init
;
810 *psign
= pmeth
->sign
;
813 void EVP_PKEY_meth_get_verify(const EVP_PKEY_METHOD
*pmeth
,
814 int (**pverify_init
) (EVP_PKEY_CTX
*ctx
),
815 int (**pverify
) (EVP_PKEY_CTX
*ctx
,
816 const unsigned char *sig
,
818 const unsigned char *tbs
,
822 *pverify_init
= pmeth
->verify_init
;
824 *pverify
= pmeth
->verify
;
827 void EVP_PKEY_meth_get_verify_recover(const EVP_PKEY_METHOD
*pmeth
,
828 int (**pverify_recover_init
) (EVP_PKEY_CTX
830 int (**pverify_recover
) (EVP_PKEY_CTX
839 if (pverify_recover_init
)
840 *pverify_recover_init
= pmeth
->verify_recover_init
;
842 *pverify_recover
= pmeth
->verify_recover
;
845 void EVP_PKEY_meth_get_signctx(const EVP_PKEY_METHOD
*pmeth
,
846 int (**psignctx_init
) (EVP_PKEY_CTX
*ctx
,
848 int (**psignctx
) (EVP_PKEY_CTX
*ctx
,
854 *psignctx_init
= pmeth
->signctx_init
;
856 *psignctx
= pmeth
->signctx
;
859 void EVP_PKEY_meth_get_verifyctx(const EVP_PKEY_METHOD
*pmeth
,
860 int (**pverifyctx_init
) (EVP_PKEY_CTX
*ctx
,
862 int (**pverifyctx
) (EVP_PKEY_CTX
*ctx
,
863 const unsigned char *sig
,
868 *pverifyctx_init
= pmeth
->verifyctx_init
;
870 *pverifyctx
= pmeth
->verifyctx
;
873 void EVP_PKEY_meth_get_encrypt(const EVP_PKEY_METHOD
*pmeth
,
874 int (**pencrypt_init
) (EVP_PKEY_CTX
*ctx
),
875 int (**pencryptfn
) (EVP_PKEY_CTX
*ctx
,
878 const unsigned char *in
,
882 *pencrypt_init
= pmeth
->encrypt_init
;
884 *pencryptfn
= pmeth
->encrypt
;
887 void EVP_PKEY_meth_get_decrypt(const EVP_PKEY_METHOD
*pmeth
,
888 int (**pdecrypt_init
) (EVP_PKEY_CTX
*ctx
),
889 int (**pdecrypt
) (EVP_PKEY_CTX
*ctx
,
892 const unsigned char *in
,
896 *pdecrypt_init
= pmeth
->decrypt_init
;
898 *pdecrypt
= pmeth
->decrypt
;
901 void EVP_PKEY_meth_get_derive(const EVP_PKEY_METHOD
*pmeth
,
902 int (**pderive_init
) (EVP_PKEY_CTX
*ctx
),
903 int (**pderive
) (EVP_PKEY_CTX
*ctx
,
908 *pderive_init
= pmeth
->derive_init
;
910 *pderive
= pmeth
->derive
;
913 void EVP_PKEY_meth_get_ctrl(const EVP_PKEY_METHOD
*pmeth
,
914 int (**pctrl
) (EVP_PKEY_CTX
*ctx
, int type
, int p1
,
916 int (**pctrl_str
) (EVP_PKEY_CTX
*ctx
,
921 *pctrl
= pmeth
->ctrl
;
923 *pctrl_str
= pmeth
->ctrl_str
;
926 void EVP_PKEY_meth_get_check(const EVP_PKEY_METHOD
*pmeth
,
927 int (**pcheck
) (EVP_PKEY
*pkey
))
930 *pcheck
= pmeth
->check
;
933 void EVP_PKEY_meth_get_public_check(const EVP_PKEY_METHOD
*pmeth
,
934 int (**pcheck
) (EVP_PKEY
*pkey
))
937 *pcheck
= pmeth
->public_check
;
940 void EVP_PKEY_meth_get_param_check(const EVP_PKEY_METHOD
*pmeth
,
941 int (**pcheck
) (EVP_PKEY
*pkey
))
944 *pcheck
= pmeth
->param_check
;
947 void EVP_PKEY_meth_get_digest_custom(EVP_PKEY_METHOD
*pmeth
,
948 int (**pdigest_custom
) (EVP_PKEY_CTX
*ctx
,
951 if (pdigest_custom
!= NULL
)
952 *pdigest_custom
= pmeth
->digest_custom
;