Coverage Report

Created: 2018-08-29 13:53

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