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"
22 #include "internal/provider.h"
25 typedef int sk_cmp_fn_type(const char *const *a
, const char *const *b
);
27 static STACK_OF(EVP_PKEY_METHOD
) *app_pkey_methods
= NULL
;
29 /* This array needs to be in order of NIDs */
30 static const EVP_PKEY_METHOD
*standard_methods
[] = {
31 #ifndef OPENSSL_NO_RSA
37 #ifndef OPENSSL_NO_DSA
44 #ifndef OPENSSL_NO_CMAC
47 #ifndef OPENSSL_NO_RSA
53 #ifndef OPENSSL_NO_SCRYPT
62 #ifndef OPENSSL_NO_POLY1305
65 #ifndef OPENSSL_NO_SIPHASH
72 #ifndef OPENSSL_NO_SM2
77 DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD
*, const EVP_PKEY_METHOD
*,
80 static int pmeth_cmp(const EVP_PKEY_METHOD
*const *a
,
81 const EVP_PKEY_METHOD
*const *b
)
83 return ((*a
)->pkey_id
- (*b
)->pkey_id
);
86 IMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD
*, const EVP_PKEY_METHOD
*,
89 const EVP_PKEY_METHOD
*EVP_PKEY_meth_find(int type
)
92 const EVP_PKEY_METHOD
*t
= &tmp
, **ret
;
94 if (app_pkey_methods
) {
96 idx
= sk_EVP_PKEY_METHOD_find(app_pkey_methods
, &tmp
);
98 return sk_EVP_PKEY_METHOD_value(app_pkey_methods
, idx
);
100 ret
= OBJ_bsearch_pmeth(&t
, standard_methods
,
101 sizeof(standard_methods
) /
102 sizeof(EVP_PKEY_METHOD
*));
108 static EVP_PKEY_CTX
*int_ctx_new(EVP_PKEY
*pkey
, ENGINE
*e
, int id
)
111 const EVP_PKEY_METHOD
*pmeth
= NULL
;
114 * When using providers, the context is bound to the algo implementation
117 if (pkey
== NULL
&& e
== NULL
&& id
== -1)
120 /* TODO(3.0) Legacy code should be removed when all is provider based */
127 #ifndef OPENSSL_NO_ENGINE
128 if (e
== NULL
&& pkey
!= NULL
)
129 e
= pkey
->pmeth_engine
!= NULL
? pkey
->pmeth_engine
: pkey
->engine
;
130 /* Try to find an ENGINE which implements this method */
132 if (!ENGINE_init(e
)) {
133 EVPerr(EVP_F_INT_CTX_NEW
, ERR_R_ENGINE_LIB
);
137 e
= ENGINE_get_pkey_meth_engine(id
);
141 * If an ENGINE handled this method look it up. Otherwise use internal
145 pmeth
= ENGINE_get_pkey_meth(e
, id
);
148 pmeth
= EVP_PKEY_meth_find(id
);
151 #ifndef OPENSSL_NO_ENGINE
154 EVPerr(EVP_F_INT_CTX_NEW
, EVP_R_UNSUPPORTED_ALGORITHM
);
160 ret
= OPENSSL_zalloc(sizeof(*ret
));
162 #ifndef OPENSSL_NO_ENGINE
165 EVPerr(EVP_F_INT_CTX_NEW
, ERR_R_MALLOC_FAILURE
);
170 ret
->operation
= EVP_PKEY_OP_UNDEFINED
;
173 EVP_PKEY_up_ref(pkey
);
175 if (pmeth
!= NULL
&& pmeth
->init
!= NULL
) {
176 if (pmeth
->init(ret
) <= 0) {
178 EVP_PKEY_CTX_free(ret
);
186 EVP_PKEY_METHOD
*EVP_PKEY_meth_new(int id
, int flags
)
188 EVP_PKEY_METHOD
*pmeth
;
190 pmeth
= OPENSSL_zalloc(sizeof(*pmeth
));
192 EVPerr(EVP_F_EVP_PKEY_METH_NEW
, ERR_R_MALLOC_FAILURE
);
197 pmeth
->flags
= flags
| EVP_PKEY_FLAG_DYNAMIC
;
201 void EVP_PKEY_meth_get0_info(int *ppkey_id
, int *pflags
,
202 const EVP_PKEY_METHOD
*meth
)
205 *ppkey_id
= meth
->pkey_id
;
207 *pflags
= meth
->flags
;
210 void EVP_PKEY_meth_copy(EVP_PKEY_METHOD
*dst
, const EVP_PKEY_METHOD
*src
)
213 dst
->init
= src
->init
;
214 dst
->copy
= src
->copy
;
215 dst
->cleanup
= src
->cleanup
;
217 dst
->paramgen_init
= src
->paramgen_init
;
218 dst
->paramgen
= src
->paramgen
;
220 dst
->keygen_init
= src
->keygen_init
;
221 dst
->keygen
= src
->keygen
;
223 dst
->sign_init
= src
->sign_init
;
224 dst
->sign
= src
->sign
;
226 dst
->verify_init
= src
->verify_init
;
227 dst
->verify
= src
->verify
;
229 dst
->verify_recover_init
= src
->verify_recover_init
;
230 dst
->verify_recover
= src
->verify_recover
;
232 dst
->signctx_init
= src
->signctx_init
;
233 dst
->signctx
= src
->signctx
;
235 dst
->verifyctx_init
= src
->verifyctx_init
;
236 dst
->verifyctx
= src
->verifyctx
;
238 dst
->encrypt_init
= src
->encrypt_init
;
239 dst
->encrypt
= src
->encrypt
;
241 dst
->decrypt_init
= src
->decrypt_init
;
242 dst
->decrypt
= src
->decrypt
;
244 dst
->derive_init
= src
->derive_init
;
245 dst
->derive
= src
->derive
;
247 dst
->ctrl
= src
->ctrl
;
248 dst
->ctrl_str
= src
->ctrl_str
;
250 dst
->check
= src
->check
;
253 void EVP_PKEY_meth_free(EVP_PKEY_METHOD
*pmeth
)
255 if (pmeth
&& (pmeth
->flags
& EVP_PKEY_FLAG_DYNAMIC
))
259 EVP_PKEY_CTX
*EVP_PKEY_CTX_new(EVP_PKEY
*pkey
, ENGINE
*e
)
261 return int_ctx_new(pkey
, e
, -1);
264 EVP_PKEY_CTX
*EVP_PKEY_CTX_new_id(int id
, ENGINE
*e
)
266 return int_ctx_new(NULL
, e
, id
);
269 EVP_PKEY_CTX
*EVP_PKEY_CTX_dup(const EVP_PKEY_CTX
*pctx
)
273 if (((pctx
->pmeth
== NULL
) || (pctx
->pmeth
->copy
== NULL
))
274 && pctx
->exchprovctx
== NULL
)
276 #ifndef OPENSSL_NO_ENGINE
277 /* Make sure it's safe to copy a pkey context using an ENGINE */
278 if (pctx
->engine
&& !ENGINE_init(pctx
->engine
)) {
279 EVPerr(EVP_F_EVP_PKEY_CTX_DUP
, ERR_R_ENGINE_LIB
);
283 rctx
= OPENSSL_zalloc(sizeof(*rctx
));
285 EVPerr(EVP_F_EVP_PKEY_CTX_DUP
, ERR_R_MALLOC_FAILURE
);
289 if (pctx
->pkey
!= NULL
)
290 EVP_PKEY_up_ref(pctx
->pkey
);
291 rctx
->pkey
= pctx
->pkey
;
292 rctx
->operation
= pctx
->operation
;
294 if (pctx
->exchprovctx
!= NULL
) {
295 if (!ossl_assert(pctx
->exchange
!= NULL
))
297 rctx
->exchange
= pctx
->exchange
;
298 if (!EVP_KEYEXCH_up_ref(rctx
->exchange
)) {
302 rctx
->exchprovctx
= pctx
->exchange
->dupctx(pctx
->exchprovctx
);
303 if (rctx
->exchprovctx
== NULL
) {
304 EVP_KEYEXCH_free(rctx
->exchange
);
311 rctx
->pmeth
= pctx
->pmeth
;
312 #ifndef OPENSSL_NO_ENGINE
313 rctx
->engine
= pctx
->engine
;
317 EVP_PKEY_up_ref(pctx
->peerkey
);
318 rctx
->peerkey
= pctx
->peerkey
;
320 if (pctx
->pmeth
->copy(rctx
, pctx
) > 0)
324 EVP_PKEY_CTX_free(rctx
);
329 int EVP_PKEY_meth_add0(const EVP_PKEY_METHOD
*pmeth
)
331 if (app_pkey_methods
== NULL
) {
332 app_pkey_methods
= sk_EVP_PKEY_METHOD_new(pmeth_cmp
);
333 if (app_pkey_methods
== NULL
){
334 EVPerr(EVP_F_EVP_PKEY_METH_ADD0
, ERR_R_MALLOC_FAILURE
);
338 if (!sk_EVP_PKEY_METHOD_push(app_pkey_methods
, pmeth
)) {
339 EVPerr(EVP_F_EVP_PKEY_METH_ADD0
, ERR_R_MALLOC_FAILURE
);
342 sk_EVP_PKEY_METHOD_sort(app_pkey_methods
);
346 void evp_app_cleanup_int(void)
348 if (app_pkey_methods
!= NULL
)
349 sk_EVP_PKEY_METHOD_pop_free(app_pkey_methods
, EVP_PKEY_meth_free
);
352 int EVP_PKEY_meth_remove(const EVP_PKEY_METHOD
*pmeth
)
354 const EVP_PKEY_METHOD
*ret
;
356 ret
= sk_EVP_PKEY_METHOD_delete_ptr(app_pkey_methods
, pmeth
);
358 return ret
== NULL
? 0 : 1;
361 size_t EVP_PKEY_meth_get_count(void)
363 size_t rv
= OSSL_NELEM(standard_methods
);
365 if (app_pkey_methods
)
366 rv
+= sk_EVP_PKEY_METHOD_num(app_pkey_methods
);
370 const EVP_PKEY_METHOD
*EVP_PKEY_meth_get0(size_t idx
)
372 if (idx
< OSSL_NELEM(standard_methods
))
373 return standard_methods
[idx
];
374 if (app_pkey_methods
== NULL
)
376 idx
-= OSSL_NELEM(standard_methods
);
377 if (idx
>= (size_t)sk_EVP_PKEY_METHOD_num(app_pkey_methods
))
379 return sk_EVP_PKEY_METHOD_value(app_pkey_methods
, idx
);
382 void EVP_PKEY_CTX_free(EVP_PKEY_CTX
*ctx
)
386 if (ctx
->pmeth
&& ctx
->pmeth
->cleanup
)
387 ctx
->pmeth
->cleanup(ctx
);
389 if (ctx
->exchprovctx
!= NULL
&& ctx
->exchange
!= NULL
)
390 ctx
->exchange
->freectx(ctx
->exchprovctx
);
392 EVP_KEYEXCH_free(ctx
->exchange
);
394 if (ctx
->sigprovctx
!= NULL
&& ctx
->signature
!= NULL
)
395 ctx
->signature
->freectx(ctx
->sigprovctx
);
397 EVP_SIGNATURE_free(ctx
->signature
);
399 EVP_PKEY_free(ctx
->pkey
);
400 EVP_PKEY_free(ctx
->peerkey
);
401 #ifndef OPENSSL_NO_ENGINE
402 ENGINE_finish(ctx
->engine
);
407 int EVP_PKEY_CTX_set_params(EVP_PKEY_CTX
*ctx
, OSSL_PARAM
*params
)
409 if (ctx
->exchprovctx
!= NULL
&& ctx
->exchange
!= NULL
)
410 return ctx
->exchange
->set_params(ctx
->exchprovctx
, params
);
411 if (ctx
->sigprovctx
!= NULL
&& ctx
->signature
!= NULL
)
412 return ctx
->signature
->set_params(ctx
->sigprovctx
, params
);
416 #ifndef OPENSSL_NO_DH
417 int EVP_PKEY_CTX_set_dh_pad(EVP_PKEY_CTX
*ctx
, int pad
)
419 OSSL_PARAM dh_pad_params
[2];
420 unsigned int upad
= pad
;
422 /* TODO(3.0): Remove this eventually when no more legacy */
423 if (ctx
->exchprovctx
== NULL
)
424 return EVP_PKEY_CTX_ctrl(ctx
, EVP_PKEY_DH
, EVP_PKEY_OP_DERIVE
,
425 EVP_PKEY_CTRL_DH_PAD
, pad
, NULL
);
427 dh_pad_params
[0] = OSSL_PARAM_construct_uint(OSSL_EXCHANGE_PARAM_PAD
, &upad
);
428 dh_pad_params
[1] = OSSL_PARAM_construct_end();
430 return EVP_PKEY_CTX_set_params(ctx
, dh_pad_params
);
434 int EVP_PKEY_CTX_set_signature_md(EVP_PKEY_CTX
*ctx
, const EVP_MD
*md
)
436 OSSL_PARAM sig_md_params
[3];
440 /* TODO(3.0): Remove this eventually when no more legacy */
441 if (ctx
->sigprovctx
== NULL
)
442 return EVP_PKEY_CTX_ctrl(ctx
, -1, EVP_PKEY_OP_TYPE_SIG
,
443 EVP_PKEY_CTRL_MD
, 0, (void *)(md
));
448 mdsize
= EVP_MD_size(md
);
449 name
= EVP_MD_name(md
);
450 sig_md_params
[0] = OSSL_PARAM_construct_utf8_string(
451 OSSL_SIGNATURE_PARAM_DIGEST
,
453 * Cast away the const. This is read only so should
458 sig_md_params
[1] = OSSL_PARAM_construct_size_t(OSSL_SIGNATURE_PARAM_DIGEST_SIZE
,
460 sig_md_params
[2] = OSSL_PARAM_construct_end();
462 return EVP_PKEY_CTX_set_params(ctx
, sig_md_params
);
466 static int legacy_ctrl_to_param(EVP_PKEY_CTX
*ctx
, int keytype
, int optype
,
467 int cmd
, int p1
, void *p2
)
470 #ifndef OPENSSL_NO_DH
471 case EVP_PKEY_CTRL_DH_PAD
:
472 return EVP_PKEY_CTX_set_dh_pad(ctx
, p1
);
474 case EVP_PKEY_CTRL_MD
:
475 return EVP_PKEY_CTX_set_signature_md(ctx
, p2
);
480 int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX
*ctx
, int keytype
, int optype
,
481 int cmd
, int p1
, void *p2
)
486 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL
, EVP_R_COMMAND_NOT_SUPPORTED
);
490 if (ctx
->exchprovctx
!= NULL
|| ctx
->sigprovctx
!= NULL
)
491 return legacy_ctrl_to_param(ctx
, keytype
, optype
, cmd
, p1
, p2
);
493 if (ctx
->pmeth
== NULL
|| ctx
->pmeth
->ctrl
== NULL
) {
494 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL
, EVP_R_COMMAND_NOT_SUPPORTED
);
497 if ((keytype
!= -1) && (ctx
->pmeth
->pkey_id
!= keytype
))
500 /* Skip the operation checks since this is called in a very early stage */
501 if (ctx
->pmeth
->digest_custom
!= NULL
)
504 if (ctx
->operation
== EVP_PKEY_OP_UNDEFINED
) {
505 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL
, EVP_R_NO_OPERATION_SET
);
509 if ((optype
!= -1) && !(ctx
->operation
& optype
)) {
510 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL
, EVP_R_INVALID_OPERATION
);
515 ret
= ctx
->pmeth
->ctrl(ctx
, cmd
, p1
, p2
);
518 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL
, EVP_R_COMMAND_NOT_SUPPORTED
);
523 int EVP_PKEY_CTX_ctrl_uint64(EVP_PKEY_CTX
*ctx
, int keytype
, int optype
,
524 int cmd
, uint64_t value
)
526 return EVP_PKEY_CTX_ctrl(ctx
, keytype
, optype
, cmd
, 0, &value
);
529 static int legacy_ctrl_str_to_param(EVP_PKEY_CTX
*ctx
, const char *name
,
532 #ifndef OPENSSL_NO_DH
533 if (strcmp(name
, "dh_pad") == 0) {
537 return EVP_PKEY_CTX_set_dh_pad(ctx
, pad
);
540 if (strcmp(name
, "digest") == 0) {
543 = EVP_MD_fetch(ossl_provider_library_context(ctx
->signature
->prov
),
547 ret
= EVP_PKEY_CTX_set_signature_md(ctx
, md
);
548 EVP_MD_meth_free(md
);
555 int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX
*ctx
,
556 const char *name
, const char *value
)
559 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR
, EVP_R_COMMAND_NOT_SUPPORTED
);
563 if (ctx
->exchprovctx
!= NULL
|| ctx
->sigprovctx
!= NULL
)
564 return legacy_ctrl_str_to_param(ctx
, name
, value
);
566 if (!ctx
|| !ctx
->pmeth
|| !ctx
->pmeth
->ctrl_str
) {
567 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR
, EVP_R_COMMAND_NOT_SUPPORTED
);
570 if (strcmp(name
, "digest") == 0)
571 return EVP_PKEY_CTX_md(ctx
, EVP_PKEY_OP_TYPE_SIG
, EVP_PKEY_CTRL_MD
,
573 return ctx
->pmeth
->ctrl_str(ctx
, name
, value
);
576 /* Utility functions to send a string of hex string to a ctrl */
578 int EVP_PKEY_CTX_str2ctrl(EVP_PKEY_CTX
*ctx
, int cmd
, const char *str
)
585 return ctx
->pmeth
->ctrl(ctx
, cmd
, len
, (void *)str
);
588 int EVP_PKEY_CTX_hex2ctrl(EVP_PKEY_CTX
*ctx
, int cmd
, const char *hex
)
594 bin
= OPENSSL_hexstr2buf(hex
, &binlen
);
597 if (binlen
<= INT_MAX
)
598 rv
= ctx
->pmeth
->ctrl(ctx
, cmd
, binlen
, bin
);
603 /* Pass a message digest to a ctrl */
604 int EVP_PKEY_CTX_md(EVP_PKEY_CTX
*ctx
, int optype
, int cmd
, const char *md
)
608 if (md
== NULL
|| (m
= EVP_get_digestbyname(md
)) == NULL
) {
609 EVPerr(EVP_F_EVP_PKEY_CTX_MD
, EVP_R_INVALID_DIGEST
);
612 return EVP_PKEY_CTX_ctrl(ctx
, -1, optype
, cmd
, 0, (void *)m
);
615 int EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX
*ctx
)
617 return ctx
->operation
;
620 void EVP_PKEY_CTX_set0_keygen_info(EVP_PKEY_CTX
*ctx
, int *dat
, int datlen
)
622 ctx
->keygen_info
= dat
;
623 ctx
->keygen_info_count
= datlen
;
626 void EVP_PKEY_CTX_set_data(EVP_PKEY_CTX
*ctx
, void *data
)
631 void *EVP_PKEY_CTX_get_data(const EVP_PKEY_CTX
*ctx
)
636 EVP_PKEY
*EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX
*ctx
)
641 EVP_PKEY
*EVP_PKEY_CTX_get0_peerkey(EVP_PKEY_CTX
*ctx
)
646 void EVP_PKEY_CTX_set_app_data(EVP_PKEY_CTX
*ctx
, void *data
)
648 ctx
->app_data
= data
;
651 void *EVP_PKEY_CTX_get_app_data(EVP_PKEY_CTX
*ctx
)
653 return ctx
->app_data
;
656 void EVP_PKEY_meth_set_init(EVP_PKEY_METHOD
*pmeth
,
657 int (*init
) (EVP_PKEY_CTX
*ctx
))
662 void EVP_PKEY_meth_set_copy(EVP_PKEY_METHOD
*pmeth
,
663 int (*copy
) (EVP_PKEY_CTX
*dst
,
664 const EVP_PKEY_CTX
*src
))
669 void EVP_PKEY_meth_set_cleanup(EVP_PKEY_METHOD
*pmeth
,
670 void (*cleanup
) (EVP_PKEY_CTX
*ctx
))
672 pmeth
->cleanup
= cleanup
;
675 void EVP_PKEY_meth_set_paramgen(EVP_PKEY_METHOD
*pmeth
,
676 int (*paramgen_init
) (EVP_PKEY_CTX
*ctx
),
677 int (*paramgen
) (EVP_PKEY_CTX
*ctx
,
680 pmeth
->paramgen_init
= paramgen_init
;
681 pmeth
->paramgen
= paramgen
;
684 void EVP_PKEY_meth_set_keygen(EVP_PKEY_METHOD
*pmeth
,
685 int (*keygen_init
) (EVP_PKEY_CTX
*ctx
),
686 int (*keygen
) (EVP_PKEY_CTX
*ctx
,
689 pmeth
->keygen_init
= keygen_init
;
690 pmeth
->keygen
= keygen
;
693 void EVP_PKEY_meth_set_sign(EVP_PKEY_METHOD
*pmeth
,
694 int (*sign_init
) (EVP_PKEY_CTX
*ctx
),
695 int (*sign
) (EVP_PKEY_CTX
*ctx
,
696 unsigned char *sig
, size_t *siglen
,
697 const unsigned char *tbs
,
700 pmeth
->sign_init
= sign_init
;
704 void EVP_PKEY_meth_set_verify(EVP_PKEY_METHOD
*pmeth
,
705 int (*verify_init
) (EVP_PKEY_CTX
*ctx
),
706 int (*verify
) (EVP_PKEY_CTX
*ctx
,
707 const unsigned char *sig
,
709 const unsigned char *tbs
,
712 pmeth
->verify_init
= verify_init
;
713 pmeth
->verify
= verify
;
716 void EVP_PKEY_meth_set_verify_recover(EVP_PKEY_METHOD
*pmeth
,
717 int (*verify_recover_init
) (EVP_PKEY_CTX
719 int (*verify_recover
) (EVP_PKEY_CTX
728 pmeth
->verify_recover_init
= verify_recover_init
;
729 pmeth
->verify_recover
= verify_recover
;
732 void EVP_PKEY_meth_set_signctx(EVP_PKEY_METHOD
*pmeth
,
733 int (*signctx_init
) (EVP_PKEY_CTX
*ctx
,
735 int (*signctx
) (EVP_PKEY_CTX
*ctx
,
740 pmeth
->signctx_init
= signctx_init
;
741 pmeth
->signctx
= signctx
;
744 void EVP_PKEY_meth_set_verifyctx(EVP_PKEY_METHOD
*pmeth
,
745 int (*verifyctx_init
) (EVP_PKEY_CTX
*ctx
,
747 int (*verifyctx
) (EVP_PKEY_CTX
*ctx
,
748 const unsigned char *sig
,
752 pmeth
->verifyctx_init
= verifyctx_init
;
753 pmeth
->verifyctx
= verifyctx
;
756 void EVP_PKEY_meth_set_encrypt(EVP_PKEY_METHOD
*pmeth
,
757 int (*encrypt_init
) (EVP_PKEY_CTX
*ctx
),
758 int (*encryptfn
) (EVP_PKEY_CTX
*ctx
,
761 const unsigned char *in
,
764 pmeth
->encrypt_init
= encrypt_init
;
765 pmeth
->encrypt
= encryptfn
;
768 void EVP_PKEY_meth_set_decrypt(EVP_PKEY_METHOD
*pmeth
,
769 int (*decrypt_init
) (EVP_PKEY_CTX
*ctx
),
770 int (*decrypt
) (EVP_PKEY_CTX
*ctx
,
773 const unsigned char *in
,
776 pmeth
->decrypt_init
= decrypt_init
;
777 pmeth
->decrypt
= decrypt
;
780 void EVP_PKEY_meth_set_derive(EVP_PKEY_METHOD
*pmeth
,
781 int (*derive_init
) (EVP_PKEY_CTX
*ctx
),
782 int (*derive
) (EVP_PKEY_CTX
*ctx
,
786 pmeth
->derive_init
= derive_init
;
787 pmeth
->derive
= derive
;
790 void EVP_PKEY_meth_set_ctrl(EVP_PKEY_METHOD
*pmeth
,
791 int (*ctrl
) (EVP_PKEY_CTX
*ctx
, int type
, int p1
,
793 int (*ctrl_str
) (EVP_PKEY_CTX
*ctx
,
798 pmeth
->ctrl_str
= ctrl_str
;
801 void EVP_PKEY_meth_set_check(EVP_PKEY_METHOD
*pmeth
,
802 int (*check
) (EVP_PKEY
*pkey
))
804 pmeth
->check
= check
;
807 void EVP_PKEY_meth_set_public_check(EVP_PKEY_METHOD
*pmeth
,
808 int (*check
) (EVP_PKEY
*pkey
))
810 pmeth
->public_check
= check
;
813 void EVP_PKEY_meth_set_param_check(EVP_PKEY_METHOD
*pmeth
,
814 int (*check
) (EVP_PKEY
*pkey
))
816 pmeth
->param_check
= check
;
819 void EVP_PKEY_meth_set_digest_custom(EVP_PKEY_METHOD
*pmeth
,
820 int (*digest_custom
) (EVP_PKEY_CTX
*ctx
,
823 pmeth
->digest_custom
= digest_custom
;
826 void EVP_PKEY_meth_get_init(const EVP_PKEY_METHOD
*pmeth
,
827 int (**pinit
) (EVP_PKEY_CTX
*ctx
))
829 *pinit
= pmeth
->init
;
832 void EVP_PKEY_meth_get_copy(const EVP_PKEY_METHOD
*pmeth
,
833 int (**pcopy
) (EVP_PKEY_CTX
*dst
,
834 const EVP_PKEY_CTX
*src
))
836 *pcopy
= pmeth
->copy
;
839 void EVP_PKEY_meth_get_cleanup(const EVP_PKEY_METHOD
*pmeth
,
840 void (**pcleanup
) (EVP_PKEY_CTX
*ctx
))
842 *pcleanup
= pmeth
->cleanup
;
845 void EVP_PKEY_meth_get_paramgen(const EVP_PKEY_METHOD
*pmeth
,
846 int (**pparamgen_init
) (EVP_PKEY_CTX
*ctx
),
847 int (**pparamgen
) (EVP_PKEY_CTX
*ctx
,
851 *pparamgen_init
= pmeth
->paramgen_init
;
853 *pparamgen
= pmeth
->paramgen
;
856 void EVP_PKEY_meth_get_keygen(const EVP_PKEY_METHOD
*pmeth
,
857 int (**pkeygen_init
) (EVP_PKEY_CTX
*ctx
),
858 int (**pkeygen
) (EVP_PKEY_CTX
*ctx
,
862 *pkeygen_init
= pmeth
->keygen_init
;
864 *pkeygen
= pmeth
->keygen
;
867 void EVP_PKEY_meth_get_sign(const EVP_PKEY_METHOD
*pmeth
,
868 int (**psign_init
) (EVP_PKEY_CTX
*ctx
),
869 int (**psign
) (EVP_PKEY_CTX
*ctx
,
870 unsigned char *sig
, size_t *siglen
,
871 const unsigned char *tbs
,
875 *psign_init
= pmeth
->sign_init
;
877 *psign
= pmeth
->sign
;
880 void EVP_PKEY_meth_get_verify(const EVP_PKEY_METHOD
*pmeth
,
881 int (**pverify_init
) (EVP_PKEY_CTX
*ctx
),
882 int (**pverify
) (EVP_PKEY_CTX
*ctx
,
883 const unsigned char *sig
,
885 const unsigned char *tbs
,
889 *pverify_init
= pmeth
->verify_init
;
891 *pverify
= pmeth
->verify
;
894 void EVP_PKEY_meth_get_verify_recover(const EVP_PKEY_METHOD
*pmeth
,
895 int (**pverify_recover_init
) (EVP_PKEY_CTX
897 int (**pverify_recover
) (EVP_PKEY_CTX
906 if (pverify_recover_init
)
907 *pverify_recover_init
= pmeth
->verify_recover_init
;
909 *pverify_recover
= pmeth
->verify_recover
;
912 void EVP_PKEY_meth_get_signctx(const EVP_PKEY_METHOD
*pmeth
,
913 int (**psignctx_init
) (EVP_PKEY_CTX
*ctx
,
915 int (**psignctx
) (EVP_PKEY_CTX
*ctx
,
921 *psignctx_init
= pmeth
->signctx_init
;
923 *psignctx
= pmeth
->signctx
;
926 void EVP_PKEY_meth_get_verifyctx(const EVP_PKEY_METHOD
*pmeth
,
927 int (**pverifyctx_init
) (EVP_PKEY_CTX
*ctx
,
929 int (**pverifyctx
) (EVP_PKEY_CTX
*ctx
,
930 const unsigned char *sig
,
935 *pverifyctx_init
= pmeth
->verifyctx_init
;
937 *pverifyctx
= pmeth
->verifyctx
;
940 void EVP_PKEY_meth_get_encrypt(const EVP_PKEY_METHOD
*pmeth
,
941 int (**pencrypt_init
) (EVP_PKEY_CTX
*ctx
),
942 int (**pencryptfn
) (EVP_PKEY_CTX
*ctx
,
945 const unsigned char *in
,
949 *pencrypt_init
= pmeth
->encrypt_init
;
951 *pencryptfn
= pmeth
->encrypt
;
954 void EVP_PKEY_meth_get_decrypt(const EVP_PKEY_METHOD
*pmeth
,
955 int (**pdecrypt_init
) (EVP_PKEY_CTX
*ctx
),
956 int (**pdecrypt
) (EVP_PKEY_CTX
*ctx
,
959 const unsigned char *in
,
963 *pdecrypt_init
= pmeth
->decrypt_init
;
965 *pdecrypt
= pmeth
->decrypt
;
968 void EVP_PKEY_meth_get_derive(const EVP_PKEY_METHOD
*pmeth
,
969 int (**pderive_init
) (EVP_PKEY_CTX
*ctx
),
970 int (**pderive
) (EVP_PKEY_CTX
*ctx
,
975 *pderive_init
= pmeth
->derive_init
;
977 *pderive
= pmeth
->derive
;
980 void EVP_PKEY_meth_get_ctrl(const EVP_PKEY_METHOD
*pmeth
,
981 int (**pctrl
) (EVP_PKEY_CTX
*ctx
, int type
, int p1
,
983 int (**pctrl_str
) (EVP_PKEY_CTX
*ctx
,
988 *pctrl
= pmeth
->ctrl
;
990 *pctrl_str
= pmeth
->ctrl_str
;
993 void EVP_PKEY_meth_get_check(const EVP_PKEY_METHOD
*pmeth
,
994 int (**pcheck
) (EVP_PKEY
*pkey
))
997 *pcheck
= pmeth
->check
;
1000 void EVP_PKEY_meth_get_public_check(const EVP_PKEY_METHOD
*pmeth
,
1001 int (**pcheck
) (EVP_PKEY
*pkey
))
1004 *pcheck
= pmeth
->public_check
;
1007 void EVP_PKEY_meth_get_param_check(const EVP_PKEY_METHOD
*pmeth
,
1008 int (**pcheck
) (EVP_PKEY
*pkey
))
1011 *pcheck
= pmeth
->param_check
;
1014 void EVP_PKEY_meth_get_digest_custom(EVP_PKEY_METHOD
*pmeth
,
1015 int (**pdigest_custom
) (EVP_PKEY_CTX
*ctx
,
1018 if (pdigest_custom
!= NULL
)
1019 *pdigest_custom
= pmeth
->digest_custom
;