]> git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/evp/pmeth_lib.c
Combined patch against master branch for the following issues:
[thirdparty/openssl.git] / crypto / evp / pmeth_lib.c
1 /*
2 * Copyright 2006-2017 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the OpenSSL license (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
8 */
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include "internal/cryptlib.h"
13 #include <openssl/engine.h>
14 #include <openssl/evp.h>
15 #include <openssl/x509v3.h>
16 #include "internal/asn1_int.h"
17 #include "internal/evp_int.h"
18 #include "internal/numbers.h"
19
20 typedef int sk_cmp_fn_type(const char *const *a, const char *const *b);
21
22 static STACK_OF(EVP_PKEY_METHOD) *app_pkey_methods = NULL;
23
24 static const EVP_PKEY_METHOD *standard_methods[] = {
25 #ifndef OPENSSL_NO_RSA
26 &rsa_pkey_meth,
27 #endif
28 #ifndef OPENSSL_NO_DH
29 &dh_pkey_meth,
30 #endif
31 #ifndef OPENSSL_NO_DSA
32 &dsa_pkey_meth,
33 #endif
34 #ifndef OPENSSL_NO_EC
35 &ec_pkey_meth,
36 #endif
37 &hmac_pkey_meth,
38 #ifndef OPENSSL_NO_CMAC
39 &cmac_pkey_meth,
40 #endif
41 #ifndef OPENSSL_NO_RSA
42 &rsa_pss_pkey_meth,
43 #endif
44 #ifndef OPENSSL_NO_DH
45 &dhx_pkey_meth,
46 #endif
47 &tls1_prf_pkey_meth,
48 #ifndef OPENSSL_NO_EC
49 &ecx25519_pkey_meth,
50 #endif
51 &hkdf_pkey_meth,
52 #ifndef OPENSSL_NO_POLY1305
53 &poly1305_pkey_meth,
54 #endif
55 #ifndef OPENSSL_NO_SIPHASH
56 &siphash_pkey_meth,
57 #endif
58 };
59
60 DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *,
61 pmeth);
62
63 static int pmeth_cmp(const EVP_PKEY_METHOD *const *a,
64 const EVP_PKEY_METHOD *const *b)
65 {
66 return ((*a)->pkey_id - (*b)->pkey_id);
67 }
68
69 IMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *,
70 pmeth);
71
72 const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type)
73 {
74 EVP_PKEY_METHOD tmp;
75 const EVP_PKEY_METHOD *t = &tmp, **ret;
76 tmp.pkey_id = type;
77 if (app_pkey_methods) {
78 int idx;
79 idx = sk_EVP_PKEY_METHOD_find(app_pkey_methods, &tmp);
80 if (idx >= 0)
81 return sk_EVP_PKEY_METHOD_value(app_pkey_methods, idx);
82 }
83 ret = OBJ_bsearch_pmeth(&t, standard_methods,
84 sizeof(standard_methods) /
85 sizeof(EVP_PKEY_METHOD *));
86 if (!ret || !*ret)
87 return NULL;
88 return *ret;
89 }
90
91 static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
92 {
93 EVP_PKEY_CTX *ret;
94 const EVP_PKEY_METHOD *pmeth;
95 if (id == -1) {
96 if (!pkey || !pkey->ameth)
97 return NULL;
98 id = pkey->ameth->pkey_id;
99 }
100 #ifndef OPENSSL_NO_ENGINE
101 if (pkey && pkey->engine)
102 e = pkey->engine;
103 /* Try to find an ENGINE which implements this method */
104 if (e) {
105 if (!ENGINE_init(e)) {
106 EVPerr(EVP_F_INT_CTX_NEW, ERR_R_ENGINE_LIB);
107 return NULL;
108 }
109 } else
110 e = ENGINE_get_pkey_meth_engine(id);
111
112 /*
113 * If an ENGINE handled this method look it up. Otherwise use internal
114 * tables.
115 */
116
117 if (e)
118 pmeth = ENGINE_get_pkey_meth(e, id);
119 else
120 #endif
121 pmeth = EVP_PKEY_meth_find(id);
122
123 if (pmeth == NULL) {
124 EVPerr(EVP_F_INT_CTX_NEW, EVP_R_UNSUPPORTED_ALGORITHM);
125 return NULL;
126 }
127
128 ret = OPENSSL_zalloc(sizeof(*ret));
129 if (ret == NULL) {
130 #ifndef OPENSSL_NO_ENGINE
131 ENGINE_finish(e);
132 #endif
133 EVPerr(EVP_F_INT_CTX_NEW, ERR_R_MALLOC_FAILURE);
134 return NULL;
135 }
136 ret->engine = e;
137 ret->pmeth = pmeth;
138 ret->operation = EVP_PKEY_OP_UNDEFINED;
139 ret->pkey = pkey;
140 if (pkey)
141 EVP_PKEY_up_ref(pkey);
142
143 if (pmeth->init) {
144 if (pmeth->init(ret) <= 0) {
145 ret->pmeth = NULL;
146 EVP_PKEY_CTX_free(ret);
147 return NULL;
148 }
149 }
150
151 return ret;
152 }
153
154 EVP_PKEY_METHOD *EVP_PKEY_meth_new(int id, int flags)
155 {
156 EVP_PKEY_METHOD *pmeth;
157
158 pmeth = OPENSSL_zalloc(sizeof(*pmeth));
159 if (pmeth == NULL)
160 return NULL;
161
162 pmeth->pkey_id = id;
163 pmeth->flags = flags | EVP_PKEY_FLAG_DYNAMIC;
164 return pmeth;
165 }
166
167 void EVP_PKEY_meth_get0_info(int *ppkey_id, int *pflags,
168 const EVP_PKEY_METHOD *meth)
169 {
170 if (ppkey_id)
171 *ppkey_id = meth->pkey_id;
172 if (pflags)
173 *pflags = meth->flags;
174 }
175
176 void EVP_PKEY_meth_copy(EVP_PKEY_METHOD *dst, const EVP_PKEY_METHOD *src)
177 {
178
179 dst->init = src->init;
180 dst->copy = src->copy;
181 dst->cleanup = src->cleanup;
182
183 dst->paramgen_init = src->paramgen_init;
184 dst->paramgen = src->paramgen;
185
186 dst->keygen_init = src->keygen_init;
187 dst->keygen = src->keygen;
188
189 dst->sign_init = src->sign_init;
190 dst->sign = src->sign;
191
192 dst->verify_init = src->verify_init;
193 dst->verify = src->verify;
194
195 dst->verify_recover_init = src->verify_recover_init;
196 dst->verify_recover = src->verify_recover;
197
198 dst->signctx_init = src->signctx_init;
199 dst->signctx = src->signctx;
200
201 dst->verifyctx_init = src->verifyctx_init;
202 dst->verifyctx = src->verifyctx;
203
204 dst->encrypt_init = src->encrypt_init;
205 dst->encrypt = src->encrypt;
206
207 dst->decrypt_init = src->decrypt_init;
208 dst->decrypt = src->decrypt;
209
210 dst->derive_init = src->derive_init;
211 dst->derive = src->derive;
212
213 dst->ctrl = src->ctrl;
214 dst->ctrl_str = src->ctrl_str;
215 }
216
217 void EVP_PKEY_meth_free(EVP_PKEY_METHOD *pmeth)
218 {
219 if (pmeth && (pmeth->flags & EVP_PKEY_FLAG_DYNAMIC))
220 OPENSSL_free(pmeth);
221 }
222
223 EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e)
224 {
225 return int_ctx_new(pkey, e, -1);
226 }
227
228 EVP_PKEY_CTX *EVP_PKEY_CTX_new_id(int id, ENGINE *e)
229 {
230 return int_ctx_new(NULL, e, id);
231 }
232
233 EVP_PKEY_CTX *EVP_PKEY_CTX_dup(EVP_PKEY_CTX *pctx)
234 {
235 EVP_PKEY_CTX *rctx;
236 if (!pctx->pmeth || !pctx->pmeth->copy)
237 return NULL;
238 #ifndef OPENSSL_NO_ENGINE
239 /* Make sure it's safe to copy a pkey context using an ENGINE */
240 if (pctx->engine && !ENGINE_init(pctx->engine)) {
241 EVPerr(EVP_F_EVP_PKEY_CTX_DUP, ERR_R_ENGINE_LIB);
242 return 0;
243 }
244 #endif
245 rctx = OPENSSL_malloc(sizeof(*rctx));
246 if (rctx == NULL)
247 return NULL;
248
249 rctx->pmeth = pctx->pmeth;
250 #ifndef OPENSSL_NO_ENGINE
251 rctx->engine = pctx->engine;
252 #endif
253
254 if (pctx->pkey)
255 EVP_PKEY_up_ref(pctx->pkey);
256
257 rctx->pkey = pctx->pkey;
258
259 if (pctx->peerkey)
260 EVP_PKEY_up_ref(pctx->peerkey);
261
262 rctx->peerkey = pctx->peerkey;
263
264 rctx->data = NULL;
265 rctx->app_data = NULL;
266 rctx->operation = pctx->operation;
267
268 if (pctx->pmeth->copy(rctx, pctx) > 0)
269 return rctx;
270
271 rctx->pmeth = NULL;
272 EVP_PKEY_CTX_free(rctx);
273 return NULL;
274
275 }
276
277 int EVP_PKEY_meth_add0(const EVP_PKEY_METHOD *pmeth)
278 {
279 if (app_pkey_methods == NULL) {
280 app_pkey_methods = sk_EVP_PKEY_METHOD_new(pmeth_cmp);
281 if (app_pkey_methods == NULL)
282 return 0;
283 }
284 if (!sk_EVP_PKEY_METHOD_push(app_pkey_methods, pmeth))
285 return 0;
286 sk_EVP_PKEY_METHOD_sort(app_pkey_methods);
287 return 1;
288 }
289
290 void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx)
291 {
292 if (ctx == NULL)
293 return;
294 if (ctx->pmeth && ctx->pmeth->cleanup)
295 ctx->pmeth->cleanup(ctx);
296 EVP_PKEY_free(ctx->pkey);
297 EVP_PKEY_free(ctx->peerkey);
298 #ifndef OPENSSL_NO_ENGINE
299 ENGINE_finish(ctx->engine);
300 #endif
301 OPENSSL_free(ctx);
302 }
303
304 int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype,
305 int cmd, int p1, void *p2)
306 {
307 int ret;
308 if (!ctx || !ctx->pmeth || !ctx->pmeth->ctrl) {
309 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_COMMAND_NOT_SUPPORTED);
310 return -2;
311 }
312 if ((keytype != -1) && (ctx->pmeth->pkey_id != keytype))
313 return -1;
314
315 if (ctx->operation == EVP_PKEY_OP_UNDEFINED) {
316 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_NO_OPERATION_SET);
317 return -1;
318 }
319
320 if ((optype != -1) && !(ctx->operation & optype)) {
321 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_INVALID_OPERATION);
322 return -1;
323 }
324
325 ret = ctx->pmeth->ctrl(ctx, cmd, p1, p2);
326
327 if (ret == -2)
328 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_COMMAND_NOT_SUPPORTED);
329
330 return ret;
331
332 }
333
334 int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx,
335 const char *name, const char *value)
336 {
337 if (!ctx || !ctx->pmeth || !ctx->pmeth->ctrl_str) {
338 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR, EVP_R_COMMAND_NOT_SUPPORTED);
339 return -2;
340 }
341 if (strcmp(name, "digest") == 0)
342 return EVP_PKEY_CTX_md(ctx, EVP_PKEY_OP_TYPE_SIG, EVP_PKEY_CTRL_MD,
343 value);
344 return ctx->pmeth->ctrl_str(ctx, name, value);
345 }
346
347 /* Utility functions to send a string of hex string to a ctrl */
348
349 int EVP_PKEY_CTX_str2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *str)
350 {
351 size_t len;
352
353 len = strlen(str);
354 if (len > INT_MAX)
355 return -1;
356 return ctx->pmeth->ctrl(ctx, cmd, len, (void *)str);
357 }
358
359 int EVP_PKEY_CTX_hex2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *hex)
360 {
361 unsigned char *bin;
362 long binlen;
363 int rv = -1;
364
365 bin = OPENSSL_hexstr2buf(hex, &binlen);
366 if (bin == NULL)
367 return 0;
368 if (binlen <= INT_MAX)
369 rv = ctx->pmeth->ctrl(ctx, cmd, binlen, bin);
370 OPENSSL_free(bin);
371 return rv;
372 }
373
374 /* Pass a message digest to a ctrl */
375 int EVP_PKEY_CTX_md(EVP_PKEY_CTX *ctx, int optype, int cmd, const char *md)
376 {
377 const EVP_MD *m;
378
379 if (md == NULL || (m = EVP_get_digestbyname(md)) == NULL) {
380 EVPerr(EVP_F_EVP_PKEY_CTX_MD, EVP_R_INVALID_DIGEST);
381 return 0;
382 }
383 return EVP_PKEY_CTX_ctrl(ctx, -1, optype, cmd, 0, (void *)m);
384 }
385
386 int EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX *ctx)
387 {
388 return ctx->operation;
389 }
390
391 void EVP_PKEY_CTX_set0_keygen_info(EVP_PKEY_CTX *ctx, int *dat, int datlen)
392 {
393 ctx->keygen_info = dat;
394 ctx->keygen_info_count = datlen;
395 }
396
397 void EVP_PKEY_CTX_set_data(EVP_PKEY_CTX *ctx, void *data)
398 {
399 ctx->data = data;
400 }
401
402 void *EVP_PKEY_CTX_get_data(EVP_PKEY_CTX *ctx)
403 {
404 return ctx->data;
405 }
406
407 EVP_PKEY *EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX *ctx)
408 {
409 return ctx->pkey;
410 }
411
412 EVP_PKEY *EVP_PKEY_CTX_get0_peerkey(EVP_PKEY_CTX *ctx)
413 {
414 return ctx->peerkey;
415 }
416
417 void EVP_PKEY_CTX_set_app_data(EVP_PKEY_CTX *ctx, void *data)
418 {
419 ctx->app_data = data;
420 }
421
422 void *EVP_PKEY_CTX_get_app_data(EVP_PKEY_CTX *ctx)
423 {
424 return ctx->app_data;
425 }
426
427 void EVP_PKEY_meth_set_init(EVP_PKEY_METHOD *pmeth,
428 int (*init) (EVP_PKEY_CTX *ctx))
429 {
430 pmeth->init = init;
431 }
432
433 void EVP_PKEY_meth_set_copy(EVP_PKEY_METHOD *pmeth,
434 int (*copy) (EVP_PKEY_CTX *dst,
435 EVP_PKEY_CTX *src))
436 {
437 pmeth->copy = copy;
438 }
439
440 void EVP_PKEY_meth_set_cleanup(EVP_PKEY_METHOD *pmeth,
441 void (*cleanup) (EVP_PKEY_CTX *ctx))
442 {
443 pmeth->cleanup = cleanup;
444 }
445
446 void EVP_PKEY_meth_set_paramgen(EVP_PKEY_METHOD *pmeth,
447 int (*paramgen_init) (EVP_PKEY_CTX *ctx),
448 int (*paramgen) (EVP_PKEY_CTX *ctx,
449 EVP_PKEY *pkey))
450 {
451 pmeth->paramgen_init = paramgen_init;
452 pmeth->paramgen = paramgen;
453 }
454
455 void EVP_PKEY_meth_set_keygen(EVP_PKEY_METHOD *pmeth,
456 int (*keygen_init) (EVP_PKEY_CTX *ctx),
457 int (*keygen) (EVP_PKEY_CTX *ctx,
458 EVP_PKEY *pkey))
459 {
460 pmeth->keygen_init = keygen_init;
461 pmeth->keygen = keygen;
462 }
463
464 void EVP_PKEY_meth_set_sign(EVP_PKEY_METHOD *pmeth,
465 int (*sign_init) (EVP_PKEY_CTX *ctx),
466 int (*sign) (EVP_PKEY_CTX *ctx,
467 unsigned char *sig, size_t *siglen,
468 const unsigned char *tbs,
469 size_t tbslen))
470 {
471 pmeth->sign_init = sign_init;
472 pmeth->sign = sign;
473 }
474
475 void EVP_PKEY_meth_set_verify(EVP_PKEY_METHOD *pmeth,
476 int (*verify_init) (EVP_PKEY_CTX *ctx),
477 int (*verify) (EVP_PKEY_CTX *ctx,
478 const unsigned char *sig,
479 size_t siglen,
480 const unsigned char *tbs,
481 size_t tbslen))
482 {
483 pmeth->verify_init = verify_init;
484 pmeth->verify = verify;
485 }
486
487 void EVP_PKEY_meth_set_verify_recover(EVP_PKEY_METHOD *pmeth,
488 int (*verify_recover_init) (EVP_PKEY_CTX
489 *ctx),
490 int (*verify_recover) (EVP_PKEY_CTX
491 *ctx,
492 unsigned char
493 *sig,
494 size_t *siglen,
495 const unsigned
496 char *tbs,
497 size_t tbslen))
498 {
499 pmeth->verify_recover_init = verify_recover_init;
500 pmeth->verify_recover = verify_recover;
501 }
502
503 void EVP_PKEY_meth_set_signctx(EVP_PKEY_METHOD *pmeth,
504 int (*signctx_init) (EVP_PKEY_CTX *ctx,
505 EVP_MD_CTX *mctx),
506 int (*signctx) (EVP_PKEY_CTX *ctx,
507 unsigned char *sig,
508 size_t *siglen,
509 EVP_MD_CTX *mctx))
510 {
511 pmeth->signctx_init = signctx_init;
512 pmeth->signctx = signctx;
513 }
514
515 void EVP_PKEY_meth_set_verifyctx(EVP_PKEY_METHOD *pmeth,
516 int (*verifyctx_init) (EVP_PKEY_CTX *ctx,
517 EVP_MD_CTX *mctx),
518 int (*verifyctx) (EVP_PKEY_CTX *ctx,
519 const unsigned char *sig,
520 int siglen,
521 EVP_MD_CTX *mctx))
522 {
523 pmeth->verifyctx_init = verifyctx_init;
524 pmeth->verifyctx = verifyctx;
525 }
526
527 void EVP_PKEY_meth_set_encrypt(EVP_PKEY_METHOD *pmeth,
528 int (*encrypt_init) (EVP_PKEY_CTX *ctx),
529 int (*encryptfn) (EVP_PKEY_CTX *ctx,
530 unsigned char *out,
531 size_t *outlen,
532 const unsigned char *in,
533 size_t inlen))
534 {
535 pmeth->encrypt_init = encrypt_init;
536 pmeth->encrypt = encryptfn;
537 }
538
539 void EVP_PKEY_meth_set_decrypt(EVP_PKEY_METHOD *pmeth,
540 int (*decrypt_init) (EVP_PKEY_CTX *ctx),
541 int (*decrypt) (EVP_PKEY_CTX *ctx,
542 unsigned char *out,
543 size_t *outlen,
544 const unsigned char *in,
545 size_t inlen))
546 {
547 pmeth->decrypt_init = decrypt_init;
548 pmeth->decrypt = decrypt;
549 }
550
551 void EVP_PKEY_meth_set_derive(EVP_PKEY_METHOD *pmeth,
552 int (*derive_init) (EVP_PKEY_CTX *ctx),
553 int (*derive) (EVP_PKEY_CTX *ctx,
554 unsigned char *key,
555 size_t *keylen))
556 {
557 pmeth->derive_init = derive_init;
558 pmeth->derive = derive;
559 }
560
561 void EVP_PKEY_meth_set_ctrl(EVP_PKEY_METHOD *pmeth,
562 int (*ctrl) (EVP_PKEY_CTX *ctx, int type, int p1,
563 void *p2),
564 int (*ctrl_str) (EVP_PKEY_CTX *ctx,
565 const char *type,
566 const char *value))
567 {
568 pmeth->ctrl = ctrl;
569 pmeth->ctrl_str = ctrl_str;
570 }
571
572 void EVP_PKEY_meth_get_init(EVP_PKEY_METHOD *pmeth,
573 int (**pinit) (EVP_PKEY_CTX *ctx))
574 {
575 *pinit = pmeth->init;
576 }
577
578 void EVP_PKEY_meth_get_copy(EVP_PKEY_METHOD *pmeth,
579 int (**pcopy) (EVP_PKEY_CTX *dst,
580 EVP_PKEY_CTX *src))
581 {
582 *pcopy = pmeth->copy;
583 }
584
585 void EVP_PKEY_meth_get_cleanup(EVP_PKEY_METHOD *pmeth,
586 void (**pcleanup) (EVP_PKEY_CTX *ctx))
587 {
588 *pcleanup = pmeth->cleanup;
589 }
590
591 void EVP_PKEY_meth_get_paramgen(EVP_PKEY_METHOD *pmeth,
592 int (**pparamgen_init) (EVP_PKEY_CTX *ctx),
593 int (**pparamgen) (EVP_PKEY_CTX *ctx,
594 EVP_PKEY *pkey))
595 {
596 if (pparamgen_init)
597 *pparamgen_init = pmeth->paramgen_init;
598 if (pparamgen)
599 *pparamgen = pmeth->paramgen;
600 }
601
602 void EVP_PKEY_meth_get_keygen(EVP_PKEY_METHOD *pmeth,
603 int (**pkeygen_init) (EVP_PKEY_CTX *ctx),
604 int (**pkeygen) (EVP_PKEY_CTX *ctx,
605 EVP_PKEY *pkey))
606 {
607 if (pkeygen_init)
608 *pkeygen_init = pmeth->keygen_init;
609 if (pkeygen)
610 *pkeygen = pmeth->keygen;
611 }
612
613 void EVP_PKEY_meth_get_sign(EVP_PKEY_METHOD *pmeth,
614 int (**psign_init) (EVP_PKEY_CTX *ctx),
615 int (**psign) (EVP_PKEY_CTX *ctx,
616 unsigned char *sig, size_t *siglen,
617 const unsigned char *tbs,
618 size_t tbslen))
619 {
620 if (psign_init)
621 *psign_init = pmeth->sign_init;
622 if (psign)
623 *psign = pmeth->sign;
624 }
625
626 void EVP_PKEY_meth_get_verify(EVP_PKEY_METHOD *pmeth,
627 int (**pverify_init) (EVP_PKEY_CTX *ctx),
628 int (**pverify) (EVP_PKEY_CTX *ctx,
629 const unsigned char *sig,
630 size_t siglen,
631 const unsigned char *tbs,
632 size_t tbslen))
633 {
634 if (pverify_init)
635 *pverify_init = pmeth->verify_init;
636 if (pverify)
637 *pverify = pmeth->verify;
638 }
639
640 void EVP_PKEY_meth_get_verify_recover(EVP_PKEY_METHOD *pmeth,
641 int (**pverify_recover_init) (EVP_PKEY_CTX
642 *ctx),
643 int (**pverify_recover) (EVP_PKEY_CTX
644 *ctx,
645 unsigned char
646 *sig,
647 size_t *siglen,
648 const unsigned
649 char *tbs,
650 size_t tbslen))
651 {
652 if (pverify_recover_init)
653 *pverify_recover_init = pmeth->verify_recover_init;
654 if (pverify_recover)
655 *pverify_recover = pmeth->verify_recover;
656 }
657
658 void EVP_PKEY_meth_get_signctx(EVP_PKEY_METHOD *pmeth,
659 int (**psignctx_init) (EVP_PKEY_CTX *ctx,
660 EVP_MD_CTX *mctx),
661 int (**psignctx) (EVP_PKEY_CTX *ctx,
662 unsigned char *sig,
663 size_t *siglen,
664 EVP_MD_CTX *mctx))
665 {
666 if (psignctx_init)
667 *psignctx_init = pmeth->signctx_init;
668 if (psignctx)
669 *psignctx = pmeth->signctx;
670 }
671
672 void EVP_PKEY_meth_get_verifyctx(EVP_PKEY_METHOD *pmeth,
673 int (**pverifyctx_init) (EVP_PKEY_CTX *ctx,
674 EVP_MD_CTX *mctx),
675 int (**pverifyctx) (EVP_PKEY_CTX *ctx,
676 const unsigned char *sig,
677 int siglen,
678 EVP_MD_CTX *mctx))
679 {
680 if (pverifyctx_init)
681 *pverifyctx_init = pmeth->verifyctx_init;
682 if (pverifyctx)
683 *pverifyctx = pmeth->verifyctx;
684 }
685
686 void EVP_PKEY_meth_get_encrypt(EVP_PKEY_METHOD *pmeth,
687 int (**pencrypt_init) (EVP_PKEY_CTX *ctx),
688 int (**pencryptfn) (EVP_PKEY_CTX *ctx,
689 unsigned char *out,
690 size_t *outlen,
691 const unsigned char *in,
692 size_t inlen))
693 {
694 if (pencrypt_init)
695 *pencrypt_init = pmeth->encrypt_init;
696 if (pencryptfn)
697 *pencryptfn = pmeth->encrypt;
698 }
699
700 void EVP_PKEY_meth_get_decrypt(EVP_PKEY_METHOD *pmeth,
701 int (**pdecrypt_init) (EVP_PKEY_CTX *ctx),
702 int (**pdecrypt) (EVP_PKEY_CTX *ctx,
703 unsigned char *out,
704 size_t *outlen,
705 const unsigned char *in,
706 size_t inlen))
707 {
708 if (pdecrypt_init)
709 *pdecrypt_init = pmeth->decrypt_init;
710 if (pdecrypt)
711 *pdecrypt = pmeth->decrypt;
712 }
713
714 void EVP_PKEY_meth_get_derive(EVP_PKEY_METHOD *pmeth,
715 int (**pderive_init) (EVP_PKEY_CTX *ctx),
716 int (**pderive) (EVP_PKEY_CTX *ctx,
717 unsigned char *key,
718 size_t *keylen))
719 {
720 if (pderive_init)
721 *pderive_init = pmeth->derive_init;
722 if (pderive)
723 *pderive = pmeth->derive;
724 }
725
726 void EVP_PKEY_meth_get_ctrl(EVP_PKEY_METHOD *pmeth,
727 int (**pctrl) (EVP_PKEY_CTX *ctx, int type, int p1,
728 void *p2),
729 int (**pctrl_str) (EVP_PKEY_CTX *ctx,
730 const char *type,
731 const char *value))
732 {
733 if (pctrl)
734 *pctrl = pmeth->ctrl;
735 if (pctrl_str)
736 *pctrl_str = pmeth->ctrl_str;
737 }