VirtualBox

source: vbox/trunk/src/libs/openssl-1.1.0g/crypto/evp/pmeth_lib.c@ 69881

Last change on this file since 69881 was 69881, checked in by vboxsync, 7 years ago

Update OpenSSL to 1.1.0g.
bugref:8070: src/libs maintenance

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette