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