1 /* $OpenBSD: pmeth_lib.c,v 1.22 2022/05/05 08:51:21 tb Exp $ */
2 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3  * project 2006.
4  */
5 /* ====================================================================
6  * Copyright (c) 2006 The OpenSSL Project.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in
17  *    the documentation and/or other materials provided with the
18  *    distribution.
19  *
20  * 3. All advertising materials mentioning features or use of this
21  *    software must display the following acknowledgment:
22  *    "This product includes software developed by the OpenSSL Project
23  *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24  *
25  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26  *    endorse or promote products derived from this software without
27  *    prior written permission. For written permission, please contact
28  *    licensing@OpenSSL.org.
29  *
30  * 5. Products derived from this software may not be called "OpenSSL"
31  *    nor may "OpenSSL" appear in their names without prior written
32  *    permission of the OpenSSL Project.
33  *
34  * 6. Redistributions of any form whatsoever must retain the following
35  *    acknowledgment:
36  *    "This product includes software developed by the OpenSSL Project
37  *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38  *
39  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
43  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50  * OF THE POSSIBILITY OF SUCH DAMAGE.
51  * ====================================================================
52  *
53  * This product includes cryptographic software written by Eric Young
54  * (eay@cryptsoft.com).  This product includes software written by Tim
55  * Hudson (tjh@cryptsoft.com).
56  *
57  */
58 
59 #include <limits.h>
60 #include <stdio.h>
61 #include <stdlib.h>
62 #include <string.h>
63 
64 #include <openssl/opensslconf.h>
65 
66 #include <openssl/err.h>
67 #include <openssl/evp.h>
68 #include <openssl/objects.h>
69 #include <openssl/x509v3.h>
70 
71 #ifndef OPENSSL_NO_ENGINE
72 #include <openssl/engine.h>
73 #endif
74 
75 #include "asn1_locl.h"
76 #include "evp_locl.h"
77 
78 typedef int sk_cmp_fn_type(const char * const *a, const char * const *b);
79 
80 DECLARE_STACK_OF(EVP_PKEY_METHOD)
81 STACK_OF(EVP_PKEY_METHOD) *app_pkey_methods = NULL;
82 
83 extern const EVP_PKEY_METHOD rsa_pkey_meth, rsa_pss_pkey_meth;
84 extern const EVP_PKEY_METHOD dh_pkey_meth, dsa_pkey_meth;
85 extern const EVP_PKEY_METHOD ec_pkey_meth, hmac_pkey_meth, cmac_pkey_meth;
86 extern const EVP_PKEY_METHOD gostimit_pkey_meth, gostr01_pkey_meth;
87 extern const EVP_PKEY_METHOD hkdf_pkey_meth;
88 
89 static const EVP_PKEY_METHOD *standard_methods[] = {
90 #ifndef OPENSSL_NO_RSA
91 	&rsa_pkey_meth,
92 #endif
93 #ifndef OPENSSL_NO_DH
94 	&dh_pkey_meth,
95 #endif
96 #ifndef OPENSSL_NO_DSA
97 	&dsa_pkey_meth,
98 #endif
99 #ifndef OPENSSL_NO_EC
100 	&ec_pkey_meth,
101 #endif
102 #ifndef OPENSSL_NO_GOST
103 	&gostr01_pkey_meth,
104 	&gostimit_pkey_meth,
105 #endif
106 	&hmac_pkey_meth,
107 	&cmac_pkey_meth,
108 #ifndef OPENSSL_NO_RSA
109 	&rsa_pss_pkey_meth,
110 #endif
111 	&hkdf_pkey_meth,
112 };
113 
114 static int pmeth_cmp_BSEARCH_CMP_FN(const void *, const void *);
115 static int pmeth_cmp(const EVP_PKEY_METHOD * const *, const EVP_PKEY_METHOD * const *);
116 static const EVP_PKEY_METHOD * *OBJ_bsearch_pmeth(const EVP_PKEY_METHOD * *key, const EVP_PKEY_METHOD * const *base, int num);
117 
118 static int
119 pmeth_cmp(const EVP_PKEY_METHOD * const *a, const EVP_PKEY_METHOD * const *b)
120 {
121 	return ((*a)->pkey_id - (*b)->pkey_id);
122 }
123 
124 
125 static int
126 pmeth_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_)
127 {
128 	const EVP_PKEY_METHOD * const *a = a_;
129 	const EVP_PKEY_METHOD * const *b = b_;
130 	return pmeth_cmp(a, b);
131 }
132 
133 static const EVP_PKEY_METHOD * *
134 OBJ_bsearch_pmeth(const EVP_PKEY_METHOD * *key, const EVP_PKEY_METHOD * const *base, int num)
135 {
136 	return (const EVP_PKEY_METHOD * *)OBJ_bsearch_(key, base, num, sizeof(const EVP_PKEY_METHOD *),
137 	    pmeth_cmp_BSEARCH_CMP_FN);
138 }
139 
140 const EVP_PKEY_METHOD *
141 EVP_PKEY_meth_find(int type)
142 {
143 	EVP_PKEY_METHOD tmp;
144 	const EVP_PKEY_METHOD *t = &tmp, **ret;
145 
146 	tmp.pkey_id = type;
147 	if (app_pkey_methods) {
148 		int idx;
149 		idx = sk_EVP_PKEY_METHOD_find(app_pkey_methods, &tmp);
150 		if (idx >= 0)
151 			return sk_EVP_PKEY_METHOD_value(app_pkey_methods, idx);
152 	}
153 	ret = OBJ_bsearch_pmeth(&t, standard_methods,
154 	    sizeof(standard_methods)/sizeof(EVP_PKEY_METHOD *));
155 	if (!ret || !*ret)
156 		return NULL;
157 	return *ret;
158 }
159 
160 static EVP_PKEY_CTX *
161 int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
162 {
163 	EVP_PKEY_CTX *ret;
164 	const EVP_PKEY_METHOD *pmeth;
165 
166 	if (id == -1) {
167 		if (!pkey || !pkey->ameth)
168 			return NULL;
169 		id = pkey->ameth->pkey_id;
170 	}
171 #ifndef OPENSSL_NO_ENGINE
172 	if (pkey && pkey->engine)
173 		e = pkey->engine;
174 	/* Try to find an ENGINE which implements this method */
175 	if (e) {
176 		if (!ENGINE_init(e)) {
177 			EVPerror(ERR_R_ENGINE_LIB);
178 			return NULL;
179 		}
180 	} else
181 		e = ENGINE_get_pkey_meth_engine(id);
182 
183 	/* If an ENGINE handled this method look it up. Othewise
184 	 * use internal tables.
185 	 */
186 
187 	if (e)
188 		pmeth = ENGINE_get_pkey_meth(e, id);
189 	else
190 #endif
191 		pmeth = EVP_PKEY_meth_find(id);
192 
193 	if (pmeth == NULL) {
194 		EVPerror(EVP_R_UNSUPPORTED_ALGORITHM);
195 		return NULL;
196 	}
197 
198 	ret = malloc(sizeof(EVP_PKEY_CTX));
199 	if (ret == NULL) {
200 #ifndef OPENSSL_NO_ENGINE
201 		ENGINE_finish(e);
202 #endif
203 		EVPerror(ERR_R_MALLOC_FAILURE);
204 		return NULL;
205 	}
206 	ret->engine = e;
207 	ret->pmeth = pmeth;
208 	ret->operation = EVP_PKEY_OP_UNDEFINED;
209 	ret->pkey = pkey;
210 	ret->peerkey = NULL;
211 	ret->pkey_gencb = 0;
212 	if (pkey)
213 		CRYPTO_add(&pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);
214 	ret->data = NULL;
215 
216 	if (pmeth->init) {
217 		if (pmeth->init(ret) <= 0) {
218 			EVP_PKEY_CTX_free(ret);
219 			return NULL;
220 		}
221 	}
222 
223 	return ret;
224 }
225 
226 EVP_PKEY_METHOD*
227 EVP_PKEY_meth_new(int id, int flags)
228 {
229 	EVP_PKEY_METHOD *pmeth;
230 
231 	if ((pmeth = calloc(1, sizeof(EVP_PKEY_METHOD))) == NULL)
232 		return NULL;
233 
234 	pmeth->pkey_id = id;
235 	pmeth->flags = flags | EVP_PKEY_FLAG_DYNAMIC;
236 
237 	return pmeth;
238 }
239 
240 void
241 EVP_PKEY_meth_get0_info(int *ppkey_id, int *pflags, const EVP_PKEY_METHOD *meth)
242 {
243 	if (ppkey_id)
244 		*ppkey_id = meth->pkey_id;
245 	if (pflags)
246 		*pflags = meth->flags;
247 }
248 
249 void
250 EVP_PKEY_meth_copy(EVP_PKEY_METHOD *dst, const EVP_PKEY_METHOD *src)
251 {
252 	EVP_PKEY_METHOD preserve;
253 
254 	preserve.pkey_id = dst->pkey_id;
255 	preserve.flags = dst->flags;
256 
257 	*dst = *src;
258 
259 	dst->pkey_id = preserve.pkey_id;
260 	dst->flags = preserve.flags;
261 }
262 
263 void
264 EVP_PKEY_meth_free(EVP_PKEY_METHOD *pmeth)
265 {
266 	if (pmeth && (pmeth->flags & EVP_PKEY_FLAG_DYNAMIC))
267 		free(pmeth);
268 }
269 
270 EVP_PKEY_CTX *
271 EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e)
272 {
273 	return int_ctx_new(pkey, e, -1);
274 }
275 
276 EVP_PKEY_CTX *
277 EVP_PKEY_CTX_new_id(int id, ENGINE *e)
278 {
279 	return int_ctx_new(NULL, e, id);
280 }
281 
282 EVP_PKEY_CTX *
283 EVP_PKEY_CTX_dup(EVP_PKEY_CTX *pctx)
284 {
285 	EVP_PKEY_CTX *rctx;
286 
287 	if (!pctx->pmeth || !pctx->pmeth->copy)
288 		return NULL;
289 #ifndef OPENSSL_NO_ENGINE
290 	/* Make sure it's safe to copy a pkey context using an ENGINE */
291 	if (pctx->engine && !ENGINE_init(pctx->engine)) {
292 		EVPerror(ERR_R_ENGINE_LIB);
293 		return 0;
294 	}
295 #endif
296 	rctx = malloc(sizeof(EVP_PKEY_CTX));
297 	if (!rctx)
298 		return NULL;
299 
300 	rctx->pmeth = pctx->pmeth;
301 #ifndef OPENSSL_NO_ENGINE
302 	rctx->engine = pctx->engine;
303 #endif
304 
305 	if (pctx->pkey)
306 		CRYPTO_add(&pctx->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);
307 
308 	rctx->pkey = pctx->pkey;
309 
310 	if (pctx->peerkey)
311 		CRYPTO_add(&pctx->peerkey->references, 1, CRYPTO_LOCK_EVP_PKEY);
312 
313 	rctx->peerkey = pctx->peerkey;
314 
315 	rctx->data = NULL;
316 	rctx->app_data = NULL;
317 	rctx->operation = pctx->operation;
318 
319 	if (pctx->pmeth->copy(rctx, pctx) > 0)
320 		return rctx;
321 
322 	EVP_PKEY_CTX_free(rctx);
323 	return NULL;
324 }
325 
326 int
327 EVP_PKEY_meth_add0(const EVP_PKEY_METHOD *pmeth)
328 {
329 	if (app_pkey_methods == NULL) {
330 		app_pkey_methods = sk_EVP_PKEY_METHOD_new(pmeth_cmp);
331 		if (!app_pkey_methods)
332 			return 0;
333 	}
334 	if (!sk_EVP_PKEY_METHOD_push(app_pkey_methods, pmeth))
335 		return 0;
336 	sk_EVP_PKEY_METHOD_sort(app_pkey_methods);
337 	return 1;
338 }
339 
340 void
341 EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx)
342 {
343 	if (ctx == NULL)
344 		return;
345 	if (ctx->pmeth && ctx->pmeth->cleanup)
346 		ctx->pmeth->cleanup(ctx);
347 	EVP_PKEY_free(ctx->pkey);
348 	EVP_PKEY_free(ctx->peerkey);
349 #ifndef OPENSSL_NO_ENGINE
350 	ENGINE_finish(ctx->engine);
351 #endif
352 	free(ctx);
353 }
354 
355 int
356 EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype, int cmd,
357     int p1, void *p2)
358 {
359 	int ret;
360 
361 	if (!ctx || !ctx->pmeth || !ctx->pmeth->ctrl) {
362 		EVPerror(EVP_R_COMMAND_NOT_SUPPORTED);
363 		return -2;
364 	}
365 	if ((keytype != -1) && (ctx->pmeth->pkey_id != keytype))
366 		return -1;
367 
368 	if (ctx->operation == EVP_PKEY_OP_UNDEFINED) {
369 		EVPerror(EVP_R_NO_OPERATION_SET);
370 		return -1;
371 	}
372 
373 	if ((optype != -1) && !(ctx->operation & optype)) {
374 		EVPerror(EVP_R_INVALID_OPERATION);
375 		return -1;
376 	}
377 
378 	ret = ctx->pmeth->ctrl(ctx, cmd, p1, p2);
379 
380 	if (ret == -2)
381 		EVPerror(EVP_R_COMMAND_NOT_SUPPORTED);
382 
383 	return ret;
384 
385 }
386 
387 int
388 EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx, const char *name, const char *value)
389 {
390 	if (!ctx || !ctx->pmeth || !ctx->pmeth->ctrl_str) {
391 		EVPerror(EVP_R_COMMAND_NOT_SUPPORTED);
392 		return -2;
393 	}
394 	if (!strcmp(name, "digest")) {
395 		return EVP_PKEY_CTX_md(ctx, EVP_PKEY_OP_TYPE_SIG,
396 		    EVP_PKEY_CTRL_MD, value);
397 	}
398 	return ctx->pmeth->ctrl_str(ctx, name, value);
399 }
400 
401 int
402 EVP_PKEY_CTX_str2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *str)
403 {
404 	size_t len;
405 
406 	if ((len = strlen(str)) > INT_MAX)
407 		return -1;
408 
409 	return ctx->pmeth->ctrl(ctx, cmd, len, (void *)str);
410 }
411 
412 int
413 EVP_PKEY_CTX_hex2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *hexstr)
414 {
415 	unsigned char *hex = NULL;
416 	long length;
417 	int ret = 0;
418 
419 	if ((hex = string_to_hex(hexstr, &length)) == NULL)
420 		goto err;
421 	if (length < 0 || length > INT_MAX) {
422 		ret = -1;
423 		goto err;
424 	}
425 
426 	ret = ctx->pmeth->ctrl(ctx, cmd, length, hex);
427 
428  err:
429 	free(hex);
430 	return ret;
431 }
432 
433 int
434 EVP_PKEY_CTX_md(EVP_PKEY_CTX *ctx, int optype, int cmd, const char *md_name)
435 {
436 	const EVP_MD *md;
437 
438 	if ((md = EVP_get_digestbyname(md_name)) == NULL) {
439 		EVPerror(EVP_R_INVALID_DIGEST);
440 		return 0;
441 	}
442 	return EVP_PKEY_CTX_ctrl(ctx, -1, optype, cmd, 0, (void *)md);
443 }
444 
445 int
446 EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX *ctx)
447 {
448 	return ctx->operation;
449 }
450 
451 void
452 EVP_PKEY_CTX_set0_keygen_info(EVP_PKEY_CTX *ctx, int *dat, int datlen)
453 {
454 	ctx->keygen_info = dat;
455 	ctx->keygen_info_count = datlen;
456 }
457 
458 void
459 EVP_PKEY_CTX_set_data(EVP_PKEY_CTX *ctx, void *data)
460 {
461 	ctx->data = data;
462 }
463 
464 void *
465 EVP_PKEY_CTX_get_data(EVP_PKEY_CTX *ctx)
466 {
467 	return ctx->data;
468 }
469 
470 EVP_PKEY *
471 EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX *ctx)
472 {
473 	return ctx->pkey;
474 }
475 
476 EVP_PKEY *
477 EVP_PKEY_CTX_get0_peerkey(EVP_PKEY_CTX *ctx)
478 {
479 	return ctx->peerkey;
480 }
481 
482 void
483 EVP_PKEY_CTX_set_app_data(EVP_PKEY_CTX *ctx, void *data)
484 {
485 	ctx->app_data = data;
486 }
487 
488 void *
489 EVP_PKEY_CTX_get_app_data(EVP_PKEY_CTX *ctx)
490 {
491 	return ctx->app_data;
492 }
493 
494 void
495 EVP_PKEY_meth_set_init(EVP_PKEY_METHOD *pmeth,
496     int (*init)(EVP_PKEY_CTX *ctx))
497 {
498 	pmeth->init = init;
499 }
500 
501 void
502 EVP_PKEY_meth_set_copy(EVP_PKEY_METHOD *pmeth,
503     int (*copy)(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src))
504 {
505 	pmeth->copy = copy;
506 }
507 
508 void
509 EVP_PKEY_meth_set_cleanup(EVP_PKEY_METHOD *pmeth,
510     void (*cleanup)(EVP_PKEY_CTX *ctx))
511 {
512 	pmeth->cleanup = cleanup;
513 }
514 
515 void
516 EVP_PKEY_meth_set_paramgen(EVP_PKEY_METHOD *pmeth,
517     int (*paramgen_init)(EVP_PKEY_CTX *ctx),
518     int (*paramgen)(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey))
519 {
520 	pmeth->paramgen_init = paramgen_init;
521 	pmeth->paramgen = paramgen;
522 }
523 
524 void
525 EVP_PKEY_meth_set_keygen(EVP_PKEY_METHOD *pmeth,
526     int (*keygen_init)(EVP_PKEY_CTX *ctx),
527     int (*keygen)(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey))
528 {
529 	pmeth->keygen_init = keygen_init;
530 	pmeth->keygen = keygen;
531 }
532 
533 void
534 EVP_PKEY_meth_set_sign(EVP_PKEY_METHOD *pmeth,
535     int (*sign_init)(EVP_PKEY_CTX *ctx),
536     int (*sign)(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
537     const unsigned char *tbs, size_t tbslen))
538 {
539 	pmeth->sign_init = sign_init;
540 	pmeth->sign = sign;
541 }
542 
543 void
544 EVP_PKEY_meth_set_verify(EVP_PKEY_METHOD *pmeth,
545     int (*verify_init)(EVP_PKEY_CTX *ctx),
546     int (*verify)(EVP_PKEY_CTX *ctx, const unsigned char *sig, size_t siglen,
547     const unsigned char *tbs, size_t tbslen))
548 {
549 	pmeth->verify_init = verify_init;
550 	pmeth->verify = verify;
551 }
552 
553 void
554 EVP_PKEY_meth_set_verify_recover(EVP_PKEY_METHOD *pmeth,
555     int (*verify_recover_init)(EVP_PKEY_CTX *ctx),
556     int (*verify_recover)(EVP_PKEY_CTX *ctx,
557     unsigned char *sig, size_t *siglen,
558     const unsigned char *tbs, size_t tbslen))
559 {
560 	pmeth->verify_recover_init = verify_recover_init;
561 	pmeth->verify_recover = verify_recover;
562 }
563 
564 void
565 EVP_PKEY_meth_set_signctx(EVP_PKEY_METHOD *pmeth,
566     int (*signctx_init)(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx),
567     int (*signctx)(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
568     EVP_MD_CTX *mctx))
569 {
570 	pmeth->signctx_init = signctx_init;
571 	pmeth->signctx = signctx;
572 }
573 
574 void
575 EVP_PKEY_meth_set_verifyctx(EVP_PKEY_METHOD *pmeth,
576     int (*verifyctx_init)(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx),
577     int (*verifyctx)(EVP_PKEY_CTX *ctx, const unsigned char *sig, int siglen,
578     EVP_MD_CTX *mctx))
579 {
580 	pmeth->verifyctx_init = verifyctx_init;
581 	pmeth->verifyctx = verifyctx;
582 }
583 
584 void
585 EVP_PKEY_meth_set_encrypt(EVP_PKEY_METHOD *pmeth,
586     int (*encrypt_init)(EVP_PKEY_CTX *ctx),
587     int (*encryptfn)(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
588     const unsigned char *in, size_t inlen))
589 {
590 	pmeth->encrypt_init = encrypt_init;
591 	pmeth->encrypt = encryptfn;
592 }
593 
594 void
595 EVP_PKEY_meth_set_decrypt(EVP_PKEY_METHOD *pmeth,
596     int (*decrypt_init)(EVP_PKEY_CTX *ctx),
597     int (*decrypt)(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
598     const unsigned char *in, size_t inlen))
599 {
600 	pmeth->decrypt_init = decrypt_init;
601 	pmeth->decrypt = decrypt;
602 }
603 
604 void
605 EVP_PKEY_meth_set_derive(EVP_PKEY_METHOD *pmeth,
606     int (*derive_init)(EVP_PKEY_CTX *ctx),
607     int (*derive)(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen))
608 {
609 	pmeth->derive_init = derive_init;
610 	pmeth->derive = derive;
611 }
612 
613 void
614 EVP_PKEY_meth_set_ctrl(EVP_PKEY_METHOD *pmeth,
615     int (*ctrl)(EVP_PKEY_CTX *ctx, int type, int p1, void *p2),
616     int (*ctrl_str)(EVP_PKEY_CTX *ctx, const char *type, const char *value))
617 {
618 	pmeth->ctrl = ctrl;
619 	pmeth->ctrl_str = ctrl_str;
620 }
621 
622 void
623 EVP_PKEY_meth_set_check(EVP_PKEY_METHOD *pmeth, int (*check)(EVP_PKEY *pkey))
624 {
625 	pmeth->check = check;
626 }
627 
628 void
629 EVP_PKEY_meth_set_public_check(EVP_PKEY_METHOD *pmeth,
630     int (*public_check)(EVP_PKEY *pkey))
631 {
632 	pmeth->public_check = public_check;
633 }
634 
635 void
636 EVP_PKEY_meth_set_param_check(EVP_PKEY_METHOD *pmeth,
637     int (*param_check)(EVP_PKEY *pkey))
638 {
639 	pmeth->param_check = param_check;
640 }
641