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->keymgmt->prov, pkey->keymgmt->name_id);
165 * TODO: I wonder if the EVP_PKEY should have the name and propquery
166 * that were used when building it.... /RL
171 /* TODO(3.0) Legacy code should be removed when all is provider based */
180 * Here, we extract what information we can for the purpose of
181 * supporting usage with implementations from providers, to make
182 * for a smooth transition from legacy stuff to provider based stuff.
184 * If an engine is given, this is entirely legacy, and we should not
185 * pretend anything else, so we only set the name when no engine is
186 * given. If both are already given, someone made a mistake, and
187 * since that can only happen internally, it's safe to make an
190 if (!ossl_assert(e == NULL || name == NULL))
193 name = OBJ_nid2sn(id);
195 # ifndef OPENSSL_NO_ENGINE
196 if (e == NULL && pkey != NULL)
197 e = pkey->pmeth_engine != NULL ? pkey->pmeth_engine : pkey->engine;
198 /* Try to find an ENGINE which implements this method */
200 if (!ENGINE_init(e)) {
201 EVPerr(EVP_F_INT_CTX_NEW, ERR_R_ENGINE_LIB);
205 e = ENGINE_get_pkey_meth_engine(id);
209 * If an ENGINE handled this method look it up. Otherwise use internal
213 pmeth = ENGINE_get_pkey_meth(e, id);
216 pmeth = EVP_PKEY_meth_find(id);
219 # ifndef OPENSSL_NO_ENGINE
222 EVPerr(EVP_F_INT_CTX_NEW, EVP_R_UNSUPPORTED_ALGORITHM);
226 #endif /* FIPS_MODE */
228 ret = OPENSSL_zalloc(sizeof(*ret));
230 #if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE)
233 EVPerr(EVP_F_INT_CTX_NEW, ERR_R_MALLOC_FAILURE);
236 ret->libctx = libctx;
238 ret->propquery = propquery;
241 ret->operation = EVP_PKEY_OP_UNDEFINED;
244 EVP_PKEY_up_ref(pkey);
246 if (pmeth != NULL && pmeth->init != NULL) {
247 if (pmeth->init(ret) <= 0) {
249 EVP_PKEY_CTX_free(ret);
257 /*- All methods below can also be used in FIPS_MODE */
259 EVP_PKEY_CTX *EVP_PKEY_CTX_new_from_name(OPENSSL_CTX *libctx,
261 const char *propquery)
263 return int_ctx_new(libctx, NULL, NULL, name, propquery, -1);
266 EVP_PKEY_CTX *EVP_PKEY_CTX_new_from_pkey(OPENSSL_CTX *libctx, EVP_PKEY *pkey,
267 const char *propquery)
269 return int_ctx_new(libctx, pkey, NULL, NULL, propquery, -1);
272 void evp_pkey_ctx_free_old_ops(EVP_PKEY_CTX *ctx)
274 if (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)) {
275 if (ctx->op.sig.sigprovctx != NULL && ctx->op.sig.signature != NULL)
276 ctx->op.sig.signature->freectx(ctx->op.sig.sigprovctx);
277 EVP_SIGNATURE_free(ctx->op.sig.signature);
278 ctx->op.sig.sigprovctx = NULL;
279 ctx->op.sig.signature = NULL;
280 } else if (EVP_PKEY_CTX_IS_DERIVE_OP(ctx)) {
281 if (ctx->op.kex.exchprovctx != NULL && ctx->op.kex.exchange != NULL)
282 ctx->op.kex.exchange->freectx(ctx->op.kex.exchprovctx);
283 EVP_KEYEXCH_free(ctx->op.kex.exchange);
284 ctx->op.kex.exchprovctx = NULL;
285 ctx->op.kex.exchange = NULL;
287 /* TODO(3.0): add dependancies and uncomment this when available for fips mode */
289 else if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)) {
290 if (ctx->op.ciph.ciphprovctx != NULL && ctx->op.ciph.cipher != NULL)
291 ctx->op.ciph.cipher->freectx(ctx->op.ciph.ciphprovctx);
292 EVP_ASYM_CIPHER_free(ctx->op.ciph.cipher);
293 ctx->op.ciph.ciphprovctx = NULL;
294 ctx->op.ciph.cipher = NULL;
295 } else if (EVP_PKEY_CTX_IS_GEN_OP(ctx)) {
296 if (ctx->op.keymgmt.genctx != NULL && ctx->keymgmt != NULL)
297 evp_keymgmt_gen_cleanup(ctx->keymgmt, ctx->op.keymgmt.genctx);
302 void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx)
306 if (ctx->pmeth && ctx->pmeth->cleanup)
307 ctx->pmeth->cleanup(ctx);
309 evp_pkey_ctx_free_old_ops(ctx);
310 EVP_KEYMGMT_free(ctx->keymgmt);
312 EVP_PKEY_free(ctx->pkey);
313 EVP_PKEY_free(ctx->peerkey);
314 #if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE)
315 ENGINE_finish(ctx->engine);
322 void EVP_PKEY_meth_get0_info(int *ppkey_id, int *pflags,
323 const EVP_PKEY_METHOD *meth)
326 *ppkey_id = meth->pkey_id;
328 *pflags = meth->flags;
331 void EVP_PKEY_meth_copy(EVP_PKEY_METHOD *dst, const EVP_PKEY_METHOD *src)
334 dst->init = src->init;
335 dst->copy = src->copy;
336 dst->cleanup = src->cleanup;
338 dst->paramgen_init = src->paramgen_init;
339 dst->paramgen = src->paramgen;
341 dst->keygen_init = src->keygen_init;
342 dst->keygen = src->keygen;
344 dst->sign_init = src->sign_init;
345 dst->sign = src->sign;
347 dst->verify_init = src->verify_init;
348 dst->verify = src->verify;
350 dst->verify_recover_init = src->verify_recover_init;
351 dst->verify_recover = src->verify_recover;
353 dst->signctx_init = src->signctx_init;
354 dst->signctx = src->signctx;
356 dst->verifyctx_init = src->verifyctx_init;
357 dst->verifyctx = src->verifyctx;
359 dst->encrypt_init = src->encrypt_init;
360 dst->encrypt = src->encrypt;
362 dst->decrypt_init = src->decrypt_init;
363 dst->decrypt = src->decrypt;
365 dst->derive_init = src->derive_init;
366 dst->derive = src->derive;
368 dst->ctrl = src->ctrl;
369 dst->ctrl_str = src->ctrl_str;
371 dst->check = src->check;
374 void EVP_PKEY_meth_free(EVP_PKEY_METHOD *pmeth)
376 if (pmeth && (pmeth->flags & EVP_PKEY_FLAG_DYNAMIC))
380 EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e)
382 return int_ctx_new(NULL, pkey, e, NULL, NULL, -1);
385 EVP_PKEY_CTX *EVP_PKEY_CTX_new_id(int id, ENGINE *e)
387 return int_ctx_new(NULL, NULL, e, NULL, NULL, id);
390 EVP_PKEY_CTX *EVP_PKEY_CTX_dup(const EVP_PKEY_CTX *pctx)
394 if (((pctx->pmeth == NULL) || (pctx->pmeth->copy == NULL))
395 && ((EVP_PKEY_CTX_IS_DERIVE_OP(pctx)
396 && pctx->op.kex.exchprovctx == NULL)
397 || (EVP_PKEY_CTX_IS_SIGNATURE_OP(pctx)
398 && pctx->op.sig.sigprovctx == NULL)))
400 # ifndef OPENSSL_NO_ENGINE
401 /* Make sure it's safe to copy a pkey context using an ENGINE */
402 if (pctx->engine && !ENGINE_init(pctx->engine)) {
403 EVPerr(EVP_F_EVP_PKEY_CTX_DUP, ERR_R_ENGINE_LIB);
407 rctx = OPENSSL_zalloc(sizeof(*rctx));
409 EVPerr(EVP_F_EVP_PKEY_CTX_DUP, ERR_R_MALLOC_FAILURE);
413 if (pctx->pkey != NULL)
414 EVP_PKEY_up_ref(pctx->pkey);
415 rctx->pkey = pctx->pkey;
416 rctx->operation = pctx->operation;
417 rctx->libctx = pctx->libctx;
418 rctx->keytype = pctx->keytype;
419 rctx->propquery = pctx->propquery;
421 if (EVP_PKEY_CTX_IS_DERIVE_OP(pctx)) {
422 if (pctx->op.kex.exchange != NULL) {
423 rctx->op.kex.exchange = pctx->op.kex.exchange;
424 if (!EVP_KEYEXCH_up_ref(rctx->op.kex.exchange)) {
429 if (pctx->op.kex.exchprovctx != NULL) {
430 if (!ossl_assert(pctx->op.kex.exchange != NULL))
432 rctx->op.kex.exchprovctx
433 = pctx->op.kex.exchange->dupctx(pctx->op.kex.exchprovctx);
434 if (rctx->op.kex.exchprovctx == NULL) {
435 EVP_KEYEXCH_free(rctx->op.kex.exchange);
441 } else if (EVP_PKEY_CTX_IS_SIGNATURE_OP(pctx)) {
442 if (pctx->op.sig.signature != NULL) {
443 rctx->op.sig.signature = pctx->op.sig.signature;
444 if (!EVP_SIGNATURE_up_ref(rctx->op.sig.signature)) {
449 if (pctx->op.sig.sigprovctx != NULL) {
450 if (!ossl_assert(pctx->op.sig.signature != NULL))
452 rctx->op.sig.sigprovctx
453 = pctx->op.sig.signature->dupctx(pctx->op.sig.sigprovctx);
454 if (rctx->op.sig.sigprovctx == NULL) {
455 EVP_SIGNATURE_free(rctx->op.sig.signature);
461 } else if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(pctx)) {
462 if (pctx->op.ciph.cipher != NULL) {
463 rctx->op.ciph.cipher = pctx->op.ciph.cipher;
464 if (!EVP_ASYM_CIPHER_up_ref(rctx->op.ciph.cipher)) {
469 if (pctx->op.ciph.ciphprovctx != NULL) {
470 if (!ossl_assert(pctx->op.ciph.cipher != NULL))
472 rctx->op.ciph.ciphprovctx
473 = pctx->op.ciph.cipher->dupctx(pctx->op.ciph.ciphprovctx);
474 if (rctx->op.ciph.ciphprovctx == NULL) {
475 EVP_ASYM_CIPHER_free(rctx->op.ciph.cipher);
483 rctx->pmeth = pctx->pmeth;
484 # ifndef OPENSSL_NO_ENGINE
485 rctx->engine = pctx->engine;
489 EVP_PKEY_up_ref(pctx->peerkey);
490 rctx->peerkey = pctx->peerkey;
492 if (pctx->pmeth->copy(rctx, pctx) > 0)
496 EVP_PKEY_CTX_free(rctx);
501 int EVP_PKEY_meth_add0(const EVP_PKEY_METHOD *pmeth)
503 if (app_pkey_methods == NULL) {
504 app_pkey_methods = sk_EVP_PKEY_METHOD_new(pmeth_cmp);
505 if (app_pkey_methods == NULL){
506 EVPerr(EVP_F_EVP_PKEY_METH_ADD0, ERR_R_MALLOC_FAILURE);
510 if (!sk_EVP_PKEY_METHOD_push(app_pkey_methods, pmeth)) {
511 EVPerr(EVP_F_EVP_PKEY_METH_ADD0, ERR_R_MALLOC_FAILURE);
514 sk_EVP_PKEY_METHOD_sort(app_pkey_methods);
518 void evp_app_cleanup_int(void)
520 if (app_pkey_methods != NULL)
521 sk_EVP_PKEY_METHOD_pop_free(app_pkey_methods, EVP_PKEY_meth_free);
524 int EVP_PKEY_meth_remove(const EVP_PKEY_METHOD *pmeth)
526 const EVP_PKEY_METHOD *ret;
528 ret = sk_EVP_PKEY_METHOD_delete_ptr(app_pkey_methods, pmeth);
530 return ret == NULL ? 0 : 1;
533 size_t EVP_PKEY_meth_get_count(void)
535 size_t rv = OSSL_NELEM(standard_methods);
537 if (app_pkey_methods)
538 rv += sk_EVP_PKEY_METHOD_num(app_pkey_methods);
542 const EVP_PKEY_METHOD *EVP_PKEY_meth_get0(size_t idx)
544 if (idx < OSSL_NELEM(standard_methods))
545 return (standard_methods[idx])();
546 if (app_pkey_methods == NULL)
548 idx -= OSSL_NELEM(standard_methods);
549 if (idx >= (size_t)sk_EVP_PKEY_METHOD_num(app_pkey_methods))
551 return sk_EVP_PKEY_METHOD_value(app_pkey_methods, idx);
555 int EVP_PKEY_CTX_set_params(EVP_PKEY_CTX *ctx, OSSL_PARAM *params)
557 if (EVP_PKEY_CTX_IS_DERIVE_OP(ctx)
558 && ctx->op.kex.exchprovctx != NULL
559 && ctx->op.kex.exchange != NULL
560 && ctx->op.kex.exchange->set_ctx_params != NULL)
561 return ctx->op.kex.exchange->set_ctx_params(ctx->op.kex.exchprovctx,
563 if (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)
564 && ctx->op.sig.sigprovctx != NULL
565 && ctx->op.sig.signature != NULL
566 && ctx->op.sig.signature->set_ctx_params != NULL)
567 return ctx->op.sig.signature->set_ctx_params(ctx->op.sig.sigprovctx,
569 if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)
570 && ctx->op.ciph.ciphprovctx != NULL
571 && ctx->op.ciph.cipher != NULL
572 && ctx->op.ciph.cipher->set_ctx_params != NULL)
573 return ctx->op.ciph.cipher->set_ctx_params(ctx->op.ciph.ciphprovctx,
575 if (EVP_PKEY_CTX_IS_GEN_OP(ctx)
576 && ctx->op.keymgmt.genctx != NULL
577 && ctx->keymgmt != NULL
578 && ctx->keymgmt->gen_set_params != NULL)
579 return evp_keymgmt_gen_set_params(ctx->keymgmt, ctx->op.keymgmt.genctx,
585 int EVP_PKEY_CTX_get_params(EVP_PKEY_CTX *ctx, OSSL_PARAM *params)
587 if (EVP_PKEY_CTX_IS_DERIVE_OP(ctx)
588 && ctx->op.kex.exchprovctx != NULL
589 && ctx->op.kex.exchange != NULL
590 && ctx->op.kex.exchange->get_ctx_params != NULL)
591 return ctx->op.kex.exchange->get_ctx_params(ctx->op.kex.exchprovctx,
593 if (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)
594 && ctx->op.sig.sigprovctx != NULL
595 && ctx->op.sig.signature != NULL
596 && ctx->op.sig.signature->get_ctx_params != NULL)
597 return ctx->op.sig.signature->get_ctx_params(ctx->op.sig.sigprovctx,
599 if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)
600 && ctx->op.ciph.ciphprovctx != NULL
601 && ctx->op.ciph.cipher != NULL
602 && ctx->op.ciph.cipher->get_ctx_params != NULL)
603 return ctx->op.ciph.cipher->get_ctx_params(ctx->op.ciph.ciphprovctx,
608 const OSSL_PARAM *EVP_PKEY_CTX_gettable_params(EVP_PKEY_CTX *ctx)
610 if (EVP_PKEY_CTX_IS_DERIVE_OP(ctx)
611 && ctx->op.kex.exchange != NULL
612 && ctx->op.kex.exchange->gettable_ctx_params != NULL)
613 return ctx->op.kex.exchange->gettable_ctx_params();
614 if (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)
615 && ctx->op.sig.signature != NULL
616 && ctx->op.sig.signature->gettable_ctx_params != NULL)
617 return ctx->op.sig.signature->gettable_ctx_params();
619 if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)
620 && ctx->op.ciph.cipher != NULL
621 && ctx->op.ciph.cipher->gettable_ctx_params != NULL)
622 return ctx->op.ciph.cipher->gettable_ctx_params();
627 const OSSL_PARAM *EVP_PKEY_CTX_settable_params(EVP_PKEY_CTX *ctx)
629 if (EVP_PKEY_CTX_IS_DERIVE_OP(ctx)
630 && ctx->op.kex.exchange != NULL
631 && ctx->op.kex.exchange->settable_ctx_params != NULL)
632 return ctx->op.kex.exchange->settable_ctx_params();
633 if (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)
634 && ctx->op.sig.signature != NULL
635 && ctx->op.sig.signature->settable_ctx_params != NULL)
636 return ctx->op.sig.signature->settable_ctx_params();
637 if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)
638 && ctx->op.ciph.cipher != NULL
639 && ctx->op.ciph.cipher->settable_ctx_params != NULL)
640 return ctx->op.ciph.cipher->settable_ctx_params();
641 if (EVP_PKEY_CTX_IS_GEN_OP(ctx)
642 && ctx->keymgmt != NULL
643 && ctx->keymgmt->gen_settable_params != NULL)
644 return evp_keymgmt_gen_settable_params(ctx->keymgmt);
650 * Internal helpers for stricter EVP_PKEY_CTX_{set,get}_params().
652 * Return 1 on success, 0 or negative for errors.
654 * In particular they return -2 if any of the params is not supported.
656 * They are not available in FIPS_MODE as they depend on
657 * - EVP_PKEY_CTX_{get,set}_params()
658 * - EVP_PKEY_CTX_{gettable,settable}_params()
661 int evp_pkey_ctx_set_params_strict(EVP_PKEY_CTX *ctx, OSSL_PARAM *params)
665 if (ctx == NULL || params == NULL)
668 for (p = params; p->key != NULL; p++) {
669 /* Check the ctx actually understands this parameter */
670 if (OSSL_PARAM_locate_const(EVP_PKEY_CTX_settable_params(ctx),
675 return EVP_PKEY_CTX_set_params(ctx, params);
678 int evp_pkey_ctx_get_params_strict(EVP_PKEY_CTX *ctx, OSSL_PARAM *params)
682 if (ctx == NULL || params == NULL)
685 for (p = params; p->key != NULL; p++ ) {
686 /* Check the ctx actually understands this parameter */
687 if (OSSL_PARAM_locate_const(EVP_PKEY_CTX_gettable_params(ctx),
692 return EVP_PKEY_CTX_get_params(ctx, params);
695 # ifndef OPENSSL_NO_DH
696 int EVP_PKEY_CTX_set_dh_pad(EVP_PKEY_CTX *ctx, int pad)
698 OSSL_PARAM dh_pad_params[2];
699 unsigned int upad = pad;
701 /* We use EVP_PKEY_CTX_ctrl return values */
702 if (ctx == NULL || !EVP_PKEY_CTX_IS_DERIVE_OP(ctx)) {
703 ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED);
707 /* TODO(3.0): Remove this eventually when no more legacy */
708 if (ctx->op.kex.exchprovctx == NULL)
709 return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DH, EVP_PKEY_OP_DERIVE,
710 EVP_PKEY_CTRL_DH_PAD, pad, NULL);
712 dh_pad_params[0] = OSSL_PARAM_construct_uint(OSSL_EXCHANGE_PARAM_PAD, &upad);
713 dh_pad_params[1] = OSSL_PARAM_construct_end();
715 return EVP_PKEY_CTX_set_params(ctx, dh_pad_params);
719 int EVP_PKEY_CTX_get_signature_md(EVP_PKEY_CTX *ctx, const EVP_MD **md)
721 OSSL_PARAM sig_md_params[3], *p = sig_md_params;
722 /* 80 should be big enough */
726 if (ctx == NULL || !EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)) {
727 ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED);
728 /* Uses the same return values as EVP_PKEY_CTX_ctrl */
732 /* TODO(3.0): Remove this eventually when no more legacy */
733 if (ctx->op.sig.sigprovctx == NULL)
734 return EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_TYPE_SIG,
735 EVP_PKEY_CTRL_GET_MD, 0, (void *)(md));
737 *p++ = OSSL_PARAM_construct_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST,
740 *p++ = OSSL_PARAM_construct_end();
742 if (!EVP_PKEY_CTX_get_params(ctx, sig_md_params))
745 tmp = evp_get_digestbyname_ex(ctx->libctx, name);
754 int EVP_PKEY_CTX_set_signature_md(EVP_PKEY_CTX *ctx, const EVP_MD *md)
756 OSSL_PARAM sig_md_params[2], *p = sig_md_params;
759 if (ctx == NULL || !EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)) {
760 ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED);
761 /* Uses the same return values as EVP_PKEY_CTX_ctrl */
765 /* TODO(3.0): Remove this eventually when no more legacy */
766 if (ctx->op.sig.sigprovctx == NULL)
767 return EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_TYPE_SIG,
768 EVP_PKEY_CTRL_MD, 0, (void *)(md));
773 name = EVP_MD_name(md);
776 *p++ = OSSL_PARAM_construct_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST,
778 * Cast away the const. This is read
779 * only so should be safe
782 *p++ = OSSL_PARAM_construct_end();
784 return EVP_PKEY_CTX_set_params(ctx, sig_md_params);
787 static int legacy_ctrl_to_param(EVP_PKEY_CTX *ctx, int keytype, int optype,
788 int cmd, int p1, void *p2)
791 * GOST CMS format is different for different cipher algorithms.
792 * Most of other algorithms don't have such a difference
793 * so this ctrl is just ignored.
795 if (cmd == EVP_PKEY_CTRL_CIPHER)
797 # ifndef OPENSSL_NO_DH
798 if (keytype == EVP_PKEY_DH) {
800 case EVP_PKEY_CTRL_DH_PAD:
801 return EVP_PKEY_CTX_set_dh_pad(ctx, p1);
805 # ifndef OPENSSL_NO_EC
806 if (keytype == EVP_PKEY_EC) {
808 case EVP_PKEY_CTRL_EC_ECDH_COFACTOR:
810 return EVP_PKEY_CTX_get_ecdh_cofactor_mode(ctx);
811 } else if (p1 < -1 || p1 > 1) {
812 /* Uses the same return values as EVP_PKEY_CTX_ctrl */
815 return EVP_PKEY_CTX_set_ecdh_cofactor_mode(ctx, p1);
817 case EVP_PKEY_CTRL_EC_KDF_TYPE:
819 return EVP_PKEY_CTX_get_ecdh_kdf_type(ctx);
821 return EVP_PKEY_CTX_set_ecdh_kdf_type(ctx, p1);
823 case EVP_PKEY_CTRL_GET_EC_KDF_MD:
824 return EVP_PKEY_CTX_get_ecdh_kdf_md(ctx, p2);
825 case EVP_PKEY_CTRL_EC_KDF_MD:
826 return EVP_PKEY_CTX_set_ecdh_kdf_md(ctx, p2);
827 case EVP_PKEY_CTRL_GET_EC_KDF_OUTLEN:
828 return EVP_PKEY_CTX_get_ecdh_kdf_outlen(ctx, p2);
829 case EVP_PKEY_CTRL_EC_KDF_OUTLEN:
830 return EVP_PKEY_CTX_set_ecdh_kdf_outlen(ctx, p1);
831 case EVP_PKEY_CTRL_GET_EC_KDF_UKM:
832 return EVP_PKEY_CTX_get0_ecdh_kdf_ukm(ctx, p2);
833 case EVP_PKEY_CTRL_EC_KDF_UKM:
834 return EVP_PKEY_CTX_set0_ecdh_kdf_ukm(ctx, p2, p1);
840 case EVP_PKEY_CTRL_MD:
841 return EVP_PKEY_CTX_set_signature_md(ctx, p2);
842 case EVP_PKEY_CTRL_GET_MD:
843 return EVP_PKEY_CTX_get_signature_md(ctx, p2);
844 case EVP_PKEY_CTRL_RSA_PADDING:
845 return EVP_PKEY_CTX_set_rsa_padding(ctx, p1);
846 case EVP_PKEY_CTRL_GET_RSA_PADDING:
847 return EVP_PKEY_CTX_get_rsa_padding(ctx, p2);
848 case EVP_PKEY_CTRL_RSA_OAEP_MD:
849 return EVP_PKEY_CTX_set_rsa_oaep_md(ctx, p2);
850 case EVP_PKEY_CTRL_GET_RSA_OAEP_MD:
851 return EVP_PKEY_CTX_get_rsa_oaep_md(ctx, p2);
852 case EVP_PKEY_CTRL_RSA_MGF1_MD:
853 return EVP_PKEY_CTX_set_rsa_oaep_md(ctx, p2);
854 case EVP_PKEY_CTRL_GET_RSA_MGF1_MD:
855 return EVP_PKEY_CTX_get_rsa_oaep_md(ctx, p2);
856 case EVP_PKEY_CTRL_RSA_OAEP_LABEL:
857 return EVP_PKEY_CTX_set0_rsa_oaep_label(ctx, p2, p1);
858 case EVP_PKEY_CTRL_GET_RSA_OAEP_LABEL:
859 return EVP_PKEY_CTX_get0_rsa_oaep_label(ctx, (unsigned char **)p2);
860 case EVP_PKEY_CTRL_RSA_PSS_SALTLEN:
861 return EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx, p1);
862 case EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN:
863 return EVP_PKEY_CTX_get_rsa_pss_saltlen(ctx, p2);
864 case EVP_PKEY_CTRL_PKCS7_ENCRYPT:
865 case EVP_PKEY_CTRL_PKCS7_DECRYPT:
866 # ifndef OPENSSL_NO_CMS
867 case EVP_PKEY_CTRL_CMS_DECRYPT:
868 case EVP_PKEY_CTRL_CMS_ENCRYPT:
870 if (ctx->pmeth->pkey_id != EVP_PKEY_RSA_PSS)
872 ERR_raise(ERR_LIB_EVP,
873 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
875 case EVP_PKEY_CTRL_RSA_KEYGEN_BITS:
876 return EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, p1);
877 case EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP:
878 return EVP_PKEY_CTX_set_rsa_keygen_pubexp(ctx, p2);
879 case EVP_PKEY_CTRL_RSA_KEYGEN_PRIMES:
880 return EVP_PKEY_CTX_set_rsa_keygen_primes(ctx, p1);
886 int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype,
887 int cmd, int p1, void *p2)
892 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_COMMAND_NOT_SUPPORTED);
896 if ((EVP_PKEY_CTX_IS_DERIVE_OP(ctx) && ctx->op.kex.exchprovctx != NULL)
897 || (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)
898 && ctx->op.sig.sigprovctx != NULL)
899 || (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)
900 && ctx->op.ciph.ciphprovctx != NULL)
901 || (EVP_PKEY_CTX_IS_GEN_OP(ctx)
902 && ctx->op.keymgmt.genctx != NULL))
903 return legacy_ctrl_to_param(ctx, keytype, optype, cmd, p1, p2);
905 if (ctx->pmeth == NULL || ctx->pmeth->ctrl == NULL) {
906 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_COMMAND_NOT_SUPPORTED);
909 if ((keytype != -1) && (ctx->pmeth->pkey_id != keytype))
912 /* Skip the operation checks since this is called in a very early stage */
913 if (ctx->pmeth->digest_custom != NULL)
916 if (ctx->operation == EVP_PKEY_OP_UNDEFINED) {
917 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_NO_OPERATION_SET);
921 if ((optype != -1) && !(ctx->operation & optype)) {
922 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_INVALID_OPERATION);
927 ret = ctx->pmeth->ctrl(ctx, cmd, p1, p2);
930 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_COMMAND_NOT_SUPPORTED);
935 int EVP_PKEY_CTX_ctrl_uint64(EVP_PKEY_CTX *ctx, int keytype, int optype,
936 int cmd, uint64_t value)
938 return EVP_PKEY_CTX_ctrl(ctx, keytype, optype, cmd, 0, &value);
941 static int legacy_ctrl_str_to_param(EVP_PKEY_CTX *ctx, const char *name,
944 if (strcmp(name, "rsa_padding_mode") == 0)
945 name = OSSL_ASYM_CIPHER_PARAM_PAD_MODE;
946 else if (strcmp(name, "rsa_mgf1_md") == 0)
947 name = OSSL_ASYM_CIPHER_PARAM_MGF1_DIGEST;
948 else if (strcmp(name, "rsa_oaep_md") == 0)
949 name = OSSL_ASYM_CIPHER_PARAM_OAEP_DIGEST;
950 else if (strcmp(name, "rsa_oaep_label") == 0)
951 name = OSSL_ASYM_CIPHER_PARAM_OAEP_LABEL;
952 else if (strcmp(name, "rsa_pss_saltlen") == 0)
953 name = OSSL_SIGNATURE_PARAM_PSS_SALTLEN;
954 else if (strcmp(name, "rsa_keygen_bits") == 0)
955 name = OSSL_PKEY_PARAM_RSA_BITS;
956 else if (strcmp(name, "rsa_keygen_pubexp") == 0)
957 name = OSSL_PKEY_PARAM_RSA_E;
958 else if (strcmp(name, "rsa_keygen_primes") == 0)
959 name = OSSL_PKEY_PARAM_RSA_PRIMES;
960 # ifndef OPENSSL_NO_DH
961 else if (strcmp(name, "dh_pad") == 0)
962 name = OSSL_EXCHANGE_PARAM_PAD;
964 # ifndef OPENSSL_NO_EC
965 else if (strcmp(name, "ecdh_cofactor_mode") == 0)
966 name = OSSL_EXCHANGE_PARAM_EC_ECDH_COFACTOR_MODE;
967 else if (strcmp(name, "ecdh_kdf_md") == 0)
968 name = OSSL_EXCHANGE_PARAM_KDF_DIGEST;
973 * TODO(3.0) reduce the code above to only translate known legacy
974 * string to the corresponding core name (see core_names.h), but
975 * otherwise leave it to this code block to do the actual work.
977 const OSSL_PARAM *settable = EVP_PKEY_CTX_settable_params(ctx);
978 OSSL_PARAM params[2] = { OSSL_PARAM_END, OSSL_PARAM_END };
982 if (!OSSL_PARAM_allocate_from_text(¶ms[0], settable, name, value,
983 strlen(value), &exists)) {
985 ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED);
990 if (EVP_PKEY_CTX_set_params(ctx, params))
992 OPENSSL_free(params[0].data);
997 int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx,
998 const char *name, const char *value)
1001 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR, EVP_R_COMMAND_NOT_SUPPORTED);
1005 if ((EVP_PKEY_CTX_IS_DERIVE_OP(ctx) && ctx->op.kex.exchprovctx != NULL)
1006 || (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)
1007 && ctx->op.sig.sigprovctx != NULL)
1008 || (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)
1009 && ctx->op.ciph.ciphprovctx != NULL)
1010 || (EVP_PKEY_CTX_IS_GEN_OP(ctx)
1011 && ctx->op.keymgmt.genctx != NULL))
1012 return legacy_ctrl_str_to_param(ctx, name, value);
1014 if (!ctx || !ctx->pmeth || !ctx->pmeth->ctrl_str) {
1015 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR, EVP_R_COMMAND_NOT_SUPPORTED);
1018 if (strcmp(name, "digest") == 0)
1019 return EVP_PKEY_CTX_md(ctx, EVP_PKEY_OP_TYPE_SIG, EVP_PKEY_CTRL_MD,
1021 return ctx->pmeth->ctrl_str(ctx, name, value);
1024 /* Utility functions to send a string of hex string to a ctrl */
1026 int EVP_PKEY_CTX_str2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *str)
1033 return ctx->pmeth->ctrl(ctx, cmd, len, (void *)str);
1036 int EVP_PKEY_CTX_hex2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *hex)
1042 bin = OPENSSL_hexstr2buf(hex, &binlen);
1045 if (binlen <= INT_MAX)
1046 rv = ctx->pmeth->ctrl(ctx, cmd, binlen, bin);
1051 /* Pass a message digest to a ctrl */
1052 int EVP_PKEY_CTX_md(EVP_PKEY_CTX *ctx, int optype, int cmd, const char *md)
1056 if (md == NULL || (m = EVP_get_digestbyname(md)) == NULL) {
1057 EVPerr(EVP_F_EVP_PKEY_CTX_MD, EVP_R_INVALID_DIGEST);
1060 return EVP_PKEY_CTX_ctrl(ctx, -1, optype, cmd, 0, (void *)m);
1063 int EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX *ctx)
1065 return ctx->operation;
1068 void EVP_PKEY_CTX_set0_keygen_info(EVP_PKEY_CTX *ctx, int *dat, int datlen)
1070 ctx->keygen_info = dat;
1071 ctx->keygen_info_count = datlen;
1074 void EVP_PKEY_CTX_set_data(EVP_PKEY_CTX *ctx, void *data)
1079 void *EVP_PKEY_CTX_get_data(const EVP_PKEY_CTX *ctx)
1084 EVP_PKEY *EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX *ctx)
1089 EVP_PKEY *EVP_PKEY_CTX_get0_peerkey(EVP_PKEY_CTX *ctx)
1091 return ctx->peerkey;
1094 void EVP_PKEY_CTX_set_app_data(EVP_PKEY_CTX *ctx, void *data)
1096 ctx->app_data = data;
1099 void *EVP_PKEY_CTX_get_app_data(EVP_PKEY_CTX *ctx)
1101 return ctx->app_data;
1104 void EVP_PKEY_meth_set_init(EVP_PKEY_METHOD *pmeth,
1105 int (*init) (EVP_PKEY_CTX *ctx))
1110 void EVP_PKEY_meth_set_copy(EVP_PKEY_METHOD *pmeth,
1111 int (*copy) (EVP_PKEY_CTX *dst,
1112 const EVP_PKEY_CTX *src))
1117 void EVP_PKEY_meth_set_cleanup(EVP_PKEY_METHOD *pmeth,
1118 void (*cleanup) (EVP_PKEY_CTX *ctx))
1120 pmeth->cleanup = cleanup;
1123 void EVP_PKEY_meth_set_paramgen(EVP_PKEY_METHOD *pmeth,
1124 int (*paramgen_init) (EVP_PKEY_CTX *ctx),
1125 int (*paramgen) (EVP_PKEY_CTX *ctx,
1128 pmeth->paramgen_init = paramgen_init;
1129 pmeth->paramgen = paramgen;
1132 void EVP_PKEY_meth_set_keygen(EVP_PKEY_METHOD *pmeth,
1133 int (*keygen_init) (EVP_PKEY_CTX *ctx),
1134 int (*keygen) (EVP_PKEY_CTX *ctx,
1137 pmeth->keygen_init = keygen_init;
1138 pmeth->keygen = keygen;
1141 void EVP_PKEY_meth_set_sign(EVP_PKEY_METHOD *pmeth,
1142 int (*sign_init) (EVP_PKEY_CTX *ctx),
1143 int (*sign) (EVP_PKEY_CTX *ctx,
1144 unsigned char *sig, size_t *siglen,
1145 const unsigned char *tbs,
1148 pmeth->sign_init = sign_init;
1152 void EVP_PKEY_meth_set_verify(EVP_PKEY_METHOD *pmeth,
1153 int (*verify_init) (EVP_PKEY_CTX *ctx),
1154 int (*verify) (EVP_PKEY_CTX *ctx,
1155 const unsigned char *sig,
1157 const unsigned char *tbs,
1160 pmeth->verify_init = verify_init;
1161 pmeth->verify = verify;
1164 void EVP_PKEY_meth_set_verify_recover(EVP_PKEY_METHOD *pmeth,
1165 int (*verify_recover_init) (EVP_PKEY_CTX
1167 int (*verify_recover) (EVP_PKEY_CTX
1176 pmeth->verify_recover_init = verify_recover_init;
1177 pmeth->verify_recover = verify_recover;
1180 void EVP_PKEY_meth_set_signctx(EVP_PKEY_METHOD *pmeth,
1181 int (*signctx_init) (EVP_PKEY_CTX *ctx,
1183 int (*signctx) (EVP_PKEY_CTX *ctx,
1188 pmeth->signctx_init = signctx_init;
1189 pmeth->signctx = signctx;
1192 void EVP_PKEY_meth_set_verifyctx(EVP_PKEY_METHOD *pmeth,
1193 int (*verifyctx_init) (EVP_PKEY_CTX *ctx,
1195 int (*verifyctx) (EVP_PKEY_CTX *ctx,
1196 const unsigned char *sig,
1200 pmeth->verifyctx_init = verifyctx_init;
1201 pmeth->verifyctx = verifyctx;
1204 void EVP_PKEY_meth_set_encrypt(EVP_PKEY_METHOD *pmeth,
1205 int (*encrypt_init) (EVP_PKEY_CTX *ctx),
1206 int (*encryptfn) (EVP_PKEY_CTX *ctx,
1209 const unsigned char *in,
1212 pmeth->encrypt_init = encrypt_init;
1213 pmeth->encrypt = encryptfn;
1216 void EVP_PKEY_meth_set_decrypt(EVP_PKEY_METHOD *pmeth,
1217 int (*decrypt_init) (EVP_PKEY_CTX *ctx),
1218 int (*decrypt) (EVP_PKEY_CTX *ctx,
1221 const unsigned char *in,
1224 pmeth->decrypt_init = decrypt_init;
1225 pmeth->decrypt = decrypt;
1228 void EVP_PKEY_meth_set_derive(EVP_PKEY_METHOD *pmeth,
1229 int (*derive_init) (EVP_PKEY_CTX *ctx),
1230 int (*derive) (EVP_PKEY_CTX *ctx,
1234 pmeth->derive_init = derive_init;
1235 pmeth->derive = derive;
1238 void EVP_PKEY_meth_set_ctrl(EVP_PKEY_METHOD *pmeth,
1239 int (*ctrl) (EVP_PKEY_CTX *ctx, int type, int p1,
1241 int (*ctrl_str) (EVP_PKEY_CTX *ctx,
1246 pmeth->ctrl_str = ctrl_str;
1249 void EVP_PKEY_meth_set_digestsign(EVP_PKEY_METHOD *pmeth,
1250 int (*digestsign) (EVP_MD_CTX *ctx, unsigned char *sig, size_t *siglen,
1251 const unsigned char *tbs, size_t tbslen))
1253 pmeth->digestsign = digestsign;
1256 void EVP_PKEY_meth_set_digestverify(EVP_PKEY_METHOD *pmeth,
1257 int (*digestverify) (EVP_MD_CTX *ctx, const unsigned char *sig,
1258 size_t siglen, const unsigned char *tbs,
1261 pmeth->digestverify = digestverify;
1264 void EVP_PKEY_meth_set_check(EVP_PKEY_METHOD *pmeth,
1265 int (*check) (EVP_PKEY *pkey))
1267 pmeth->check = check;
1270 void EVP_PKEY_meth_set_public_check(EVP_PKEY_METHOD *pmeth,
1271 int (*check) (EVP_PKEY *pkey))
1273 pmeth->public_check = check;
1276 void EVP_PKEY_meth_set_param_check(EVP_PKEY_METHOD *pmeth,
1277 int (*check) (EVP_PKEY *pkey))
1279 pmeth->param_check = check;
1282 void EVP_PKEY_meth_set_digest_custom(EVP_PKEY_METHOD *pmeth,
1283 int (*digest_custom) (EVP_PKEY_CTX *ctx,
1286 pmeth->digest_custom = digest_custom;
1289 void EVP_PKEY_meth_get_init(const EVP_PKEY_METHOD *pmeth,
1290 int (**pinit) (EVP_PKEY_CTX *ctx))
1292 *pinit = pmeth->init;
1295 void EVP_PKEY_meth_get_copy(const EVP_PKEY_METHOD *pmeth,
1296 int (**pcopy) (EVP_PKEY_CTX *dst,
1297 const EVP_PKEY_CTX *src))
1299 *pcopy = pmeth->copy;
1302 void EVP_PKEY_meth_get_cleanup(const EVP_PKEY_METHOD *pmeth,
1303 void (**pcleanup) (EVP_PKEY_CTX *ctx))
1305 *pcleanup = pmeth->cleanup;
1308 void EVP_PKEY_meth_get_paramgen(const EVP_PKEY_METHOD *pmeth,
1309 int (**pparamgen_init) (EVP_PKEY_CTX *ctx),
1310 int (**pparamgen) (EVP_PKEY_CTX *ctx,
1314 *pparamgen_init = pmeth->paramgen_init;
1316 *pparamgen = pmeth->paramgen;
1319 void EVP_PKEY_meth_get_keygen(const EVP_PKEY_METHOD *pmeth,
1320 int (**pkeygen_init) (EVP_PKEY_CTX *ctx),
1321 int (**pkeygen) (EVP_PKEY_CTX *ctx,
1325 *pkeygen_init = pmeth->keygen_init;
1327 *pkeygen = pmeth->keygen;
1330 void EVP_PKEY_meth_get_sign(const EVP_PKEY_METHOD *pmeth,
1331 int (**psign_init) (EVP_PKEY_CTX *ctx),
1332 int (**psign) (EVP_PKEY_CTX *ctx,
1333 unsigned char *sig, size_t *siglen,
1334 const unsigned char *tbs,
1338 *psign_init = pmeth->sign_init;
1340 *psign = pmeth->sign;
1343 void EVP_PKEY_meth_get_verify(const EVP_PKEY_METHOD *pmeth,
1344 int (**pverify_init) (EVP_PKEY_CTX *ctx),
1345 int (**pverify) (EVP_PKEY_CTX *ctx,
1346 const unsigned char *sig,
1348 const unsigned char *tbs,
1352 *pverify_init = pmeth->verify_init;
1354 *pverify = pmeth->verify;
1357 void EVP_PKEY_meth_get_verify_recover(const EVP_PKEY_METHOD *pmeth,
1358 int (**pverify_recover_init) (EVP_PKEY_CTX
1360 int (**pverify_recover) (EVP_PKEY_CTX
1369 if (pverify_recover_init)
1370 *pverify_recover_init = pmeth->verify_recover_init;
1371 if (pverify_recover)
1372 *pverify_recover = pmeth->verify_recover;
1375 void EVP_PKEY_meth_get_signctx(const EVP_PKEY_METHOD *pmeth,
1376 int (**psignctx_init) (EVP_PKEY_CTX *ctx,
1378 int (**psignctx) (EVP_PKEY_CTX *ctx,
1384 *psignctx_init = pmeth->signctx_init;
1386 *psignctx = pmeth->signctx;
1389 void EVP_PKEY_meth_get_verifyctx(const EVP_PKEY_METHOD *pmeth,
1390 int (**pverifyctx_init) (EVP_PKEY_CTX *ctx,
1392 int (**pverifyctx) (EVP_PKEY_CTX *ctx,
1393 const unsigned char *sig,
1397 if (pverifyctx_init)
1398 *pverifyctx_init = pmeth->verifyctx_init;
1400 *pverifyctx = pmeth->verifyctx;
1403 void EVP_PKEY_meth_get_encrypt(const EVP_PKEY_METHOD *pmeth,
1404 int (**pencrypt_init) (EVP_PKEY_CTX *ctx),
1405 int (**pencryptfn) (EVP_PKEY_CTX *ctx,
1408 const unsigned char *in,
1412 *pencrypt_init = pmeth->encrypt_init;
1414 *pencryptfn = pmeth->encrypt;
1417 void EVP_PKEY_meth_get_decrypt(const EVP_PKEY_METHOD *pmeth,
1418 int (**pdecrypt_init) (EVP_PKEY_CTX *ctx),
1419 int (**pdecrypt) (EVP_PKEY_CTX *ctx,
1422 const unsigned char *in,
1426 *pdecrypt_init = pmeth->decrypt_init;
1428 *pdecrypt = pmeth->decrypt;
1431 void EVP_PKEY_meth_get_derive(const EVP_PKEY_METHOD *pmeth,
1432 int (**pderive_init) (EVP_PKEY_CTX *ctx),
1433 int (**pderive) (EVP_PKEY_CTX *ctx,
1438 *pderive_init = pmeth->derive_init;
1440 *pderive = pmeth->derive;
1443 void EVP_PKEY_meth_get_ctrl(const EVP_PKEY_METHOD *pmeth,
1444 int (**pctrl) (EVP_PKEY_CTX *ctx, int type, int p1,
1446 int (**pctrl_str) (EVP_PKEY_CTX *ctx,
1451 *pctrl = pmeth->ctrl;
1453 *pctrl_str = pmeth->ctrl_str;
1456 void EVP_PKEY_meth_get_digestsign(EVP_PKEY_METHOD *pmeth,
1457 int (**digestsign) (EVP_MD_CTX *ctx, unsigned char *sig, size_t *siglen,
1458 const unsigned char *tbs, size_t tbslen))
1461 *digestsign = pmeth->digestsign;
1464 void EVP_PKEY_meth_get_digestverify(EVP_PKEY_METHOD *pmeth,
1465 int (**digestverify) (EVP_MD_CTX *ctx, const unsigned char *sig,
1466 size_t siglen, const unsigned char *tbs,
1470 *digestverify = pmeth->digestverify;
1473 void EVP_PKEY_meth_get_check(const EVP_PKEY_METHOD *pmeth,
1474 int (**pcheck) (EVP_PKEY *pkey))
1477 *pcheck = pmeth->check;
1480 void EVP_PKEY_meth_get_public_check(const EVP_PKEY_METHOD *pmeth,
1481 int (**pcheck) (EVP_PKEY *pkey))
1484 *pcheck = pmeth->public_check;
1487 void EVP_PKEY_meth_get_param_check(const EVP_PKEY_METHOD *pmeth,
1488 int (**pcheck) (EVP_PKEY *pkey))
1491 *pcheck = pmeth->param_check;
1494 void EVP_PKEY_meth_get_digest_custom(EVP_PKEY_METHOD *pmeth,
1495 int (**pdigest_custom) (EVP_PKEY_CTX *ctx,
1498 if (pdigest_custom != NULL)
1499 *pdigest_custom = pmeth->digest_custom;
1502 #endif /* FIPS_MODE */