2 * Copyright 2006-2021 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 * Low level key APIs (DH etc) 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 <openssl/kdf.h>
25 #include "internal/cryptlib.h"
26 #include "crypto/asn1.h"
27 #include "crypto/evp.h"
28 #include "crypto/dh.h"
29 #include "crypto/ec.h"
30 #include "internal/ffc.h"
31 #include "internal/numbers.h"
32 #include "internal/provider.h"
33 #include "evp_local.h"
37 static int evp_pkey_ctx_store_cached_data(EVP_PKEY_CTX
*ctx
,
38 int keytype
, int optype
,
39 int cmd
, const char *name
,
40 const void *data
, size_t data_len
);
41 static void evp_pkey_ctx_free_cached_data(EVP_PKEY_CTX
*ctx
,
42 int cmd
, const char *name
);
43 static void evp_pkey_ctx_free_all_cached_data(EVP_PKEY_CTX
*ctx
);
45 typedef const EVP_PKEY_METHOD
*(*pmeth_fn
)(void);
46 typedef int sk_cmp_fn_type(const char *const *a
, const char *const *b
);
48 static STACK_OF(EVP_PKEY_METHOD
) *app_pkey_methods
= NULL
;
50 /* This array needs to be in order of NIDs */
51 static pmeth_fn standard_methods
[] = {
53 # ifndef OPENSSL_NO_DH
56 # ifndef OPENSSL_NO_DSA
59 # ifndef OPENSSL_NO_EC
62 ossl_rsa_pss_pkey_method
,
63 # ifndef OPENSSL_NO_DH
66 # ifndef OPENSSL_NO_EC
67 ossl_ecx25519_pkey_method
,
68 ossl_ecx448_pkey_method
,
70 # ifndef OPENSSL_NO_EC
71 ossl_ed25519_pkey_method
,
72 ossl_ed448_pkey_method
,
76 DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD
*, pmeth_fn
, pmeth_func
);
78 static int pmeth_func_cmp(const EVP_PKEY_METHOD
*const *a
, pmeth_fn
const *b
)
80 return ((*a
)->pkey_id
- ((**b
)())->pkey_id
);
83 IMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD
*, pmeth_fn
, pmeth_func
);
85 static int pmeth_cmp(const EVP_PKEY_METHOD
*const *a
,
86 const EVP_PKEY_METHOD
*const *b
)
88 return ((*a
)->pkey_id
- (*b
)->pkey_id
);
91 static const EVP_PKEY_METHOD
*evp_pkey_meth_find_added_by_application(int type
)
93 if (app_pkey_methods
!= NULL
) {
98 idx
= sk_EVP_PKEY_METHOD_find(app_pkey_methods
, &tmp
);
100 return sk_EVP_PKEY_METHOD_value(app_pkey_methods
, idx
);
105 const EVP_PKEY_METHOD
*EVP_PKEY_meth_find(int type
)
109 const EVP_PKEY_METHOD
*t
;
111 if ((t
= evp_pkey_meth_find_added_by_application(type
)) != NULL
)
116 ret
= OBJ_bsearch_pmeth_func(&t
, standard_methods
,
117 OSSL_NELEM(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 ERR_raise(ERR_LIB_EVP
, ERR_R_MALLOC_FAILURE
);
134 pmeth
->flags
= flags
| EVP_PKEY_FLAG_DYNAMIC
;
138 static void help_get_legacy_alg_type_from_keymgmt(const char *keytype
,
143 if (*type
== NID_undef
)
144 *type
= evp_pkey_name2type(keytype
);
147 static int get_legacy_alg_type_from_keymgmt(const EVP_KEYMGMT
*keymgmt
)
149 int type
= NID_undef
;
151 EVP_KEYMGMT_names_do_all(keymgmt
, help_get_legacy_alg_type_from_keymgmt
,
155 #endif /* FIPS_MODULE */
157 int evp_pkey_ctx_state(const EVP_PKEY_CTX
*ctx
)
159 if (ctx
->operation
== EVP_PKEY_OP_UNDEFINED
)
160 return EVP_PKEY_STATE_UNKNOWN
;
162 if ((EVP_PKEY_CTX_IS_DERIVE_OP(ctx
)
163 && ctx
->op
.kex
.exchprovctx
!= NULL
)
164 || (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx
)
165 && ctx
->op
.sig
.sigprovctx
!= NULL
)
166 || (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx
)
167 && ctx
->op
.ciph
.ciphprovctx
!= NULL
)
168 || (EVP_PKEY_CTX_IS_GEN_OP(ctx
)
169 && ctx
->op
.keymgmt
.genctx
!= NULL
)
170 || (EVP_PKEY_CTX_IS_KEM_OP(ctx
)
171 && ctx
->op
.encap
.kemprovctx
!= NULL
))
172 return EVP_PKEY_STATE_PROVIDER
;
174 return EVP_PKEY_STATE_LEGACY
;
177 static EVP_PKEY_CTX
*int_ctx_new(OSSL_LIB_CTX
*libctx
,
178 EVP_PKEY
*pkey
, ENGINE
*e
,
179 const char *keytype
, const char *propquery
,
183 EVP_PKEY_CTX
*ret
= NULL
;
184 const EVP_PKEY_METHOD
*pmeth
= NULL
;
185 EVP_KEYMGMT
*keymgmt
= NULL
;
188 * If the given |pkey| is provided, we extract the keytype from its
189 * keymgmt and skip over the legacy code.
191 if (pkey
!= NULL
&& evp_pkey_is_provided(pkey
)) {
192 /* If we have an engine, something went wrong somewhere... */
193 if (!ossl_assert(e
== NULL
))
195 keytype
= evp_first_name(pkey
->keymgmt
->prov
, pkey
->keymgmt
->name_id
);
200 /* Code below to be removed when legacy support is dropped. */
205 else if (keytype
!= NULL
)
206 id
= evp_pkey_name2type(keytype
);
210 /* If no ID was found here, we can only resort to find a keymgmt */
215 * Here, we extract what information we can for the purpose of
216 * supporting usage with implementations from providers, to make
217 * for a smooth transition from legacy stuff to provider based stuff.
219 * If an engine is given, this is entirely legacy, and we should not
220 * pretend anything else, so we only set the name when no engine is
221 * given. If both are already given, someone made a mistake, and
222 * since that can only happen internally, it's safe to make an
225 if (!ossl_assert(e
== NULL
|| keytype
== NULL
))
228 keytype
= OBJ_nid2sn(id
);
230 # ifndef OPENSSL_NO_ENGINE
231 if (e
== NULL
&& pkey
!= NULL
)
232 e
= pkey
->pmeth_engine
!= NULL
? pkey
->pmeth_engine
: pkey
->engine
;
233 /* Try to find an ENGINE which implements this method */
235 if (!ENGINE_init(e
)) {
236 ERR_raise(ERR_LIB_EVP
, ERR_R_ENGINE_LIB
);
240 e
= ENGINE_get_pkey_meth_engine(id
);
244 * If an ENGINE handled this method look it up. Otherwise use internal
248 pmeth
= ENGINE_get_pkey_meth(e
, id
);
251 pmeth
= evp_pkey_meth_find_added_by_application(id
);
254 #endif /* FIPS_MODULE */
257 * If there's no engine and there's a name, we try fetching a provider
260 if (e
== NULL
&& keytype
!= NULL
) {
261 keymgmt
= EVP_KEYMGMT_fetch(libctx
, keytype
, propquery
);
263 return NULL
; /* EVP_KEYMGMT_fetch() recorded an error */
267 * Chase down the legacy NID, as that might be needed for diverse
268 * purposes, such as ensure that EVP_PKEY_type() can return sensible
269 * values. We go through all keymgmt names, because the keytype
270 * that's passed to this function doesn't necessarily translate
272 * TODO: Remove this when #legacy keys are gone.
274 if (keymgmt
!= NULL
) {
275 int tmp_id
= get_legacy_alg_type_from_keymgmt(keymgmt
);
277 if (tmp_id
!= NID_undef
) {
282 * It really really shouldn't differ. If it still does,
283 * something is very wrong.
285 if (!ossl_assert(id
== tmp_id
)) {
286 ERR_raise(ERR_LIB_EVP
, ERR_R_INTERNAL_ERROR
);
287 EVP_KEYMGMT_free(keymgmt
);
296 if (pmeth
== NULL
&& keymgmt
== NULL
) {
297 ERR_raise(ERR_LIB_EVP
, EVP_R_UNSUPPORTED_ALGORITHM
);
299 ret
= OPENSSL_zalloc(sizeof(*ret
));
301 ERR_raise(ERR_LIB_EVP
, ERR_R_MALLOC_FAILURE
);
304 #if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE)
305 if ((ret
== NULL
|| pmeth
== NULL
) && e
!= NULL
)
310 EVP_KEYMGMT_free(keymgmt
);
313 if (propquery
!= NULL
) {
314 ret
->propquery
= OPENSSL_strdup(propquery
);
315 if (ret
->propquery
== NULL
) {
316 EVP_KEYMGMT_free(keymgmt
);
320 ret
->libctx
= libctx
;
321 ret
->keytype
= keytype
;
322 ret
->keymgmt
= keymgmt
;
323 ret
->legacy_keytype
= id
; /* TODO: Remove when #legacy key are gone */
326 ret
->operation
= EVP_PKEY_OP_UNDEFINED
;
329 EVP_PKEY_up_ref(pkey
);
331 if (pmeth
!= NULL
&& pmeth
->init
!= NULL
) {
332 if (pmeth
->init(ret
) <= 0) {
334 EVP_PKEY_CTX_free(ret
);
342 /*- All methods below can also be used in FIPS_MODULE */
344 EVP_PKEY_CTX
*EVP_PKEY_CTX_new_from_name(OSSL_LIB_CTX
*libctx
,
346 const char *propquery
)
348 return int_ctx_new(libctx
, NULL
, NULL
, name
, propquery
, -1);
351 EVP_PKEY_CTX
*EVP_PKEY_CTX_new_from_pkey(OSSL_LIB_CTX
*libctx
, EVP_PKEY
*pkey
,
352 const char *propquery
)
354 return int_ctx_new(libctx
, pkey
, NULL
, NULL
, propquery
, -1);
357 void evp_pkey_ctx_free_old_ops(EVP_PKEY_CTX
*ctx
)
359 if (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx
)) {
360 if (ctx
->op
.sig
.sigprovctx
!= NULL
&& ctx
->op
.sig
.signature
!= NULL
)
361 ctx
->op
.sig
.signature
->freectx(ctx
->op
.sig
.sigprovctx
);
362 EVP_SIGNATURE_free(ctx
->op
.sig
.signature
);
363 ctx
->op
.sig
.sigprovctx
= NULL
;
364 ctx
->op
.sig
.signature
= NULL
;
365 } else if (EVP_PKEY_CTX_IS_DERIVE_OP(ctx
)) {
366 if (ctx
->op
.kex
.exchprovctx
!= NULL
&& ctx
->op
.kex
.exchange
!= NULL
)
367 ctx
->op
.kex
.exchange
->freectx(ctx
->op
.kex
.exchprovctx
);
368 EVP_KEYEXCH_free(ctx
->op
.kex
.exchange
);
369 ctx
->op
.kex
.exchprovctx
= NULL
;
370 ctx
->op
.kex
.exchange
= NULL
;
371 } else if (EVP_PKEY_CTX_IS_KEM_OP(ctx
)) {
372 if (ctx
->op
.encap
.kemprovctx
!= NULL
&& ctx
->op
.encap
.kem
!= NULL
)
373 ctx
->op
.encap
.kem
->freectx(ctx
->op
.encap
.kemprovctx
);
374 EVP_KEM_free(ctx
->op
.encap
.kem
);
375 ctx
->op
.encap
.kemprovctx
= NULL
;
376 ctx
->op
.encap
.kem
= NULL
;
378 else if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx
)) {
379 if (ctx
->op
.ciph
.ciphprovctx
!= NULL
&& ctx
->op
.ciph
.cipher
!= NULL
)
380 ctx
->op
.ciph
.cipher
->freectx(ctx
->op
.ciph
.ciphprovctx
);
381 EVP_ASYM_CIPHER_free(ctx
->op
.ciph
.cipher
);
382 ctx
->op
.ciph
.ciphprovctx
= NULL
;
383 ctx
->op
.ciph
.cipher
= NULL
;
384 } else if (EVP_PKEY_CTX_IS_GEN_OP(ctx
)) {
385 if (ctx
->op
.keymgmt
.genctx
!= NULL
&& ctx
->keymgmt
!= NULL
)
386 evp_keymgmt_gen_cleanup(ctx
->keymgmt
, ctx
->op
.keymgmt
.genctx
);
390 void EVP_PKEY_CTX_free(EVP_PKEY_CTX
*ctx
)
394 if (ctx
->pmeth
&& ctx
->pmeth
->cleanup
)
395 ctx
->pmeth
->cleanup(ctx
);
397 evp_pkey_ctx_free_old_ops(ctx
);
399 evp_pkey_ctx_free_all_cached_data(ctx
);
401 EVP_KEYMGMT_free(ctx
->keymgmt
);
403 OPENSSL_free(ctx
->propquery
);
404 EVP_PKEY_free(ctx
->pkey
);
405 EVP_PKEY_free(ctx
->peerkey
);
406 #if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE)
407 ENGINE_finish(ctx
->engine
);
409 BN_free(ctx
->rsa_pubexp
);
415 void EVP_PKEY_meth_get0_info(int *ppkey_id
, int *pflags
,
416 const EVP_PKEY_METHOD
*meth
)
419 *ppkey_id
= meth
->pkey_id
;
421 *pflags
= meth
->flags
;
424 void EVP_PKEY_meth_copy(EVP_PKEY_METHOD
*dst
, const EVP_PKEY_METHOD
*src
)
426 int pkey_id
= dst
->pkey_id
;
427 int flags
= dst
->flags
;
431 /* We only copy the function pointers so restore the other values */
432 dst
->pkey_id
= pkey_id
;
436 void EVP_PKEY_meth_free(EVP_PKEY_METHOD
*pmeth
)
438 if (pmeth
&& (pmeth
->flags
& EVP_PKEY_FLAG_DYNAMIC
))
442 EVP_PKEY_CTX
*EVP_PKEY_CTX_new(EVP_PKEY
*pkey
, ENGINE
*e
)
444 return int_ctx_new(NULL
, pkey
, e
, NULL
, NULL
, -1);
447 EVP_PKEY_CTX
*EVP_PKEY_CTX_new_id(int id
, ENGINE
*e
)
449 return int_ctx_new(NULL
, NULL
, e
, NULL
, NULL
, id
);
452 EVP_PKEY_CTX
*EVP_PKEY_CTX_dup(const EVP_PKEY_CTX
*pctx
)
456 # ifndef OPENSSL_NO_ENGINE
457 /* Make sure it's safe to copy a pkey context using an ENGINE */
458 if (pctx
->engine
&& !ENGINE_init(pctx
->engine
)) {
459 ERR_raise(ERR_LIB_EVP
, ERR_R_ENGINE_LIB
);
463 rctx
= OPENSSL_zalloc(sizeof(*rctx
));
465 ERR_raise(ERR_LIB_EVP
, ERR_R_MALLOC_FAILURE
);
469 if (pctx
->pkey
!= NULL
)
470 EVP_PKEY_up_ref(pctx
->pkey
);
471 rctx
->pkey
= pctx
->pkey
;
472 rctx
->operation
= pctx
->operation
;
473 rctx
->libctx
= pctx
->libctx
;
474 rctx
->keytype
= pctx
->keytype
;
475 rctx
->propquery
= NULL
;
476 if (pctx
->propquery
!= NULL
) {
477 rctx
->propquery
= OPENSSL_strdup(pctx
->propquery
);
478 if (rctx
->propquery
== NULL
)
481 rctx
->legacy_keytype
= pctx
->legacy_keytype
;
483 if (EVP_PKEY_CTX_IS_DERIVE_OP(pctx
)) {
484 if (pctx
->op
.kex
.exchange
!= NULL
) {
485 rctx
->op
.kex
.exchange
= pctx
->op
.kex
.exchange
;
486 if (!EVP_KEYEXCH_up_ref(rctx
->op
.kex
.exchange
))
489 if (pctx
->op
.kex
.exchprovctx
!= NULL
) {
490 if (!ossl_assert(pctx
->op
.kex
.exchange
!= NULL
))
492 rctx
->op
.kex
.exchprovctx
493 = pctx
->op
.kex
.exchange
->dupctx(pctx
->op
.kex
.exchprovctx
);
494 if (rctx
->op
.kex
.exchprovctx
== NULL
) {
495 EVP_KEYEXCH_free(rctx
->op
.kex
.exchange
);
500 } else if (EVP_PKEY_CTX_IS_SIGNATURE_OP(pctx
)) {
501 if (pctx
->op
.sig
.signature
!= NULL
) {
502 rctx
->op
.sig
.signature
= pctx
->op
.sig
.signature
;
503 if (!EVP_SIGNATURE_up_ref(rctx
->op
.sig
.signature
))
506 if (pctx
->op
.sig
.sigprovctx
!= NULL
) {
507 if (!ossl_assert(pctx
->op
.sig
.signature
!= NULL
))
509 rctx
->op
.sig
.sigprovctx
510 = pctx
->op
.sig
.signature
->dupctx(pctx
->op
.sig
.sigprovctx
);
511 if (rctx
->op
.sig
.sigprovctx
== NULL
) {
512 EVP_SIGNATURE_free(rctx
->op
.sig
.signature
);
517 } else if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(pctx
)) {
518 if (pctx
->op
.ciph
.cipher
!= NULL
) {
519 rctx
->op
.ciph
.cipher
= pctx
->op
.ciph
.cipher
;
520 if (!EVP_ASYM_CIPHER_up_ref(rctx
->op
.ciph
.cipher
))
523 if (pctx
->op
.ciph
.ciphprovctx
!= NULL
) {
524 if (!ossl_assert(pctx
->op
.ciph
.cipher
!= NULL
))
526 rctx
->op
.ciph
.ciphprovctx
527 = pctx
->op
.ciph
.cipher
->dupctx(pctx
->op
.ciph
.ciphprovctx
);
528 if (rctx
->op
.ciph
.ciphprovctx
== NULL
) {
529 EVP_ASYM_CIPHER_free(rctx
->op
.ciph
.cipher
);
534 } else if (EVP_PKEY_CTX_IS_KEM_OP(pctx
)) {
535 if (pctx
->op
.encap
.kem
!= NULL
) {
536 rctx
->op
.encap
.kem
= pctx
->op
.encap
.kem
;
537 if (!EVP_KEM_up_ref(rctx
->op
.encap
.kem
))
540 if (pctx
->op
.encap
.kemprovctx
!= NULL
) {
541 if (!ossl_assert(pctx
->op
.encap
.kem
!= NULL
))
543 rctx
->op
.encap
.kemprovctx
544 = pctx
->op
.encap
.kem
->dupctx(pctx
->op
.encap
.kemprovctx
);
545 if (rctx
->op
.encap
.kemprovctx
== NULL
) {
546 EVP_KEM_free(rctx
->op
.encap
.kem
);
551 } else if (EVP_PKEY_CTX_IS_GEN_OP(pctx
)) {
552 /* Not supported - This would need a gen_dupctx() to work */
556 rctx
->pmeth
= pctx
->pmeth
;
557 # ifndef OPENSSL_NO_ENGINE
558 rctx
->engine
= pctx
->engine
;
561 if (pctx
->peerkey
!= NULL
)
562 EVP_PKEY_up_ref(pctx
->peerkey
);
563 rctx
->peerkey
= pctx
->peerkey
;
565 if (pctx
->pmeth
== NULL
) {
566 if (rctx
->operation
== EVP_PKEY_OP_UNDEFINED
) {
567 EVP_KEYMGMT
*tmp_keymgmt
= pctx
->keymgmt
;
570 provkey
= evp_pkey_export_to_provider(pctx
->pkey
, pctx
->libctx
,
571 &tmp_keymgmt
, pctx
->propquery
);
574 if (!EVP_KEYMGMT_up_ref(tmp_keymgmt
))
576 EVP_KEYMGMT_free(rctx
->keymgmt
);
577 rctx
->keymgmt
= tmp_keymgmt
;
580 } else if (pctx
->pmeth
->copy(rctx
, pctx
) > 0) {
585 EVP_PKEY_CTX_free(rctx
);
589 int EVP_PKEY_meth_add0(const EVP_PKEY_METHOD
*pmeth
)
591 if (app_pkey_methods
== NULL
) {
592 app_pkey_methods
= sk_EVP_PKEY_METHOD_new(pmeth_cmp
);
593 if (app_pkey_methods
== NULL
){
594 ERR_raise(ERR_LIB_EVP
, ERR_R_MALLOC_FAILURE
);
598 if (!sk_EVP_PKEY_METHOD_push(app_pkey_methods
, pmeth
)) {
599 ERR_raise(ERR_LIB_EVP
, ERR_R_MALLOC_FAILURE
);
602 sk_EVP_PKEY_METHOD_sort(app_pkey_methods
);
606 void evp_app_cleanup_int(void)
608 if (app_pkey_methods
!= NULL
)
609 sk_EVP_PKEY_METHOD_pop_free(app_pkey_methods
, EVP_PKEY_meth_free
);
612 int EVP_PKEY_meth_remove(const EVP_PKEY_METHOD
*pmeth
)
614 const EVP_PKEY_METHOD
*ret
;
616 ret
= sk_EVP_PKEY_METHOD_delete_ptr(app_pkey_methods
, pmeth
);
618 return ret
== NULL
? 0 : 1;
621 size_t EVP_PKEY_meth_get_count(void)
623 size_t rv
= OSSL_NELEM(standard_methods
);
625 if (app_pkey_methods
)
626 rv
+= sk_EVP_PKEY_METHOD_num(app_pkey_methods
);
630 const EVP_PKEY_METHOD
*EVP_PKEY_meth_get0(size_t idx
)
632 if (idx
< OSSL_NELEM(standard_methods
))
633 return (standard_methods
[idx
])();
634 if (app_pkey_methods
== NULL
)
636 idx
-= OSSL_NELEM(standard_methods
);
637 if (idx
>= (size_t)sk_EVP_PKEY_METHOD_num(app_pkey_methods
))
639 return sk_EVP_PKEY_METHOD_value(app_pkey_methods
, idx
);
643 int EVP_PKEY_CTX_is_a(EVP_PKEY_CTX
*ctx
, const char *keytype
)
646 if (evp_pkey_ctx_is_legacy(ctx
))
647 return (ctx
->pmeth
->pkey_id
== evp_pkey_name2type(keytype
));
649 return EVP_KEYMGMT_is_a(ctx
->keymgmt
, keytype
);
652 int EVP_PKEY_CTX_set_params(EVP_PKEY_CTX
*ctx
, OSSL_PARAM
*params
)
654 switch (evp_pkey_ctx_state(ctx
)) {
655 case EVP_PKEY_STATE_PROVIDER
:
656 if (EVP_PKEY_CTX_IS_DERIVE_OP(ctx
)
657 && ctx
->op
.kex
.exchange
!= NULL
658 && ctx
->op
.kex
.exchange
->set_ctx_params
!= NULL
)
660 ctx
->op
.kex
.exchange
->set_ctx_params(ctx
->op
.kex
.exchprovctx
,
662 if (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx
)
663 && ctx
->op
.sig
.signature
!= NULL
664 && ctx
->op
.sig
.signature
->set_ctx_params
!= NULL
)
666 ctx
->op
.sig
.signature
->set_ctx_params(ctx
->op
.sig
.sigprovctx
,
668 if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx
)
669 && ctx
->op
.ciph
.cipher
!= NULL
670 && ctx
->op
.ciph
.cipher
->set_ctx_params
!= NULL
)
672 ctx
->op
.ciph
.cipher
->set_ctx_params(ctx
->op
.ciph
.ciphprovctx
,
674 if (EVP_PKEY_CTX_IS_GEN_OP(ctx
)
675 && ctx
->keymgmt
!= NULL
676 && ctx
->keymgmt
->gen_set_params
!= NULL
)
678 evp_keymgmt_gen_set_params(ctx
->keymgmt
, ctx
->op
.keymgmt
.genctx
,
680 if (EVP_PKEY_CTX_IS_KEM_OP(ctx
)
681 && ctx
->op
.encap
.kem
!= NULL
682 && ctx
->op
.encap
.kem
->set_ctx_params
!= NULL
)
684 ctx
->op
.encap
.kem
->set_ctx_params(ctx
->op
.encap
.kemprovctx
,
688 case EVP_PKEY_STATE_UNKNOWN
:
689 case EVP_PKEY_STATE_LEGACY
:
690 return evp_pkey_ctx_set_params_to_ctrl(ctx
, params
);
696 int EVP_PKEY_CTX_get_params(EVP_PKEY_CTX
*ctx
, OSSL_PARAM
*params
)
698 switch (evp_pkey_ctx_state(ctx
)) {
699 case EVP_PKEY_STATE_PROVIDER
:
700 if (EVP_PKEY_CTX_IS_DERIVE_OP(ctx
)
701 && ctx
->op
.kex
.exchange
!= NULL
702 && ctx
->op
.kex
.exchange
->get_ctx_params
!= NULL
)
704 ctx
->op
.kex
.exchange
->get_ctx_params(ctx
->op
.kex
.exchprovctx
,
706 if (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx
)
707 && ctx
->op
.sig
.signature
!= NULL
708 && ctx
->op
.sig
.signature
->get_ctx_params
!= NULL
)
710 ctx
->op
.sig
.signature
->get_ctx_params(ctx
->op
.sig
.sigprovctx
,
712 if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx
)
713 && ctx
->op
.ciph
.cipher
!= NULL
714 && ctx
->op
.ciph
.cipher
->get_ctx_params
!= NULL
)
716 ctx
->op
.ciph
.cipher
->get_ctx_params(ctx
->op
.ciph
.ciphprovctx
,
718 if (EVP_PKEY_CTX_IS_KEM_OP(ctx
)
719 && ctx
->op
.encap
.kem
!= NULL
720 && ctx
->op
.encap
.kem
->get_ctx_params
!= NULL
)
722 ctx
->op
.encap
.kem
->get_ctx_params(ctx
->op
.encap
.kemprovctx
,
726 case EVP_PKEY_STATE_UNKNOWN
:
727 case EVP_PKEY_STATE_LEGACY
:
728 return evp_pkey_ctx_get_params_to_ctrl(ctx
, params
);
735 const OSSL_PARAM
*EVP_PKEY_CTX_gettable_params(EVP_PKEY_CTX
*ctx
)
739 if (EVP_PKEY_CTX_IS_DERIVE_OP(ctx
)
740 && ctx
->op
.kex
.exchange
!= NULL
741 && ctx
->op
.kex
.exchange
->gettable_ctx_params
!= NULL
) {
742 provctx
= ossl_provider_ctx(EVP_KEYEXCH_provider(ctx
->op
.kex
.exchange
));
743 return ctx
->op
.kex
.exchange
->gettable_ctx_params(ctx
->op
.kex
.exchprovctx
,
746 if (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx
)
747 && ctx
->op
.sig
.signature
!= NULL
748 && ctx
->op
.sig
.signature
->gettable_ctx_params
!= NULL
) {
749 provctx
= ossl_provider_ctx(
750 EVP_SIGNATURE_provider(ctx
->op
.sig
.signature
));
751 return ctx
->op
.sig
.signature
->gettable_ctx_params(ctx
->op
.sig
.sigprovctx
,
754 if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx
)
755 && ctx
->op
.ciph
.cipher
!= NULL
756 && ctx
->op
.ciph
.cipher
->gettable_ctx_params
!= NULL
) {
757 provctx
= ossl_provider_ctx(
758 EVP_ASYM_CIPHER_provider(ctx
->op
.ciph
.cipher
));
759 return ctx
->op
.ciph
.cipher
->gettable_ctx_params(ctx
->op
.ciph
.ciphprovctx
,
762 if (EVP_PKEY_CTX_IS_KEM_OP(ctx
)
763 && ctx
->op
.encap
.kem
!= NULL
764 && ctx
->op
.encap
.kem
->gettable_ctx_params
!= NULL
) {
765 provctx
= ossl_provider_ctx(EVP_KEM_provider(ctx
->op
.encap
.kem
));
766 return ctx
->op
.encap
.kem
->gettable_ctx_params(ctx
->op
.encap
.kemprovctx
,
772 const OSSL_PARAM
*EVP_PKEY_CTX_settable_params(EVP_PKEY_CTX
*ctx
)
776 if (EVP_PKEY_CTX_IS_DERIVE_OP(ctx
)
777 && ctx
->op
.kex
.exchange
!= NULL
778 && ctx
->op
.kex
.exchange
->settable_ctx_params
!= NULL
) {
779 provctx
= ossl_provider_ctx(EVP_KEYEXCH_provider(ctx
->op
.kex
.exchange
));
780 return ctx
->op
.kex
.exchange
->settable_ctx_params(ctx
->op
.kex
.exchprovctx
,
783 if (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx
)
784 && ctx
->op
.sig
.signature
!= NULL
785 && ctx
->op
.sig
.signature
->settable_ctx_params
!= NULL
) {
786 provctx
= ossl_provider_ctx(
787 EVP_SIGNATURE_provider(ctx
->op
.sig
.signature
));
788 return ctx
->op
.sig
.signature
->settable_ctx_params(ctx
->op
.sig
.sigprovctx
,
791 if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx
)
792 && ctx
->op
.ciph
.cipher
!= NULL
793 && ctx
->op
.ciph
.cipher
->settable_ctx_params
!= NULL
) {
794 provctx
= ossl_provider_ctx(
795 EVP_ASYM_CIPHER_provider(ctx
->op
.ciph
.cipher
));
796 return ctx
->op
.ciph
.cipher
->settable_ctx_params(ctx
->op
.ciph
.ciphprovctx
,
799 if (EVP_PKEY_CTX_IS_GEN_OP(ctx
)
800 && ctx
->keymgmt
!= NULL
801 && ctx
->keymgmt
->gen_settable_params
!= NULL
) {
802 provctx
= ossl_provider_ctx(EVP_KEYMGMT_provider(ctx
->keymgmt
));
803 return ctx
->keymgmt
->gen_settable_params(ctx
->op
.keymgmt
.genctx
,
806 if (EVP_PKEY_CTX_IS_KEM_OP(ctx
)
807 && ctx
->op
.encap
.kem
!= NULL
808 && ctx
->op
.encap
.kem
->settable_ctx_params
!= NULL
) {
809 provctx
= ossl_provider_ctx(EVP_KEM_provider(ctx
->op
.encap
.kem
));
810 return ctx
->op
.encap
.kem
->settable_ctx_params(ctx
->op
.encap
.kemprovctx
,
817 * Internal helpers for stricter EVP_PKEY_CTX_{set,get}_params().
819 * Return 1 on success, 0 or negative for errors.
821 * In particular they return -2 if any of the params is not supported.
823 * They are not available in FIPS_MODULE as they depend on
824 * - EVP_PKEY_CTX_{get,set}_params()
825 * - EVP_PKEY_CTX_{gettable,settable}_params()
828 int evp_pkey_ctx_set_params_strict(EVP_PKEY_CTX
*ctx
, OSSL_PARAM
*params
)
830 if (ctx
== NULL
|| params
== NULL
)
834 * We only check for provider side EVP_PKEY_CTX. For #legacy, we
835 * depend on the translation that happens in EVP_PKEY_CTX_set_params()
836 * call, and that the resulting ctrl call will return -2 if it doesn't
837 * known the ctrl command number.
839 if (evp_pkey_ctx_is_provided(ctx
)) {
840 const OSSL_PARAM
*settable
= EVP_PKEY_CTX_settable_params(ctx
);
843 for (p
= params
; p
->key
!= NULL
; p
++) {
844 /* Check the ctx actually understands this parameter */
845 if (OSSL_PARAM_locate_const(settable
, p
->key
) == NULL
)
850 return EVP_PKEY_CTX_set_params(ctx
, params
);
853 int evp_pkey_ctx_get_params_strict(EVP_PKEY_CTX
*ctx
, OSSL_PARAM
*params
)
855 if (ctx
== NULL
|| params
== NULL
)
859 * We only check for provider side EVP_PKEY_CTX. For #legacy, we
860 * depend on the translation that happens in EVP_PKEY_CTX_get_params()
861 * call, and that the resulting ctrl call will return -2 if it doesn't
862 * known the ctrl command number.
864 if (evp_pkey_ctx_is_provided(ctx
)) {
865 const OSSL_PARAM
*gettable
= EVP_PKEY_CTX_gettable_params(ctx
);
868 for (p
= params
; p
->key
!= NULL
; p
++ ) {
869 /* Check the ctx actually understands this parameter */
870 if (OSSL_PARAM_locate_const(gettable
, p
->key
) == NULL
)
875 return EVP_PKEY_CTX_get_params(ctx
, params
);
878 /* TODO(3.0): Deprecate in favour of get_signature_md_name */
879 int EVP_PKEY_CTX_get_signature_md(EVP_PKEY_CTX
*ctx
, const EVP_MD
**md
)
881 OSSL_PARAM sig_md_params
[2], *p
= sig_md_params
;
882 /* 80 should be big enough */
886 if (ctx
== NULL
|| !EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx
)) {
887 ERR_raise(ERR_LIB_EVP
, EVP_R_COMMAND_NOT_SUPPORTED
);
888 /* Uses the same return values as EVP_PKEY_CTX_ctrl */
892 if (ctx
->op
.sig
.sigprovctx
== NULL
)
893 return EVP_PKEY_CTX_ctrl(ctx
, -1, EVP_PKEY_OP_TYPE_SIG
,
894 EVP_PKEY_CTRL_GET_MD
, 0, (void *)(md
));
896 *p
++ = OSSL_PARAM_construct_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST
,
899 *p
= OSSL_PARAM_construct_end();
901 if (!EVP_PKEY_CTX_get_params(ctx
, sig_md_params
))
904 tmp
= evp_get_digestbyname_ex(ctx
->libctx
, name
);
914 * TODO(3.0): Deprecate functions calling this in favour of
915 * functions setting md name.
917 static int evp_pkey_ctx_set_md(EVP_PKEY_CTX
*ctx
, const EVP_MD
*md
,
918 int fallback
, const char *param
, int op
,
921 OSSL_PARAM md_params
[2], *p
= md_params
;
924 if (ctx
== NULL
|| (ctx
->operation
& op
) == 0) {
925 ERR_raise(ERR_LIB_EVP
, EVP_R_COMMAND_NOT_SUPPORTED
);
926 /* Uses the same return values as EVP_PKEY_CTX_ctrl */
931 return EVP_PKEY_CTX_ctrl(ctx
, -1, op
, ctrl
, 0, (void *)(md
));
936 name
= EVP_MD_name(md
);
939 *p
++ = OSSL_PARAM_construct_utf8_string(param
,
941 * Cast away the const. This is read
942 * only so should be safe
945 *p
= OSSL_PARAM_construct_end();
947 return EVP_PKEY_CTX_set_params(ctx
, md_params
);
950 int EVP_PKEY_CTX_set_signature_md(EVP_PKEY_CTX
*ctx
, const EVP_MD
*md
)
952 return evp_pkey_ctx_set_md(ctx
, md
, ctx
->op
.sig
.sigprovctx
== NULL
,
953 OSSL_SIGNATURE_PARAM_DIGEST
,
954 EVP_PKEY_OP_TYPE_SIG
, EVP_PKEY_CTRL_MD
);
957 int EVP_PKEY_CTX_set_tls1_prf_md(EVP_PKEY_CTX
*ctx
, const EVP_MD
*md
)
959 return evp_pkey_ctx_set_md(ctx
, md
, ctx
->op
.kex
.exchprovctx
== NULL
,
960 OSSL_KDF_PARAM_DIGEST
,
961 EVP_PKEY_OP_DERIVE
, EVP_PKEY_CTRL_TLS_MD
);
964 static int evp_pkey_ctx_set1_octet_string(EVP_PKEY_CTX
*ctx
, int fallback
,
965 const char *param
, int op
, int ctrl
,
966 const unsigned char *data
,
969 OSSL_PARAM octet_string_params
[2], *p
= octet_string_params
;
971 if (ctx
== NULL
|| (ctx
->operation
& op
) == 0) {
972 ERR_raise(ERR_LIB_EVP
, EVP_R_COMMAND_NOT_SUPPORTED
);
973 /* Uses the same return values as EVP_PKEY_CTX_ctrl */
977 /* Code below to be removed when legacy support is dropped. */
979 return EVP_PKEY_CTX_ctrl(ctx
, -1, op
, ctrl
, datalen
, (void *)(data
));
980 /* end of legacy support */
983 ERR_raise(ERR_LIB_EVP
, EVP_R_INVALID_LENGTH
);
987 *p
++ = OSSL_PARAM_construct_octet_string(param
,
989 * Cast away the const. This is read
990 * only so should be safe
992 (unsigned char *)data
,
994 *p
= OSSL_PARAM_construct_end();
996 return EVP_PKEY_CTX_set_params(ctx
, octet_string_params
);
999 int EVP_PKEY_CTX_set1_tls1_prf_secret(EVP_PKEY_CTX
*ctx
,
1000 const unsigned char *sec
, int seclen
)
1002 return evp_pkey_ctx_set1_octet_string(ctx
, ctx
->op
.kex
.exchprovctx
== NULL
,
1003 OSSL_KDF_PARAM_SECRET
,
1005 EVP_PKEY_CTRL_TLS_SECRET
,
1009 int EVP_PKEY_CTX_add1_tls1_prf_seed(EVP_PKEY_CTX
*ctx
,
1010 const unsigned char *seed
, int seedlen
)
1012 return evp_pkey_ctx_set1_octet_string(ctx
, ctx
->op
.kex
.exchprovctx
== NULL
,
1013 OSSL_KDF_PARAM_SEED
,
1015 EVP_PKEY_CTRL_TLS_SEED
,
1019 int EVP_PKEY_CTX_set_hkdf_md(EVP_PKEY_CTX
*ctx
, const EVP_MD
*md
)
1021 return evp_pkey_ctx_set_md(ctx
, md
, ctx
->op
.kex
.exchprovctx
== NULL
,
1022 OSSL_KDF_PARAM_DIGEST
,
1023 EVP_PKEY_OP_DERIVE
, EVP_PKEY_CTRL_HKDF_MD
);
1026 int EVP_PKEY_CTX_set1_hkdf_salt(EVP_PKEY_CTX
*ctx
,
1027 const unsigned char *salt
, int saltlen
)
1029 return evp_pkey_ctx_set1_octet_string(ctx
, ctx
->op
.kex
.exchprovctx
== NULL
,
1030 OSSL_KDF_PARAM_SALT
,
1032 EVP_PKEY_CTRL_HKDF_SALT
,
1036 int EVP_PKEY_CTX_set1_hkdf_key(EVP_PKEY_CTX
*ctx
,
1037 const unsigned char *key
, int keylen
)
1039 return evp_pkey_ctx_set1_octet_string(ctx
, ctx
->op
.kex
.exchprovctx
== NULL
,
1042 EVP_PKEY_CTRL_HKDF_KEY
,
1046 int EVP_PKEY_CTX_add1_hkdf_info(EVP_PKEY_CTX
*ctx
,
1047 const unsigned char *info
, int infolen
)
1049 return evp_pkey_ctx_set1_octet_string(ctx
, ctx
->op
.kex
.exchprovctx
== NULL
,
1050 OSSL_KDF_PARAM_INFO
,
1052 EVP_PKEY_CTRL_HKDF_INFO
,
1056 int EVP_PKEY_CTX_hkdf_mode(EVP_PKEY_CTX
*ctx
, int mode
)
1058 OSSL_PARAM int_params
[2], *p
= int_params
;
1060 if (ctx
== NULL
|| !EVP_PKEY_CTX_IS_DERIVE_OP(ctx
)) {
1061 ERR_raise(ERR_LIB_EVP
, EVP_R_COMMAND_NOT_SUPPORTED
);
1062 /* Uses the same return values as EVP_PKEY_CTX_ctrl */
1066 /* Code below to be removed when legacy support is dropped. */
1067 if (ctx
->op
.kex
.exchprovctx
== NULL
)
1068 return EVP_PKEY_CTX_ctrl(ctx
, -1, EVP_PKEY_OP_DERIVE
,
1069 EVP_PKEY_CTRL_HKDF_MODE
, mode
, NULL
);
1070 /* end of legacy support */
1073 ERR_raise(ERR_LIB_EVP
, EVP_R_INVALID_VALUE
);
1077 *p
++ = OSSL_PARAM_construct_int(OSSL_KDF_PARAM_MODE
, &mode
);
1078 *p
= OSSL_PARAM_construct_end();
1080 return EVP_PKEY_CTX_set_params(ctx
, int_params
);
1083 int EVP_PKEY_CTX_set1_pbe_pass(EVP_PKEY_CTX
*ctx
, const char *pass
,
1086 return evp_pkey_ctx_set1_octet_string(ctx
, ctx
->op
.kex
.exchprovctx
== NULL
,
1087 OSSL_KDF_PARAM_PASSWORD
,
1090 (const unsigned char *)pass
, passlen
);
1093 int EVP_PKEY_CTX_set1_scrypt_salt(EVP_PKEY_CTX
*ctx
,
1094 const unsigned char *salt
, int saltlen
)
1096 return evp_pkey_ctx_set1_octet_string(ctx
, ctx
->op
.kex
.exchprovctx
== NULL
,
1097 OSSL_KDF_PARAM_SALT
,
1099 EVP_PKEY_CTRL_SCRYPT_SALT
,
1103 static int evp_pkey_ctx_set_uint64(EVP_PKEY_CTX
*ctx
, const char *param
,
1104 int op
, int ctrl
, uint64_t val
)
1106 OSSL_PARAM uint64_params
[2], *p
= uint64_params
;
1108 if (ctx
== NULL
|| !EVP_PKEY_CTX_IS_DERIVE_OP(ctx
)) {
1109 ERR_raise(ERR_LIB_EVP
, EVP_R_COMMAND_NOT_SUPPORTED
);
1110 /* Uses the same return values as EVP_PKEY_CTX_ctrl */
1114 /* Code below to be removed when legacy support is dropped. */
1115 if (ctx
->op
.kex
.exchprovctx
== NULL
)
1116 return EVP_PKEY_CTX_ctrl_uint64(ctx
, -1, op
, ctrl
, val
);
1117 /* end of legacy support */
1119 *p
++ = OSSL_PARAM_construct_uint64(param
, &val
);
1120 *p
= OSSL_PARAM_construct_end();
1122 return EVP_PKEY_CTX_set_params(ctx
, uint64_params
);
1125 int EVP_PKEY_CTX_set_scrypt_N(EVP_PKEY_CTX
*ctx
, uint64_t n
)
1127 return evp_pkey_ctx_set_uint64(ctx
, OSSL_KDF_PARAM_SCRYPT_N
,
1128 EVP_PKEY_OP_DERIVE
, EVP_PKEY_CTRL_SCRYPT_N
,
1132 int EVP_PKEY_CTX_set_scrypt_r(EVP_PKEY_CTX
*ctx
, uint64_t r
)
1134 return evp_pkey_ctx_set_uint64(ctx
, OSSL_KDF_PARAM_SCRYPT_R
,
1135 EVP_PKEY_OP_DERIVE
, EVP_PKEY_CTRL_SCRYPT_R
,
1139 int EVP_PKEY_CTX_set_scrypt_p(EVP_PKEY_CTX
*ctx
, uint64_t p
)
1141 return evp_pkey_ctx_set_uint64(ctx
, OSSL_KDF_PARAM_SCRYPT_P
,
1142 EVP_PKEY_OP_DERIVE
, EVP_PKEY_CTRL_SCRYPT_P
,
1146 int EVP_PKEY_CTX_set_scrypt_maxmem_bytes(EVP_PKEY_CTX
*ctx
,
1147 uint64_t maxmem_bytes
)
1149 return evp_pkey_ctx_set_uint64(ctx
, OSSL_KDF_PARAM_SCRYPT_MAXMEM
,
1151 EVP_PKEY_CTRL_SCRYPT_MAXMEM_BYTES
,
1155 int EVP_PKEY_CTX_set_mac_key(EVP_PKEY_CTX
*ctx
, const unsigned char *key
,
1158 return evp_pkey_ctx_set1_octet_string(ctx
, ctx
->op
.keymgmt
.genctx
== NULL
,
1159 OSSL_PKEY_PARAM_PRIV_KEY
,
1161 EVP_PKEY_CTRL_SET_MAC_KEY
,
1165 int EVP_PKEY_CTX_set_kem_op(EVP_PKEY_CTX
*ctx
, const char *op
)
1167 OSSL_PARAM params
[2], *p
= params
;
1169 if (ctx
== NULL
|| op
== NULL
) {
1170 ERR_raise(ERR_LIB_EVP
, EVP_R_INVALID_VALUE
);
1173 if (!EVP_PKEY_CTX_IS_KEM_OP(ctx
)) {
1174 ERR_raise(ERR_LIB_EVP
, EVP_R_COMMAND_NOT_SUPPORTED
);
1177 *p
++ = OSSL_PARAM_construct_utf8_string(OSSL_KEM_PARAM_OPERATION
,
1179 *p
= OSSL_PARAM_construct_end();
1180 return EVP_PKEY_CTX_set_params(ctx
, params
);
1183 int evp_pkey_ctx_set1_id_prov(EVP_PKEY_CTX
*ctx
, const void *id
, int len
)
1185 OSSL_PARAM params
[2], *p
= params
;
1188 if (!EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx
)) {
1189 ERR_raise(ERR_LIB_EVP
, EVP_R_COMMAND_NOT_SUPPORTED
);
1190 /* Uses the same return values as EVP_PKEY_CTX_ctrl */
1194 *p
++ = OSSL_PARAM_construct_octet_string(OSSL_PKEY_PARAM_DIST_ID
,
1196 * Cast away the const. This is
1197 * read only so should be safe
1199 (void *)id
, (size_t)len
);
1200 *p
++ = OSSL_PARAM_construct_end();
1202 ret
= evp_pkey_ctx_set_params_strict(ctx
, params
);
1204 ERR_raise(ERR_LIB_EVP
, EVP_R_COMMAND_NOT_SUPPORTED
);
1208 int EVP_PKEY_CTX_set1_id(EVP_PKEY_CTX
*ctx
, const void *id
, int len
)
1210 return EVP_PKEY_CTX_ctrl(ctx
, -1, -1,
1211 EVP_PKEY_CTRL_SET1_ID
, (int)len
, (void*)(id
));
1214 static int get1_id_data(EVP_PKEY_CTX
*ctx
, void *id
, size_t *id_len
)
1217 void *tmp_id
= NULL
;
1218 OSSL_PARAM params
[2], *p
= params
;
1220 if (!EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx
)) {
1221 ERR_raise(ERR_LIB_EVP
, EVP_R_COMMAND_NOT_SUPPORTED
);
1222 /* Uses the same return values as EVP_PKEY_CTX_ctrl */
1226 *p
++ = OSSL_PARAM_construct_octet_ptr(OSSL_PKEY_PARAM_DIST_ID
,
1228 *p
++ = OSSL_PARAM_construct_end();
1230 ret
= evp_pkey_ctx_get_params_strict(ctx
, params
);
1232 ERR_raise(ERR_LIB_EVP
, EVP_R_COMMAND_NOT_SUPPORTED
);
1233 } else if (ret
> 0) {
1234 size_t tmp_id_len
= params
[0].return_size
;
1237 memcpy(id
, tmp_id
, tmp_id_len
);
1239 *id_len
= tmp_id_len
;
1244 int evp_pkey_ctx_get1_id_prov(EVP_PKEY_CTX
*ctx
, void *id
)
1246 return get1_id_data(ctx
, id
, NULL
);
1249 int evp_pkey_ctx_get1_id_len_prov(EVP_PKEY_CTX
*ctx
, size_t *id_len
)
1251 return get1_id_data(ctx
, NULL
, id_len
);
1254 int EVP_PKEY_CTX_get1_id(EVP_PKEY_CTX
*ctx
, void *id
)
1256 return EVP_PKEY_CTX_ctrl(ctx
, -1, -1, EVP_PKEY_CTRL_GET1_ID
, 0, (void*)id
);
1259 int EVP_PKEY_CTX_get1_id_len(EVP_PKEY_CTX
*ctx
, size_t *id_len
)
1261 return EVP_PKEY_CTX_ctrl(ctx
, -1, -1,
1262 EVP_PKEY_CTRL_GET1_ID_LEN
, 0, (void*)id_len
);
1265 static int evp_pkey_ctx_ctrl_int(EVP_PKEY_CTX
*ctx
, int keytype
, int optype
,
1266 int cmd
, int p1
, void *p2
)
1271 * If the method has a |digest_custom| function, we can relax the
1272 * operation type check, since this can be called before the operation
1275 if (ctx
->pmeth
== NULL
|| ctx
->pmeth
->digest_custom
== NULL
) {
1276 if (ctx
->operation
== EVP_PKEY_OP_UNDEFINED
) {
1277 ERR_raise(ERR_LIB_EVP
, EVP_R_NO_OPERATION_SET
);
1281 if ((optype
!= -1) && !(ctx
->operation
& optype
)) {
1282 ERR_raise(ERR_LIB_EVP
, EVP_R_INVALID_OPERATION
);
1287 switch (evp_pkey_ctx_state(ctx
)) {
1288 case EVP_PKEY_STATE_PROVIDER
:
1289 return evp_pkey_ctx_ctrl_to_param(ctx
, keytype
, optype
, cmd
, p1
, p2
);
1290 case EVP_PKEY_STATE_UNKNOWN
:
1291 case EVP_PKEY_STATE_LEGACY
:
1292 if (ctx
->pmeth
== NULL
|| ctx
->pmeth
->ctrl
== NULL
) {
1293 ERR_raise(ERR_LIB_EVP
, EVP_R_COMMAND_NOT_SUPPORTED
);
1296 if ((keytype
!= -1) && (ctx
->pmeth
->pkey_id
!= keytype
))
1299 ret
= ctx
->pmeth
->ctrl(ctx
, cmd
, p1
, p2
);
1302 ERR_raise(ERR_LIB_EVP
, EVP_R_COMMAND_NOT_SUPPORTED
);
1308 int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX
*ctx
, int keytype
, int optype
,
1309 int cmd
, int p1
, void *p2
)
1314 ERR_raise(ERR_LIB_EVP
, EVP_R_COMMAND_NOT_SUPPORTED
);
1317 /* If unsupported, we don't want that reported here */
1319 ret
= evp_pkey_ctx_store_cached_data(ctx
, keytype
, optype
,
1324 ERR_clear_last_mark();
1326 * If there was an error, there was an error.
1327 * If the operation isn't initialized yet, we also return, as
1328 * the saved values will be used then anyway.
1330 if (ret
< 1 || ctx
->operation
== EVP_PKEY_OP_UNDEFINED
)
1333 return evp_pkey_ctx_ctrl_int(ctx
, keytype
, optype
, cmd
, p1
, p2
);
1336 int EVP_PKEY_CTX_ctrl_uint64(EVP_PKEY_CTX
*ctx
, int keytype
, int optype
,
1337 int cmd
, uint64_t value
)
1339 return EVP_PKEY_CTX_ctrl(ctx
, keytype
, optype
, cmd
, 0, &value
);
1343 static int evp_pkey_ctx_ctrl_str_int(EVP_PKEY_CTX
*ctx
,
1344 const char *name
, const char *value
)
1349 ERR_raise(ERR_LIB_EVP
, EVP_R_COMMAND_NOT_SUPPORTED
);
1353 switch (evp_pkey_ctx_state(ctx
)) {
1354 case EVP_PKEY_STATE_PROVIDER
:
1355 return evp_pkey_ctx_ctrl_str_to_param(ctx
, name
, value
);
1356 case EVP_PKEY_STATE_UNKNOWN
:
1357 case EVP_PKEY_STATE_LEGACY
:
1358 if (ctx
== NULL
|| ctx
->pmeth
== NULL
|| ctx
->pmeth
->ctrl_str
== NULL
) {
1359 ERR_raise(ERR_LIB_EVP
, EVP_R_COMMAND_NOT_SUPPORTED
);
1362 if (strcmp(name
, "digest") == 0)
1363 ret
= EVP_PKEY_CTX_md(ctx
,
1364 EVP_PKEY_OP_TYPE_SIG
| EVP_PKEY_OP_TYPE_CRYPT
,
1365 EVP_PKEY_CTRL_MD
, value
);
1367 ret
= ctx
->pmeth
->ctrl_str(ctx
, name
, value
);
1374 int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX
*ctx
,
1375 const char *name
, const char *value
)
1379 /* If unsupported, we don't want that reported here */
1381 ret
= evp_pkey_ctx_store_cached_data(ctx
, -1, -1, -1,
1382 name
, value
, strlen(value
) + 1);
1386 ERR_clear_last_mark();
1388 * If there was an error, there was an error.
1389 * If the operation isn't initialized yet, we also return, as
1390 * the saved values will be used then anyway.
1392 if (ret
< 1 || ctx
->operation
== EVP_PKEY_OP_UNDEFINED
)
1396 return evp_pkey_ctx_ctrl_str_int(ctx
, name
, value
);
1399 static int decode_cmd(int cmd
, const char *name
)
1403 * The consequence of the assertion not being true is that this
1404 * function will return -1, which will cause the calling functions
1405 * to signal that the command is unsupported... in non-debug mode.
1407 if (ossl_assert(name
!= NULL
))
1408 if (strcmp(name
, "distid") == 0 || strcmp(name
, "hexdistid") == 0)
1409 cmd
= EVP_PKEY_CTRL_SET1_ID
;
1415 static int evp_pkey_ctx_store_cached_data(EVP_PKEY_CTX
*ctx
,
1416 int keytype
, int optype
,
1417 int cmd
, const char *name
,
1418 const void *data
, size_t data_len
)
1421 * Check that it's one of the supported commands. The ctrl commands
1422 * number cases here must correspond to the cases in the bottom switch
1425 switch (cmd
= decode_cmd(cmd
, name
)) {
1426 case EVP_PKEY_CTRL_SET1_ID
:
1429 ERR_raise(ERR_LIB_EVP
, EVP_R_COMMAND_NOT_SUPPORTED
);
1433 if (keytype
!= -1) {
1434 switch (evp_pkey_ctx_state(ctx
)) {
1435 case EVP_PKEY_STATE_PROVIDER
:
1436 if (ctx
->keymgmt
== NULL
) {
1437 ERR_raise(ERR_LIB_EVP
, EVP_R_COMMAND_NOT_SUPPORTED
);
1440 if (!EVP_KEYMGMT_is_a(ctx
->keymgmt
,
1441 evp_pkey_type2name(keytype
))) {
1442 ERR_raise(ERR_LIB_EVP
, EVP_R_INVALID_OPERATION
);
1446 case EVP_PKEY_STATE_UNKNOWN
:
1447 case EVP_PKEY_STATE_LEGACY
:
1448 if (ctx
->pmeth
== NULL
) {
1449 ERR_raise(ERR_LIB_EVP
, EVP_R_COMMAND_NOT_SUPPORTED
);
1452 if (EVP_PKEY_type(ctx
->pmeth
->pkey_id
) != EVP_PKEY_type(keytype
)) {
1453 ERR_raise(ERR_LIB_EVP
, EVP_R_INVALID_OPERATION
);
1459 if (optype
!= -1 && (ctx
->operation
& optype
) == 0) {
1460 ERR_raise(ERR_LIB_EVP
, EVP_R_INVALID_OPERATION
);
1465 case EVP_PKEY_CTRL_SET1_ID
:
1466 evp_pkey_ctx_free_cached_data(ctx
, cmd
, name
);
1468 ctx
->cached_parameters
.dist_id_name
= OPENSSL_strdup(name
);
1469 if (ctx
->cached_parameters
.dist_id_name
== NULL
) {
1470 ERR_raise(ERR_LIB_EVP
, ERR_R_MALLOC_FAILURE
);
1475 ctx
->cached_parameters
.dist_id
= OPENSSL_memdup(data
, data_len
);
1476 if (ctx
->cached_parameters
.dist_id
== NULL
) {
1477 ERR_raise(ERR_LIB_EVP
, ERR_R_MALLOC_FAILURE
);
1481 ctx
->cached_parameters
.dist_id_set
= 1;
1482 ctx
->cached_parameters
.dist_id_len
= data_len
;
1488 static void evp_pkey_ctx_free_cached_data(EVP_PKEY_CTX
*ctx
,
1489 int cmd
, const char *name
)
1491 cmd
= decode_cmd(cmd
, name
);
1493 case EVP_PKEY_CTRL_SET1_ID
:
1494 OPENSSL_free(ctx
->cached_parameters
.dist_id
);
1495 OPENSSL_free(ctx
->cached_parameters
.dist_id_name
);
1496 ctx
->cached_parameters
.dist_id
= NULL
;
1497 ctx
->cached_parameters
.dist_id_name
= NULL
;
1502 static void evp_pkey_ctx_free_all_cached_data(EVP_PKEY_CTX
*ctx
)
1504 evp_pkey_ctx_free_cached_data(ctx
, EVP_PKEY_CTRL_SET1_ID
, NULL
);
1507 int evp_pkey_ctx_use_cached_data(EVP_PKEY_CTX
*ctx
)
1511 if (ret
&& ctx
->cached_parameters
.dist_id_set
) {
1512 const char *name
= ctx
->cached_parameters
.dist_id_name
;
1513 const void *val
= ctx
->cached_parameters
.dist_id
;
1514 size_t len
= ctx
->cached_parameters
.dist_id_len
;
1517 ret
= evp_pkey_ctx_ctrl_str_int(ctx
, name
, val
);
1519 ret
= evp_pkey_ctx_ctrl_int(ctx
, -1, ctx
->operation
,
1520 EVP_PKEY_CTRL_SET1_ID
,
1521 (int)len
, (void *)val
);
1527 OSSL_LIB_CTX
*EVP_PKEY_CTX_get0_libctx(EVP_PKEY_CTX
*ctx
)
1532 const char *EVP_PKEY_CTX_get0_propq(EVP_PKEY_CTX
*ctx
)
1534 return ctx
->propquery
;
1537 /* Utility functions to send a string of hex string to a ctrl */
1539 int EVP_PKEY_CTX_str2ctrl(EVP_PKEY_CTX
*ctx
, int cmd
, const char *str
)
1546 return ctx
->pmeth
->ctrl(ctx
, cmd
, len
, (void *)str
);
1549 int EVP_PKEY_CTX_hex2ctrl(EVP_PKEY_CTX
*ctx
, int cmd
, const char *hex
)
1555 bin
= OPENSSL_hexstr2buf(hex
, &binlen
);
1558 if (binlen
<= INT_MAX
)
1559 rv
= ctx
->pmeth
->ctrl(ctx
, cmd
, binlen
, bin
);
1564 /* Pass a message digest to a ctrl */
1565 int EVP_PKEY_CTX_md(EVP_PKEY_CTX
*ctx
, int optype
, int cmd
, const char *md
)
1569 if (md
== NULL
|| (m
= EVP_get_digestbyname(md
)) == NULL
) {
1570 ERR_raise(ERR_LIB_EVP
, EVP_R_INVALID_DIGEST
);
1573 return EVP_PKEY_CTX_ctrl(ctx
, -1, optype
, cmd
, 0, (void *)m
);
1576 int EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX
*ctx
)
1578 return ctx
->operation
;
1581 void EVP_PKEY_CTX_set0_keygen_info(EVP_PKEY_CTX
*ctx
, int *dat
, int datlen
)
1583 ctx
->keygen_info
= dat
;
1584 ctx
->keygen_info_count
= datlen
;
1587 void EVP_PKEY_CTX_set_data(EVP_PKEY_CTX
*ctx
, void *data
)
1592 void *EVP_PKEY_CTX_get_data(const EVP_PKEY_CTX
*ctx
)
1597 EVP_PKEY
*EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX
*ctx
)
1602 EVP_PKEY
*EVP_PKEY_CTX_get0_peerkey(EVP_PKEY_CTX
*ctx
)
1604 return ctx
->peerkey
;
1607 void EVP_PKEY_CTX_set_app_data(EVP_PKEY_CTX
*ctx
, void *data
)
1609 ctx
->app_data
= data
;
1612 void *EVP_PKEY_CTX_get_app_data(EVP_PKEY_CTX
*ctx
)
1614 return ctx
->app_data
;
1617 void EVP_PKEY_meth_set_init(EVP_PKEY_METHOD
*pmeth
,
1618 int (*init
) (EVP_PKEY_CTX
*ctx
))
1623 void EVP_PKEY_meth_set_copy(EVP_PKEY_METHOD
*pmeth
,
1624 int (*copy
) (EVP_PKEY_CTX
*dst
,
1625 const EVP_PKEY_CTX
*src
))
1630 void EVP_PKEY_meth_set_cleanup(EVP_PKEY_METHOD
*pmeth
,
1631 void (*cleanup
) (EVP_PKEY_CTX
*ctx
))
1633 pmeth
->cleanup
= cleanup
;
1636 void EVP_PKEY_meth_set_paramgen(EVP_PKEY_METHOD
*pmeth
,
1637 int (*paramgen_init
) (EVP_PKEY_CTX
*ctx
),
1638 int (*paramgen
) (EVP_PKEY_CTX
*ctx
,
1641 pmeth
->paramgen_init
= paramgen_init
;
1642 pmeth
->paramgen
= paramgen
;
1645 void EVP_PKEY_meth_set_keygen(EVP_PKEY_METHOD
*pmeth
,
1646 int (*keygen_init
) (EVP_PKEY_CTX
*ctx
),
1647 int (*keygen
) (EVP_PKEY_CTX
*ctx
,
1650 pmeth
->keygen_init
= keygen_init
;
1651 pmeth
->keygen
= keygen
;
1654 void EVP_PKEY_meth_set_sign(EVP_PKEY_METHOD
*pmeth
,
1655 int (*sign_init
) (EVP_PKEY_CTX
*ctx
),
1656 int (*sign
) (EVP_PKEY_CTX
*ctx
,
1657 unsigned char *sig
, size_t *siglen
,
1658 const unsigned char *tbs
,
1661 pmeth
->sign_init
= sign_init
;
1665 void EVP_PKEY_meth_set_verify(EVP_PKEY_METHOD
*pmeth
,
1666 int (*verify_init
) (EVP_PKEY_CTX
*ctx
),
1667 int (*verify
) (EVP_PKEY_CTX
*ctx
,
1668 const unsigned char *sig
,
1670 const unsigned char *tbs
,
1673 pmeth
->verify_init
= verify_init
;
1674 pmeth
->verify
= verify
;
1677 void EVP_PKEY_meth_set_verify_recover(EVP_PKEY_METHOD
*pmeth
,
1678 int (*verify_recover_init
) (EVP_PKEY_CTX
1680 int (*verify_recover
) (EVP_PKEY_CTX
1689 pmeth
->verify_recover_init
= verify_recover_init
;
1690 pmeth
->verify_recover
= verify_recover
;
1693 void EVP_PKEY_meth_set_signctx(EVP_PKEY_METHOD
*pmeth
,
1694 int (*signctx_init
) (EVP_PKEY_CTX
*ctx
,
1696 int (*signctx
) (EVP_PKEY_CTX
*ctx
,
1701 pmeth
->signctx_init
= signctx_init
;
1702 pmeth
->signctx
= signctx
;
1705 void EVP_PKEY_meth_set_verifyctx(EVP_PKEY_METHOD
*pmeth
,
1706 int (*verifyctx_init
) (EVP_PKEY_CTX
*ctx
,
1708 int (*verifyctx
) (EVP_PKEY_CTX
*ctx
,
1709 const unsigned char *sig
,
1713 pmeth
->verifyctx_init
= verifyctx_init
;
1714 pmeth
->verifyctx
= verifyctx
;
1717 void EVP_PKEY_meth_set_encrypt(EVP_PKEY_METHOD
*pmeth
,
1718 int (*encrypt_init
) (EVP_PKEY_CTX
*ctx
),
1719 int (*encryptfn
) (EVP_PKEY_CTX
*ctx
,
1722 const unsigned char *in
,
1725 pmeth
->encrypt_init
= encrypt_init
;
1726 pmeth
->encrypt
= encryptfn
;
1729 void EVP_PKEY_meth_set_decrypt(EVP_PKEY_METHOD
*pmeth
,
1730 int (*decrypt_init
) (EVP_PKEY_CTX
*ctx
),
1731 int (*decrypt
) (EVP_PKEY_CTX
*ctx
,
1734 const unsigned char *in
,
1737 pmeth
->decrypt_init
= decrypt_init
;
1738 pmeth
->decrypt
= decrypt
;
1741 void EVP_PKEY_meth_set_derive(EVP_PKEY_METHOD
*pmeth
,
1742 int (*derive_init
) (EVP_PKEY_CTX
*ctx
),
1743 int (*derive
) (EVP_PKEY_CTX
*ctx
,
1747 pmeth
->derive_init
= derive_init
;
1748 pmeth
->derive
= derive
;
1751 void EVP_PKEY_meth_set_ctrl(EVP_PKEY_METHOD
*pmeth
,
1752 int (*ctrl
) (EVP_PKEY_CTX
*ctx
, int type
, int p1
,
1754 int (*ctrl_str
) (EVP_PKEY_CTX
*ctx
,
1759 pmeth
->ctrl_str
= ctrl_str
;
1762 void EVP_PKEY_meth_set_digestsign(EVP_PKEY_METHOD
*pmeth
,
1763 int (*digestsign
) (EVP_MD_CTX
*ctx
, unsigned char *sig
, size_t *siglen
,
1764 const unsigned char *tbs
, size_t tbslen
))
1766 pmeth
->digestsign
= digestsign
;
1769 void EVP_PKEY_meth_set_digestverify(EVP_PKEY_METHOD
*pmeth
,
1770 int (*digestverify
) (EVP_MD_CTX
*ctx
, const unsigned char *sig
,
1771 size_t siglen
, const unsigned char *tbs
,
1774 pmeth
->digestverify
= digestverify
;
1777 void EVP_PKEY_meth_set_check(EVP_PKEY_METHOD
*pmeth
,
1778 int (*check
) (EVP_PKEY
*pkey
))
1780 pmeth
->check
= check
;
1783 void EVP_PKEY_meth_set_public_check(EVP_PKEY_METHOD
*pmeth
,
1784 int (*check
) (EVP_PKEY
*pkey
))
1786 pmeth
->public_check
= check
;
1789 void EVP_PKEY_meth_set_param_check(EVP_PKEY_METHOD
*pmeth
,
1790 int (*check
) (EVP_PKEY
*pkey
))
1792 pmeth
->param_check
= check
;
1795 void EVP_PKEY_meth_set_digest_custom(EVP_PKEY_METHOD
*pmeth
,
1796 int (*digest_custom
) (EVP_PKEY_CTX
*ctx
,
1799 pmeth
->digest_custom
= digest_custom
;
1802 void EVP_PKEY_meth_get_init(const EVP_PKEY_METHOD
*pmeth
,
1803 int (**pinit
) (EVP_PKEY_CTX
*ctx
))
1805 *pinit
= pmeth
->init
;
1808 void EVP_PKEY_meth_get_copy(const EVP_PKEY_METHOD
*pmeth
,
1809 int (**pcopy
) (EVP_PKEY_CTX
*dst
,
1810 const EVP_PKEY_CTX
*src
))
1812 *pcopy
= pmeth
->copy
;
1815 void EVP_PKEY_meth_get_cleanup(const EVP_PKEY_METHOD
*pmeth
,
1816 void (**pcleanup
) (EVP_PKEY_CTX
*ctx
))
1818 *pcleanup
= pmeth
->cleanup
;
1821 void EVP_PKEY_meth_get_paramgen(const EVP_PKEY_METHOD
*pmeth
,
1822 int (**pparamgen_init
) (EVP_PKEY_CTX
*ctx
),
1823 int (**pparamgen
) (EVP_PKEY_CTX
*ctx
,
1827 *pparamgen_init
= pmeth
->paramgen_init
;
1829 *pparamgen
= pmeth
->paramgen
;
1832 void EVP_PKEY_meth_get_keygen(const EVP_PKEY_METHOD
*pmeth
,
1833 int (**pkeygen_init
) (EVP_PKEY_CTX
*ctx
),
1834 int (**pkeygen
) (EVP_PKEY_CTX
*ctx
,
1838 *pkeygen_init
= pmeth
->keygen_init
;
1840 *pkeygen
= pmeth
->keygen
;
1843 void EVP_PKEY_meth_get_sign(const EVP_PKEY_METHOD
*pmeth
,
1844 int (**psign_init
) (EVP_PKEY_CTX
*ctx
),
1845 int (**psign
) (EVP_PKEY_CTX
*ctx
,
1846 unsigned char *sig
, size_t *siglen
,
1847 const unsigned char *tbs
,
1851 *psign_init
= pmeth
->sign_init
;
1853 *psign
= pmeth
->sign
;
1856 void EVP_PKEY_meth_get_verify(const EVP_PKEY_METHOD
*pmeth
,
1857 int (**pverify_init
) (EVP_PKEY_CTX
*ctx
),
1858 int (**pverify
) (EVP_PKEY_CTX
*ctx
,
1859 const unsigned char *sig
,
1861 const unsigned char *tbs
,
1865 *pverify_init
= pmeth
->verify_init
;
1867 *pverify
= pmeth
->verify
;
1870 void EVP_PKEY_meth_get_verify_recover(const EVP_PKEY_METHOD
*pmeth
,
1871 int (**pverify_recover_init
) (EVP_PKEY_CTX
1873 int (**pverify_recover
) (EVP_PKEY_CTX
1882 if (pverify_recover_init
)
1883 *pverify_recover_init
= pmeth
->verify_recover_init
;
1884 if (pverify_recover
)
1885 *pverify_recover
= pmeth
->verify_recover
;
1888 void EVP_PKEY_meth_get_signctx(const EVP_PKEY_METHOD
*pmeth
,
1889 int (**psignctx_init
) (EVP_PKEY_CTX
*ctx
,
1891 int (**psignctx
) (EVP_PKEY_CTX
*ctx
,
1897 *psignctx_init
= pmeth
->signctx_init
;
1899 *psignctx
= pmeth
->signctx
;
1902 void EVP_PKEY_meth_get_verifyctx(const EVP_PKEY_METHOD
*pmeth
,
1903 int (**pverifyctx_init
) (EVP_PKEY_CTX
*ctx
,
1905 int (**pverifyctx
) (EVP_PKEY_CTX
*ctx
,
1906 const unsigned char *sig
,
1910 if (pverifyctx_init
)
1911 *pverifyctx_init
= pmeth
->verifyctx_init
;
1913 *pverifyctx
= pmeth
->verifyctx
;
1916 void EVP_PKEY_meth_get_encrypt(const EVP_PKEY_METHOD
*pmeth
,
1917 int (**pencrypt_init
) (EVP_PKEY_CTX
*ctx
),
1918 int (**pencryptfn
) (EVP_PKEY_CTX
*ctx
,
1921 const unsigned char *in
,
1925 *pencrypt_init
= pmeth
->encrypt_init
;
1927 *pencryptfn
= pmeth
->encrypt
;
1930 void EVP_PKEY_meth_get_decrypt(const EVP_PKEY_METHOD
*pmeth
,
1931 int (**pdecrypt_init
) (EVP_PKEY_CTX
*ctx
),
1932 int (**pdecrypt
) (EVP_PKEY_CTX
*ctx
,
1935 const unsigned char *in
,
1939 *pdecrypt_init
= pmeth
->decrypt_init
;
1941 *pdecrypt
= pmeth
->decrypt
;
1944 void EVP_PKEY_meth_get_derive(const EVP_PKEY_METHOD
*pmeth
,
1945 int (**pderive_init
) (EVP_PKEY_CTX
*ctx
),
1946 int (**pderive
) (EVP_PKEY_CTX
*ctx
,
1951 *pderive_init
= pmeth
->derive_init
;
1953 *pderive
= pmeth
->derive
;
1956 void EVP_PKEY_meth_get_ctrl(const EVP_PKEY_METHOD
*pmeth
,
1957 int (**pctrl
) (EVP_PKEY_CTX
*ctx
, int type
, int p1
,
1959 int (**pctrl_str
) (EVP_PKEY_CTX
*ctx
,
1964 *pctrl
= pmeth
->ctrl
;
1966 *pctrl_str
= pmeth
->ctrl_str
;
1969 void EVP_PKEY_meth_get_digestsign(EVP_PKEY_METHOD
*pmeth
,
1970 int (**digestsign
) (EVP_MD_CTX
*ctx
, unsigned char *sig
, size_t *siglen
,
1971 const unsigned char *tbs
, size_t tbslen
))
1974 *digestsign
= pmeth
->digestsign
;
1977 void EVP_PKEY_meth_get_digestverify(EVP_PKEY_METHOD
*pmeth
,
1978 int (**digestverify
) (EVP_MD_CTX
*ctx
, const unsigned char *sig
,
1979 size_t siglen
, const unsigned char *tbs
,
1983 *digestverify
= pmeth
->digestverify
;
1986 void EVP_PKEY_meth_get_check(const EVP_PKEY_METHOD
*pmeth
,
1987 int (**pcheck
) (EVP_PKEY
*pkey
))
1990 *pcheck
= pmeth
->check
;
1993 void EVP_PKEY_meth_get_public_check(const EVP_PKEY_METHOD
*pmeth
,
1994 int (**pcheck
) (EVP_PKEY
*pkey
))
1997 *pcheck
= pmeth
->public_check
;
2000 void EVP_PKEY_meth_get_param_check(const EVP_PKEY_METHOD
*pmeth
,
2001 int (**pcheck
) (EVP_PKEY
*pkey
))
2004 *pcheck
= pmeth
->param_check
;
2007 void EVP_PKEY_meth_get_digest_custom(EVP_PKEY_METHOD
*pmeth
,
2008 int (**pdigest_custom
) (EVP_PKEY_CTX
*ctx
,
2011 if (pdigest_custom
!= NULL
)
2012 *pdigest_custom
= pmeth
->digest_custom
;
2015 #endif /* FIPS_MODULE */