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 int EVP_PKEY_CTX_set_dh_pad(EVP_PKEY_CTX
*ctx
, int pad
)
398 OSSL_PARAM dh_pad_params
[2];
400 /* TODO(3.0): Remove this eventually when no more legacy */
401 if (ctx
->exchprovctx
== NULL
)
402 return EVP_PKEY_CTX_ctrl(ctx
, EVP_PKEY_DH
, EVP_PKEY_OP_DERIVE
,
403 EVP_PKEY_CTRL_DH_PAD
, pad
, NULL
);
405 dh_pad_params
[0] = OSSL_PARAM_construct_int(OSSL_EXCHANGE_PARAM_PAD
, &pad
);
406 dh_pad_params
[1] = OSSL_PARAM_construct_end();
408 return EVP_PKEY_CTX_set_params(ctx
, dh_pad_params
);
411 static int legacy_ctrl_to_param(EVP_PKEY_CTX
*ctx
, int keytype
, int optype
,
412 int cmd
, int p1
, void *p2
)
415 case EVP_PKEY_CTRL_DH_PAD
:
416 return EVP_PKEY_CTX_set_dh_pad(ctx
, p1
);
421 int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX
*ctx
, int keytype
, int optype
,
422 int cmd
, int p1
, void *p2
)
427 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL
, EVP_R_COMMAND_NOT_SUPPORTED
);
431 if (ctx
->exchprovctx
!= NULL
)
432 return legacy_ctrl_to_param(ctx
, keytype
, optype
, cmd
, p1
, p2
);
434 if (ctx
->pmeth
== NULL
|| ctx
->pmeth
->ctrl
== NULL
) {
435 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL
, EVP_R_COMMAND_NOT_SUPPORTED
);
438 if ((keytype
!= -1) && (ctx
->pmeth
->pkey_id
!= keytype
))
441 /* Skip the operation checks since this is called in a very early stage */
442 if (ctx
->pmeth
->digest_custom
!= NULL
)
445 if (ctx
->operation
== EVP_PKEY_OP_UNDEFINED
) {
446 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL
, EVP_R_NO_OPERATION_SET
);
450 if ((optype
!= -1) && !(ctx
->operation
& optype
)) {
451 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL
, EVP_R_INVALID_OPERATION
);
456 ret
= ctx
->pmeth
->ctrl(ctx
, cmd
, p1
, p2
);
459 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL
, EVP_R_COMMAND_NOT_SUPPORTED
);
464 int EVP_PKEY_CTX_ctrl_uint64(EVP_PKEY_CTX
*ctx
, int keytype
, int optype
,
465 int cmd
, uint64_t value
)
467 return EVP_PKEY_CTX_ctrl(ctx
, keytype
, optype
, cmd
, 0, &value
);
470 static int legacy_ctrl_str_to_param(EVP_PKEY_CTX
*ctx
, const char *name
,
473 if (strcmp(name
, "dh_pad") == 0) {
477 return EVP_PKEY_CTX_set_dh_pad(ctx
, pad
);
482 int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX
*ctx
,
483 const char *name
, const char *value
)
486 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR
, EVP_R_COMMAND_NOT_SUPPORTED
);
490 if (ctx
->exchprovctx
!= NULL
)
491 return legacy_ctrl_str_to_param(ctx
, name
, value
);
493 if (!ctx
|| !ctx
->pmeth
|| !ctx
->pmeth
->ctrl_str
) {
494 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR
, EVP_R_COMMAND_NOT_SUPPORTED
);
497 if (strcmp(name
, "digest") == 0)
498 return EVP_PKEY_CTX_md(ctx
, EVP_PKEY_OP_TYPE_SIG
, EVP_PKEY_CTRL_MD
,
500 return ctx
->pmeth
->ctrl_str(ctx
, name
, value
);
503 /* Utility functions to send a string of hex string to a ctrl */
505 int EVP_PKEY_CTX_str2ctrl(EVP_PKEY_CTX
*ctx
, int cmd
, const char *str
)
512 return ctx
->pmeth
->ctrl(ctx
, cmd
, len
, (void *)str
);
515 int EVP_PKEY_CTX_hex2ctrl(EVP_PKEY_CTX
*ctx
, int cmd
, const char *hex
)
521 bin
= OPENSSL_hexstr2buf(hex
, &binlen
);
524 if (binlen
<= INT_MAX
)
525 rv
= ctx
->pmeth
->ctrl(ctx
, cmd
, binlen
, bin
);
530 /* Pass a message digest to a ctrl */
531 int EVP_PKEY_CTX_md(EVP_PKEY_CTX
*ctx
, int optype
, int cmd
, const char *md
)
535 if (md
== NULL
|| (m
= EVP_get_digestbyname(md
)) == NULL
) {
536 EVPerr(EVP_F_EVP_PKEY_CTX_MD
, EVP_R_INVALID_DIGEST
);
539 return EVP_PKEY_CTX_ctrl(ctx
, -1, optype
, cmd
, 0, (void *)m
);
542 int EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX
*ctx
)
544 return ctx
->operation
;
547 void EVP_PKEY_CTX_set0_keygen_info(EVP_PKEY_CTX
*ctx
, int *dat
, int datlen
)
549 ctx
->keygen_info
= dat
;
550 ctx
->keygen_info_count
= datlen
;
553 void EVP_PKEY_CTX_set_data(EVP_PKEY_CTX
*ctx
, void *data
)
558 void *EVP_PKEY_CTX_get_data(const EVP_PKEY_CTX
*ctx
)
563 EVP_PKEY
*EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX
*ctx
)
568 EVP_PKEY
*EVP_PKEY_CTX_get0_peerkey(EVP_PKEY_CTX
*ctx
)
573 void EVP_PKEY_CTX_set_app_data(EVP_PKEY_CTX
*ctx
, void *data
)
575 ctx
->app_data
= data
;
578 void *EVP_PKEY_CTX_get_app_data(EVP_PKEY_CTX
*ctx
)
580 return ctx
->app_data
;
583 void EVP_PKEY_meth_set_init(EVP_PKEY_METHOD
*pmeth
,
584 int (*init
) (EVP_PKEY_CTX
*ctx
))
589 void EVP_PKEY_meth_set_copy(EVP_PKEY_METHOD
*pmeth
,
590 int (*copy
) (EVP_PKEY_CTX
*dst
,
591 const EVP_PKEY_CTX
*src
))
596 void EVP_PKEY_meth_set_cleanup(EVP_PKEY_METHOD
*pmeth
,
597 void (*cleanup
) (EVP_PKEY_CTX
*ctx
))
599 pmeth
->cleanup
= cleanup
;
602 void EVP_PKEY_meth_set_paramgen(EVP_PKEY_METHOD
*pmeth
,
603 int (*paramgen_init
) (EVP_PKEY_CTX
*ctx
),
604 int (*paramgen
) (EVP_PKEY_CTX
*ctx
,
607 pmeth
->paramgen_init
= paramgen_init
;
608 pmeth
->paramgen
= paramgen
;
611 void EVP_PKEY_meth_set_keygen(EVP_PKEY_METHOD
*pmeth
,
612 int (*keygen_init
) (EVP_PKEY_CTX
*ctx
),
613 int (*keygen
) (EVP_PKEY_CTX
*ctx
,
616 pmeth
->keygen_init
= keygen_init
;
617 pmeth
->keygen
= keygen
;
620 void EVP_PKEY_meth_set_sign(EVP_PKEY_METHOD
*pmeth
,
621 int (*sign_init
) (EVP_PKEY_CTX
*ctx
),
622 int (*sign
) (EVP_PKEY_CTX
*ctx
,
623 unsigned char *sig
, size_t *siglen
,
624 const unsigned char *tbs
,
627 pmeth
->sign_init
= sign_init
;
631 void EVP_PKEY_meth_set_verify(EVP_PKEY_METHOD
*pmeth
,
632 int (*verify_init
) (EVP_PKEY_CTX
*ctx
),
633 int (*verify
) (EVP_PKEY_CTX
*ctx
,
634 const unsigned char *sig
,
636 const unsigned char *tbs
,
639 pmeth
->verify_init
= verify_init
;
640 pmeth
->verify
= verify
;
643 void EVP_PKEY_meth_set_verify_recover(EVP_PKEY_METHOD
*pmeth
,
644 int (*verify_recover_init
) (EVP_PKEY_CTX
646 int (*verify_recover
) (EVP_PKEY_CTX
655 pmeth
->verify_recover_init
= verify_recover_init
;
656 pmeth
->verify_recover
= verify_recover
;
659 void EVP_PKEY_meth_set_signctx(EVP_PKEY_METHOD
*pmeth
,
660 int (*signctx_init
) (EVP_PKEY_CTX
*ctx
,
662 int (*signctx
) (EVP_PKEY_CTX
*ctx
,
667 pmeth
->signctx_init
= signctx_init
;
668 pmeth
->signctx
= signctx
;
671 void EVP_PKEY_meth_set_verifyctx(EVP_PKEY_METHOD
*pmeth
,
672 int (*verifyctx_init
) (EVP_PKEY_CTX
*ctx
,
674 int (*verifyctx
) (EVP_PKEY_CTX
*ctx
,
675 const unsigned char *sig
,
679 pmeth
->verifyctx_init
= verifyctx_init
;
680 pmeth
->verifyctx
= verifyctx
;
683 void EVP_PKEY_meth_set_encrypt(EVP_PKEY_METHOD
*pmeth
,
684 int (*encrypt_init
) (EVP_PKEY_CTX
*ctx
),
685 int (*encryptfn
) (EVP_PKEY_CTX
*ctx
,
688 const unsigned char *in
,
691 pmeth
->encrypt_init
= encrypt_init
;
692 pmeth
->encrypt
= encryptfn
;
695 void EVP_PKEY_meth_set_decrypt(EVP_PKEY_METHOD
*pmeth
,
696 int (*decrypt_init
) (EVP_PKEY_CTX
*ctx
),
697 int (*decrypt
) (EVP_PKEY_CTX
*ctx
,
700 const unsigned char *in
,
703 pmeth
->decrypt_init
= decrypt_init
;
704 pmeth
->decrypt
= decrypt
;
707 void EVP_PKEY_meth_set_derive(EVP_PKEY_METHOD
*pmeth
,
708 int (*derive_init
) (EVP_PKEY_CTX
*ctx
),
709 int (*derive
) (EVP_PKEY_CTX
*ctx
,
713 pmeth
->derive_init
= derive_init
;
714 pmeth
->derive
= derive
;
717 void EVP_PKEY_meth_set_ctrl(EVP_PKEY_METHOD
*pmeth
,
718 int (*ctrl
) (EVP_PKEY_CTX
*ctx
, int type
, int p1
,
720 int (*ctrl_str
) (EVP_PKEY_CTX
*ctx
,
725 pmeth
->ctrl_str
= ctrl_str
;
728 void EVP_PKEY_meth_set_check(EVP_PKEY_METHOD
*pmeth
,
729 int (*check
) (EVP_PKEY
*pkey
))
731 pmeth
->check
= check
;
734 void EVP_PKEY_meth_set_public_check(EVP_PKEY_METHOD
*pmeth
,
735 int (*check
) (EVP_PKEY
*pkey
))
737 pmeth
->public_check
= check
;
740 void EVP_PKEY_meth_set_param_check(EVP_PKEY_METHOD
*pmeth
,
741 int (*check
) (EVP_PKEY
*pkey
))
743 pmeth
->param_check
= check
;
746 void EVP_PKEY_meth_set_digest_custom(EVP_PKEY_METHOD
*pmeth
,
747 int (*digest_custom
) (EVP_PKEY_CTX
*ctx
,
750 pmeth
->digest_custom
= digest_custom
;
753 void EVP_PKEY_meth_get_init(const EVP_PKEY_METHOD
*pmeth
,
754 int (**pinit
) (EVP_PKEY_CTX
*ctx
))
756 *pinit
= pmeth
->init
;
759 void EVP_PKEY_meth_get_copy(const EVP_PKEY_METHOD
*pmeth
,
760 int (**pcopy
) (EVP_PKEY_CTX
*dst
,
761 const EVP_PKEY_CTX
*src
))
763 *pcopy
= pmeth
->copy
;
766 void EVP_PKEY_meth_get_cleanup(const EVP_PKEY_METHOD
*pmeth
,
767 void (**pcleanup
) (EVP_PKEY_CTX
*ctx
))
769 *pcleanup
= pmeth
->cleanup
;
772 void EVP_PKEY_meth_get_paramgen(const EVP_PKEY_METHOD
*pmeth
,
773 int (**pparamgen_init
) (EVP_PKEY_CTX
*ctx
),
774 int (**pparamgen
) (EVP_PKEY_CTX
*ctx
,
778 *pparamgen_init
= pmeth
->paramgen_init
;
780 *pparamgen
= pmeth
->paramgen
;
783 void EVP_PKEY_meth_get_keygen(const EVP_PKEY_METHOD
*pmeth
,
784 int (**pkeygen_init
) (EVP_PKEY_CTX
*ctx
),
785 int (**pkeygen
) (EVP_PKEY_CTX
*ctx
,
789 *pkeygen_init
= pmeth
->keygen_init
;
791 *pkeygen
= pmeth
->keygen
;
794 void EVP_PKEY_meth_get_sign(const EVP_PKEY_METHOD
*pmeth
,
795 int (**psign_init
) (EVP_PKEY_CTX
*ctx
),
796 int (**psign
) (EVP_PKEY_CTX
*ctx
,
797 unsigned char *sig
, size_t *siglen
,
798 const unsigned char *tbs
,
802 *psign_init
= pmeth
->sign_init
;
804 *psign
= pmeth
->sign
;
807 void EVP_PKEY_meth_get_verify(const EVP_PKEY_METHOD
*pmeth
,
808 int (**pverify_init
) (EVP_PKEY_CTX
*ctx
),
809 int (**pverify
) (EVP_PKEY_CTX
*ctx
,
810 const unsigned char *sig
,
812 const unsigned char *tbs
,
816 *pverify_init
= pmeth
->verify_init
;
818 *pverify
= pmeth
->verify
;
821 void EVP_PKEY_meth_get_verify_recover(const EVP_PKEY_METHOD
*pmeth
,
822 int (**pverify_recover_init
) (EVP_PKEY_CTX
824 int (**pverify_recover
) (EVP_PKEY_CTX
833 if (pverify_recover_init
)
834 *pverify_recover_init
= pmeth
->verify_recover_init
;
836 *pverify_recover
= pmeth
->verify_recover
;
839 void EVP_PKEY_meth_get_signctx(const EVP_PKEY_METHOD
*pmeth
,
840 int (**psignctx_init
) (EVP_PKEY_CTX
*ctx
,
842 int (**psignctx
) (EVP_PKEY_CTX
*ctx
,
848 *psignctx_init
= pmeth
->signctx_init
;
850 *psignctx
= pmeth
->signctx
;
853 void EVP_PKEY_meth_get_verifyctx(const EVP_PKEY_METHOD
*pmeth
,
854 int (**pverifyctx_init
) (EVP_PKEY_CTX
*ctx
,
856 int (**pverifyctx
) (EVP_PKEY_CTX
*ctx
,
857 const unsigned char *sig
,
862 *pverifyctx_init
= pmeth
->verifyctx_init
;
864 *pverifyctx
= pmeth
->verifyctx
;
867 void EVP_PKEY_meth_get_encrypt(const EVP_PKEY_METHOD
*pmeth
,
868 int (**pencrypt_init
) (EVP_PKEY_CTX
*ctx
),
869 int (**pencryptfn
) (EVP_PKEY_CTX
*ctx
,
872 const unsigned char *in
,
876 *pencrypt_init
= pmeth
->encrypt_init
;
878 *pencryptfn
= pmeth
->encrypt
;
881 void EVP_PKEY_meth_get_decrypt(const EVP_PKEY_METHOD
*pmeth
,
882 int (**pdecrypt_init
) (EVP_PKEY_CTX
*ctx
),
883 int (**pdecrypt
) (EVP_PKEY_CTX
*ctx
,
886 const unsigned char *in
,
890 *pdecrypt_init
= pmeth
->decrypt_init
;
892 *pdecrypt
= pmeth
->decrypt
;
895 void EVP_PKEY_meth_get_derive(const EVP_PKEY_METHOD
*pmeth
,
896 int (**pderive_init
) (EVP_PKEY_CTX
*ctx
),
897 int (**pderive
) (EVP_PKEY_CTX
*ctx
,
902 *pderive_init
= pmeth
->derive_init
;
904 *pderive
= pmeth
->derive
;
907 void EVP_PKEY_meth_get_ctrl(const EVP_PKEY_METHOD
*pmeth
,
908 int (**pctrl
) (EVP_PKEY_CTX
*ctx
, int type
, int p1
,
910 int (**pctrl_str
) (EVP_PKEY_CTX
*ctx
,
915 *pctrl
= pmeth
->ctrl
;
917 *pctrl_str
= pmeth
->ctrl_str
;
920 void EVP_PKEY_meth_get_check(const EVP_PKEY_METHOD
*pmeth
,
921 int (**pcheck
) (EVP_PKEY
*pkey
))
924 *pcheck
= pmeth
->check
;
927 void EVP_PKEY_meth_get_public_check(const EVP_PKEY_METHOD
*pmeth
,
928 int (**pcheck
) (EVP_PKEY
*pkey
))
931 *pcheck
= pmeth
->public_check
;
934 void EVP_PKEY_meth_get_param_check(const EVP_PKEY_METHOD
*pmeth
,
935 int (**pcheck
) (EVP_PKEY
*pkey
))
938 *pcheck
= pmeth
->param_check
;
941 void EVP_PKEY_meth_get_digest_custom(EVP_PKEY_METHOD
*pmeth
,
942 int (**pdigest_custom
) (EVP_PKEY_CTX
*ctx
,
945 if (pdigest_custom
!= NULL
)
946 *pdigest_custom
= pmeth
->digest_custom
;