Coverage Report

Created: 2022-08-24 06:30

/src/libressl/crypto/evp/pmeth_lib.c
Line
Count
Source (jump to first uncovered line)
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
0
{
121
0
  return ((*a)->pkey_id - (*b)->pkey_id);
122
0
}
123
124
125
static int
126
pmeth_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_)
127
0
{
128
0
  const EVP_PKEY_METHOD * const *a = a_;
129
0
  const EVP_PKEY_METHOD * const *b = b_;
130
0
  return pmeth_cmp(a, b);
131
0
}
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
0
{
136
0
  return (const EVP_PKEY_METHOD * *)OBJ_bsearch_(key, base, num, sizeof(const EVP_PKEY_METHOD *),
137
0
      pmeth_cmp_BSEARCH_CMP_FN);
138
0
}
139
140
const EVP_PKEY_METHOD *
141
EVP_PKEY_meth_find(int type)
142
0
{
143
0
  EVP_PKEY_METHOD tmp;
144
0
  const EVP_PKEY_METHOD *t = &tmp, **ret;
145
146
0
  tmp.pkey_id = type;
147
0
  if (app_pkey_methods) {
148
0
    int idx;
149
0
    idx = sk_EVP_PKEY_METHOD_find(app_pkey_methods, &tmp);
150
0
    if (idx >= 0)
151
0
      return sk_EVP_PKEY_METHOD_value(app_pkey_methods, idx);
152
0
  }
153
0
  ret = OBJ_bsearch_pmeth(&t, standard_methods,
154
0
      sizeof(standard_methods)/sizeof(EVP_PKEY_METHOD *));
155
0
  if (!ret || !*ret)
156
0
    return NULL;
157
0
  return *ret;
158
0
}
159
160
static EVP_PKEY_CTX *
161
int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
162
0
{
163
0
  EVP_PKEY_CTX *ret;
164
0
  const EVP_PKEY_METHOD *pmeth;
165
166
0
  if (id == -1) {
167
0
    if (!pkey || !pkey->ameth)
168
0
      return NULL;
169
0
    id = pkey->ameth->pkey_id;
170
0
  }
171
0
#ifndef OPENSSL_NO_ENGINE
172
0
  if (pkey && pkey->engine)
173
0
    e = pkey->engine;
174
  /* Try to find an ENGINE which implements this method */
175
0
  if (e) {
176
0
    if (!ENGINE_init(e)) {
177
0
      EVPerror(ERR_R_ENGINE_LIB);
178
0
      return NULL;
179
0
    }
180
0
  } else
181
0
    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
0
  if (e)
188
0
    pmeth = ENGINE_get_pkey_meth(e, id);
189
0
  else
190
0
#endif
191
0
    pmeth = EVP_PKEY_meth_find(id);
192
193
0
  if (pmeth == NULL) {
194
0
    EVPerror(EVP_R_UNSUPPORTED_ALGORITHM);
195
0
    return NULL;
196
0
  }
197
198
0
  ret = malloc(sizeof(EVP_PKEY_CTX));
199
0
  if (ret == NULL) {
200
0
#ifndef OPENSSL_NO_ENGINE
201
0
    ENGINE_finish(e);
202
0
#endif
203
0
    EVPerror(ERR_R_MALLOC_FAILURE);
204
0
    return NULL;
205
0
  }
206
0
  ret->engine = e;
207
0
  ret->pmeth = pmeth;
208
0
  ret->operation = EVP_PKEY_OP_UNDEFINED;
209
0
  ret->pkey = pkey;
210
0
  ret->peerkey = NULL;
211
0
  ret->pkey_gencb = 0;
212
0
  if (pkey)
213
0
    CRYPTO_add(&pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);
214
0
  ret->data = NULL;
215
216
0
  if (pmeth->init) {
217
0
    if (pmeth->init(ret) <= 0) {
218
0
      EVP_PKEY_CTX_free(ret);
219
0
      return NULL;
220
0
    }
221
0
  }
222
223
0
  return ret;
224
0
}
225
226
EVP_PKEY_METHOD*
227
EVP_PKEY_meth_new(int id, int flags)
228
0
{
229
0
  EVP_PKEY_METHOD *pmeth;
230
231
0
  if ((pmeth = calloc(1, sizeof(EVP_PKEY_METHOD))) == NULL)
232
0
    return NULL;
233
234
0
  pmeth->pkey_id = id;
235
0
  pmeth->flags = flags | EVP_PKEY_FLAG_DYNAMIC;
236
237
0
  return pmeth;
238
0
}
239
240
void
241
EVP_PKEY_meth_get0_info(int *ppkey_id, int *pflags, const EVP_PKEY_METHOD *meth)
242
0
{
243
0
  if (ppkey_id)
244
0
    *ppkey_id = meth->pkey_id;
245
0
  if (pflags)
246
0
    *pflags = meth->flags;
247
0
}
248
249
void
250
EVP_PKEY_meth_copy(EVP_PKEY_METHOD *dst, const EVP_PKEY_METHOD *src)
251
0
{
252
0
  EVP_PKEY_METHOD preserve;
253
254
0
  preserve.pkey_id = dst->pkey_id;
255
0
  preserve.flags = dst->flags;
256
257
0
  *dst = *src;
258
259
0
  dst->pkey_id = preserve.pkey_id;
260
0
  dst->flags = preserve.flags;
261
0
}
262
263
void
264
EVP_PKEY_meth_free(EVP_PKEY_METHOD *pmeth)
265
0
{
266
0
  if (pmeth && (pmeth->flags & EVP_PKEY_FLAG_DYNAMIC))
267
0
    free(pmeth);
268
0
}
269
270
EVP_PKEY_CTX *
271
EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e)
272
0
{
273
0
  return int_ctx_new(pkey, e, -1);
274
0
}
275
276
EVP_PKEY_CTX *
277
EVP_PKEY_CTX_new_id(int id, ENGINE *e)
278
0
{
279
0
  return int_ctx_new(NULL, e, id);
280
0
}
281
282
EVP_PKEY_CTX *
283
EVP_PKEY_CTX_dup(EVP_PKEY_CTX *pctx)
284
0
{
285
0
  EVP_PKEY_CTX *rctx;
286
287
0
  if (!pctx->pmeth || !pctx->pmeth->copy)
288
0
    return NULL;
289
0
#ifndef OPENSSL_NO_ENGINE
290
  /* Make sure it's safe to copy a pkey context using an ENGINE */
291
0
  if (pctx->engine && !ENGINE_init(pctx->engine)) {
292
0
    EVPerror(ERR_R_ENGINE_LIB);
293
0
    return 0;
294
0
  }
295
0
#endif
296
0
  rctx = malloc(sizeof(EVP_PKEY_CTX));
297
0
  if (!rctx)
298
0
    return NULL;
299
300
0
  rctx->pmeth = pctx->pmeth;
301
0
#ifndef OPENSSL_NO_ENGINE
302
0
  rctx->engine = pctx->engine;
303
0
#endif
304
305
0
  if (pctx->pkey)
306
0
    CRYPTO_add(&pctx->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);
307
308
0
  rctx->pkey = pctx->pkey;
309
310
0
  if (pctx->peerkey)
311
0
    CRYPTO_add(&pctx->peerkey->references, 1, CRYPTO_LOCK_EVP_PKEY);
312
313
0
  rctx->peerkey = pctx->peerkey;
314
315
0
  rctx->data = NULL;
316
0
  rctx->app_data = NULL;
317
0
  rctx->operation = pctx->operation;
318
319
0
  if (pctx->pmeth->copy(rctx, pctx) > 0)
320
0
    return rctx;
321
322
0
  EVP_PKEY_CTX_free(rctx);
323
0
  return NULL;
324
0
}
325
326
int
327
EVP_PKEY_meth_add0(const EVP_PKEY_METHOD *pmeth)
328
0
{
329
0
  if (app_pkey_methods == NULL) {
330
0
    app_pkey_methods = sk_EVP_PKEY_METHOD_new(pmeth_cmp);
331
0
    if (!app_pkey_methods)
332
0
      return 0;
333
0
  }
334
0
  if (!sk_EVP_PKEY_METHOD_push(app_pkey_methods, pmeth))
335
0
    return 0;
336
0
  sk_EVP_PKEY_METHOD_sort(app_pkey_methods);
337
0
  return 1;
338
0
}
339
340
void
341
EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx)
342
4.72k
{
343
4.72k
  if (ctx == NULL)
344
4.72k
    return;
345
0
  if (ctx->pmeth && ctx->pmeth->cleanup)
346
0
    ctx->pmeth->cleanup(ctx);
347
0
  EVP_PKEY_free(ctx->pkey);
348
0
  EVP_PKEY_free(ctx->peerkey);
349
0
#ifndef OPENSSL_NO_ENGINE
350
0
  ENGINE_finish(ctx->engine);
351
0
#endif
352
0
  free(ctx);
353
0
}
354
355
int
356
EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype, int cmd,
357
    int p1, void *p2)
358
0
{
359
0
  int ret;
360
361
0
  if (!ctx || !ctx->pmeth || !ctx->pmeth->ctrl) {
362
0
    EVPerror(EVP_R_COMMAND_NOT_SUPPORTED);
363
0
    return -2;
364
0
  }
365
0
  if ((keytype != -1) && (ctx->pmeth->pkey_id != keytype))
366
0
    return -1;
367
368
0
  if (ctx->operation == EVP_PKEY_OP_UNDEFINED) {
369
0
    EVPerror(EVP_R_NO_OPERATION_SET);
370
0
    return -1;
371
0
  }
372
373
0
  if ((optype != -1) && !(ctx->operation & optype)) {
374
0
    EVPerror(EVP_R_INVALID_OPERATION);
375
0
    return -1;
376
0
  }
377
378
0
  ret = ctx->pmeth->ctrl(ctx, cmd, p1, p2);
379
380
0
  if (ret == -2)
381
0
    EVPerror(EVP_R_COMMAND_NOT_SUPPORTED);
382
383
0
  return ret;
384
385
0
}
386
387
int
388
EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx, const char *name, const char *value)
389
0
{
390
0
  if (!ctx || !ctx->pmeth || !ctx->pmeth->ctrl_str) {
391
0
    EVPerror(EVP_R_COMMAND_NOT_SUPPORTED);
392
0
    return -2;
393
0
  }
394
0
  if (!strcmp(name, "digest")) {
395
0
    return EVP_PKEY_CTX_md(ctx, EVP_PKEY_OP_TYPE_SIG,
396
0
        EVP_PKEY_CTRL_MD, value);
397
0
  }
398
0
  return ctx->pmeth->ctrl_str(ctx, name, value);
399
0
}
400
401
int
402
EVP_PKEY_CTX_str2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *str)
403
0
{
404
0
  size_t len;
405
406
0
  if ((len = strlen(str)) > INT_MAX)
407
0
    return -1;
408
409
0
  return ctx->pmeth->ctrl(ctx, cmd, len, (void *)str);
410
0
}
411
412
int
413
EVP_PKEY_CTX_hex2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *hexstr)
414
0
{
415
0
  unsigned char *hex = NULL;
416
0
  long length;
417
0
  int ret = 0;
418
419
0
  if ((hex = string_to_hex(hexstr, &length)) == NULL)
420
0
    goto err;
421
0
  if (length < 0 || length > INT_MAX) {
422
0
    ret = -1;
423
0
    goto err;
424
0
  }
425
426
0
  ret = ctx->pmeth->ctrl(ctx, cmd, length, hex);
427
428
0
 err:
429
0
  free(hex);
430
0
  return ret;
431
0
}
432
433
int
434
EVP_PKEY_CTX_md(EVP_PKEY_CTX *ctx, int optype, int cmd, const char *md_name)
435
0
{
436
0
  const EVP_MD *md;
437
438
0
  if ((md = EVP_get_digestbyname(md_name)) == NULL) {
439
0
    EVPerror(EVP_R_INVALID_DIGEST);
440
0
    return 0;
441
0
  }
442
0
  return EVP_PKEY_CTX_ctrl(ctx, -1, optype, cmd, 0, (void *)md);
443
0
}
444
445
int
446
EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX *ctx)
447
0
{
448
0
  return ctx->operation;
449
0
}
450
451
void
452
EVP_PKEY_CTX_set0_keygen_info(EVP_PKEY_CTX *ctx, int *dat, int datlen)
453
0
{
454
0
  ctx->keygen_info = dat;
455
0
  ctx->keygen_info_count = datlen;
456
0
}
457
458
void
459
EVP_PKEY_CTX_set_data(EVP_PKEY_CTX *ctx, void *data)
460
0
{
461
0
  ctx->data = data;
462
0
}
463
464
void *
465
EVP_PKEY_CTX_get_data(EVP_PKEY_CTX *ctx)
466
0
{
467
0
  return ctx->data;
468
0
}
469
470
EVP_PKEY *
471
EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX *ctx)
472
0
{
473
0
  return ctx->pkey;
474
0
}
475
476
EVP_PKEY *
477
EVP_PKEY_CTX_get0_peerkey(EVP_PKEY_CTX *ctx)
478
0
{
479
0
  return ctx->peerkey;
480
0
}
481
482
void
483
EVP_PKEY_CTX_set_app_data(EVP_PKEY_CTX *ctx, void *data)
484
0
{
485
0
  ctx->app_data = data;
486
0
}
487
488
void *
489
EVP_PKEY_CTX_get_app_data(EVP_PKEY_CTX *ctx)
490
0
{
491
0
  return ctx->app_data;
492
0
}
493
494
void
495
EVP_PKEY_meth_set_init(EVP_PKEY_METHOD *pmeth,
496
    int (*init)(EVP_PKEY_CTX *ctx))
497
0
{
498
0
  pmeth->init = init;
499
0
}
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
0
{
505
0
  pmeth->copy = copy;
506
0
}
507
508
void
509
EVP_PKEY_meth_set_cleanup(EVP_PKEY_METHOD *pmeth,
510
    void (*cleanup)(EVP_PKEY_CTX *ctx))
511
0
{
512
0
  pmeth->cleanup = cleanup;
513
0
}
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
0
{
520
0
  pmeth->paramgen_init = paramgen_init;
521
0
  pmeth->paramgen = paramgen;
522
0
}
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
0
{
529
0
  pmeth->keygen_init = keygen_init;
530
0
  pmeth->keygen = keygen;
531
0
}
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
0
{
539
0
  pmeth->sign_init = sign_init;
540
0
  pmeth->sign = sign;
541
0
}
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
0
{
549
0
  pmeth->verify_init = verify_init;
550
0
  pmeth->verify = verify;
551
0
}
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
0
{
560
0
  pmeth->verify_recover_init = verify_recover_init;
561
0
  pmeth->verify_recover = verify_recover;
562
0
}
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
0
{
570
0
  pmeth->signctx_init = signctx_init;
571
0
  pmeth->signctx = signctx;
572
0
}
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
0
{
580
0
  pmeth->verifyctx_init = verifyctx_init;
581
0
  pmeth->verifyctx = verifyctx;
582
0
}
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
0
{
590
0
  pmeth->encrypt_init = encrypt_init;
591
0
  pmeth->encrypt = encryptfn;
592
0
}
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
0
{
600
0
  pmeth->decrypt_init = decrypt_init;
601
0
  pmeth->decrypt = decrypt;
602
0
}
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
0
{
609
0
  pmeth->derive_init = derive_init;
610
0
  pmeth->derive = derive;
611
0
}
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
0
{
618
0
  pmeth->ctrl = ctrl;
619
0
  pmeth->ctrl_str = ctrl_str;
620
0
}
621
622
void
623
EVP_PKEY_meth_set_check(EVP_PKEY_METHOD *pmeth, int (*check)(EVP_PKEY *pkey))
624
0
{
625
0
  pmeth->check = check;
626
0
}
627
628
void
629
EVP_PKEY_meth_set_public_check(EVP_PKEY_METHOD *pmeth,
630
    int (*public_check)(EVP_PKEY *pkey))
631
0
{
632
0
  pmeth->public_check = public_check;
633
0
}
634
635
void
636
EVP_PKEY_meth_set_param_check(EVP_PKEY_METHOD *pmeth,
637
    int (*param_check)(EVP_PKEY *pkey))
638
0
{
639
0
  pmeth->param_check = param_check;
640
0
}