3 * Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved.
5 * Licensed under the Apache License 2.0 (the "License"). You may not use
6 * this file except in compliance with the License. You can obtain a copy
7 * in the file LICENSE in the source distribution or at
8 * https://www.openssl.org/source/license.html
13 #include <openssl/engine.h>
14 #include <openssl/evp.h>
15 #include <openssl/x509v3.h>
16 #include <openssl/core_names.h>
17 #include <openssl/dh.h>
18 #include "internal/cryptlib.h"
19 #include "internal/asn1_int.h"
20 #include "internal/evp_int.h"
21 #include "internal/numbers.h"
24 typedef int sk_cmp_fn_type(const char *const *a
, const char *const *b
);
26 static STACK_OF(EVP_PKEY_METHOD
) *app_pkey_methods
= NULL
;
28 /* This array needs to be in order of NIDs */
29 static const EVP_PKEY_METHOD
*standard_methods
[] = {
30 #ifndef OPENSSL_NO_RSA
36 #ifndef OPENSSL_NO_DSA
43 #ifndef OPENSSL_NO_CMAC
46 #ifndef OPENSSL_NO_RSA
52 #ifndef OPENSSL_NO_SCRYPT
61 #ifndef OPENSSL_NO_POLY1305
64 #ifndef OPENSSL_NO_SIPHASH
71 #ifndef OPENSSL_NO_SM2
76 DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD
*, const EVP_PKEY_METHOD
*,
79 static int pmeth_cmp(const EVP_PKEY_METHOD
*const *a
,
80 const EVP_PKEY_METHOD
*const *b
)
82 return ((*a
)->pkey_id
- (*b
)->pkey_id
);
85 IMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD
*, const EVP_PKEY_METHOD
*,
88 const EVP_PKEY_METHOD
*EVP_PKEY_meth_find(int type
)
91 const EVP_PKEY_METHOD
*t
= &tmp
, **ret
;
93 if (app_pkey_methods
) {
95 idx
= sk_EVP_PKEY_METHOD_find(app_pkey_methods
, &tmp
);
97 return sk_EVP_PKEY_METHOD_value(app_pkey_methods
, idx
);
99 ret
= OBJ_bsearch_pmeth(&t
, standard_methods
,
100 sizeof(standard_methods
) /
101 sizeof(EVP_PKEY_METHOD
*));
107 static EVP_PKEY_CTX
*int_ctx_new(EVP_PKEY
*pkey
, ENGINE
*e
, int id
)
110 const EVP_PKEY_METHOD
*pmeth
= NULL
;
113 * When using providers, the context is bound to the algo implementation
116 if (pkey
== NULL
&& e
== NULL
&& id
== -1)
119 /* TODO(3.0) Legacy code should be removed when all is provider based */
126 #ifndef OPENSSL_NO_ENGINE
127 if (e
== NULL
&& pkey
!= NULL
)
128 e
= pkey
->pmeth_engine
!= NULL
? pkey
->pmeth_engine
: pkey
->engine
;
129 /* Try to find an ENGINE which implements this method */
131 if (!ENGINE_init(e
)) {
132 EVPerr(EVP_F_INT_CTX_NEW
, ERR_R_ENGINE_LIB
);
136 e
= ENGINE_get_pkey_meth_engine(id
);
140 * If an ENGINE handled this method look it up. Otherwise use internal
144 pmeth
= ENGINE_get_pkey_meth(e
, id
);
147 pmeth
= EVP_PKEY_meth_find(id
);
150 #ifndef OPENSSL_NO_ENGINE
153 EVPerr(EVP_F_INT_CTX_NEW
, EVP_R_UNSUPPORTED_ALGORITHM
);
159 ret
= OPENSSL_zalloc(sizeof(*ret
));
161 #ifndef OPENSSL_NO_ENGINE
164 EVPerr(EVP_F_INT_CTX_NEW
, ERR_R_MALLOC_FAILURE
);
169 ret
->operation
= EVP_PKEY_OP_UNDEFINED
;
172 EVP_PKEY_up_ref(pkey
);
174 if (pmeth
!= NULL
&& pmeth
->init
!= NULL
) {
175 if (pmeth
->init(ret
) <= 0) {
177 EVP_PKEY_CTX_free(ret
);
185 EVP_PKEY_METHOD
*EVP_PKEY_meth_new(int id
, int flags
)
187 EVP_PKEY_METHOD
*pmeth
;
189 pmeth
= OPENSSL_zalloc(sizeof(*pmeth
));
191 EVPerr(EVP_F_EVP_PKEY_METH_NEW
, ERR_R_MALLOC_FAILURE
);
196 pmeth
->flags
= flags
| EVP_PKEY_FLAG_DYNAMIC
;
200 void EVP_PKEY_meth_get0_info(int *ppkey_id
, int *pflags
,
201 const EVP_PKEY_METHOD
*meth
)
204 *ppkey_id
= meth
->pkey_id
;
206 *pflags
= meth
->flags
;
209 void EVP_PKEY_meth_copy(EVP_PKEY_METHOD
*dst
, const EVP_PKEY_METHOD
*src
)
212 dst
->init
= src
->init
;
213 dst
->copy
= src
->copy
;
214 dst
->cleanup
= src
->cleanup
;
216 dst
->paramgen_init
= src
->paramgen_init
;
217 dst
->paramgen
= src
->paramgen
;
219 dst
->keygen_init
= src
->keygen_init
;
220 dst
->keygen
= src
->keygen
;
222 dst
->sign_init
= src
->sign_init
;
223 dst
->sign
= src
->sign
;
225 dst
->verify_init
= src
->verify_init
;
226 dst
->verify
= src
->verify
;
228 dst
->verify_recover_init
= src
->verify_recover_init
;
229 dst
->verify_recover
= src
->verify_recover
;
231 dst
->signctx_init
= src
->signctx_init
;
232 dst
->signctx
= src
->signctx
;
234 dst
->verifyctx_init
= src
->verifyctx_init
;
235 dst
->verifyctx
= src
->verifyctx
;
237 dst
->encrypt_init
= src
->encrypt_init
;
238 dst
->encrypt
= src
->encrypt
;
240 dst
->decrypt_init
= src
->decrypt_init
;
241 dst
->decrypt
= src
->decrypt
;
243 dst
->derive_init
= src
->derive_init
;
244 dst
->derive
= src
->derive
;
246 dst
->ctrl
= src
->ctrl
;
247 dst
->ctrl_str
= src
->ctrl_str
;
249 dst
->check
= src
->check
;
252 void EVP_PKEY_meth_free(EVP_PKEY_METHOD
*pmeth
)
254 if (pmeth
&& (pmeth
->flags
& EVP_PKEY_FLAG_DYNAMIC
))
258 EVP_PKEY_CTX
*EVP_PKEY_CTX_new(EVP_PKEY
*pkey
, ENGINE
*e
)
260 return int_ctx_new(pkey
, e
, -1);
263 EVP_PKEY_CTX
*EVP_PKEY_CTX_new_id(int id
, ENGINE
*e
)
265 return int_ctx_new(NULL
, e
, id
);
268 EVP_PKEY_CTX
*EVP_PKEY_CTX_dup(const EVP_PKEY_CTX
*pctx
)
272 if (((pctx
->pmeth
== NULL
) || (pctx
->pmeth
->copy
== NULL
))
273 && pctx
->exchprovctx
== NULL
)
275 #ifndef OPENSSL_NO_ENGINE
276 /* Make sure it's safe to copy a pkey context using an ENGINE */
277 if (pctx
->engine
&& !ENGINE_init(pctx
->engine
)) {
278 EVPerr(EVP_F_EVP_PKEY_CTX_DUP
, ERR_R_ENGINE_LIB
);
282 rctx
= OPENSSL_zalloc(sizeof(*rctx
));
284 EVPerr(EVP_F_EVP_PKEY_CTX_DUP
, ERR_R_MALLOC_FAILURE
);
288 if (pctx
->pkey
!= NULL
)
289 EVP_PKEY_up_ref(pctx
->pkey
);
290 rctx
->pkey
= pctx
->pkey
;
291 rctx
->operation
= pctx
->operation
;
293 if (pctx
->exchprovctx
!= NULL
) {
294 if (!ossl_assert(pctx
->exchange
!= NULL
))
296 rctx
->exchange
= pctx
->exchange
;
297 if (!EVP_KEYEXCH_up_ref(rctx
->exchange
)) {
301 rctx
->exchprovctx
= pctx
->exchange
->dupctx(pctx
->exchprovctx
);
302 if (rctx
->exchprovctx
== NULL
) {
303 EVP_KEYEXCH_free(rctx
->exchange
);
310 rctx
->pmeth
= pctx
->pmeth
;
311 #ifndef OPENSSL_NO_ENGINE
312 rctx
->engine
= pctx
->engine
;
316 EVP_PKEY_up_ref(pctx
->peerkey
);
317 rctx
->peerkey
= pctx
->peerkey
;
319 if (pctx
->pmeth
->copy(rctx
, pctx
) > 0)
323 EVP_PKEY_CTX_free(rctx
);
328 int EVP_PKEY_meth_add0(const EVP_PKEY_METHOD
*pmeth
)
330 if (app_pkey_methods
== NULL
) {
331 app_pkey_methods
= sk_EVP_PKEY_METHOD_new(pmeth_cmp
);
332 if (app_pkey_methods
== NULL
){
333 EVPerr(EVP_F_EVP_PKEY_METH_ADD0
, ERR_R_MALLOC_FAILURE
);
337 if (!sk_EVP_PKEY_METHOD_push(app_pkey_methods
, pmeth
)) {
338 EVPerr(EVP_F_EVP_PKEY_METH_ADD0
, ERR_R_MALLOC_FAILURE
);
341 sk_EVP_PKEY_METHOD_sort(app_pkey_methods
);
345 void evp_app_cleanup_int(void)
347 if (app_pkey_methods
!= NULL
)
348 sk_EVP_PKEY_METHOD_pop_free(app_pkey_methods
, EVP_PKEY_meth_free
);
351 int EVP_PKEY_meth_remove(const EVP_PKEY_METHOD
*pmeth
)
353 const EVP_PKEY_METHOD
*ret
;
355 ret
= sk_EVP_PKEY_METHOD_delete_ptr(app_pkey_methods
, pmeth
);
357 return ret
== NULL
? 0 : 1;
360 size_t EVP_PKEY_meth_get_count(void)
362 size_t rv
= OSSL_NELEM(standard_methods
);
364 if (app_pkey_methods
)
365 rv
+= sk_EVP_PKEY_METHOD_num(app_pkey_methods
);
369 const EVP_PKEY_METHOD
*EVP_PKEY_meth_get0(size_t idx
)
371 if (idx
< OSSL_NELEM(standard_methods
))
372 return standard_methods
[idx
];
373 if (app_pkey_methods
== NULL
)
375 idx
-= OSSL_NELEM(standard_methods
);
376 if (idx
>= (size_t)sk_EVP_PKEY_METHOD_num(app_pkey_methods
))
378 return sk_EVP_PKEY_METHOD_value(app_pkey_methods
, idx
);
381 void EVP_PKEY_CTX_free(EVP_PKEY_CTX
*ctx
)
385 if (ctx
->pmeth
&& ctx
->pmeth
->cleanup
)
386 ctx
->pmeth
->cleanup(ctx
);
388 if (ctx
->exchprovctx
!= NULL
&& ctx
->exchange
!= NULL
)
389 ctx
->exchange
->freectx(ctx
->exchprovctx
);
391 EVP_KEYEXCH_free(ctx
->exchange
);
393 if (ctx
->sigprovctx
!= NULL
&& ctx
->signature
!= NULL
)
394 ctx
->signature
->freectx(ctx
->sigprovctx
);
396 EVP_SIGNATURE_free(ctx
->signature
);
398 EVP_PKEY_free(ctx
->pkey
);
399 EVP_PKEY_free(ctx
->peerkey
);
400 #ifndef OPENSSL_NO_ENGINE
401 ENGINE_finish(ctx
->engine
);
406 int EVP_PKEY_CTX_set_params(EVP_PKEY_CTX
*ctx
, OSSL_PARAM
*params
)
408 if (ctx
->exchprovctx
!= NULL
&& ctx
->exchange
!= NULL
)
409 return ctx
->exchange
->set_params(ctx
->exchprovctx
, params
);
410 if (ctx
->sigprovctx
!= NULL
&& ctx
->signature
!= NULL
)
411 return ctx
->signature
->set_params(ctx
->sigprovctx
, params
);
415 #ifndef OPENSSL_NO_DH
416 int EVP_PKEY_CTX_set_dh_pad(EVP_PKEY_CTX
*ctx
, int pad
)
418 OSSL_PARAM dh_pad_params
[2];
419 unsigned int upad
= pad
;
421 /* TODO(3.0): Remove this eventually when no more legacy */
422 if (ctx
->exchprovctx
== NULL
)
423 return EVP_PKEY_CTX_ctrl(ctx
, EVP_PKEY_DH
, EVP_PKEY_OP_DERIVE
,
424 EVP_PKEY_CTRL_DH_PAD
, pad
, NULL
);
426 dh_pad_params
[0] = OSSL_PARAM_construct_uint(OSSL_EXCHANGE_PARAM_PAD
, &upad
);
427 dh_pad_params
[1] = OSSL_PARAM_construct_end();
429 return EVP_PKEY_CTX_set_params(ctx
, dh_pad_params
);
433 int EVP_PKEY_CTX_set_signature_md(EVP_PKEY_CTX
*ctx
, const EVP_MD
*md
)
435 OSSL_PARAM sig_md_params
[3];
439 /* TODO(3.0): Remove this eventually when no more legacy */
440 if (ctx
->sigprovctx
== NULL
)
441 return EVP_PKEY_CTX_ctrl(ctx
, -1, EVP_PKEY_OP_TYPE_SIG
,
442 EVP_PKEY_CTRL_MD
, 0, (void *)(md
));
447 mdsize
= EVP_MD_size(md
);
448 name
= EVP_MD_name(md
);
449 sig_md_params
[0] = OSSL_PARAM_construct_utf8_string(
450 OSSL_SIGNATURE_PARAM_DIGEST
,
452 * Cast away the const. This is read only so should
457 sig_md_params
[1] = OSSL_PARAM_construct_size_t(OSSL_SIGNATURE_PARAM_DIGEST_SIZE
,
459 sig_md_params
[2] = OSSL_PARAM_construct_end();
461 return EVP_PKEY_CTX_set_params(ctx
, sig_md_params
);
465 static int legacy_ctrl_to_param(EVP_PKEY_CTX
*ctx
, int keytype
, int optype
,
466 int cmd
, int p1
, void *p2
)
469 #ifndef OPENSSL_NO_DH
470 case EVP_PKEY_CTRL_DH_PAD
:
471 return EVP_PKEY_CTX_set_dh_pad(ctx
, p1
);
477 int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX
*ctx
, int keytype
, int optype
,
478 int cmd
, int p1
, void *p2
)
483 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL
, EVP_R_COMMAND_NOT_SUPPORTED
);
487 if (ctx
->exchprovctx
!= NULL
)
488 return legacy_ctrl_to_param(ctx
, keytype
, optype
, cmd
, p1
, p2
);
490 if (ctx
->pmeth
== NULL
|| ctx
->pmeth
->ctrl
== NULL
) {
491 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL
, EVP_R_COMMAND_NOT_SUPPORTED
);
494 if ((keytype
!= -1) && (ctx
->pmeth
->pkey_id
!= keytype
))
497 /* Skip the operation checks since this is called in a very early stage */
498 if (ctx
->pmeth
->digest_custom
!= NULL
)
501 if (ctx
->operation
== EVP_PKEY_OP_UNDEFINED
) {
502 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL
, EVP_R_NO_OPERATION_SET
);
506 if ((optype
!= -1) && !(ctx
->operation
& optype
)) {
507 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL
, EVP_R_INVALID_OPERATION
);
512 ret
= ctx
->pmeth
->ctrl(ctx
, cmd
, p1
, p2
);
515 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL
, EVP_R_COMMAND_NOT_SUPPORTED
);
520 int EVP_PKEY_CTX_ctrl_uint64(EVP_PKEY_CTX
*ctx
, int keytype
, int optype
,
521 int cmd
, uint64_t value
)
523 return EVP_PKEY_CTX_ctrl(ctx
, keytype
, optype
, cmd
, 0, &value
);
526 static int legacy_ctrl_str_to_param(EVP_PKEY_CTX
*ctx
, const char *name
,
529 #ifndef OPENSSL_NO_DH
530 if (strcmp(name
, "dh_pad") == 0) {
534 return EVP_PKEY_CTX_set_dh_pad(ctx
, pad
);
540 int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX
*ctx
,
541 const char *name
, const char *value
)
544 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR
, EVP_R_COMMAND_NOT_SUPPORTED
);
548 if (ctx
->exchprovctx
!= NULL
)
549 return legacy_ctrl_str_to_param(ctx
, name
, value
);
551 if (!ctx
|| !ctx
->pmeth
|| !ctx
->pmeth
->ctrl_str
) {
552 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR
, EVP_R_COMMAND_NOT_SUPPORTED
);
555 if (strcmp(name
, "digest") == 0)
556 return EVP_PKEY_CTX_md(ctx
, EVP_PKEY_OP_TYPE_SIG
, EVP_PKEY_CTRL_MD
,
558 return ctx
->pmeth
->ctrl_str(ctx
, name
, value
);
561 /* Utility functions to send a string of hex string to a ctrl */
563 int EVP_PKEY_CTX_str2ctrl(EVP_PKEY_CTX
*ctx
, int cmd
, const char *str
)
570 return ctx
->pmeth
->ctrl(ctx
, cmd
, len
, (void *)str
);
573 int EVP_PKEY_CTX_hex2ctrl(EVP_PKEY_CTX
*ctx
, int cmd
, const char *hex
)
579 bin
= OPENSSL_hexstr2buf(hex
, &binlen
);
582 if (binlen
<= INT_MAX
)
583 rv
= ctx
->pmeth
->ctrl(ctx
, cmd
, binlen
, bin
);
588 /* Pass a message digest to a ctrl */
589 int EVP_PKEY_CTX_md(EVP_PKEY_CTX
*ctx
, int optype
, int cmd
, const char *md
)
593 if (md
== NULL
|| (m
= EVP_get_digestbyname(md
)) == NULL
) {
594 EVPerr(EVP_F_EVP_PKEY_CTX_MD
, EVP_R_INVALID_DIGEST
);
597 return EVP_PKEY_CTX_ctrl(ctx
, -1, optype
, cmd
, 0, (void *)m
);
600 int EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX
*ctx
)
602 return ctx
->operation
;
605 void EVP_PKEY_CTX_set0_keygen_info(EVP_PKEY_CTX
*ctx
, int *dat
, int datlen
)
607 ctx
->keygen_info
= dat
;
608 ctx
->keygen_info_count
= datlen
;
611 void EVP_PKEY_CTX_set_data(EVP_PKEY_CTX
*ctx
, void *data
)
616 void *EVP_PKEY_CTX_get_data(const EVP_PKEY_CTX
*ctx
)
621 EVP_PKEY
*EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX
*ctx
)
626 EVP_PKEY
*EVP_PKEY_CTX_get0_peerkey(EVP_PKEY_CTX
*ctx
)
631 void EVP_PKEY_CTX_set_app_data(EVP_PKEY_CTX
*ctx
, void *data
)
633 ctx
->app_data
= data
;
636 void *EVP_PKEY_CTX_get_app_data(EVP_PKEY_CTX
*ctx
)
638 return ctx
->app_data
;
641 void EVP_PKEY_meth_set_init(EVP_PKEY_METHOD
*pmeth
,
642 int (*init
) (EVP_PKEY_CTX
*ctx
))
647 void EVP_PKEY_meth_set_copy(EVP_PKEY_METHOD
*pmeth
,
648 int (*copy
) (EVP_PKEY_CTX
*dst
,
649 const EVP_PKEY_CTX
*src
))
654 void EVP_PKEY_meth_set_cleanup(EVP_PKEY_METHOD
*pmeth
,
655 void (*cleanup
) (EVP_PKEY_CTX
*ctx
))
657 pmeth
->cleanup
= cleanup
;
660 void EVP_PKEY_meth_set_paramgen(EVP_PKEY_METHOD
*pmeth
,
661 int (*paramgen_init
) (EVP_PKEY_CTX
*ctx
),
662 int (*paramgen
) (EVP_PKEY_CTX
*ctx
,
665 pmeth
->paramgen_init
= paramgen_init
;
666 pmeth
->paramgen
= paramgen
;
669 void EVP_PKEY_meth_set_keygen(EVP_PKEY_METHOD
*pmeth
,
670 int (*keygen_init
) (EVP_PKEY_CTX
*ctx
),
671 int (*keygen
) (EVP_PKEY_CTX
*ctx
,
674 pmeth
->keygen_init
= keygen_init
;
675 pmeth
->keygen
= keygen
;
678 void EVP_PKEY_meth_set_sign(EVP_PKEY_METHOD
*pmeth
,
679 int (*sign_init
) (EVP_PKEY_CTX
*ctx
),
680 int (*sign
) (EVP_PKEY_CTX
*ctx
,
681 unsigned char *sig
, size_t *siglen
,
682 const unsigned char *tbs
,
685 pmeth
->sign_init
= sign_init
;
689 void EVP_PKEY_meth_set_verify(EVP_PKEY_METHOD
*pmeth
,
690 int (*verify_init
) (EVP_PKEY_CTX
*ctx
),
691 int (*verify
) (EVP_PKEY_CTX
*ctx
,
692 const unsigned char *sig
,
694 const unsigned char *tbs
,
697 pmeth
->verify_init
= verify_init
;
698 pmeth
->verify
= verify
;
701 void EVP_PKEY_meth_set_verify_recover(EVP_PKEY_METHOD
*pmeth
,
702 int (*verify_recover_init
) (EVP_PKEY_CTX
704 int (*verify_recover
) (EVP_PKEY_CTX
713 pmeth
->verify_recover_init
= verify_recover_init
;
714 pmeth
->verify_recover
= verify_recover
;
717 void EVP_PKEY_meth_set_signctx(EVP_PKEY_METHOD
*pmeth
,
718 int (*signctx_init
) (EVP_PKEY_CTX
*ctx
,
720 int (*signctx
) (EVP_PKEY_CTX
*ctx
,
725 pmeth
->signctx_init
= signctx_init
;
726 pmeth
->signctx
= signctx
;
729 void EVP_PKEY_meth_set_verifyctx(EVP_PKEY_METHOD
*pmeth
,
730 int (*verifyctx_init
) (EVP_PKEY_CTX
*ctx
,
732 int (*verifyctx
) (EVP_PKEY_CTX
*ctx
,
733 const unsigned char *sig
,
737 pmeth
->verifyctx_init
= verifyctx_init
;
738 pmeth
->verifyctx
= verifyctx
;
741 void EVP_PKEY_meth_set_encrypt(EVP_PKEY_METHOD
*pmeth
,
742 int (*encrypt_init
) (EVP_PKEY_CTX
*ctx
),
743 int (*encryptfn
) (EVP_PKEY_CTX
*ctx
,
746 const unsigned char *in
,
749 pmeth
->encrypt_init
= encrypt_init
;
750 pmeth
->encrypt
= encryptfn
;
753 void EVP_PKEY_meth_set_decrypt(EVP_PKEY_METHOD
*pmeth
,
754 int (*decrypt_init
) (EVP_PKEY_CTX
*ctx
),
755 int (*decrypt
) (EVP_PKEY_CTX
*ctx
,
758 const unsigned char *in
,
761 pmeth
->decrypt_init
= decrypt_init
;
762 pmeth
->decrypt
= decrypt
;
765 void EVP_PKEY_meth_set_derive(EVP_PKEY_METHOD
*pmeth
,
766 int (*derive_init
) (EVP_PKEY_CTX
*ctx
),
767 int (*derive
) (EVP_PKEY_CTX
*ctx
,
771 pmeth
->derive_init
= derive_init
;
772 pmeth
->derive
= derive
;
775 void EVP_PKEY_meth_set_ctrl(EVP_PKEY_METHOD
*pmeth
,
776 int (*ctrl
) (EVP_PKEY_CTX
*ctx
, int type
, int p1
,
778 int (*ctrl_str
) (EVP_PKEY_CTX
*ctx
,
783 pmeth
->ctrl_str
= ctrl_str
;
786 void EVP_PKEY_meth_set_check(EVP_PKEY_METHOD
*pmeth
,
787 int (*check
) (EVP_PKEY
*pkey
))
789 pmeth
->check
= check
;
792 void EVP_PKEY_meth_set_public_check(EVP_PKEY_METHOD
*pmeth
,
793 int (*check
) (EVP_PKEY
*pkey
))
795 pmeth
->public_check
= check
;
798 void EVP_PKEY_meth_set_param_check(EVP_PKEY_METHOD
*pmeth
,
799 int (*check
) (EVP_PKEY
*pkey
))
801 pmeth
->param_check
= check
;
804 void EVP_PKEY_meth_set_digest_custom(EVP_PKEY_METHOD
*pmeth
,
805 int (*digest_custom
) (EVP_PKEY_CTX
*ctx
,
808 pmeth
->digest_custom
= digest_custom
;
811 void EVP_PKEY_meth_get_init(const EVP_PKEY_METHOD
*pmeth
,
812 int (**pinit
) (EVP_PKEY_CTX
*ctx
))
814 *pinit
= pmeth
->init
;
817 void EVP_PKEY_meth_get_copy(const EVP_PKEY_METHOD
*pmeth
,
818 int (**pcopy
) (EVP_PKEY_CTX
*dst
,
819 const EVP_PKEY_CTX
*src
))
821 *pcopy
= pmeth
->copy
;
824 void EVP_PKEY_meth_get_cleanup(const EVP_PKEY_METHOD
*pmeth
,
825 void (**pcleanup
) (EVP_PKEY_CTX
*ctx
))
827 *pcleanup
= pmeth
->cleanup
;
830 void EVP_PKEY_meth_get_paramgen(const EVP_PKEY_METHOD
*pmeth
,
831 int (**pparamgen_init
) (EVP_PKEY_CTX
*ctx
),
832 int (**pparamgen
) (EVP_PKEY_CTX
*ctx
,
836 *pparamgen_init
= pmeth
->paramgen_init
;
838 *pparamgen
= pmeth
->paramgen
;
841 void EVP_PKEY_meth_get_keygen(const EVP_PKEY_METHOD
*pmeth
,
842 int (**pkeygen_init
) (EVP_PKEY_CTX
*ctx
),
843 int (**pkeygen
) (EVP_PKEY_CTX
*ctx
,
847 *pkeygen_init
= pmeth
->keygen_init
;
849 *pkeygen
= pmeth
->keygen
;
852 void EVP_PKEY_meth_get_sign(const EVP_PKEY_METHOD
*pmeth
,
853 int (**psign_init
) (EVP_PKEY_CTX
*ctx
),
854 int (**psign
) (EVP_PKEY_CTX
*ctx
,
855 unsigned char *sig
, size_t *siglen
,
856 const unsigned char *tbs
,
860 *psign_init
= pmeth
->sign_init
;
862 *psign
= pmeth
->sign
;
865 void EVP_PKEY_meth_get_verify(const EVP_PKEY_METHOD
*pmeth
,
866 int (**pverify_init
) (EVP_PKEY_CTX
*ctx
),
867 int (**pverify
) (EVP_PKEY_CTX
*ctx
,
868 const unsigned char *sig
,
870 const unsigned char *tbs
,
874 *pverify_init
= pmeth
->verify_init
;
876 *pverify
= pmeth
->verify
;
879 void EVP_PKEY_meth_get_verify_recover(const EVP_PKEY_METHOD
*pmeth
,
880 int (**pverify_recover_init
) (EVP_PKEY_CTX
882 int (**pverify_recover
) (EVP_PKEY_CTX
891 if (pverify_recover_init
)
892 *pverify_recover_init
= pmeth
->verify_recover_init
;
894 *pverify_recover
= pmeth
->verify_recover
;
897 void EVP_PKEY_meth_get_signctx(const EVP_PKEY_METHOD
*pmeth
,
898 int (**psignctx_init
) (EVP_PKEY_CTX
*ctx
,
900 int (**psignctx
) (EVP_PKEY_CTX
*ctx
,
906 *psignctx_init
= pmeth
->signctx_init
;
908 *psignctx
= pmeth
->signctx
;
911 void EVP_PKEY_meth_get_verifyctx(const EVP_PKEY_METHOD
*pmeth
,
912 int (**pverifyctx_init
) (EVP_PKEY_CTX
*ctx
,
914 int (**pverifyctx
) (EVP_PKEY_CTX
*ctx
,
915 const unsigned char *sig
,
920 *pverifyctx_init
= pmeth
->verifyctx_init
;
922 *pverifyctx
= pmeth
->verifyctx
;
925 void EVP_PKEY_meth_get_encrypt(const EVP_PKEY_METHOD
*pmeth
,
926 int (**pencrypt_init
) (EVP_PKEY_CTX
*ctx
),
927 int (**pencryptfn
) (EVP_PKEY_CTX
*ctx
,
930 const unsigned char *in
,
934 *pencrypt_init
= pmeth
->encrypt_init
;
936 *pencryptfn
= pmeth
->encrypt
;
939 void EVP_PKEY_meth_get_decrypt(const EVP_PKEY_METHOD
*pmeth
,
940 int (**pdecrypt_init
) (EVP_PKEY_CTX
*ctx
),
941 int (**pdecrypt
) (EVP_PKEY_CTX
*ctx
,
944 const unsigned char *in
,
948 *pdecrypt_init
= pmeth
->decrypt_init
;
950 *pdecrypt
= pmeth
->decrypt
;
953 void EVP_PKEY_meth_get_derive(const EVP_PKEY_METHOD
*pmeth
,
954 int (**pderive_init
) (EVP_PKEY_CTX
*ctx
),
955 int (**pderive
) (EVP_PKEY_CTX
*ctx
,
960 *pderive_init
= pmeth
->derive_init
;
962 *pderive
= pmeth
->derive
;
965 void EVP_PKEY_meth_get_ctrl(const EVP_PKEY_METHOD
*pmeth
,
966 int (**pctrl
) (EVP_PKEY_CTX
*ctx
, int type
, int p1
,
968 int (**pctrl_str
) (EVP_PKEY_CTX
*ctx
,
973 *pctrl
= pmeth
->ctrl
;
975 *pctrl_str
= pmeth
->ctrl_str
;
978 void EVP_PKEY_meth_get_check(const EVP_PKEY_METHOD
*pmeth
,
979 int (**pcheck
) (EVP_PKEY
*pkey
))
982 *pcheck
= pmeth
->check
;
985 void EVP_PKEY_meth_get_public_check(const EVP_PKEY_METHOD
*pmeth
,
986 int (**pcheck
) (EVP_PKEY
*pkey
))
989 *pcheck
= pmeth
->public_check
;
992 void EVP_PKEY_meth_get_param_check(const EVP_PKEY_METHOD
*pmeth
,
993 int (**pcheck
) (EVP_PKEY
*pkey
))
996 *pcheck
= pmeth
->param_check
;
999 void EVP_PKEY_meth_get_digest_custom(EVP_PKEY_METHOD
*pmeth
,
1000 int (**pdigest_custom
) (EVP_PKEY_CTX
*ctx
,
1003 if (pdigest_custom
!= NULL
)
1004 *pdigest_custom
= pmeth
->digest_custom
;