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
11 * DH low level APIs are deprecated for public use, but still ok for
14 #include "internal/deprecated.h"
18 #include <openssl/engine.h>
19 #include <openssl/evp.h>
20 #include <openssl/x509v3.h>
21 #include <openssl/core_names.h>
22 #include <openssl/dh.h>
23 #include <openssl/rsa.h>
24 #include "internal/cryptlib.h"
25 #include "crypto/asn1.h"
26 #include "crypto/evp.h"
27 #include "internal/numbers.h"
28 #include "internal/provider.h"
29 #include "evp_local.h"
33 typedef const EVP_PKEY_METHOD *(*pmeth_fn)(void);
34 typedef int sk_cmp_fn_type(const char *const *a, const char *const *b);
36 static STACK_OF(EVP_PKEY_METHOD) *app_pkey_methods = NULL;
38 /* This array needs to be in order of NIDs */
39 static pmeth_fn standard_methods[] = {
40 # ifndef OPENSSL_NO_RSA
43 # ifndef OPENSSL_NO_DH
46 # ifndef OPENSSL_NO_DSA
49 # ifndef OPENSSL_NO_EC
53 # ifndef OPENSSL_NO_CMAC
56 # ifndef OPENSSL_NO_RSA
59 # ifndef OPENSSL_NO_DH
62 # ifndef OPENSSL_NO_SCRYPT
66 # ifndef OPENSSL_NO_EC
71 # ifndef OPENSSL_NO_POLY1305
74 # ifndef OPENSSL_NO_SIPHASH
77 # ifndef OPENSSL_NO_EC
81 # ifndef OPENSSL_NO_SM2
86 DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, pmeth_fn, pmeth_func);
88 static int pmeth_func_cmp(const EVP_PKEY_METHOD *const *a, pmeth_fn const *b)
90 return ((*a)->pkey_id - ((**b)())->pkey_id);
93 IMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, pmeth_fn, pmeth_func);
95 static int pmeth_cmp(const EVP_PKEY_METHOD *const *a,
96 const EVP_PKEY_METHOD *const *b)
98 return ((*a)->pkey_id - (*b)->pkey_id);
101 const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type)
105 const EVP_PKEY_METHOD *t = &tmp;
108 if (app_pkey_methods) {
110 idx = sk_EVP_PKEY_METHOD_find(app_pkey_methods, &tmp);
112 return sk_EVP_PKEY_METHOD_value(app_pkey_methods, idx);
114 ret = OBJ_bsearch_pmeth_func(&t, standard_methods,
115 sizeof(standard_methods) /
117 if (ret == NULL || *ret == NULL)
122 EVP_PKEY_METHOD *EVP_PKEY_meth_new(int id, int flags)
124 EVP_PKEY_METHOD *pmeth;
126 pmeth = OPENSSL_zalloc(sizeof(*pmeth));
128 EVPerr(EVP_F_EVP_PKEY_METH_NEW, ERR_R_MALLOC_FAILURE);
133 pmeth->flags = flags | EVP_PKEY_FLAG_DYNAMIC;
136 #endif /* FIPS_MODE */
138 static EVP_PKEY_CTX *int_ctx_new(OPENSSL_CTX *libctx,
139 EVP_PKEY *pkey, ENGINE *e,
140 const char *keytype, const char *propquery,
145 const EVP_PKEY_METHOD *pmeth = NULL;
146 EVP_KEYMGMT *keymgmt = NULL;
149 * When using providers, the context is bound to the algo implementation
152 if (pkey == NULL && e == NULL && id == -1)
156 * If the key doesn't contain anything legacy, then it must be provided,
157 * so we extract the necessary information and use that.
159 if (pkey != NULL && pkey->type == EVP_PKEY_NONE) {
160 /* If we have an engine, something went wrong somewhere... */
161 if (!ossl_assert(e == NULL))
163 keytype = evp_first_name(pkey->keymgmt->prov, pkey->keymgmt->name_id);
167 /* TODO(3.0) Legacy code should be removed when all is provider based */
176 * Here, we extract what information we can for the purpose of
177 * supporting usage with implementations from providers, to make
178 * for a smooth transition from legacy stuff to provider based stuff.
180 * If an engine is given, this is entirely legacy, and we should not
181 * pretend anything else, so we only set the name when no engine is
182 * given. If both are already given, someone made a mistake, and
183 * since that can only happen internally, it's safe to make an
186 if (!ossl_assert(e == NULL || keytype == NULL))
189 keytype = OBJ_nid2sn(id);
191 # ifndef OPENSSL_NO_ENGINE
192 if (e == NULL && pkey != NULL)
193 e = pkey->pmeth_engine != NULL ? pkey->pmeth_engine : pkey->engine;
194 /* Try to find an ENGINE which implements this method */
196 if (!ENGINE_init(e)) {
197 EVPerr(EVP_F_INT_CTX_NEW, ERR_R_ENGINE_LIB);
201 e = ENGINE_get_pkey_meth_engine(id);
205 * If an ENGINE handled this method look it up. Otherwise use internal
209 pmeth = ENGINE_get_pkey_meth(e, id);
212 pmeth = EVP_PKEY_meth_find(id);
215 # ifndef OPENSSL_NO_ENGINE
218 EVPerr(EVP_F_INT_CTX_NEW, EVP_R_UNSUPPORTED_ALGORITHM);
222 #endif /* FIPS_MODE */
225 * If there's no engine and there's a name, we try fetching a provider
228 if (e == NULL && keytype != NULL) {
229 /* This could fail so ignore errors */
231 keymgmt = EVP_KEYMGMT_fetch(libctx, keytype, propquery);
235 ret = OPENSSL_zalloc(sizeof(*ret));
237 #if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE)
240 EVPerr(EVP_F_INT_CTX_NEW, ERR_R_MALLOC_FAILURE);
243 ret->libctx = libctx;
244 ret->propquery = propquery;
245 ret->keytype = keytype;
246 ret->keymgmt = keymgmt;
249 ret->operation = EVP_PKEY_OP_UNDEFINED;
252 EVP_PKEY_up_ref(pkey);
254 if (pmeth != NULL && pmeth->init != NULL) {
255 if (pmeth->init(ret) <= 0) {
257 EVP_PKEY_CTX_free(ret);
265 /*- All methods below can also be used in FIPS_MODE */
267 EVP_PKEY_CTX *EVP_PKEY_CTX_new_from_name(OPENSSL_CTX *libctx,
269 const char *propquery)
271 return int_ctx_new(libctx, NULL, NULL, name, propquery, -1);
274 EVP_PKEY_CTX *EVP_PKEY_CTX_new_from_pkey(OPENSSL_CTX *libctx, EVP_PKEY *pkey,
275 const char *propquery)
277 return int_ctx_new(libctx, pkey, NULL, NULL, propquery, -1);
280 void evp_pkey_ctx_free_old_ops(EVP_PKEY_CTX *ctx)
282 if (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)) {
283 if (ctx->op.sig.sigprovctx != NULL && ctx->op.sig.signature != NULL)
284 ctx->op.sig.signature->freectx(ctx->op.sig.sigprovctx);
285 EVP_SIGNATURE_free(ctx->op.sig.signature);
286 ctx->op.sig.sigprovctx = NULL;
287 ctx->op.sig.signature = NULL;
288 } else if (EVP_PKEY_CTX_IS_DERIVE_OP(ctx)) {
289 if (ctx->op.kex.exchprovctx != NULL && ctx->op.kex.exchange != NULL)
290 ctx->op.kex.exchange->freectx(ctx->op.kex.exchprovctx);
291 EVP_KEYEXCH_free(ctx->op.kex.exchange);
292 ctx->op.kex.exchprovctx = NULL;
293 ctx->op.kex.exchange = NULL;
295 /* TODO(3.0): add dependancies and uncomment this when available for fips mode */
297 else if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)) {
298 if (ctx->op.ciph.ciphprovctx != NULL && ctx->op.ciph.cipher != NULL)
299 ctx->op.ciph.cipher->freectx(ctx->op.ciph.ciphprovctx);
300 EVP_ASYM_CIPHER_free(ctx->op.ciph.cipher);
301 ctx->op.ciph.ciphprovctx = NULL;
302 ctx->op.ciph.cipher = NULL;
303 } else if (EVP_PKEY_CTX_IS_GEN_OP(ctx)) {
304 if (ctx->op.keymgmt.genctx != NULL && ctx->keymgmt != NULL)
305 evp_keymgmt_gen_cleanup(ctx->keymgmt, ctx->op.keymgmt.genctx);
310 void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx)
314 if (ctx->pmeth && ctx->pmeth->cleanup)
315 ctx->pmeth->cleanup(ctx);
317 evp_pkey_ctx_free_old_ops(ctx);
318 EVP_KEYMGMT_free(ctx->keymgmt);
320 EVP_PKEY_free(ctx->pkey);
321 EVP_PKEY_free(ctx->peerkey);
322 #if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE)
323 ENGINE_finish(ctx->engine);
330 void EVP_PKEY_meth_get0_info(int *ppkey_id, int *pflags,
331 const EVP_PKEY_METHOD *meth)
334 *ppkey_id = meth->pkey_id;
336 *pflags = meth->flags;
339 void EVP_PKEY_meth_copy(EVP_PKEY_METHOD *dst, const EVP_PKEY_METHOD *src)
342 dst->init = src->init;
343 dst->copy = src->copy;
344 dst->cleanup = src->cleanup;
346 dst->paramgen_init = src->paramgen_init;
347 dst->paramgen = src->paramgen;
349 dst->keygen_init = src->keygen_init;
350 dst->keygen = src->keygen;
352 dst->sign_init = src->sign_init;
353 dst->sign = src->sign;
355 dst->verify_init = src->verify_init;
356 dst->verify = src->verify;
358 dst->verify_recover_init = src->verify_recover_init;
359 dst->verify_recover = src->verify_recover;
361 dst->signctx_init = src->signctx_init;
362 dst->signctx = src->signctx;
364 dst->verifyctx_init = src->verifyctx_init;
365 dst->verifyctx = src->verifyctx;
367 dst->encrypt_init = src->encrypt_init;
368 dst->encrypt = src->encrypt;
370 dst->decrypt_init = src->decrypt_init;
371 dst->decrypt = src->decrypt;
373 dst->derive_init = src->derive_init;
374 dst->derive = src->derive;
376 dst->ctrl = src->ctrl;
377 dst->ctrl_str = src->ctrl_str;
379 dst->check = src->check;
382 void EVP_PKEY_meth_free(EVP_PKEY_METHOD *pmeth)
384 if (pmeth && (pmeth->flags & EVP_PKEY_FLAG_DYNAMIC))
388 EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e)
390 return int_ctx_new(NULL, pkey, e, NULL, NULL, -1);
393 EVP_PKEY_CTX *EVP_PKEY_CTX_new_id(int id, ENGINE *e)
395 return int_ctx_new(NULL, NULL, e, NULL, NULL, id);
398 EVP_PKEY_CTX *EVP_PKEY_CTX_dup(const EVP_PKEY_CTX *pctx)
402 if (((pctx->pmeth == NULL) || (pctx->pmeth->copy == NULL))
403 && ((EVP_PKEY_CTX_IS_DERIVE_OP(pctx)
404 && pctx->op.kex.exchprovctx == NULL)
405 || (EVP_PKEY_CTX_IS_SIGNATURE_OP(pctx)
406 && pctx->op.sig.sigprovctx == NULL)))
408 # ifndef OPENSSL_NO_ENGINE
409 /* Make sure it's safe to copy a pkey context using an ENGINE */
410 if (pctx->engine && !ENGINE_init(pctx->engine)) {
411 EVPerr(EVP_F_EVP_PKEY_CTX_DUP, ERR_R_ENGINE_LIB);
415 rctx = OPENSSL_zalloc(sizeof(*rctx));
417 EVPerr(EVP_F_EVP_PKEY_CTX_DUP, ERR_R_MALLOC_FAILURE);
421 if (pctx->pkey != NULL)
422 EVP_PKEY_up_ref(pctx->pkey);
423 rctx->pkey = pctx->pkey;
424 rctx->operation = pctx->operation;
425 rctx->libctx = pctx->libctx;
426 rctx->keytype = pctx->keytype;
427 rctx->propquery = pctx->propquery;
429 if (EVP_PKEY_CTX_IS_DERIVE_OP(pctx)) {
430 if (pctx->op.kex.exchange != NULL) {
431 rctx->op.kex.exchange = pctx->op.kex.exchange;
432 if (!EVP_KEYEXCH_up_ref(rctx->op.kex.exchange)) {
437 if (pctx->op.kex.exchprovctx != NULL) {
438 if (!ossl_assert(pctx->op.kex.exchange != NULL))
440 rctx->op.kex.exchprovctx
441 = pctx->op.kex.exchange->dupctx(pctx->op.kex.exchprovctx);
442 if (rctx->op.kex.exchprovctx == NULL) {
443 EVP_KEYEXCH_free(rctx->op.kex.exchange);
449 } else if (EVP_PKEY_CTX_IS_SIGNATURE_OP(pctx)) {
450 if (pctx->op.sig.signature != NULL) {
451 rctx->op.sig.signature = pctx->op.sig.signature;
452 if (!EVP_SIGNATURE_up_ref(rctx->op.sig.signature)) {
457 if (pctx->op.sig.sigprovctx != NULL) {
458 if (!ossl_assert(pctx->op.sig.signature != NULL))
460 rctx->op.sig.sigprovctx
461 = pctx->op.sig.signature->dupctx(pctx->op.sig.sigprovctx);
462 if (rctx->op.sig.sigprovctx == NULL) {
463 EVP_SIGNATURE_free(rctx->op.sig.signature);
469 } else if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(pctx)) {
470 if (pctx->op.ciph.cipher != NULL) {
471 rctx->op.ciph.cipher = pctx->op.ciph.cipher;
472 if (!EVP_ASYM_CIPHER_up_ref(rctx->op.ciph.cipher)) {
477 if (pctx->op.ciph.ciphprovctx != NULL) {
478 if (!ossl_assert(pctx->op.ciph.cipher != NULL))
480 rctx->op.ciph.ciphprovctx
481 = pctx->op.ciph.cipher->dupctx(pctx->op.ciph.ciphprovctx);
482 if (rctx->op.ciph.ciphprovctx == NULL) {
483 EVP_ASYM_CIPHER_free(rctx->op.ciph.cipher);
491 rctx->pmeth = pctx->pmeth;
492 # ifndef OPENSSL_NO_ENGINE
493 rctx->engine = pctx->engine;
497 EVP_PKEY_up_ref(pctx->peerkey);
498 rctx->peerkey = pctx->peerkey;
500 if (pctx->pmeth->copy(rctx, pctx) > 0)
504 EVP_PKEY_CTX_free(rctx);
509 int EVP_PKEY_meth_add0(const EVP_PKEY_METHOD *pmeth)
511 if (app_pkey_methods == NULL) {
512 app_pkey_methods = sk_EVP_PKEY_METHOD_new(pmeth_cmp);
513 if (app_pkey_methods == NULL){
514 EVPerr(EVP_F_EVP_PKEY_METH_ADD0, ERR_R_MALLOC_FAILURE);
518 if (!sk_EVP_PKEY_METHOD_push(app_pkey_methods, pmeth)) {
519 EVPerr(EVP_F_EVP_PKEY_METH_ADD0, ERR_R_MALLOC_FAILURE);
522 sk_EVP_PKEY_METHOD_sort(app_pkey_methods);
526 void evp_app_cleanup_int(void)
528 if (app_pkey_methods != NULL)
529 sk_EVP_PKEY_METHOD_pop_free(app_pkey_methods, EVP_PKEY_meth_free);
532 int EVP_PKEY_meth_remove(const EVP_PKEY_METHOD *pmeth)
534 const EVP_PKEY_METHOD *ret;
536 ret = sk_EVP_PKEY_METHOD_delete_ptr(app_pkey_methods, pmeth);
538 return ret == NULL ? 0 : 1;
541 size_t EVP_PKEY_meth_get_count(void)
543 size_t rv = OSSL_NELEM(standard_methods);
545 if (app_pkey_methods)
546 rv += sk_EVP_PKEY_METHOD_num(app_pkey_methods);
550 const EVP_PKEY_METHOD *EVP_PKEY_meth_get0(size_t idx)
552 if (idx < OSSL_NELEM(standard_methods))
553 return (standard_methods[idx])();
554 if (app_pkey_methods == NULL)
556 idx -= OSSL_NELEM(standard_methods);
557 if (idx >= (size_t)sk_EVP_PKEY_METHOD_num(app_pkey_methods))
559 return sk_EVP_PKEY_METHOD_value(app_pkey_methods, idx);
563 int EVP_PKEY_CTX_set_params(EVP_PKEY_CTX *ctx, OSSL_PARAM *params)
565 if (EVP_PKEY_CTX_IS_DERIVE_OP(ctx)
566 && ctx->op.kex.exchprovctx != NULL
567 && ctx->op.kex.exchange != NULL
568 && ctx->op.kex.exchange->set_ctx_params != NULL)
569 return ctx->op.kex.exchange->set_ctx_params(ctx->op.kex.exchprovctx,
571 if (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)
572 && ctx->op.sig.sigprovctx != NULL
573 && ctx->op.sig.signature != NULL
574 && ctx->op.sig.signature->set_ctx_params != NULL)
575 return ctx->op.sig.signature->set_ctx_params(ctx->op.sig.sigprovctx,
577 if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)
578 && ctx->op.ciph.ciphprovctx != NULL
579 && ctx->op.ciph.cipher != NULL
580 && ctx->op.ciph.cipher->set_ctx_params != NULL)
581 return ctx->op.ciph.cipher->set_ctx_params(ctx->op.ciph.ciphprovctx,
583 if (EVP_PKEY_CTX_IS_GEN_OP(ctx)
584 && ctx->op.keymgmt.genctx != NULL
585 && ctx->keymgmt != NULL
586 && ctx->keymgmt->gen_set_params != NULL)
587 return evp_keymgmt_gen_set_params(ctx->keymgmt, ctx->op.keymgmt.genctx,
593 int EVP_PKEY_CTX_get_params(EVP_PKEY_CTX *ctx, OSSL_PARAM *params)
595 if (EVP_PKEY_CTX_IS_DERIVE_OP(ctx)
596 && ctx->op.kex.exchprovctx != NULL
597 && ctx->op.kex.exchange != NULL
598 && ctx->op.kex.exchange->get_ctx_params != NULL)
599 return ctx->op.kex.exchange->get_ctx_params(ctx->op.kex.exchprovctx,
601 if (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)
602 && ctx->op.sig.sigprovctx != NULL
603 && ctx->op.sig.signature != NULL
604 && ctx->op.sig.signature->get_ctx_params != NULL)
605 return ctx->op.sig.signature->get_ctx_params(ctx->op.sig.sigprovctx,
607 if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)
608 && ctx->op.ciph.ciphprovctx != NULL
609 && ctx->op.ciph.cipher != NULL
610 && ctx->op.ciph.cipher->get_ctx_params != NULL)
611 return ctx->op.ciph.cipher->get_ctx_params(ctx->op.ciph.ciphprovctx,
613 if (EVP_PKEY_CTX_IS_GEN_OP(ctx)
614 && ctx->op.keymgmt.genctx != NULL
615 && ctx->keymgmt != NULL
616 && ctx->keymgmt->gen_get_params != NULL)
617 return evp_keymgmt_gen_get_params(ctx->keymgmt, ctx->op.keymgmt.genctx,
622 const OSSL_PARAM *EVP_PKEY_CTX_gettable_params(EVP_PKEY_CTX *ctx)
624 if (EVP_PKEY_CTX_IS_DERIVE_OP(ctx)
625 && ctx->op.kex.exchange != NULL
626 && ctx->op.kex.exchange->gettable_ctx_params != NULL)
627 return ctx->op.kex.exchange->gettable_ctx_params();
628 if (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)
629 && ctx->op.sig.signature != NULL
630 && ctx->op.sig.signature->gettable_ctx_params != NULL)
631 return ctx->op.sig.signature->gettable_ctx_params();
633 if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)
634 && ctx->op.ciph.cipher != NULL
635 && ctx->op.ciph.cipher->gettable_ctx_params != NULL)
636 return ctx->op.ciph.cipher->gettable_ctx_params();
641 const OSSL_PARAM *EVP_PKEY_CTX_settable_params(EVP_PKEY_CTX *ctx)
643 if (EVP_PKEY_CTX_IS_DERIVE_OP(ctx)
644 && ctx->op.kex.exchange != NULL
645 && ctx->op.kex.exchange->settable_ctx_params != NULL)
646 return ctx->op.kex.exchange->settable_ctx_params();
647 if (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)
648 && ctx->op.sig.signature != NULL
649 && ctx->op.sig.signature->settable_ctx_params != NULL)
650 return ctx->op.sig.signature->settable_ctx_params();
651 if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)
652 && ctx->op.ciph.cipher != NULL
653 && ctx->op.ciph.cipher->settable_ctx_params != NULL)
654 return ctx->op.ciph.cipher->settable_ctx_params();
655 if (EVP_PKEY_CTX_IS_GEN_OP(ctx)
656 && ctx->keymgmt != NULL
657 && ctx->keymgmt->gen_settable_params != NULL)
658 return evp_keymgmt_gen_settable_params(ctx->keymgmt);
664 * Internal helpers for stricter EVP_PKEY_CTX_{set,get}_params().
666 * Return 1 on success, 0 or negative for errors.
668 * In particular they return -2 if any of the params is not supported.
670 * They are not available in FIPS_MODE as they depend on
671 * - EVP_PKEY_CTX_{get,set}_params()
672 * - EVP_PKEY_CTX_{gettable,settable}_params()
675 int evp_pkey_ctx_set_params_strict(EVP_PKEY_CTX *ctx, OSSL_PARAM *params)
679 if (ctx == NULL || params == NULL)
682 for (p = params; p->key != NULL; p++) {
683 /* Check the ctx actually understands this parameter */
684 if (OSSL_PARAM_locate_const(EVP_PKEY_CTX_settable_params(ctx),
689 return EVP_PKEY_CTX_set_params(ctx, params);
692 int evp_pkey_ctx_get_params_strict(EVP_PKEY_CTX *ctx, OSSL_PARAM *params)
696 if (ctx == NULL || params == NULL)
699 for (p = params; p->key != NULL; p++ ) {
700 /* Check the ctx actually understands this parameter */
701 if (OSSL_PARAM_locate_const(EVP_PKEY_CTX_gettable_params(ctx),
706 return EVP_PKEY_CTX_get_params(ctx, params);
709 # ifndef OPENSSL_NO_DH
710 int EVP_PKEY_CTX_set_dh_pad(EVP_PKEY_CTX *ctx, int pad)
712 OSSL_PARAM dh_pad_params[2];
713 unsigned int upad = pad;
715 /* We use EVP_PKEY_CTX_ctrl return values */
716 if (ctx == NULL || !EVP_PKEY_CTX_IS_DERIVE_OP(ctx)) {
717 ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED);
721 /* TODO(3.0): Remove this eventually when no more legacy */
722 if (ctx->op.kex.exchprovctx == NULL)
723 return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DH, EVP_PKEY_OP_DERIVE,
724 EVP_PKEY_CTRL_DH_PAD, pad, NULL);
726 dh_pad_params[0] = OSSL_PARAM_construct_uint(OSSL_EXCHANGE_PARAM_PAD, &upad);
727 dh_pad_params[1] = OSSL_PARAM_construct_end();
729 return EVP_PKEY_CTX_set_params(ctx, dh_pad_params);
733 int EVP_PKEY_CTX_get_signature_md(EVP_PKEY_CTX *ctx, const EVP_MD **md)
735 OSSL_PARAM sig_md_params[3], *p = sig_md_params;
736 /* 80 should be big enough */
740 if (ctx == NULL || !EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)) {
741 ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED);
742 /* Uses the same return values as EVP_PKEY_CTX_ctrl */
746 /* TODO(3.0): Remove this eventually when no more legacy */
747 if (ctx->op.sig.sigprovctx == NULL)
748 return EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_TYPE_SIG,
749 EVP_PKEY_CTRL_GET_MD, 0, (void *)(md));
751 *p++ = OSSL_PARAM_construct_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST,
754 *p++ = OSSL_PARAM_construct_end();
756 if (!EVP_PKEY_CTX_get_params(ctx, sig_md_params))
759 tmp = evp_get_digestbyname_ex(ctx->libctx, name);
768 int EVP_PKEY_CTX_set_signature_md(EVP_PKEY_CTX *ctx, const EVP_MD *md)
770 OSSL_PARAM sig_md_params[2], *p = sig_md_params;
773 if (ctx == NULL || !EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)) {
774 ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED);
775 /* Uses the same return values as EVP_PKEY_CTX_ctrl */
779 /* TODO(3.0): Remove this eventually when no more legacy */
780 if (ctx->op.sig.sigprovctx == NULL)
781 return EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_TYPE_SIG,
782 EVP_PKEY_CTRL_MD, 0, (void *)(md));
787 name = EVP_MD_name(md);
790 *p++ = OSSL_PARAM_construct_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST,
792 * Cast away the const. This is read
793 * only so should be safe
796 *p++ = OSSL_PARAM_construct_end();
798 return EVP_PKEY_CTX_set_params(ctx, sig_md_params);
801 static int legacy_ctrl_to_param(EVP_PKEY_CTX *ctx, int keytype, int optype,
802 int cmd, int p1, void *p2)
805 * GOST CMS format is different for different cipher algorithms.
806 * Most of other algorithms don't have such a difference
807 * so this ctrl is just ignored.
809 if (cmd == EVP_PKEY_CTRL_CIPHER)
811 # ifndef OPENSSL_NO_DH
812 if (keytype == EVP_PKEY_DH) {
814 case EVP_PKEY_CTRL_DH_PAD:
815 return EVP_PKEY_CTX_set_dh_pad(ctx, p1);
819 # ifndef OPENSSL_NO_EC
820 if (keytype == EVP_PKEY_EC) {
822 case EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID:
823 return EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, p1);
824 case EVP_PKEY_CTRL_EC_ECDH_COFACTOR:
826 return EVP_PKEY_CTX_get_ecdh_cofactor_mode(ctx);
827 } else if (p1 < -1 || p1 > 1) {
828 /* Uses the same return values as EVP_PKEY_CTX_ctrl */
831 return EVP_PKEY_CTX_set_ecdh_cofactor_mode(ctx, p1);
833 case EVP_PKEY_CTRL_EC_KDF_TYPE:
835 return EVP_PKEY_CTX_get_ecdh_kdf_type(ctx);
837 return EVP_PKEY_CTX_set_ecdh_kdf_type(ctx, p1);
839 case EVP_PKEY_CTRL_GET_EC_KDF_MD:
840 return EVP_PKEY_CTX_get_ecdh_kdf_md(ctx, p2);
841 case EVP_PKEY_CTRL_EC_KDF_MD:
842 return EVP_PKEY_CTX_set_ecdh_kdf_md(ctx, p2);
843 case EVP_PKEY_CTRL_GET_EC_KDF_OUTLEN:
844 return EVP_PKEY_CTX_get_ecdh_kdf_outlen(ctx, p2);
845 case EVP_PKEY_CTRL_EC_KDF_OUTLEN:
846 return EVP_PKEY_CTX_set_ecdh_kdf_outlen(ctx, p1);
847 case EVP_PKEY_CTRL_GET_EC_KDF_UKM:
848 return EVP_PKEY_CTX_get0_ecdh_kdf_ukm(ctx, p2);
849 case EVP_PKEY_CTRL_EC_KDF_UKM:
850 return EVP_PKEY_CTX_set0_ecdh_kdf_ukm(ctx, p2, p1);
854 if (keytype == EVP_PKEY_RSA) {
856 case EVP_PKEY_CTRL_RSA_OAEP_MD:
857 return EVP_PKEY_CTX_set_rsa_oaep_md(ctx, p2);
858 case EVP_PKEY_CTRL_GET_RSA_OAEP_MD:
859 return EVP_PKEY_CTX_get_rsa_oaep_md(ctx, p2);
860 case EVP_PKEY_CTRL_RSA_MGF1_MD:
861 return EVP_PKEY_CTX_set_rsa_oaep_md(ctx, p2);
862 case EVP_PKEY_CTRL_RSA_OAEP_LABEL:
863 return EVP_PKEY_CTX_set0_rsa_oaep_label(ctx, p2, p1);
864 case EVP_PKEY_CTRL_GET_RSA_OAEP_LABEL:
865 return EVP_PKEY_CTX_get0_rsa_oaep_label(ctx, (unsigned char **)p2);
866 case EVP_PKEY_CTRL_RSA_KEYGEN_BITS:
867 return EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, p1);
868 case EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP:
869 return EVP_PKEY_CTX_set_rsa_keygen_pubexp(ctx, p2);
870 case EVP_PKEY_CTRL_RSA_KEYGEN_PRIMES:
871 return EVP_PKEY_CTX_set_rsa_keygen_primes(ctx, p1);
875 * keytype == -1 is used when several key types share the same structure,
876 * or for generic controls that are the same across multiple key types.
880 case EVP_PKEY_CTRL_MD:
881 return EVP_PKEY_CTX_set_signature_md(ctx, p2);
882 case EVP_PKEY_CTRL_GET_MD:
883 return EVP_PKEY_CTX_get_signature_md(ctx, p2);
884 case EVP_PKEY_CTRL_RSA_PADDING:
885 return EVP_PKEY_CTX_set_rsa_padding(ctx, p1);
886 case EVP_PKEY_CTRL_GET_RSA_PADDING:
887 return EVP_PKEY_CTX_get_rsa_padding(ctx, p2);
888 case EVP_PKEY_CTRL_GET_RSA_MGF1_MD:
889 return EVP_PKEY_CTX_get_rsa_oaep_md(ctx, p2);
890 case EVP_PKEY_CTRL_RSA_PSS_SALTLEN:
891 return EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx, p1);
892 case EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN:
893 return EVP_PKEY_CTX_get_rsa_pss_saltlen(ctx, p2);
894 case EVP_PKEY_CTRL_PKCS7_ENCRYPT:
895 case EVP_PKEY_CTRL_PKCS7_DECRYPT:
896 # ifndef OPENSSL_NO_CMS
897 case EVP_PKEY_CTRL_CMS_DECRYPT:
898 case EVP_PKEY_CTRL_CMS_ENCRYPT:
900 /* TODO (3.0) Temporary hack, this should probe */
901 if (!EVP_PKEY_is_a(EVP_PKEY_CTX_get0_pkey(ctx), "RSASSA-PSS"))
903 ERR_raise(ERR_LIB_EVP,
904 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
911 int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype,
912 int cmd, int p1, void *p2)
917 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_COMMAND_NOT_SUPPORTED);
921 if ((EVP_PKEY_CTX_IS_DERIVE_OP(ctx) && ctx->op.kex.exchprovctx != NULL)
922 || (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)
923 && ctx->op.sig.sigprovctx != NULL)
924 || (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)
925 && ctx->op.ciph.ciphprovctx != NULL)
926 || (EVP_PKEY_CTX_IS_GEN_OP(ctx)
927 && ctx->op.keymgmt.genctx != NULL))
928 return legacy_ctrl_to_param(ctx, keytype, optype, cmd, p1, p2);
930 if (ctx->pmeth == NULL || ctx->pmeth->ctrl == NULL) {
931 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_COMMAND_NOT_SUPPORTED);
934 if ((keytype != -1) && (ctx->pmeth->pkey_id != keytype))
937 /* Skip the operation checks since this is called in a very early stage */
938 if (ctx->pmeth->digest_custom != NULL)
941 if (ctx->operation == EVP_PKEY_OP_UNDEFINED) {
942 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_NO_OPERATION_SET);
946 if ((optype != -1) && !(ctx->operation & optype)) {
947 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_INVALID_OPERATION);
952 ret = ctx->pmeth->ctrl(ctx, cmd, p1, p2);
955 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_COMMAND_NOT_SUPPORTED);
960 int EVP_PKEY_CTX_ctrl_uint64(EVP_PKEY_CTX *ctx, int keytype, int optype,
961 int cmd, uint64_t value)
963 return EVP_PKEY_CTX_ctrl(ctx, keytype, optype, cmd, 0, &value);
966 static int legacy_ctrl_str_to_param(EVP_PKEY_CTX *ctx, const char *name,
970 /* Special cases that we intercept */
971 # ifndef OPENSSL_NO_EC
973 * We don't support encoding settings for providers, i.e. the only
974 * possible encoding is "named_curve", so we simply fail when something
975 * else is given, and otherwise just pretend all is fine.
977 if (strcmp(name, "ec_param_enc") == 0) {
978 if (strcmp(value, "named_curve") == 0) {
981 ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED);
987 if (strcmp(name, "rsa_padding_mode") == 0)
988 name = OSSL_ASYM_CIPHER_PARAM_PAD_MODE;
989 else if (strcmp(name, "rsa_mgf1_md") == 0)
990 name = OSSL_ASYM_CIPHER_PARAM_MGF1_DIGEST;
991 else if (strcmp(name, "rsa_oaep_md") == 0)
992 name = OSSL_ASYM_CIPHER_PARAM_OAEP_DIGEST;
993 else if (strcmp(name, "rsa_oaep_label") == 0)
994 name = OSSL_ASYM_CIPHER_PARAM_OAEP_LABEL;
995 else if (strcmp(name, "rsa_pss_saltlen") == 0)
996 name = OSSL_SIGNATURE_PARAM_PSS_SALTLEN;
997 else if (strcmp(name, "rsa_keygen_bits") == 0)
998 name = OSSL_PKEY_PARAM_RSA_BITS;
999 else if (strcmp(name, "rsa_keygen_pubexp") == 0)
1000 name = OSSL_PKEY_PARAM_RSA_E;
1001 else if (strcmp(name, "rsa_keygen_primes") == 0)
1002 name = OSSL_PKEY_PARAM_RSA_PRIMES;
1003 # ifndef OPENSSL_NO_DH
1004 else if (strcmp(name, "dh_pad") == 0)
1005 name = OSSL_EXCHANGE_PARAM_PAD;
1007 # ifndef OPENSSL_NO_EC
1008 else if (strcmp(name, "ec_paramgen_curve") == 0)
1009 name = OSSL_PKEY_PARAM_EC_NAME;
1010 else if (strcmp(name, "ecdh_cofactor_mode") == 0)
1011 name = OSSL_EXCHANGE_PARAM_EC_ECDH_COFACTOR_MODE;
1012 else if (strcmp(name, "ecdh_kdf_md") == 0)
1013 name = OSSL_EXCHANGE_PARAM_KDF_DIGEST;
1018 * TODO(3.0) reduce the code above to only translate known legacy
1019 * string to the corresponding core name (see core_names.h), but
1020 * otherwise leave it to this code block to do the actual work.
1022 const OSSL_PARAM *settable = EVP_PKEY_CTX_settable_params(ctx);
1023 OSSL_PARAM params[2] = { OSSL_PARAM_END, OSSL_PARAM_END };
1027 if (!OSSL_PARAM_allocate_from_text(¶ms[0], settable, name, value,
1028 strlen(value), &exists)) {
1030 ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED);
1035 if (EVP_PKEY_CTX_set_params(ctx, params))
1037 OPENSSL_free(params[0].data);
1042 int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx,
1043 const char *name, const char *value)
1046 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR, EVP_R_COMMAND_NOT_SUPPORTED);
1050 if ((EVP_PKEY_CTX_IS_DERIVE_OP(ctx) && ctx->op.kex.exchprovctx != NULL)
1051 || (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)
1052 && ctx->op.sig.sigprovctx != NULL)
1053 || (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)
1054 && ctx->op.ciph.ciphprovctx != NULL)
1055 || (EVP_PKEY_CTX_IS_GEN_OP(ctx)
1056 && ctx->op.keymgmt.genctx != NULL))
1057 return legacy_ctrl_str_to_param(ctx, name, value);
1059 if (!ctx || !ctx->pmeth || !ctx->pmeth->ctrl_str) {
1060 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR, EVP_R_COMMAND_NOT_SUPPORTED);
1063 if (strcmp(name, "digest") == 0)
1064 return EVP_PKEY_CTX_md(ctx, EVP_PKEY_OP_TYPE_SIG, EVP_PKEY_CTRL_MD,
1066 return ctx->pmeth->ctrl_str(ctx, name, value);
1069 /* Utility functions to send a string of hex string to a ctrl */
1071 int EVP_PKEY_CTX_str2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *str)
1078 return ctx->pmeth->ctrl(ctx, cmd, len, (void *)str);
1081 int EVP_PKEY_CTX_hex2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *hex)
1087 bin = OPENSSL_hexstr2buf(hex, &binlen);
1090 if (binlen <= INT_MAX)
1091 rv = ctx->pmeth->ctrl(ctx, cmd, binlen, bin);
1096 /* Pass a message digest to a ctrl */
1097 int EVP_PKEY_CTX_md(EVP_PKEY_CTX *ctx, int optype, int cmd, const char *md)
1101 if (md == NULL || (m = EVP_get_digestbyname(md)) == NULL) {
1102 EVPerr(EVP_F_EVP_PKEY_CTX_MD, EVP_R_INVALID_DIGEST);
1105 return EVP_PKEY_CTX_ctrl(ctx, -1, optype, cmd, 0, (void *)m);
1108 int EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX *ctx)
1110 return ctx->operation;
1113 void EVP_PKEY_CTX_set0_keygen_info(EVP_PKEY_CTX *ctx, int *dat, int datlen)
1115 ctx->keygen_info = dat;
1116 ctx->keygen_info_count = datlen;
1119 void EVP_PKEY_CTX_set_data(EVP_PKEY_CTX *ctx, void *data)
1124 void *EVP_PKEY_CTX_get_data(const EVP_PKEY_CTX *ctx)
1129 EVP_PKEY *EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX *ctx)
1134 EVP_PKEY *EVP_PKEY_CTX_get0_peerkey(EVP_PKEY_CTX *ctx)
1136 return ctx->peerkey;
1139 void EVP_PKEY_CTX_set_app_data(EVP_PKEY_CTX *ctx, void *data)
1141 ctx->app_data = data;
1144 void *EVP_PKEY_CTX_get_app_data(EVP_PKEY_CTX *ctx)
1146 return ctx->app_data;
1149 void EVP_PKEY_meth_set_init(EVP_PKEY_METHOD *pmeth,
1150 int (*init) (EVP_PKEY_CTX *ctx))
1155 void EVP_PKEY_meth_set_copy(EVP_PKEY_METHOD *pmeth,
1156 int (*copy) (EVP_PKEY_CTX *dst,
1157 const EVP_PKEY_CTX *src))
1162 void EVP_PKEY_meth_set_cleanup(EVP_PKEY_METHOD *pmeth,
1163 void (*cleanup) (EVP_PKEY_CTX *ctx))
1165 pmeth->cleanup = cleanup;
1168 void EVP_PKEY_meth_set_paramgen(EVP_PKEY_METHOD *pmeth,
1169 int (*paramgen_init) (EVP_PKEY_CTX *ctx),
1170 int (*paramgen) (EVP_PKEY_CTX *ctx,
1173 pmeth->paramgen_init = paramgen_init;
1174 pmeth->paramgen = paramgen;
1177 void EVP_PKEY_meth_set_keygen(EVP_PKEY_METHOD *pmeth,
1178 int (*keygen_init) (EVP_PKEY_CTX *ctx),
1179 int (*keygen) (EVP_PKEY_CTX *ctx,
1182 pmeth->keygen_init = keygen_init;
1183 pmeth->keygen = keygen;
1186 void EVP_PKEY_meth_set_sign(EVP_PKEY_METHOD *pmeth,
1187 int (*sign_init) (EVP_PKEY_CTX *ctx),
1188 int (*sign) (EVP_PKEY_CTX *ctx,
1189 unsigned char *sig, size_t *siglen,
1190 const unsigned char *tbs,
1193 pmeth->sign_init = sign_init;
1197 void EVP_PKEY_meth_set_verify(EVP_PKEY_METHOD *pmeth,
1198 int (*verify_init) (EVP_PKEY_CTX *ctx),
1199 int (*verify) (EVP_PKEY_CTX *ctx,
1200 const unsigned char *sig,
1202 const unsigned char *tbs,
1205 pmeth->verify_init = verify_init;
1206 pmeth->verify = verify;
1209 void EVP_PKEY_meth_set_verify_recover(EVP_PKEY_METHOD *pmeth,
1210 int (*verify_recover_init) (EVP_PKEY_CTX
1212 int (*verify_recover) (EVP_PKEY_CTX
1221 pmeth->verify_recover_init = verify_recover_init;
1222 pmeth->verify_recover = verify_recover;
1225 void EVP_PKEY_meth_set_signctx(EVP_PKEY_METHOD *pmeth,
1226 int (*signctx_init) (EVP_PKEY_CTX *ctx,
1228 int (*signctx) (EVP_PKEY_CTX *ctx,
1233 pmeth->signctx_init = signctx_init;
1234 pmeth->signctx = signctx;
1237 void EVP_PKEY_meth_set_verifyctx(EVP_PKEY_METHOD *pmeth,
1238 int (*verifyctx_init) (EVP_PKEY_CTX *ctx,
1240 int (*verifyctx) (EVP_PKEY_CTX *ctx,
1241 const unsigned char *sig,
1245 pmeth->verifyctx_init = verifyctx_init;
1246 pmeth->verifyctx = verifyctx;
1249 void EVP_PKEY_meth_set_encrypt(EVP_PKEY_METHOD *pmeth,
1250 int (*encrypt_init) (EVP_PKEY_CTX *ctx),
1251 int (*encryptfn) (EVP_PKEY_CTX *ctx,
1254 const unsigned char *in,
1257 pmeth->encrypt_init = encrypt_init;
1258 pmeth->encrypt = encryptfn;
1261 void EVP_PKEY_meth_set_decrypt(EVP_PKEY_METHOD *pmeth,
1262 int (*decrypt_init) (EVP_PKEY_CTX *ctx),
1263 int (*decrypt) (EVP_PKEY_CTX *ctx,
1266 const unsigned char *in,
1269 pmeth->decrypt_init = decrypt_init;
1270 pmeth->decrypt = decrypt;
1273 void EVP_PKEY_meth_set_derive(EVP_PKEY_METHOD *pmeth,
1274 int (*derive_init) (EVP_PKEY_CTX *ctx),
1275 int (*derive) (EVP_PKEY_CTX *ctx,
1279 pmeth->derive_init = derive_init;
1280 pmeth->derive = derive;
1283 void EVP_PKEY_meth_set_ctrl(EVP_PKEY_METHOD *pmeth,
1284 int (*ctrl) (EVP_PKEY_CTX *ctx, int type, int p1,
1286 int (*ctrl_str) (EVP_PKEY_CTX *ctx,
1291 pmeth->ctrl_str = ctrl_str;
1294 void EVP_PKEY_meth_set_digestsign(EVP_PKEY_METHOD *pmeth,
1295 int (*digestsign) (EVP_MD_CTX *ctx, unsigned char *sig, size_t *siglen,
1296 const unsigned char *tbs, size_t tbslen))
1298 pmeth->digestsign = digestsign;
1301 void EVP_PKEY_meth_set_digestverify(EVP_PKEY_METHOD *pmeth,
1302 int (*digestverify) (EVP_MD_CTX *ctx, const unsigned char *sig,
1303 size_t siglen, const unsigned char *tbs,
1306 pmeth->digestverify = digestverify;
1309 void EVP_PKEY_meth_set_check(EVP_PKEY_METHOD *pmeth,
1310 int (*check) (EVP_PKEY *pkey))
1312 pmeth->check = check;
1315 void EVP_PKEY_meth_set_public_check(EVP_PKEY_METHOD *pmeth,
1316 int (*check) (EVP_PKEY *pkey))
1318 pmeth->public_check = check;
1321 void EVP_PKEY_meth_set_param_check(EVP_PKEY_METHOD *pmeth,
1322 int (*check) (EVP_PKEY *pkey))
1324 pmeth->param_check = check;
1327 void EVP_PKEY_meth_set_digest_custom(EVP_PKEY_METHOD *pmeth,
1328 int (*digest_custom) (EVP_PKEY_CTX *ctx,
1331 pmeth->digest_custom = digest_custom;
1334 void EVP_PKEY_meth_get_init(const EVP_PKEY_METHOD *pmeth,
1335 int (**pinit) (EVP_PKEY_CTX *ctx))
1337 *pinit = pmeth->init;
1340 void EVP_PKEY_meth_get_copy(const EVP_PKEY_METHOD *pmeth,
1341 int (**pcopy) (EVP_PKEY_CTX *dst,
1342 const EVP_PKEY_CTX *src))
1344 *pcopy = pmeth->copy;
1347 void EVP_PKEY_meth_get_cleanup(const EVP_PKEY_METHOD *pmeth,
1348 void (**pcleanup) (EVP_PKEY_CTX *ctx))
1350 *pcleanup = pmeth->cleanup;
1353 void EVP_PKEY_meth_get_paramgen(const EVP_PKEY_METHOD *pmeth,
1354 int (**pparamgen_init) (EVP_PKEY_CTX *ctx),
1355 int (**pparamgen) (EVP_PKEY_CTX *ctx,
1359 *pparamgen_init = pmeth->paramgen_init;
1361 *pparamgen = pmeth->paramgen;
1364 void EVP_PKEY_meth_get_keygen(const EVP_PKEY_METHOD *pmeth,
1365 int (**pkeygen_init) (EVP_PKEY_CTX *ctx),
1366 int (**pkeygen) (EVP_PKEY_CTX *ctx,
1370 *pkeygen_init = pmeth->keygen_init;
1372 *pkeygen = pmeth->keygen;
1375 void EVP_PKEY_meth_get_sign(const EVP_PKEY_METHOD *pmeth,
1376 int (**psign_init) (EVP_PKEY_CTX *ctx),
1377 int (**psign) (EVP_PKEY_CTX *ctx,
1378 unsigned char *sig, size_t *siglen,
1379 const unsigned char *tbs,
1383 *psign_init = pmeth->sign_init;
1385 *psign = pmeth->sign;
1388 void EVP_PKEY_meth_get_verify(const EVP_PKEY_METHOD *pmeth,
1389 int (**pverify_init) (EVP_PKEY_CTX *ctx),
1390 int (**pverify) (EVP_PKEY_CTX *ctx,
1391 const unsigned char *sig,
1393 const unsigned char *tbs,
1397 *pverify_init = pmeth->verify_init;
1399 *pverify = pmeth->verify;
1402 void EVP_PKEY_meth_get_verify_recover(const EVP_PKEY_METHOD *pmeth,
1403 int (**pverify_recover_init) (EVP_PKEY_CTX
1405 int (**pverify_recover) (EVP_PKEY_CTX
1414 if (pverify_recover_init)
1415 *pverify_recover_init = pmeth->verify_recover_init;
1416 if (pverify_recover)
1417 *pverify_recover = pmeth->verify_recover;
1420 void EVP_PKEY_meth_get_signctx(const EVP_PKEY_METHOD *pmeth,
1421 int (**psignctx_init) (EVP_PKEY_CTX *ctx,
1423 int (**psignctx) (EVP_PKEY_CTX *ctx,
1429 *psignctx_init = pmeth->signctx_init;
1431 *psignctx = pmeth->signctx;
1434 void EVP_PKEY_meth_get_verifyctx(const EVP_PKEY_METHOD *pmeth,
1435 int (**pverifyctx_init) (EVP_PKEY_CTX *ctx,
1437 int (**pverifyctx) (EVP_PKEY_CTX *ctx,
1438 const unsigned char *sig,
1442 if (pverifyctx_init)
1443 *pverifyctx_init = pmeth->verifyctx_init;
1445 *pverifyctx = pmeth->verifyctx;
1448 void EVP_PKEY_meth_get_encrypt(const EVP_PKEY_METHOD *pmeth,
1449 int (**pencrypt_init) (EVP_PKEY_CTX *ctx),
1450 int (**pencryptfn) (EVP_PKEY_CTX *ctx,
1453 const unsigned char *in,
1457 *pencrypt_init = pmeth->encrypt_init;
1459 *pencryptfn = pmeth->encrypt;
1462 void EVP_PKEY_meth_get_decrypt(const EVP_PKEY_METHOD *pmeth,
1463 int (**pdecrypt_init) (EVP_PKEY_CTX *ctx),
1464 int (**pdecrypt) (EVP_PKEY_CTX *ctx,
1467 const unsigned char *in,
1471 *pdecrypt_init = pmeth->decrypt_init;
1473 *pdecrypt = pmeth->decrypt;
1476 void EVP_PKEY_meth_get_derive(const EVP_PKEY_METHOD *pmeth,
1477 int (**pderive_init) (EVP_PKEY_CTX *ctx),
1478 int (**pderive) (EVP_PKEY_CTX *ctx,
1483 *pderive_init = pmeth->derive_init;
1485 *pderive = pmeth->derive;
1488 void EVP_PKEY_meth_get_ctrl(const EVP_PKEY_METHOD *pmeth,
1489 int (**pctrl) (EVP_PKEY_CTX *ctx, int type, int p1,
1491 int (**pctrl_str) (EVP_PKEY_CTX *ctx,
1496 *pctrl = pmeth->ctrl;
1498 *pctrl_str = pmeth->ctrl_str;
1501 void EVP_PKEY_meth_get_digestsign(EVP_PKEY_METHOD *pmeth,
1502 int (**digestsign) (EVP_MD_CTX *ctx, unsigned char *sig, size_t *siglen,
1503 const unsigned char *tbs, size_t tbslen))
1506 *digestsign = pmeth->digestsign;
1509 void EVP_PKEY_meth_get_digestverify(EVP_PKEY_METHOD *pmeth,
1510 int (**digestverify) (EVP_MD_CTX *ctx, const unsigned char *sig,
1511 size_t siglen, const unsigned char *tbs,
1515 *digestverify = pmeth->digestverify;
1518 void EVP_PKEY_meth_get_check(const EVP_PKEY_METHOD *pmeth,
1519 int (**pcheck) (EVP_PKEY *pkey))
1522 *pcheck = pmeth->check;
1525 void EVP_PKEY_meth_get_public_check(const EVP_PKEY_METHOD *pmeth,
1526 int (**pcheck) (EVP_PKEY *pkey))
1529 *pcheck = pmeth->public_check;
1532 void EVP_PKEY_meth_get_param_check(const EVP_PKEY_METHOD *pmeth,
1533 int (**pcheck) (EVP_PKEY *pkey))
1536 *pcheck = pmeth->param_check;
1539 void EVP_PKEY_meth_get_digest_custom(EVP_PKEY_METHOD *pmeth,
1540 int (**pdigest_custom) (EVP_PKEY_CTX *ctx,
1543 if (pdigest_custom != NULL)
1544 *pdigest_custom = pmeth->digest_custom;
1547 #endif /* FIPS_MODE */