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
12 * DH low level APIs are deprecated for public use, but still ok for
15 #include "internal/deprecated.h"
19 #include <openssl/engine.h>
20 #include <openssl/evp.h>
21 #include <openssl/x509v3.h>
22 #include <openssl/core_names.h>
23 #include <openssl/dh.h>
24 #include <openssl/rsa.h>
25 #include "internal/cryptlib.h"
26 #include "crypto/asn1.h"
27 #include "crypto/evp.h"
28 #include "internal/numbers.h"
29 #include "internal/provider.h"
30 #include "evp_local.h"
34 typedef const EVP_PKEY_METHOD *(*pmeth_fn)(void);
35 typedef int sk_cmp_fn_type(const char *const *a, const char *const *b);
37 static STACK_OF(EVP_PKEY_METHOD) *app_pkey_methods = NULL;
39 /* This array needs to be in order of NIDs */
40 static pmeth_fn standard_methods[] = {
41 # ifndef OPENSSL_NO_RSA
44 # ifndef OPENSSL_NO_DH
47 # ifndef OPENSSL_NO_DSA
50 # ifndef OPENSSL_NO_EC
54 # ifndef OPENSSL_NO_CMAC
57 # ifndef OPENSSL_NO_RSA
60 # ifndef OPENSSL_NO_DH
63 # ifndef OPENSSL_NO_SCRYPT
67 # ifndef OPENSSL_NO_EC
72 # ifndef OPENSSL_NO_POLY1305
75 # ifndef OPENSSL_NO_SIPHASH
78 # ifndef OPENSSL_NO_EC
82 # ifndef OPENSSL_NO_SM2
87 DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, pmeth_fn, pmeth_func);
89 static int pmeth_func_cmp(const EVP_PKEY_METHOD *const *a, pmeth_fn const *b)
91 return ((*a)->pkey_id - ((**b)())->pkey_id);
94 IMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, pmeth_fn, pmeth_func);
96 static int pmeth_cmp(const EVP_PKEY_METHOD *const *a,
97 const EVP_PKEY_METHOD *const *b)
99 return ((*a)->pkey_id - (*b)->pkey_id);
102 const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type)
106 const EVP_PKEY_METHOD *t = &tmp;
109 if (app_pkey_methods) {
111 idx = sk_EVP_PKEY_METHOD_find(app_pkey_methods, &tmp);
113 return sk_EVP_PKEY_METHOD_value(app_pkey_methods, idx);
115 ret = OBJ_bsearch_pmeth_func(&t, standard_methods,
116 sizeof(standard_methods) /
118 if (ret == NULL || *ret == NULL)
123 EVP_PKEY_METHOD *EVP_PKEY_meth_new(int id, int flags)
125 EVP_PKEY_METHOD *pmeth;
127 pmeth = OPENSSL_zalloc(sizeof(*pmeth));
129 EVPerr(EVP_F_EVP_PKEY_METH_NEW, ERR_R_MALLOC_FAILURE);
134 pmeth->flags = flags | EVP_PKEY_FLAG_DYNAMIC;
137 #endif /* FIPS_MODE */
139 static EVP_PKEY_CTX *int_ctx_new(OPENSSL_CTX *libctx,
140 EVP_PKEY *pkey, ENGINE *e,
141 const char *name, const char *propquery,
146 const EVP_PKEY_METHOD *pmeth = 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->ameth == NULL) {
160 /* If we have an engine, something went wrong somewhere... */
161 if (!ossl_assert(e == NULL))
163 name = evp_first_name(pkey->pkeys[0].keymgmt->prov,
164 pkey->pkeys[0].keymgmt->name_id);
166 * TODO: I wonder if the EVP_PKEY should have the name and propquery
167 * that were used when building it.... /RL
172 /* TODO(3.0) Legacy code should be removed when all is provider based */
181 * Here, we extract what information we can for the purpose of
182 * supporting usage with implementations from providers, to make
183 * for a smooth transition from legacy stuff to provider based stuff.
185 * If an engine is given, this is entirely legacy, and we should not
186 * pretend anything else, so we only set the name when no engine is
187 * given. If both are already given, someone made a mistake, and
188 * since that can only happen internally, it's safe to make an
191 if (!ossl_assert(e == NULL || name == NULL))
194 name = OBJ_nid2sn(id);
196 # ifndef OPENSSL_NO_ENGINE
197 if (e == NULL && pkey != NULL)
198 e = pkey->pmeth_engine != NULL ? pkey->pmeth_engine : pkey->engine;
199 /* Try to find an ENGINE which implements this method */
201 if (!ENGINE_init(e)) {
202 EVPerr(EVP_F_INT_CTX_NEW, ERR_R_ENGINE_LIB);
206 e = ENGINE_get_pkey_meth_engine(id);
210 * If an ENGINE handled this method look it up. Otherwise use internal
214 pmeth = ENGINE_get_pkey_meth(e, id);
217 pmeth = EVP_PKEY_meth_find(id);
220 # ifndef OPENSSL_NO_ENGINE
223 EVPerr(EVP_F_INT_CTX_NEW, EVP_R_UNSUPPORTED_ALGORITHM);
227 #endif /* FIPS_MODE */
229 ret = OPENSSL_zalloc(sizeof(*ret));
231 #if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE)
234 EVPerr(EVP_F_INT_CTX_NEW, ERR_R_MALLOC_FAILURE);
237 ret->libctx = libctx;
239 ret->propquery = propquery;
242 ret->operation = EVP_PKEY_OP_UNDEFINED;
245 EVP_PKEY_up_ref(pkey);
247 if (pmeth != NULL && pmeth->init != NULL) {
248 if (pmeth->init(ret) <= 0) {
250 EVP_PKEY_CTX_free(ret);
258 /*- All methods below can also be used in FIPS_MODE */
260 EVP_PKEY_CTX *EVP_PKEY_CTX_new_from_name(OPENSSL_CTX *libctx,
262 const char *propquery)
264 return int_ctx_new(libctx, NULL, NULL, name, propquery, -1);
267 EVP_PKEY_CTX *EVP_PKEY_CTX_new_from_pkey(OPENSSL_CTX *libctx, EVP_PKEY *pkey,
268 const char *propquery)
270 return int_ctx_new(libctx, pkey, NULL, NULL, propquery, -1);
273 void evp_pkey_ctx_free_old_ops(EVP_PKEY_CTX *ctx)
275 if (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)) {
276 if (ctx->op.sig.sigprovctx != NULL && ctx->op.sig.signature != NULL)
277 ctx->op.sig.signature->freectx(ctx->op.sig.sigprovctx);
278 EVP_SIGNATURE_free(ctx->op.sig.signature);
279 ctx->op.sig.sigprovctx = NULL;
280 ctx->op.sig.signature = NULL;
281 } else if (EVP_PKEY_CTX_IS_DERIVE_OP(ctx)) {
282 if (ctx->op.kex.exchprovctx != NULL && ctx->op.kex.exchange != NULL)
283 ctx->op.kex.exchange->freectx(ctx->op.kex.exchprovctx);
284 EVP_KEYEXCH_free(ctx->op.kex.exchange);
285 ctx->op.kex.exchprovctx = NULL;
286 ctx->op.kex.exchange = NULL;
288 /* TODO(3.0): add dependancies and uncomment this when available for fips mode */
290 else if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)) {
291 if (ctx->op.ciph.ciphprovctx != NULL && ctx->op.ciph.cipher != NULL)
292 ctx->op.ciph.cipher->freectx(ctx->op.ciph.ciphprovctx);
293 EVP_ASYM_CIPHER_free(ctx->op.ciph.cipher);
294 ctx->op.ciph.ciphprovctx = NULL;
295 ctx->op.ciph.cipher = NULL;
300 void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx)
304 if (ctx->pmeth && ctx->pmeth->cleanup)
305 ctx->pmeth->cleanup(ctx);
307 evp_pkey_ctx_free_old_ops(ctx);
308 EVP_KEYMGMT_free(ctx->keymgmt);
310 EVP_PKEY_free(ctx->pkey);
311 EVP_PKEY_free(ctx->peerkey);
312 #if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE)
313 ENGINE_finish(ctx->engine);
320 void EVP_PKEY_meth_get0_info(int *ppkey_id, int *pflags,
321 const EVP_PKEY_METHOD *meth)
324 *ppkey_id = meth->pkey_id;
326 *pflags = meth->flags;
329 void EVP_PKEY_meth_copy(EVP_PKEY_METHOD *dst, const EVP_PKEY_METHOD *src)
332 dst->init = src->init;
333 dst->copy = src->copy;
334 dst->cleanup = src->cleanup;
336 dst->paramgen_init = src->paramgen_init;
337 dst->paramgen = src->paramgen;
339 dst->keygen_init = src->keygen_init;
340 dst->keygen = src->keygen;
342 dst->sign_init = src->sign_init;
343 dst->sign = src->sign;
345 dst->verify_init = src->verify_init;
346 dst->verify = src->verify;
348 dst->verify_recover_init = src->verify_recover_init;
349 dst->verify_recover = src->verify_recover;
351 dst->signctx_init = src->signctx_init;
352 dst->signctx = src->signctx;
354 dst->verifyctx_init = src->verifyctx_init;
355 dst->verifyctx = src->verifyctx;
357 dst->encrypt_init = src->encrypt_init;
358 dst->encrypt = src->encrypt;
360 dst->decrypt_init = src->decrypt_init;
361 dst->decrypt = src->decrypt;
363 dst->derive_init = src->derive_init;
364 dst->derive = src->derive;
366 dst->ctrl = src->ctrl;
367 dst->ctrl_str = src->ctrl_str;
369 dst->check = src->check;
372 void EVP_PKEY_meth_free(EVP_PKEY_METHOD *pmeth)
374 if (pmeth && (pmeth->flags & EVP_PKEY_FLAG_DYNAMIC))
378 EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e)
380 return int_ctx_new(NULL, pkey, e, NULL, NULL, -1);
383 EVP_PKEY_CTX *EVP_PKEY_CTX_new_id(int id, ENGINE *e)
385 return int_ctx_new(NULL, NULL, e, NULL, NULL, id);
388 EVP_PKEY_CTX *EVP_PKEY_CTX_dup(const EVP_PKEY_CTX *pctx)
392 if (((pctx->pmeth == NULL) || (pctx->pmeth->copy == NULL))
393 && ((EVP_PKEY_CTX_IS_DERIVE_OP(pctx)
394 && pctx->op.kex.exchprovctx == NULL)
395 || (EVP_PKEY_CTX_IS_SIGNATURE_OP(pctx)
396 && pctx->op.sig.sigprovctx == NULL)))
398 # ifndef OPENSSL_NO_ENGINE
399 /* Make sure it's safe to copy a pkey context using an ENGINE */
400 if (pctx->engine && !ENGINE_init(pctx->engine)) {
401 EVPerr(EVP_F_EVP_PKEY_CTX_DUP, ERR_R_ENGINE_LIB);
405 rctx = OPENSSL_zalloc(sizeof(*rctx));
407 EVPerr(EVP_F_EVP_PKEY_CTX_DUP, ERR_R_MALLOC_FAILURE);
411 if (pctx->pkey != NULL)
412 EVP_PKEY_up_ref(pctx->pkey);
413 rctx->pkey = pctx->pkey;
414 rctx->operation = pctx->operation;
415 rctx->libctx = pctx->libctx;
416 rctx->keytype = pctx->keytype;
417 rctx->propquery = pctx->propquery;
419 if (EVP_PKEY_CTX_IS_DERIVE_OP(pctx)) {
420 if (pctx->op.kex.exchange != NULL) {
421 rctx->op.kex.exchange = pctx->op.kex.exchange;
422 if (!EVP_KEYEXCH_up_ref(rctx->op.kex.exchange)) {
427 if (pctx->op.kex.exchprovctx != NULL) {
428 if (!ossl_assert(pctx->op.kex.exchange != NULL))
430 rctx->op.kex.exchprovctx
431 = pctx->op.kex.exchange->dupctx(pctx->op.kex.exchprovctx);
432 if (rctx->op.kex.exchprovctx == NULL) {
433 EVP_KEYEXCH_free(rctx->op.kex.exchange);
439 } else if (EVP_PKEY_CTX_IS_SIGNATURE_OP(pctx)) {
440 if (pctx->op.sig.signature != NULL) {
441 rctx->op.sig.signature = pctx->op.sig.signature;
442 if (!EVP_SIGNATURE_up_ref(rctx->op.sig.signature)) {
447 if (pctx->op.sig.sigprovctx != NULL) {
448 if (!ossl_assert(pctx->op.sig.signature != NULL))
450 rctx->op.sig.sigprovctx
451 = pctx->op.sig.signature->dupctx(pctx->op.sig.sigprovctx);
452 if (rctx->op.sig.sigprovctx == NULL) {
453 EVP_SIGNATURE_free(rctx->op.sig.signature);
459 } else if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(pctx)) {
460 if (pctx->op.ciph.cipher != NULL) {
461 rctx->op.ciph.cipher = pctx->op.ciph.cipher;
462 if (!EVP_ASYM_CIPHER_up_ref(rctx->op.ciph.cipher)) {
467 if (pctx->op.ciph.ciphprovctx != NULL) {
468 if (!ossl_assert(pctx->op.ciph.cipher != NULL))
470 rctx->op.ciph.ciphprovctx
471 = pctx->op.ciph.cipher->dupctx(pctx->op.ciph.ciphprovctx);
472 if (rctx->op.ciph.ciphprovctx == NULL) {
473 EVP_ASYM_CIPHER_free(rctx->op.ciph.cipher);
481 rctx->pmeth = pctx->pmeth;
482 # ifndef OPENSSL_NO_ENGINE
483 rctx->engine = pctx->engine;
487 EVP_PKEY_up_ref(pctx->peerkey);
488 rctx->peerkey = pctx->peerkey;
490 if (pctx->pmeth->copy(rctx, pctx) > 0)
494 EVP_PKEY_CTX_free(rctx);
499 int EVP_PKEY_meth_add0(const EVP_PKEY_METHOD *pmeth)
501 if (app_pkey_methods == NULL) {
502 app_pkey_methods = sk_EVP_PKEY_METHOD_new(pmeth_cmp);
503 if (app_pkey_methods == NULL){
504 EVPerr(EVP_F_EVP_PKEY_METH_ADD0, ERR_R_MALLOC_FAILURE);
508 if (!sk_EVP_PKEY_METHOD_push(app_pkey_methods, pmeth)) {
509 EVPerr(EVP_F_EVP_PKEY_METH_ADD0, ERR_R_MALLOC_FAILURE);
512 sk_EVP_PKEY_METHOD_sort(app_pkey_methods);
516 void evp_app_cleanup_int(void)
518 if (app_pkey_methods != NULL)
519 sk_EVP_PKEY_METHOD_pop_free(app_pkey_methods, EVP_PKEY_meth_free);
522 int EVP_PKEY_meth_remove(const EVP_PKEY_METHOD *pmeth)
524 const EVP_PKEY_METHOD *ret;
526 ret = sk_EVP_PKEY_METHOD_delete_ptr(app_pkey_methods, pmeth);
528 return ret == NULL ? 0 : 1;
531 size_t EVP_PKEY_meth_get_count(void)
533 size_t rv = OSSL_NELEM(standard_methods);
535 if (app_pkey_methods)
536 rv += sk_EVP_PKEY_METHOD_num(app_pkey_methods);
540 const EVP_PKEY_METHOD *EVP_PKEY_meth_get0(size_t idx)
542 if (idx < OSSL_NELEM(standard_methods))
543 return (standard_methods[idx])();
544 if (app_pkey_methods == NULL)
546 idx -= OSSL_NELEM(standard_methods);
547 if (idx >= (size_t)sk_EVP_PKEY_METHOD_num(app_pkey_methods))
549 return sk_EVP_PKEY_METHOD_value(app_pkey_methods, idx);
553 int EVP_PKEY_CTX_set_params(EVP_PKEY_CTX *ctx, OSSL_PARAM *params)
555 if (EVP_PKEY_CTX_IS_DERIVE_OP(ctx)
556 && ctx->op.kex.exchprovctx != NULL
557 && ctx->op.kex.exchange != NULL
558 && ctx->op.kex.exchange->set_ctx_params != NULL)
559 return ctx->op.kex.exchange->set_ctx_params(ctx->op.kex.exchprovctx,
561 if (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)
562 && ctx->op.sig.sigprovctx != NULL
563 && ctx->op.sig.signature != NULL
564 && ctx->op.sig.signature->set_ctx_params != NULL)
565 return ctx->op.sig.signature->set_ctx_params(ctx->op.sig.sigprovctx,
567 if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)
568 && ctx->op.ciph.ciphprovctx != NULL
569 && ctx->op.ciph.cipher != NULL
570 && ctx->op.ciph.cipher->set_ctx_params != NULL)
571 return ctx->op.ciph.cipher->set_ctx_params(ctx->op.ciph.ciphprovctx,
577 int EVP_PKEY_CTX_get_params(EVP_PKEY_CTX *ctx, OSSL_PARAM *params)
579 if (EVP_PKEY_CTX_IS_DERIVE_OP(ctx)
580 && ctx->op.kex.exchprovctx != NULL
581 && ctx->op.kex.exchange != NULL
582 && ctx->op.kex.exchange->get_ctx_params != NULL)
583 return ctx->op.kex.exchange->get_ctx_params(ctx->op.kex.exchprovctx,
585 if (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)
586 && ctx->op.sig.sigprovctx != NULL
587 && ctx->op.sig.signature != NULL
588 && ctx->op.sig.signature->get_ctx_params != NULL)
589 return ctx->op.sig.signature->get_ctx_params(ctx->op.sig.sigprovctx,
591 if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)
592 && ctx->op.ciph.ciphprovctx != NULL
593 && ctx->op.ciph.cipher != NULL
594 && ctx->op.ciph.cipher->get_ctx_params != NULL)
595 return ctx->op.ciph.cipher->get_ctx_params(ctx->op.ciph.ciphprovctx,
600 const OSSL_PARAM *EVP_PKEY_CTX_gettable_params(EVP_PKEY_CTX *ctx)
602 if (EVP_PKEY_CTX_IS_DERIVE_OP(ctx)
603 && ctx->op.kex.exchange != NULL
604 && ctx->op.kex.exchange->gettable_ctx_params != NULL)
605 return ctx->op.kex.exchange->gettable_ctx_params();
606 if (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)
607 && ctx->op.sig.signature != NULL
608 && ctx->op.sig.signature->gettable_ctx_params != NULL)
609 return ctx->op.sig.signature->gettable_ctx_params();
611 if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)
612 && ctx->op.ciph.cipher != NULL
613 && ctx->op.ciph.cipher->gettable_ctx_params != NULL)
614 return ctx->op.ciph.cipher->gettable_ctx_params();
619 const OSSL_PARAM *EVP_PKEY_CTX_settable_params(EVP_PKEY_CTX *ctx)
621 if (EVP_PKEY_CTX_IS_DERIVE_OP(ctx)
622 && ctx->op.kex.exchange != NULL
623 && ctx->op.kex.exchange->settable_ctx_params != NULL)
624 return ctx->op.kex.exchange->settable_ctx_params();
625 if (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)
626 && ctx->op.sig.signature != NULL
627 && ctx->op.sig.signature->settable_ctx_params != NULL)
628 return ctx->op.sig.signature->settable_ctx_params();
629 if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)
630 && ctx->op.ciph.cipher != NULL
631 && ctx->op.ciph.cipher->settable_ctx_params != NULL)
632 return ctx->op.ciph.cipher->settable_ctx_params();
638 * Internal helpers for stricter EVP_PKEY_CTX_{set,get}_params().
640 * Return 1 on success, 0 or negative for errors.
642 * In particular they return -2 if any of the params is not supported.
644 * They are not available in FIPS_MODE as they depend on
645 * - EVP_PKEY_CTX_{get,set}_params()
646 * - EVP_PKEY_CTX_{gettable,settable}_params()
649 int evp_pkey_ctx_set_params_strict(EVP_PKEY_CTX *ctx, OSSL_PARAM *params)
653 if (ctx == NULL || params == NULL)
656 for (p = params; p->key != NULL; p++) {
657 /* Check the ctx actually understands this parameter */
658 if (OSSL_PARAM_locate_const(EVP_PKEY_CTX_settable_params(ctx),
663 return EVP_PKEY_CTX_set_params(ctx, params);
666 int evp_pkey_ctx_get_params_strict(EVP_PKEY_CTX *ctx, OSSL_PARAM *params)
670 if (ctx == NULL || params == NULL)
673 for (p = params; p->key != NULL; p++ ) {
674 /* Check the ctx actually understands this parameter */
675 if (OSSL_PARAM_locate_const(EVP_PKEY_CTX_gettable_params(ctx),
680 return EVP_PKEY_CTX_get_params(ctx, params);
683 # ifndef OPENSSL_NO_DH
684 int EVP_PKEY_CTX_set_dh_pad(EVP_PKEY_CTX *ctx, int pad)
686 OSSL_PARAM dh_pad_params[2];
687 unsigned int upad = pad;
689 /* We use EVP_PKEY_CTX_ctrl return values */
690 if (ctx == NULL || !EVP_PKEY_CTX_IS_DERIVE_OP(ctx)) {
691 ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED);
695 /* TODO(3.0): Remove this eventually when no more legacy */
696 if (ctx->op.kex.exchprovctx == NULL)
697 return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DH, EVP_PKEY_OP_DERIVE,
698 EVP_PKEY_CTRL_DH_PAD, pad, NULL);
700 dh_pad_params[0] = OSSL_PARAM_construct_uint(OSSL_EXCHANGE_PARAM_PAD, &upad);
701 dh_pad_params[1] = OSSL_PARAM_construct_end();
703 return EVP_PKEY_CTX_set_params(ctx, dh_pad_params);
707 int EVP_PKEY_CTX_get_signature_md(EVP_PKEY_CTX *ctx, const EVP_MD **md)
709 OSSL_PARAM sig_md_params[3], *p = sig_md_params;
710 /* 80 should be big enough */
714 if (ctx == NULL || !EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)) {
715 ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED);
716 /* Uses the same return values as EVP_PKEY_CTX_ctrl */
720 /* TODO(3.0): Remove this eventually when no more legacy */
721 if (ctx->op.sig.sigprovctx == NULL)
722 return EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_TYPE_SIG,
723 EVP_PKEY_CTRL_GET_MD, 0, (void *)(md));
725 *p++ = OSSL_PARAM_construct_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST,
728 *p++ = OSSL_PARAM_construct_end();
730 if (!EVP_PKEY_CTX_get_params(ctx, sig_md_params))
733 tmp = evp_get_digestbyname_ex(ctx->libctx, name);
742 int EVP_PKEY_CTX_set_signature_md(EVP_PKEY_CTX *ctx, const EVP_MD *md)
744 OSSL_PARAM sig_md_params[2], *p = sig_md_params;
747 if (ctx == NULL || !EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)) {
748 ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED);
749 /* Uses the same return values as EVP_PKEY_CTX_ctrl */
753 /* TODO(3.0): Remove this eventually when no more legacy */
754 if (ctx->op.sig.sigprovctx == NULL)
755 return EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_TYPE_SIG,
756 EVP_PKEY_CTRL_MD, 0, (void *)(md));
761 name = EVP_MD_name(md);
764 *p++ = OSSL_PARAM_construct_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST,
766 * Cast away the const. This is read
767 * only so should be safe
770 *p++ = OSSL_PARAM_construct_end();
772 return EVP_PKEY_CTX_set_params(ctx, sig_md_params);
775 static int legacy_ctrl_to_param(EVP_PKEY_CTX *ctx, int keytype, int optype,
776 int cmd, int p1, void *p2)
778 # ifndef OPENSSL_NO_DH
779 if (keytype == EVP_PKEY_DH) {
781 case EVP_PKEY_CTRL_DH_PAD:
782 return EVP_PKEY_CTX_set_dh_pad(ctx, p1);
786 # ifndef OPENSSL_NO_EC
787 if (keytype == EVP_PKEY_EC) {
789 case EVP_PKEY_CTRL_EC_ECDH_COFACTOR:
791 return EVP_PKEY_CTX_get_ecdh_cofactor_mode(ctx);
792 } else if (p1 < -1 || p1 > 1) {
793 /* Uses the same return values as EVP_PKEY_CTX_ctrl */
796 return EVP_PKEY_CTX_set_ecdh_cofactor_mode(ctx, p1);
798 case EVP_PKEY_CTRL_EC_KDF_TYPE:
800 return EVP_PKEY_CTX_get_ecdh_kdf_type(ctx);
802 return EVP_PKEY_CTX_set_ecdh_kdf_type(ctx, p1);
804 case EVP_PKEY_CTRL_GET_EC_KDF_MD:
805 return EVP_PKEY_CTX_get_ecdh_kdf_md(ctx, p2);
806 case EVP_PKEY_CTRL_EC_KDF_MD:
807 return EVP_PKEY_CTX_set_ecdh_kdf_md(ctx, p2);
808 case EVP_PKEY_CTRL_GET_EC_KDF_OUTLEN:
809 return EVP_PKEY_CTX_get_ecdh_kdf_outlen(ctx, p2);
810 case EVP_PKEY_CTRL_EC_KDF_OUTLEN:
811 return EVP_PKEY_CTX_set_ecdh_kdf_outlen(ctx, p1);
812 case EVP_PKEY_CTRL_GET_EC_KDF_UKM:
813 return EVP_PKEY_CTX_get0_ecdh_kdf_ukm(ctx, p2);
814 case EVP_PKEY_CTRL_EC_KDF_UKM:
815 return EVP_PKEY_CTX_set0_ecdh_kdf_ukm(ctx, p2, p1);
821 case EVP_PKEY_CTRL_MD:
822 return EVP_PKEY_CTX_set_signature_md(ctx, p2);
823 case EVP_PKEY_CTRL_GET_MD:
824 return EVP_PKEY_CTX_get_signature_md(ctx, p2);
825 case EVP_PKEY_CTRL_RSA_PADDING:
826 return EVP_PKEY_CTX_set_rsa_padding(ctx, p1);
827 case EVP_PKEY_CTRL_GET_RSA_PADDING:
828 return EVP_PKEY_CTX_get_rsa_padding(ctx, p2);
829 case EVP_PKEY_CTRL_RSA_OAEP_MD:
830 return EVP_PKEY_CTX_set_rsa_oaep_md(ctx, p2);
831 case EVP_PKEY_CTRL_GET_RSA_OAEP_MD:
832 return EVP_PKEY_CTX_get_rsa_oaep_md(ctx, p2);
833 case EVP_PKEY_CTRL_RSA_MGF1_MD:
834 return EVP_PKEY_CTX_set_rsa_oaep_md(ctx, p2);
835 case EVP_PKEY_CTRL_GET_RSA_MGF1_MD:
836 return EVP_PKEY_CTX_get_rsa_oaep_md(ctx, p2);
837 case EVP_PKEY_CTRL_RSA_OAEP_LABEL:
838 return EVP_PKEY_CTX_set0_rsa_oaep_label(ctx, p2, p1);
839 case EVP_PKEY_CTRL_GET_RSA_OAEP_LABEL:
840 return EVP_PKEY_CTX_get0_rsa_oaep_label(ctx, (unsigned char **)p2);
841 case EVP_PKEY_CTRL_RSA_PSS_SALTLEN:
842 return EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx, p1);
843 case EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN:
844 return EVP_PKEY_CTX_get_rsa_pss_saltlen(ctx, p2);
845 case EVP_PKEY_CTRL_PKCS7_ENCRYPT:
846 case EVP_PKEY_CTRL_PKCS7_DECRYPT:
847 # ifndef OPENSSL_NO_CMS
848 case EVP_PKEY_CTRL_CMS_DECRYPT:
849 case EVP_PKEY_CTRL_CMS_ENCRYPT:
851 if (ctx->pmeth->pkey_id != EVP_PKEY_RSA_PSS)
853 ERR_raise(ERR_LIB_EVP,
854 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
861 int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype,
862 int cmd, int p1, void *p2)
867 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_COMMAND_NOT_SUPPORTED);
871 if ((EVP_PKEY_CTX_IS_DERIVE_OP(ctx) && ctx->op.kex.exchprovctx != NULL)
872 || (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)
873 && ctx->op.sig.sigprovctx != NULL)
874 || (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)
875 && ctx->op.ciph.ciphprovctx != NULL))
876 return legacy_ctrl_to_param(ctx, keytype, optype, cmd, p1, p2);
878 if (ctx->pmeth == NULL || ctx->pmeth->ctrl == NULL) {
879 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_COMMAND_NOT_SUPPORTED);
882 if ((keytype != -1) && (ctx->pmeth->pkey_id != keytype))
885 /* Skip the operation checks since this is called in a very early stage */
886 if (ctx->pmeth->digest_custom != NULL)
889 if (ctx->operation == EVP_PKEY_OP_UNDEFINED) {
890 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_NO_OPERATION_SET);
894 if ((optype != -1) && !(ctx->operation & optype)) {
895 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_INVALID_OPERATION);
900 ret = ctx->pmeth->ctrl(ctx, cmd, p1, p2);
903 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_COMMAND_NOT_SUPPORTED);
908 int EVP_PKEY_CTX_ctrl_uint64(EVP_PKEY_CTX *ctx, int keytype, int optype,
909 int cmd, uint64_t value)
911 return EVP_PKEY_CTX_ctrl(ctx, keytype, optype, cmd, 0, &value);
914 static int legacy_ctrl_str_to_param(EVP_PKEY_CTX *ctx, const char *name,
917 if (strcmp(name, "rsa_padding_mode") == 0)
918 name = OSSL_ASYM_CIPHER_PARAM_PAD_MODE;
919 else if (strcmp(name, "rsa_mgf1_md") == 0)
920 name = OSSL_ASYM_CIPHER_PARAM_MGF1_DIGEST;
921 else if (strcmp(name, "rsa_oaep_md") == 0)
922 name = OSSL_ASYM_CIPHER_PARAM_OAEP_DIGEST;
923 else if (strcmp(name, "rsa_oaep_label") == 0)
924 name = OSSL_ASYM_CIPHER_PARAM_OAEP_LABEL;
925 else if (strcmp(name, "rsa_pss_saltlen") == 0)
926 name = OSSL_SIGNATURE_PARAM_PSS_SALTLEN;
927 # ifndef OPENSSL_NO_DH
928 else if (strcmp(name, "dh_pad") == 0)
929 name = OSSL_EXCHANGE_PARAM_PAD;
931 # ifndef OPENSSL_NO_EC
932 else if (strcmp(name, "ecdh_cofactor_mode") == 0)
933 name = OSSL_EXCHANGE_PARAM_EC_ECDH_COFACTOR_MODE;
934 else if (strcmp(name, "ecdh_kdf_md") == 0)
935 name = OSSL_EXCHANGE_PARAM_KDF_TYPE;
940 * TODO(3.0) reduce the code above to only translate known legacy
941 * string to the corresponding core name (see core_names.h), but
942 * otherwise leave it to this code block to do the actual work.
944 const OSSL_PARAM *settable = EVP_PKEY_CTX_settable_params(ctx);
945 OSSL_PARAM params[2] = { OSSL_PARAM_END, OSSL_PARAM_END };
949 if (!OSSL_PARAM_allocate_from_text(¶ms[0], settable, name, value,
950 strlen(value), &exists)) {
952 ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED);
957 if (EVP_PKEY_CTX_set_params(ctx, params))
959 OPENSSL_free(params[0].data);
964 int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx,
965 const char *name, const char *value)
968 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR, EVP_R_COMMAND_NOT_SUPPORTED);
972 if ((EVP_PKEY_CTX_IS_DERIVE_OP(ctx) && ctx->op.kex.exchprovctx != NULL)
973 || (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)
974 && ctx->op.sig.sigprovctx != NULL)
975 || (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)
976 && ctx->op.ciph.ciphprovctx != NULL))
977 return legacy_ctrl_str_to_param(ctx, name, value);
979 if (!ctx || !ctx->pmeth || !ctx->pmeth->ctrl_str) {
980 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR, EVP_R_COMMAND_NOT_SUPPORTED);
983 if (strcmp(name, "digest") == 0)
984 return EVP_PKEY_CTX_md(ctx, EVP_PKEY_OP_TYPE_SIG, EVP_PKEY_CTRL_MD,
986 return ctx->pmeth->ctrl_str(ctx, name, value);
989 /* Utility functions to send a string of hex string to a ctrl */
991 int EVP_PKEY_CTX_str2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *str)
998 return ctx->pmeth->ctrl(ctx, cmd, len, (void *)str);
1001 int EVP_PKEY_CTX_hex2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *hex)
1007 bin = OPENSSL_hexstr2buf(hex, &binlen);
1010 if (binlen <= INT_MAX)
1011 rv = ctx->pmeth->ctrl(ctx, cmd, binlen, bin);
1016 /* Pass a message digest to a ctrl */
1017 int EVP_PKEY_CTX_md(EVP_PKEY_CTX *ctx, int optype, int cmd, const char *md)
1021 if (md == NULL || (m = EVP_get_digestbyname(md)) == NULL) {
1022 EVPerr(EVP_F_EVP_PKEY_CTX_MD, EVP_R_INVALID_DIGEST);
1025 return EVP_PKEY_CTX_ctrl(ctx, -1, optype, cmd, 0, (void *)m);
1028 int EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX *ctx)
1030 return ctx->operation;
1033 void EVP_PKEY_CTX_set0_keygen_info(EVP_PKEY_CTX *ctx, int *dat, int datlen)
1035 ctx->keygen_info = dat;
1036 ctx->keygen_info_count = datlen;
1039 void EVP_PKEY_CTX_set_data(EVP_PKEY_CTX *ctx, void *data)
1044 void *EVP_PKEY_CTX_get_data(const EVP_PKEY_CTX *ctx)
1049 EVP_PKEY *EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX *ctx)
1054 EVP_PKEY *EVP_PKEY_CTX_get0_peerkey(EVP_PKEY_CTX *ctx)
1056 return ctx->peerkey;
1059 void EVP_PKEY_CTX_set_app_data(EVP_PKEY_CTX *ctx, void *data)
1061 ctx->app_data = data;
1064 void *EVP_PKEY_CTX_get_app_data(EVP_PKEY_CTX *ctx)
1066 return ctx->app_data;
1069 void EVP_PKEY_meth_set_init(EVP_PKEY_METHOD *pmeth,
1070 int (*init) (EVP_PKEY_CTX *ctx))
1075 void EVP_PKEY_meth_set_copy(EVP_PKEY_METHOD *pmeth,
1076 int (*copy) (EVP_PKEY_CTX *dst,
1077 const EVP_PKEY_CTX *src))
1082 void EVP_PKEY_meth_set_cleanup(EVP_PKEY_METHOD *pmeth,
1083 void (*cleanup) (EVP_PKEY_CTX *ctx))
1085 pmeth->cleanup = cleanup;
1088 void EVP_PKEY_meth_set_paramgen(EVP_PKEY_METHOD *pmeth,
1089 int (*paramgen_init) (EVP_PKEY_CTX *ctx),
1090 int (*paramgen) (EVP_PKEY_CTX *ctx,
1093 pmeth->paramgen_init = paramgen_init;
1094 pmeth->paramgen = paramgen;
1097 void EVP_PKEY_meth_set_keygen(EVP_PKEY_METHOD *pmeth,
1098 int (*keygen_init) (EVP_PKEY_CTX *ctx),
1099 int (*keygen) (EVP_PKEY_CTX *ctx,
1102 pmeth->keygen_init = keygen_init;
1103 pmeth->keygen = keygen;
1106 void EVP_PKEY_meth_set_sign(EVP_PKEY_METHOD *pmeth,
1107 int (*sign_init) (EVP_PKEY_CTX *ctx),
1108 int (*sign) (EVP_PKEY_CTX *ctx,
1109 unsigned char *sig, size_t *siglen,
1110 const unsigned char *tbs,
1113 pmeth->sign_init = sign_init;
1117 void EVP_PKEY_meth_set_verify(EVP_PKEY_METHOD *pmeth,
1118 int (*verify_init) (EVP_PKEY_CTX *ctx),
1119 int (*verify) (EVP_PKEY_CTX *ctx,
1120 const unsigned char *sig,
1122 const unsigned char *tbs,
1125 pmeth->verify_init = verify_init;
1126 pmeth->verify = verify;
1129 void EVP_PKEY_meth_set_verify_recover(EVP_PKEY_METHOD *pmeth,
1130 int (*verify_recover_init) (EVP_PKEY_CTX
1132 int (*verify_recover) (EVP_PKEY_CTX
1141 pmeth->verify_recover_init = verify_recover_init;
1142 pmeth->verify_recover = verify_recover;
1145 void EVP_PKEY_meth_set_signctx(EVP_PKEY_METHOD *pmeth,
1146 int (*signctx_init) (EVP_PKEY_CTX *ctx,
1148 int (*signctx) (EVP_PKEY_CTX *ctx,
1153 pmeth->signctx_init = signctx_init;
1154 pmeth->signctx = signctx;
1157 void EVP_PKEY_meth_set_verifyctx(EVP_PKEY_METHOD *pmeth,
1158 int (*verifyctx_init) (EVP_PKEY_CTX *ctx,
1160 int (*verifyctx) (EVP_PKEY_CTX *ctx,
1161 const unsigned char *sig,
1165 pmeth->verifyctx_init = verifyctx_init;
1166 pmeth->verifyctx = verifyctx;
1169 void EVP_PKEY_meth_set_encrypt(EVP_PKEY_METHOD *pmeth,
1170 int (*encrypt_init) (EVP_PKEY_CTX *ctx),
1171 int (*encryptfn) (EVP_PKEY_CTX *ctx,
1174 const unsigned char *in,
1177 pmeth->encrypt_init = encrypt_init;
1178 pmeth->encrypt = encryptfn;
1181 void EVP_PKEY_meth_set_decrypt(EVP_PKEY_METHOD *pmeth,
1182 int (*decrypt_init) (EVP_PKEY_CTX *ctx),
1183 int (*decrypt) (EVP_PKEY_CTX *ctx,
1186 const unsigned char *in,
1189 pmeth->decrypt_init = decrypt_init;
1190 pmeth->decrypt = decrypt;
1193 void EVP_PKEY_meth_set_derive(EVP_PKEY_METHOD *pmeth,
1194 int (*derive_init) (EVP_PKEY_CTX *ctx),
1195 int (*derive) (EVP_PKEY_CTX *ctx,
1199 pmeth->derive_init = derive_init;
1200 pmeth->derive = derive;
1203 void EVP_PKEY_meth_set_ctrl(EVP_PKEY_METHOD *pmeth,
1204 int (*ctrl) (EVP_PKEY_CTX *ctx, int type, int p1,
1206 int (*ctrl_str) (EVP_PKEY_CTX *ctx,
1211 pmeth->ctrl_str = ctrl_str;
1214 void EVP_PKEY_meth_set_digestsign(EVP_PKEY_METHOD *pmeth,
1215 int (*digestsign) (EVP_MD_CTX *ctx, unsigned char *sig, size_t *siglen,
1216 const unsigned char *tbs, size_t tbslen))
1218 pmeth->digestsign = digestsign;
1221 void EVP_PKEY_meth_set_digestverify(EVP_PKEY_METHOD *pmeth,
1222 int (*digestverify) (EVP_MD_CTX *ctx, const unsigned char *sig,
1223 size_t siglen, const unsigned char *tbs,
1226 pmeth->digestverify = digestverify;
1229 void EVP_PKEY_meth_set_check(EVP_PKEY_METHOD *pmeth,
1230 int (*check) (EVP_PKEY *pkey))
1232 pmeth->check = check;
1235 void EVP_PKEY_meth_set_public_check(EVP_PKEY_METHOD *pmeth,
1236 int (*check) (EVP_PKEY *pkey))
1238 pmeth->public_check = check;
1241 void EVP_PKEY_meth_set_param_check(EVP_PKEY_METHOD *pmeth,
1242 int (*check) (EVP_PKEY *pkey))
1244 pmeth->param_check = check;
1247 void EVP_PKEY_meth_set_digest_custom(EVP_PKEY_METHOD *pmeth,
1248 int (*digest_custom) (EVP_PKEY_CTX *ctx,
1251 pmeth->digest_custom = digest_custom;
1254 void EVP_PKEY_meth_get_init(const EVP_PKEY_METHOD *pmeth,
1255 int (**pinit) (EVP_PKEY_CTX *ctx))
1257 *pinit = pmeth->init;
1260 void EVP_PKEY_meth_get_copy(const EVP_PKEY_METHOD *pmeth,
1261 int (**pcopy) (EVP_PKEY_CTX *dst,
1262 const EVP_PKEY_CTX *src))
1264 *pcopy = pmeth->copy;
1267 void EVP_PKEY_meth_get_cleanup(const EVP_PKEY_METHOD *pmeth,
1268 void (**pcleanup) (EVP_PKEY_CTX *ctx))
1270 *pcleanup = pmeth->cleanup;
1273 void EVP_PKEY_meth_get_paramgen(const EVP_PKEY_METHOD *pmeth,
1274 int (**pparamgen_init) (EVP_PKEY_CTX *ctx),
1275 int (**pparamgen) (EVP_PKEY_CTX *ctx,
1279 *pparamgen_init = pmeth->paramgen_init;
1281 *pparamgen = pmeth->paramgen;
1284 void EVP_PKEY_meth_get_keygen(const EVP_PKEY_METHOD *pmeth,
1285 int (**pkeygen_init) (EVP_PKEY_CTX *ctx),
1286 int (**pkeygen) (EVP_PKEY_CTX *ctx,
1290 *pkeygen_init = pmeth->keygen_init;
1292 *pkeygen = pmeth->keygen;
1295 void EVP_PKEY_meth_get_sign(const EVP_PKEY_METHOD *pmeth,
1296 int (**psign_init) (EVP_PKEY_CTX *ctx),
1297 int (**psign) (EVP_PKEY_CTX *ctx,
1298 unsigned char *sig, size_t *siglen,
1299 const unsigned char *tbs,
1303 *psign_init = pmeth->sign_init;
1305 *psign = pmeth->sign;
1308 void EVP_PKEY_meth_get_verify(const EVP_PKEY_METHOD *pmeth,
1309 int (**pverify_init) (EVP_PKEY_CTX *ctx),
1310 int (**pverify) (EVP_PKEY_CTX *ctx,
1311 const unsigned char *sig,
1313 const unsigned char *tbs,
1317 *pverify_init = pmeth->verify_init;
1319 *pverify = pmeth->verify;
1322 void EVP_PKEY_meth_get_verify_recover(const EVP_PKEY_METHOD *pmeth,
1323 int (**pverify_recover_init) (EVP_PKEY_CTX
1325 int (**pverify_recover) (EVP_PKEY_CTX
1334 if (pverify_recover_init)
1335 *pverify_recover_init = pmeth->verify_recover_init;
1336 if (pverify_recover)
1337 *pverify_recover = pmeth->verify_recover;
1340 void EVP_PKEY_meth_get_signctx(const EVP_PKEY_METHOD *pmeth,
1341 int (**psignctx_init) (EVP_PKEY_CTX *ctx,
1343 int (**psignctx) (EVP_PKEY_CTX *ctx,
1349 *psignctx_init = pmeth->signctx_init;
1351 *psignctx = pmeth->signctx;
1354 void EVP_PKEY_meth_get_verifyctx(const EVP_PKEY_METHOD *pmeth,
1355 int (**pverifyctx_init) (EVP_PKEY_CTX *ctx,
1357 int (**pverifyctx) (EVP_PKEY_CTX *ctx,
1358 const unsigned char *sig,
1362 if (pverifyctx_init)
1363 *pverifyctx_init = pmeth->verifyctx_init;
1365 *pverifyctx = pmeth->verifyctx;
1368 void EVP_PKEY_meth_get_encrypt(const EVP_PKEY_METHOD *pmeth,
1369 int (**pencrypt_init) (EVP_PKEY_CTX *ctx),
1370 int (**pencryptfn) (EVP_PKEY_CTX *ctx,
1373 const unsigned char *in,
1377 *pencrypt_init = pmeth->encrypt_init;
1379 *pencryptfn = pmeth->encrypt;
1382 void EVP_PKEY_meth_get_decrypt(const EVP_PKEY_METHOD *pmeth,
1383 int (**pdecrypt_init) (EVP_PKEY_CTX *ctx),
1384 int (**pdecrypt) (EVP_PKEY_CTX *ctx,
1387 const unsigned char *in,
1391 *pdecrypt_init = pmeth->decrypt_init;
1393 *pdecrypt = pmeth->decrypt;
1396 void EVP_PKEY_meth_get_derive(const EVP_PKEY_METHOD *pmeth,
1397 int (**pderive_init) (EVP_PKEY_CTX *ctx),
1398 int (**pderive) (EVP_PKEY_CTX *ctx,
1403 *pderive_init = pmeth->derive_init;
1405 *pderive = pmeth->derive;
1408 void EVP_PKEY_meth_get_ctrl(const EVP_PKEY_METHOD *pmeth,
1409 int (**pctrl) (EVP_PKEY_CTX *ctx, int type, int p1,
1411 int (**pctrl_str) (EVP_PKEY_CTX *ctx,
1416 *pctrl = pmeth->ctrl;
1418 *pctrl_str = pmeth->ctrl_str;
1421 void EVP_PKEY_meth_get_digestsign(EVP_PKEY_METHOD *pmeth,
1422 int (**digestsign) (EVP_MD_CTX *ctx, unsigned char *sig, size_t *siglen,
1423 const unsigned char *tbs, size_t tbslen))
1426 *digestsign = pmeth->digestsign;
1429 void EVP_PKEY_meth_get_digestverify(EVP_PKEY_METHOD *pmeth,
1430 int (**digestverify) (EVP_MD_CTX *ctx, const unsigned char *sig,
1431 size_t siglen, const unsigned char *tbs,
1435 *digestverify = pmeth->digestverify;
1438 void EVP_PKEY_meth_get_check(const EVP_PKEY_METHOD *pmeth,
1439 int (**pcheck) (EVP_PKEY *pkey))
1442 *pcheck = pmeth->check;
1445 void EVP_PKEY_meth_get_public_check(const EVP_PKEY_METHOD *pmeth,
1446 int (**pcheck) (EVP_PKEY *pkey))
1449 *pcheck = pmeth->public_check;
1452 void EVP_PKEY_meth_get_param_check(const EVP_PKEY_METHOD *pmeth,
1453 int (**pcheck) (EVP_PKEY *pkey))
1456 *pcheck = pmeth->param_check;
1459 void EVP_PKEY_meth_get_digest_custom(EVP_PKEY_METHOD *pmeth,
1460 int (**pdigest_custom) (EVP_PKEY_CTX *ctx,
1463 if (pdigest_custom != NULL)
1464 *pdigest_custom = pmeth->digest_custom;
1467 #endif /* FIPS_MODE */