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