/src/openssl/crypto/evp/pmeth_lib.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* pmeth_lib.c */ |
2 | | /* |
3 | | * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project |
4 | | * 2006. |
5 | | */ |
6 | | /* ==================================================================== |
7 | | * Copyright (c) 2006 The OpenSSL Project. All rights reserved. |
8 | | * |
9 | | * Redistribution and use in source and binary forms, with or without |
10 | | * modification, are permitted provided that the following conditions |
11 | | * are met: |
12 | | * |
13 | | * 1. Redistributions of source code must retain the above copyright |
14 | | * notice, this list of conditions and the following disclaimer. |
15 | | * |
16 | | * 2. Redistributions in binary form must reproduce the above copyright |
17 | | * notice, this list of conditions and the following disclaimer in |
18 | | * the documentation and/or other materials provided with the |
19 | | * distribution. |
20 | | * |
21 | | * 3. All advertising materials mentioning features or use of this |
22 | | * software must display the following acknowledgment: |
23 | | * "This product includes software developed by the OpenSSL Project |
24 | | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" |
25 | | * |
26 | | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to |
27 | | * endorse or promote products derived from this software without |
28 | | * prior written permission. For written permission, please contact |
29 | | * licensing@OpenSSL.org. |
30 | | * |
31 | | * 5. Products derived from this software may not be called "OpenSSL" |
32 | | * nor may "OpenSSL" appear in their names without prior written |
33 | | * permission of the OpenSSL Project. |
34 | | * |
35 | | * 6. Redistributions of any form whatsoever must retain the following |
36 | | * acknowledgment: |
37 | | * "This product includes software developed by the OpenSSL Project |
38 | | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" |
39 | | * |
40 | | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY |
41 | | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
42 | | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
43 | | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR |
44 | | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
45 | | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
46 | | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
47 | | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
48 | | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
49 | | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
50 | | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
51 | | * OF THE POSSIBILITY OF SUCH DAMAGE. |
52 | | * ==================================================================== |
53 | | * |
54 | | * This product includes cryptographic software written by Eric Young |
55 | | * (eay@cryptsoft.com). This product includes software written by Tim |
56 | | * Hudson (tjh@cryptsoft.com). |
57 | | * |
58 | | */ |
59 | | |
60 | | #include <stdio.h> |
61 | | #include <stdlib.h> |
62 | | #include "cryptlib.h" |
63 | | #include <openssl/objects.h> |
64 | | #include <openssl/evp.h> |
65 | | #ifndef OPENSSL_NO_ENGINE |
66 | | # include <openssl/engine.h> |
67 | | #endif |
68 | | #include "asn1_locl.h" |
69 | | #include "evp_locl.h" |
70 | | |
71 | | typedef int sk_cmp_fn_type(const char *const *a, const char *const *b); |
72 | | |
73 | | DECLARE_STACK_OF(EVP_PKEY_METHOD) |
74 | | STACK_OF(EVP_PKEY_METHOD) *app_pkey_methods = NULL; |
75 | | |
76 | | extern const EVP_PKEY_METHOD rsa_pkey_meth, dh_pkey_meth, dsa_pkey_meth; |
77 | | extern const EVP_PKEY_METHOD ec_pkey_meth, hmac_pkey_meth, cmac_pkey_meth; |
78 | | extern const EVP_PKEY_METHOD dhx_pkey_meth; |
79 | | |
80 | | static const EVP_PKEY_METHOD *standard_methods[] = { |
81 | | #ifndef OPENSSL_NO_RSA |
82 | | &rsa_pkey_meth, |
83 | | #endif |
84 | | #ifndef OPENSSL_NO_DH |
85 | | &dh_pkey_meth, |
86 | | #endif |
87 | | #ifndef OPENSSL_NO_DSA |
88 | | &dsa_pkey_meth, |
89 | | #endif |
90 | | #ifndef OPENSSL_NO_EC |
91 | | &ec_pkey_meth, |
92 | | #endif |
93 | | &hmac_pkey_meth, |
94 | | #ifndef OPENSSL_NO_CMAC |
95 | | &cmac_pkey_meth, |
96 | | #endif |
97 | | #ifndef OPENSSL_NO_DH |
98 | | &dhx_pkey_meth |
99 | | #endif |
100 | | }; |
101 | | |
102 | | DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *, |
103 | | pmeth); |
104 | | |
105 | | static int pmeth_cmp(const EVP_PKEY_METHOD *const *a, |
106 | | const EVP_PKEY_METHOD *const *b) |
107 | 0 | { |
108 | 0 | return ((*a)->pkey_id - (*b)->pkey_id); |
109 | 0 | } |
110 | | |
111 | | IMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *, |
112 | | pmeth); |
113 | | |
114 | | const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type) |
115 | 0 | { |
116 | 0 | EVP_PKEY_METHOD tmp; |
117 | 0 | const EVP_PKEY_METHOD *t = &tmp, **ret; |
118 | 0 | tmp.pkey_id = type; |
119 | 0 | if (app_pkey_methods) { |
120 | 0 | int idx; |
121 | 0 | idx = sk_EVP_PKEY_METHOD_find(app_pkey_methods, &tmp); |
122 | 0 | if (idx >= 0) |
123 | 0 | return sk_EVP_PKEY_METHOD_value(app_pkey_methods, idx); |
124 | 0 | } |
125 | 0 | ret = OBJ_bsearch_pmeth(&t, standard_methods, |
126 | 0 | sizeof(standard_methods) / |
127 | 0 | sizeof(EVP_PKEY_METHOD *)); |
128 | 0 | if (!ret || !*ret) |
129 | 0 | return NULL; |
130 | 0 | return *ret; |
131 | 0 | } |
132 | | |
133 | | static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id) |
134 | 0 | { |
135 | 0 | EVP_PKEY_CTX *ret; |
136 | 0 | const EVP_PKEY_METHOD *pmeth; |
137 | 0 | if (id == -1) { |
138 | 0 | if (!pkey || !pkey->ameth) |
139 | 0 | return NULL; |
140 | 0 | id = pkey->ameth->pkey_id; |
141 | 0 | } |
142 | 0 | #ifndef OPENSSL_NO_ENGINE |
143 | 0 | if (pkey && pkey->engine) |
144 | 0 | e = pkey->engine; |
145 | | /* Try to find an ENGINE which implements this method */ |
146 | 0 | if (e) { |
147 | 0 | if (!ENGINE_init(e)) { |
148 | 0 | EVPerr(EVP_F_INT_CTX_NEW, ERR_R_ENGINE_LIB); |
149 | 0 | return NULL; |
150 | 0 | } |
151 | 0 | } else |
152 | 0 | e = ENGINE_get_pkey_meth_engine(id); |
153 | | |
154 | | /* |
155 | | * If an ENGINE handled this method look it up. Othewise use internal |
156 | | * tables. |
157 | | */ |
158 | | |
159 | 0 | if (e) |
160 | 0 | pmeth = ENGINE_get_pkey_meth(e, id); |
161 | 0 | else |
162 | 0 | #endif |
163 | 0 | pmeth = EVP_PKEY_meth_find(id); |
164 | |
|
165 | 0 | if (pmeth == NULL) { |
166 | 0 | EVPerr(EVP_F_INT_CTX_NEW, EVP_R_UNSUPPORTED_ALGORITHM); |
167 | 0 | return NULL; |
168 | 0 | } |
169 | | |
170 | 0 | ret = OPENSSL_malloc(sizeof(EVP_PKEY_CTX)); |
171 | 0 | if (!ret) { |
172 | 0 | #ifndef OPENSSL_NO_ENGINE |
173 | 0 | if (e) |
174 | 0 | ENGINE_finish(e); |
175 | 0 | #endif |
176 | 0 | EVPerr(EVP_F_INT_CTX_NEW, ERR_R_MALLOC_FAILURE); |
177 | 0 | return NULL; |
178 | 0 | } |
179 | 0 | ret->engine = e; |
180 | 0 | ret->pmeth = pmeth; |
181 | 0 | ret->operation = EVP_PKEY_OP_UNDEFINED; |
182 | 0 | ret->pkey = pkey; |
183 | 0 | ret->peerkey = NULL; |
184 | 0 | ret->pkey_gencb = 0; |
185 | 0 | if (pkey) |
186 | 0 | CRYPTO_add(&pkey->references, 1, CRYPTO_LOCK_EVP_PKEY); |
187 | 0 | ret->data = NULL; |
188 | |
|
189 | 0 | if (pmeth->init) { |
190 | 0 | if (pmeth->init(ret) <= 0) { |
191 | 0 | ret->pmeth = NULL; |
192 | 0 | EVP_PKEY_CTX_free(ret); |
193 | 0 | return NULL; |
194 | 0 | } |
195 | 0 | } |
196 | | |
197 | 0 | return ret; |
198 | 0 | } |
199 | | |
200 | | EVP_PKEY_METHOD *EVP_PKEY_meth_new(int id, int flags) |
201 | 57 | { |
202 | 57 | EVP_PKEY_METHOD *pmeth; |
203 | | |
204 | 57 | pmeth = OPENSSL_malloc(sizeof(EVP_PKEY_METHOD)); |
205 | 57 | if (!pmeth) |
206 | 0 | return NULL; |
207 | | |
208 | 57 | memset(pmeth, 0, sizeof(EVP_PKEY_METHOD)); |
209 | | |
210 | 57 | pmeth->pkey_id = id; |
211 | 57 | pmeth->flags = flags | EVP_PKEY_FLAG_DYNAMIC; |
212 | 57 | return pmeth; |
213 | 57 | } |
214 | | |
215 | | void EVP_PKEY_meth_get0_info(int *ppkey_id, int *pflags, |
216 | | const EVP_PKEY_METHOD *meth) |
217 | 0 | { |
218 | 0 | if (ppkey_id) |
219 | 0 | *ppkey_id = meth->pkey_id; |
220 | 0 | if (pflags) |
221 | 0 | *pflags = meth->flags; |
222 | 0 | } |
223 | | |
224 | | void EVP_PKEY_meth_copy(EVP_PKEY_METHOD *dst, const EVP_PKEY_METHOD *src) |
225 | 0 | { |
226 | |
|
227 | 0 | dst->init = src->init; |
228 | 0 | dst->copy = src->copy; |
229 | 0 | dst->cleanup = src->cleanup; |
230 | |
|
231 | 0 | dst->paramgen_init = src->paramgen_init; |
232 | 0 | dst->paramgen = src->paramgen; |
233 | |
|
234 | 0 | dst->keygen_init = src->keygen_init; |
235 | 0 | dst->keygen = src->keygen; |
236 | |
|
237 | 0 | dst->sign_init = src->sign_init; |
238 | 0 | dst->sign = src->sign; |
239 | |
|
240 | 0 | dst->verify_init = src->verify_init; |
241 | 0 | dst->verify = src->verify; |
242 | |
|
243 | 0 | dst->verify_recover_init = src->verify_recover_init; |
244 | 0 | dst->verify_recover = src->verify_recover; |
245 | |
|
246 | 0 | dst->signctx_init = src->signctx_init; |
247 | 0 | dst->signctx = src->signctx; |
248 | |
|
249 | 0 | dst->verifyctx_init = src->verifyctx_init; |
250 | 0 | dst->verifyctx = src->verifyctx; |
251 | |
|
252 | 0 | dst->encrypt_init = src->encrypt_init; |
253 | 0 | dst->encrypt = src->encrypt; |
254 | |
|
255 | 0 | dst->decrypt_init = src->decrypt_init; |
256 | 0 | dst->decrypt = src->decrypt; |
257 | |
|
258 | 0 | dst->derive_init = src->derive_init; |
259 | 0 | dst->derive = src->derive; |
260 | |
|
261 | 0 | dst->ctrl = src->ctrl; |
262 | 0 | dst->ctrl_str = src->ctrl_str; |
263 | 0 | } |
264 | | |
265 | | void EVP_PKEY_meth_free(EVP_PKEY_METHOD *pmeth) |
266 | 0 | { |
267 | 0 | if (pmeth && (pmeth->flags & EVP_PKEY_FLAG_DYNAMIC)) |
268 | 0 | OPENSSL_free(pmeth); |
269 | 0 | } |
270 | | |
271 | | EVP_PKEY_CTX *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 *EVP_PKEY_CTX_new_id(int id, ENGINE *e) |
277 | 0 | { |
278 | 0 | return int_ctx_new(NULL, e, id); |
279 | 0 | } |
280 | | |
281 | | EVP_PKEY_CTX *EVP_PKEY_CTX_dup(EVP_PKEY_CTX *pctx) |
282 | 0 | { |
283 | 0 | EVP_PKEY_CTX *rctx; |
284 | 0 | if (!pctx->pmeth || !pctx->pmeth->copy) |
285 | 0 | return NULL; |
286 | 0 | #ifndef OPENSSL_NO_ENGINE |
287 | | /* Make sure it's safe to copy a pkey context using an ENGINE */ |
288 | 0 | if (pctx->engine && !ENGINE_init(pctx->engine)) { |
289 | 0 | EVPerr(EVP_F_EVP_PKEY_CTX_DUP, ERR_R_ENGINE_LIB); |
290 | 0 | return 0; |
291 | 0 | } |
292 | 0 | #endif |
293 | 0 | rctx = OPENSSL_malloc(sizeof(EVP_PKEY_CTX)); |
294 | 0 | if (!rctx) |
295 | 0 | return NULL; |
296 | | |
297 | 0 | rctx->pmeth = pctx->pmeth; |
298 | 0 | #ifndef OPENSSL_NO_ENGINE |
299 | 0 | rctx->engine = pctx->engine; |
300 | 0 | #endif |
301 | |
|
302 | 0 | if (pctx->pkey) |
303 | 0 | CRYPTO_add(&pctx->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY); |
304 | |
|
305 | 0 | rctx->pkey = pctx->pkey; |
306 | |
|
307 | 0 | if (pctx->peerkey) |
308 | 0 | CRYPTO_add(&pctx->peerkey->references, 1, CRYPTO_LOCK_EVP_PKEY); |
309 | |
|
310 | 0 | rctx->peerkey = pctx->peerkey; |
311 | |
|
312 | 0 | rctx->data = NULL; |
313 | 0 | rctx->app_data = NULL; |
314 | 0 | rctx->operation = pctx->operation; |
315 | |
|
316 | 0 | if (pctx->pmeth->copy(rctx, pctx) > 0) |
317 | 0 | return rctx; |
318 | | |
319 | 0 | rctx->pmeth = NULL; |
320 | 0 | EVP_PKEY_CTX_free(rctx); |
321 | 0 | return NULL; |
322 | |
|
323 | 0 | } |
324 | | |
325 | | int EVP_PKEY_meth_add0(const EVP_PKEY_METHOD *pmeth) |
326 | 0 | { |
327 | 0 | if (app_pkey_methods == NULL) { |
328 | 0 | app_pkey_methods = sk_EVP_PKEY_METHOD_new(pmeth_cmp); |
329 | 0 | if (!app_pkey_methods) |
330 | 0 | return 0; |
331 | 0 | } |
332 | 0 | if (!sk_EVP_PKEY_METHOD_push(app_pkey_methods, pmeth)) |
333 | 0 | return 0; |
334 | 0 | sk_EVP_PKEY_METHOD_sort(app_pkey_methods); |
335 | 0 | return 1; |
336 | 0 | } |
337 | | |
338 | | void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx) |
339 | 0 | { |
340 | 0 | if (ctx == NULL) |
341 | 0 | return; |
342 | 0 | if (ctx->pmeth && ctx->pmeth->cleanup) |
343 | 0 | ctx->pmeth->cleanup(ctx); |
344 | 0 | if (ctx->pkey) |
345 | 0 | EVP_PKEY_free(ctx->pkey); |
346 | 0 | if (ctx->peerkey) |
347 | 0 | EVP_PKEY_free(ctx->peerkey); |
348 | 0 | #ifndef OPENSSL_NO_ENGINE |
349 | 0 | if (ctx->engine) |
350 | | /* |
351 | | * The EVP_PKEY_CTX we used belongs to an ENGINE, release the |
352 | | * functional reference we held for this reason. |
353 | | */ |
354 | 0 | ENGINE_finish(ctx->engine); |
355 | 0 | #endif |
356 | 0 | OPENSSL_free(ctx); |
357 | 0 | } |
358 | | |
359 | | int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype, |
360 | | int cmd, int p1, void *p2) |
361 | 0 | { |
362 | 0 | int ret; |
363 | 0 | if (!ctx || !ctx->pmeth || !ctx->pmeth->ctrl) { |
364 | 0 | EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_COMMAND_NOT_SUPPORTED); |
365 | 0 | return -2; |
366 | 0 | } |
367 | 0 | if ((keytype != -1) && (ctx->pmeth->pkey_id != keytype)) |
368 | 0 | return -1; |
369 | | |
370 | 0 | if (ctx->operation == EVP_PKEY_OP_UNDEFINED) { |
371 | 0 | EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_NO_OPERATION_SET); |
372 | 0 | return -1; |
373 | 0 | } |
374 | | |
375 | 0 | if ((optype != -1) && !(ctx->operation & optype)) { |
376 | 0 | EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_INVALID_OPERATION); |
377 | 0 | return -1; |
378 | 0 | } |
379 | | |
380 | 0 | ret = ctx->pmeth->ctrl(ctx, cmd, p1, p2); |
381 | |
|
382 | 0 | if (ret == -2) |
383 | 0 | EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_COMMAND_NOT_SUPPORTED); |
384 | |
|
385 | 0 | return ret; |
386 | |
|
387 | 0 | } |
388 | | |
389 | | int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx, |
390 | | const char *name, const char *value) |
391 | 0 | { |
392 | 0 | if (!ctx || !ctx->pmeth || !ctx->pmeth->ctrl_str) { |
393 | 0 | EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR, EVP_R_COMMAND_NOT_SUPPORTED); |
394 | 0 | return -2; |
395 | 0 | } |
396 | 0 | if (!strcmp(name, "digest")) { |
397 | 0 | const EVP_MD *md; |
398 | 0 | if (!value || !(md = EVP_get_digestbyname(value))) { |
399 | 0 | EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR, EVP_R_INVALID_DIGEST); |
400 | 0 | return 0; |
401 | 0 | } |
402 | 0 | return EVP_PKEY_CTX_set_signature_md(ctx, md); |
403 | 0 | } |
404 | 0 | return ctx->pmeth->ctrl_str(ctx, name, value); |
405 | 0 | } |
406 | | |
407 | | int EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX *ctx) |
408 | 0 | { |
409 | 0 | return ctx->operation; |
410 | 0 | } |
411 | | |
412 | | void EVP_PKEY_CTX_set0_keygen_info(EVP_PKEY_CTX *ctx, int *dat, int datlen) |
413 | 0 | { |
414 | 0 | ctx->keygen_info = dat; |
415 | 0 | ctx->keygen_info_count = datlen; |
416 | 0 | } |
417 | | |
418 | | void EVP_PKEY_CTX_set_data(EVP_PKEY_CTX *ctx, void *data) |
419 | 0 | { |
420 | 0 | ctx->data = data; |
421 | 0 | } |
422 | | |
423 | | void *EVP_PKEY_CTX_get_data(EVP_PKEY_CTX *ctx) |
424 | 0 | { |
425 | 0 | return ctx->data; |
426 | 0 | } |
427 | | |
428 | | EVP_PKEY *EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX *ctx) |
429 | 0 | { |
430 | 0 | return ctx->pkey; |
431 | 0 | } |
432 | | |
433 | | EVP_PKEY *EVP_PKEY_CTX_get0_peerkey(EVP_PKEY_CTX *ctx) |
434 | 0 | { |
435 | 0 | return ctx->peerkey; |
436 | 0 | } |
437 | | |
438 | | void EVP_PKEY_CTX_set_app_data(EVP_PKEY_CTX *ctx, void *data) |
439 | 0 | { |
440 | 0 | ctx->app_data = data; |
441 | 0 | } |
442 | | |
443 | | void *EVP_PKEY_CTX_get_app_data(EVP_PKEY_CTX *ctx) |
444 | 0 | { |
445 | 0 | return ctx->app_data; |
446 | 0 | } |
447 | | |
448 | | void EVP_PKEY_meth_set_init(EVP_PKEY_METHOD *pmeth, |
449 | | int (*init) (EVP_PKEY_CTX *ctx)) |
450 | 57 | { |
451 | 57 | pmeth->init = init; |
452 | 57 | } |
453 | | |
454 | | void EVP_PKEY_meth_set_copy(EVP_PKEY_METHOD *pmeth, |
455 | | int (*copy) (EVP_PKEY_CTX *dst, |
456 | | EVP_PKEY_CTX *src)) |
457 | 57 | { |
458 | 57 | pmeth->copy = copy; |
459 | 57 | } |
460 | | |
461 | | void EVP_PKEY_meth_set_cleanup(EVP_PKEY_METHOD *pmeth, |
462 | | void (*cleanup) (EVP_PKEY_CTX *ctx)) |
463 | 57 | { |
464 | 57 | pmeth->cleanup = cleanup; |
465 | 57 | } |
466 | | |
467 | | void EVP_PKEY_meth_set_paramgen(EVP_PKEY_METHOD *pmeth, |
468 | | int (*paramgen_init) (EVP_PKEY_CTX *ctx), |
469 | | int (*paramgen) (EVP_PKEY_CTX *ctx, |
470 | | EVP_PKEY *pkey)) |
471 | 38 | { |
472 | 38 | pmeth->paramgen_init = paramgen_init; |
473 | 38 | pmeth->paramgen = paramgen; |
474 | 38 | } |
475 | | |
476 | | void EVP_PKEY_meth_set_keygen(EVP_PKEY_METHOD *pmeth, |
477 | | int (*keygen_init) (EVP_PKEY_CTX *ctx), |
478 | | int (*keygen) (EVP_PKEY_CTX *ctx, |
479 | | EVP_PKEY *pkey)) |
480 | 57 | { |
481 | 57 | pmeth->keygen_init = keygen_init; |
482 | 57 | pmeth->keygen = keygen; |
483 | 57 | } |
484 | | |
485 | | void EVP_PKEY_meth_set_sign(EVP_PKEY_METHOD *pmeth, |
486 | | int (*sign_init) (EVP_PKEY_CTX *ctx), |
487 | | int (*sign) (EVP_PKEY_CTX *ctx, |
488 | | unsigned char *sig, size_t *siglen, |
489 | | const unsigned char *tbs, |
490 | | size_t tbslen)) |
491 | 38 | { |
492 | 38 | pmeth->sign_init = sign_init; |
493 | 38 | pmeth->sign = sign; |
494 | 38 | } |
495 | | |
496 | | void EVP_PKEY_meth_set_verify(EVP_PKEY_METHOD *pmeth, |
497 | | int (*verify_init) (EVP_PKEY_CTX *ctx), |
498 | | int (*verify) (EVP_PKEY_CTX *ctx, |
499 | | const unsigned char *sig, |
500 | | size_t siglen, |
501 | | const unsigned char *tbs, |
502 | | size_t tbslen)) |
503 | 38 | { |
504 | 38 | pmeth->verify_init = verify_init; |
505 | 38 | pmeth->verify = verify; |
506 | 38 | } |
507 | | |
508 | | void EVP_PKEY_meth_set_verify_recover(EVP_PKEY_METHOD *pmeth, |
509 | | int (*verify_recover_init) (EVP_PKEY_CTX |
510 | | *ctx), |
511 | | int (*verify_recover) (EVP_PKEY_CTX |
512 | | *ctx, |
513 | | unsigned char |
514 | | *sig, |
515 | | size_t *siglen, |
516 | | const unsigned |
517 | | char *tbs, |
518 | | size_t tbslen)) |
519 | 0 | { |
520 | 0 | pmeth->verify_recover_init = verify_recover_init; |
521 | 0 | pmeth->verify_recover = verify_recover; |
522 | 0 | } |
523 | | |
524 | | void EVP_PKEY_meth_set_signctx(EVP_PKEY_METHOD *pmeth, |
525 | | int (*signctx_init) (EVP_PKEY_CTX *ctx, |
526 | | EVP_MD_CTX *mctx), |
527 | | int (*signctx) (EVP_PKEY_CTX *ctx, |
528 | | unsigned char *sig, |
529 | | size_t *siglen, |
530 | | EVP_MD_CTX *mctx)) |
531 | 19 | { |
532 | 19 | pmeth->signctx_init = signctx_init; |
533 | 19 | pmeth->signctx = signctx; |
534 | 19 | } |
535 | | |
536 | | void EVP_PKEY_meth_set_verifyctx(EVP_PKEY_METHOD *pmeth, |
537 | | int (*verifyctx_init) (EVP_PKEY_CTX *ctx, |
538 | | EVP_MD_CTX *mctx), |
539 | | int (*verifyctx) (EVP_PKEY_CTX *ctx, |
540 | | const unsigned char *sig, |
541 | | int siglen, |
542 | | EVP_MD_CTX *mctx)) |
543 | 0 | { |
544 | 0 | pmeth->verifyctx_init = verifyctx_init; |
545 | 0 | pmeth->verifyctx = verifyctx; |
546 | 0 | } |
547 | | |
548 | | void EVP_PKEY_meth_set_encrypt(EVP_PKEY_METHOD *pmeth, |
549 | | int (*encrypt_init) (EVP_PKEY_CTX *ctx), |
550 | | int (*encryptfn) (EVP_PKEY_CTX *ctx, |
551 | | unsigned char *out, |
552 | | size_t *outlen, |
553 | | const unsigned char *in, |
554 | | size_t inlen)) |
555 | 38 | { |
556 | 38 | pmeth->encrypt_init = encrypt_init; |
557 | 38 | pmeth->encrypt = encryptfn; |
558 | 38 | } |
559 | | |
560 | | void EVP_PKEY_meth_set_decrypt(EVP_PKEY_METHOD *pmeth, |
561 | | int (*decrypt_init) (EVP_PKEY_CTX *ctx), |
562 | | int (*decrypt) (EVP_PKEY_CTX *ctx, |
563 | | unsigned char *out, |
564 | | size_t *outlen, |
565 | | const unsigned char *in, |
566 | | size_t inlen)) |
567 | 38 | { |
568 | 38 | pmeth->decrypt_init = decrypt_init; |
569 | 38 | pmeth->decrypt = decrypt; |
570 | 38 | } |
571 | | |
572 | | void EVP_PKEY_meth_set_derive(EVP_PKEY_METHOD *pmeth, |
573 | | int (*derive_init) (EVP_PKEY_CTX *ctx), |
574 | | int (*derive) (EVP_PKEY_CTX *ctx, |
575 | | unsigned char *key, |
576 | | size_t *keylen)) |
577 | 38 | { |
578 | 38 | pmeth->derive_init = derive_init; |
579 | 38 | pmeth->derive = derive; |
580 | 38 | } |
581 | | |
582 | | void EVP_PKEY_meth_set_ctrl(EVP_PKEY_METHOD *pmeth, |
583 | | int (*ctrl) (EVP_PKEY_CTX *ctx, int type, int p1, |
584 | | void *p2), |
585 | | int (*ctrl_str) (EVP_PKEY_CTX *ctx, |
586 | | const char *type, |
587 | | const char *value)) |
588 | 57 | { |
589 | 57 | pmeth->ctrl = ctrl; |
590 | 57 | pmeth->ctrl_str = ctrl_str; |
591 | 57 | } |
592 | | |
593 | | void EVP_PKEY_meth_get_init(EVP_PKEY_METHOD *pmeth, |
594 | | int (**pinit) (EVP_PKEY_CTX *ctx)) |
595 | 0 | { |
596 | 0 | *pinit = pmeth->init; |
597 | 0 | } |
598 | | |
599 | | void EVP_PKEY_meth_get_copy(EVP_PKEY_METHOD *pmeth, |
600 | | int (**pcopy) (EVP_PKEY_CTX *dst, |
601 | | EVP_PKEY_CTX *src)) |
602 | 0 | { |
603 | 0 | *pcopy = pmeth->copy; |
604 | 0 | } |
605 | | |
606 | | void EVP_PKEY_meth_get_cleanup(EVP_PKEY_METHOD *pmeth, |
607 | | void (**pcleanup) (EVP_PKEY_CTX *ctx)) |
608 | 0 | { |
609 | 0 | *pcleanup = pmeth->cleanup; |
610 | 0 | } |
611 | | |
612 | | void EVP_PKEY_meth_get_paramgen(EVP_PKEY_METHOD *pmeth, |
613 | | int (**pparamgen_init) (EVP_PKEY_CTX *ctx), |
614 | | int (**pparamgen) (EVP_PKEY_CTX *ctx, |
615 | | EVP_PKEY *pkey)) |
616 | 0 | { |
617 | 0 | if (pparamgen_init) |
618 | 0 | *pparamgen_init = pmeth->paramgen_init; |
619 | 0 | if (pparamgen) |
620 | 0 | *pparamgen = pmeth->paramgen; |
621 | 0 | } |
622 | | |
623 | | void EVP_PKEY_meth_get_keygen(EVP_PKEY_METHOD *pmeth, |
624 | | int (**pkeygen_init) (EVP_PKEY_CTX *ctx), |
625 | | int (**pkeygen) (EVP_PKEY_CTX *ctx, |
626 | | EVP_PKEY *pkey)) |
627 | 0 | { |
628 | 0 | if (pkeygen_init) |
629 | 0 | *pkeygen_init = pmeth->keygen_init; |
630 | 0 | if (pkeygen) |
631 | 0 | *pkeygen = pmeth->keygen; |
632 | 0 | } |
633 | | |
634 | | void EVP_PKEY_meth_get_sign(EVP_PKEY_METHOD *pmeth, |
635 | | int (**psign_init) (EVP_PKEY_CTX *ctx), |
636 | | int (**psign) (EVP_PKEY_CTX *ctx, |
637 | | unsigned char *sig, size_t *siglen, |
638 | | const unsigned char *tbs, |
639 | | size_t tbslen)) |
640 | 0 | { |
641 | 0 | if (psign_init) |
642 | 0 | *psign_init = pmeth->sign_init; |
643 | 0 | if (psign) |
644 | 0 | *psign = pmeth->sign; |
645 | 0 | } |
646 | | |
647 | | void EVP_PKEY_meth_get_verify(EVP_PKEY_METHOD *pmeth, |
648 | | int (**pverify_init) (EVP_PKEY_CTX *ctx), |
649 | | int (**pverify) (EVP_PKEY_CTX *ctx, |
650 | | const unsigned char *sig, |
651 | | size_t siglen, |
652 | | const unsigned char *tbs, |
653 | | size_t tbslen)) |
654 | 0 | { |
655 | 0 | if (pverify_init) |
656 | 0 | *pverify_init = pmeth->verify_init; |
657 | 0 | if (pverify) |
658 | 0 | *pverify = pmeth->verify; |
659 | 0 | } |
660 | | |
661 | | void EVP_PKEY_meth_get_verify_recover(EVP_PKEY_METHOD *pmeth, |
662 | | int (**pverify_recover_init) (EVP_PKEY_CTX |
663 | | *ctx), |
664 | | int (**pverify_recover) (EVP_PKEY_CTX |
665 | | *ctx, |
666 | | unsigned char |
667 | | *sig, |
668 | | size_t *siglen, |
669 | | const unsigned |
670 | | char *tbs, |
671 | | size_t tbslen)) |
672 | 0 | { |
673 | 0 | if (pverify_recover_init) |
674 | 0 | *pverify_recover_init = pmeth->verify_recover_init; |
675 | 0 | if (pverify_recover) |
676 | 0 | *pverify_recover = pmeth->verify_recover; |
677 | 0 | } |
678 | | |
679 | | void EVP_PKEY_meth_get_signctx(EVP_PKEY_METHOD *pmeth, |
680 | | int (**psignctx_init) (EVP_PKEY_CTX *ctx, |
681 | | EVP_MD_CTX *mctx), |
682 | | int (**psignctx) (EVP_PKEY_CTX *ctx, |
683 | | unsigned char *sig, |
684 | | size_t *siglen, |
685 | | EVP_MD_CTX *mctx)) |
686 | 0 | { |
687 | 0 | if (psignctx_init) |
688 | 0 | *psignctx_init = pmeth->signctx_init; |
689 | 0 | if (psignctx) |
690 | 0 | *psignctx = pmeth->signctx; |
691 | 0 | } |
692 | | |
693 | | void EVP_PKEY_meth_get_verifyctx(EVP_PKEY_METHOD *pmeth, |
694 | | int (**pverifyctx_init) (EVP_PKEY_CTX *ctx, |
695 | | EVP_MD_CTX *mctx), |
696 | | int (**pverifyctx) (EVP_PKEY_CTX *ctx, |
697 | | const unsigned char *sig, |
698 | | int siglen, |
699 | | EVP_MD_CTX *mctx)) |
700 | 0 | { |
701 | 0 | if (pverifyctx_init) |
702 | 0 | *pverifyctx_init = pmeth->verifyctx_init; |
703 | 0 | if (pverifyctx) |
704 | 0 | *pverifyctx = pmeth->verifyctx; |
705 | 0 | } |
706 | | |
707 | | void EVP_PKEY_meth_get_encrypt(EVP_PKEY_METHOD *pmeth, |
708 | | int (**pencrypt_init) (EVP_PKEY_CTX *ctx), |
709 | | int (**pencryptfn) (EVP_PKEY_CTX *ctx, |
710 | | unsigned char *out, |
711 | | size_t *outlen, |
712 | | const unsigned char *in, |
713 | | size_t inlen)) |
714 | 0 | { |
715 | 0 | if (pencrypt_init) |
716 | 0 | *pencrypt_init = pmeth->encrypt_init; |
717 | 0 | if (pencryptfn) |
718 | 0 | *pencryptfn = pmeth->encrypt; |
719 | 0 | } |
720 | | |
721 | | void EVP_PKEY_meth_get_decrypt(EVP_PKEY_METHOD *pmeth, |
722 | | int (**pdecrypt_init) (EVP_PKEY_CTX *ctx), |
723 | | int (**pdecrypt) (EVP_PKEY_CTX *ctx, |
724 | | unsigned char *out, |
725 | | size_t *outlen, |
726 | | const unsigned char *in, |
727 | | size_t inlen)) |
728 | 0 | { |
729 | 0 | if (pdecrypt_init) |
730 | 0 | *pdecrypt_init = pmeth->decrypt_init; |
731 | 0 | if (pdecrypt) |
732 | 0 | *pdecrypt = pmeth->decrypt; |
733 | 0 | } |
734 | | |
735 | | void EVP_PKEY_meth_get_derive(EVP_PKEY_METHOD *pmeth, |
736 | | int (**pderive_init) (EVP_PKEY_CTX *ctx), |
737 | | int (**pderive) (EVP_PKEY_CTX *ctx, |
738 | | unsigned char *key, |
739 | | size_t *keylen)) |
740 | 0 | { |
741 | 0 | if (pderive_init) |
742 | 0 | *pderive_init = pmeth->derive_init; |
743 | 0 | if (pderive) |
744 | 0 | *pderive = pmeth->derive; |
745 | 0 | } |
746 | | |
747 | | void EVP_PKEY_meth_get_ctrl(EVP_PKEY_METHOD *pmeth, |
748 | | int (**pctrl) (EVP_PKEY_CTX *ctx, int type, int p1, |
749 | | void *p2), |
750 | | int (**pctrl_str) (EVP_PKEY_CTX *ctx, |
751 | | const char *type, |
752 | | const char *value)) |
753 | 0 | { |
754 | 0 | if (pctrl) |
755 | 0 | *pctrl = pmeth->ctrl; |
756 | 0 | if (pctrl_str) |
757 | 0 | *pctrl_str = pmeth->ctrl_str; |
758 | 0 | } |