]>
Commit | Line | Data |
---|---|---|
0f113f3e MC |
1 | /* |
2 | * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project | |
3 | * 2006. | |
0b6f3c66 DSH |
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 | |
0f113f3e | 13 | * notice, this list of conditions and the following disclaimer. |
0b6f3c66 DSH |
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 <stdio.h> | |
60 | #include <stdlib.h> | |
b39fc560 | 61 | #include "internal/cryptlib.h" |
c9777d26 | 62 | #ifndef OPENSSL_NO_ENGINE |
0f113f3e | 63 | # include <openssl/engine.h> |
c9777d26 | 64 | #endif |
33bed28b | 65 | #include <openssl/evp.h> |
99119000 | 66 | #include <openssl/x509v3.h> |
5fe736e5 | 67 | #include "internal/asn1_int.h" |
27af42f9 | 68 | #include "internal/evp_int.h" |
99119000 | 69 | #include "internal/numbers.h" |
0b6f3c66 | 70 | |
0f113f3e | 71 | typedef int sk_cmp_fn_type(const char *const *a, const char *const *b); |
5ce278a7 | 72 | |
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 |
1eff3485 | 91 | &dhx_pkey_meth, |
afb14cda | 92 | #endif |
1eff3485 | 93 | &tls1_prf_pkey_meth |
0f113f3e | 94 | }; |
0b6f3c66 | 95 | |
606f6c47 | 96 | DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *, |
0f113f3e | 97 | pmeth); |
babb3798 | 98 | |
0f113f3e MC |
99 | static int pmeth_cmp(const EVP_PKEY_METHOD *const *a, |
100 | const EVP_PKEY_METHOD *const *b) | |
101 | { | |
102 | return ((*a)->pkey_id - (*b)->pkey_id); | |
103 | } | |
0b6f3c66 | 104 | |
606f6c47 | 105 | IMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *, |
0f113f3e | 106 | pmeth); |
babb3798 | 107 | |
c9777d26 | 108 | const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type) |
0f113f3e MC |
109 | { |
110 | EVP_PKEY_METHOD tmp; | |
111 | const EVP_PKEY_METHOD *t = &tmp, **ret; | |
112 | tmp.pkey_id = type; | |
113 | if (app_pkey_methods) { | |
114 | int idx; | |
115 | idx = sk_EVP_PKEY_METHOD_find(app_pkey_methods, &tmp); | |
116 | if (idx >= 0) | |
117 | return sk_EVP_PKEY_METHOD_value(app_pkey_methods, idx); | |
118 | } | |
119 | ret = OBJ_bsearch_pmeth(&t, standard_methods, | |
120 | sizeof(standard_methods) / | |
121 | sizeof(EVP_PKEY_METHOD *)); | |
122 | if (!ret || !*ret) | |
123 | return NULL; | |
124 | return *ret; | |
125 | } | |
0b6f3c66 | 126 | |
f5cda4cb | 127 | static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id) |
0f113f3e MC |
128 | { |
129 | EVP_PKEY_CTX *ret; | |
130 | const EVP_PKEY_METHOD *pmeth; | |
131 | if (id == -1) { | |
132 | if (!pkey || !pkey->ameth) | |
133 | return NULL; | |
134 | id = pkey->ameth->pkey_id; | |
135 | } | |
a63bf2c5 | 136 | #ifndef OPENSSL_NO_ENGINE |
0f113f3e MC |
137 | if (pkey && pkey->engine) |
138 | e = pkey->engine; | |
139 | /* Try to find an ENGINE which implements this method */ | |
140 | if (e) { | |
141 | if (!ENGINE_init(e)) { | |
142 | EVPerr(EVP_F_INT_CTX_NEW, ERR_R_ENGINE_LIB); | |
143 | return NULL; | |
144 | } | |
145 | } else | |
146 | e = ENGINE_get_pkey_meth_engine(id); | |
147 | ||
148 | /* | |
0d4fb843 | 149 | * If an ENGINE handled this method look it up. Otherwise use internal |
0f113f3e MC |
150 | * tables. |
151 | */ | |
152 | ||
153 | if (e) | |
154 | pmeth = ENGINE_get_pkey_meth(e, id); | |
155 | else | |
a63bf2c5 | 156 | #endif |
0f113f3e | 157 | pmeth = EVP_PKEY_meth_find(id); |
c9777d26 | 158 | |
0f113f3e MC |
159 | if (pmeth == NULL) { |
160 | EVPerr(EVP_F_INT_CTX_NEW, EVP_R_UNSUPPORTED_ALGORITHM); | |
161 | return NULL; | |
162 | } | |
c9777d26 | 163 | |
64b25758 | 164 | ret = OPENSSL_zalloc(sizeof(*ret)); |
90945fa3 | 165 | if (ret == NULL) { |
a63bf2c5 | 166 | #ifndef OPENSSL_NO_ENGINE |
7c96dbcd | 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 |
7c96dbcd | 333 | ENGINE_finish(ctx->engine); |
c9777d26 | 334 | #endif |
0f113f3e MC |
335 | OPENSSL_free(ctx); |
336 | } | |
5da98aa6 | 337 | |
0b6f3c66 | 338 | int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype, |
0f113f3e MC |
339 | int cmd, int p1, void *p2) |
340 | { | |
341 | int ret; | |
342 | if (!ctx || !ctx->pmeth || !ctx->pmeth->ctrl) { | |
343 | EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_COMMAND_NOT_SUPPORTED); | |
344 | return -2; | |
345 | } | |
346 | if ((keytype != -1) && (ctx->pmeth->pkey_id != keytype)) | |
347 | return -1; | |
348 | ||
349 | if (ctx->operation == EVP_PKEY_OP_UNDEFINED) { | |
350 | EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_NO_OPERATION_SET); | |
351 | return -1; | |
352 | } | |
353 | ||
354 | if ((optype != -1) && !(ctx->operation & optype)) { | |
355 | EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_INVALID_OPERATION); | |
356 | return -1; | |
357 | } | |
358 | ||
359 | ret = ctx->pmeth->ctrl(ctx, cmd, p1, p2); | |
360 | ||
361 | if (ret == -2) | |
362 | EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_COMMAND_NOT_SUPPORTED); | |
363 | ||
364 | return ret; | |
365 | ||
366 | } | |
0b6f3c66 | 367 | |
4a3dc3c0 | 368 | int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx, |
0f113f3e MC |
369 | const char *name, const char *value) |
370 | { | |
371 | if (!ctx || !ctx->pmeth || !ctx->pmeth->ctrl_str) { | |
372 | EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR, EVP_R_COMMAND_NOT_SUPPORTED); | |
373 | return -2; | |
374 | } | |
86885c28 | 375 | if (strcmp(name, "digest") == 0) { |
0f113f3e | 376 | const EVP_MD *md; |
75ebbd9a | 377 | if (value == NULL || (md = EVP_get_digestbyname(value)) == NULL) { |
0f113f3e MC |
378 | EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR, EVP_R_INVALID_DIGEST); |
379 | return 0; | |
380 | } | |
381 | return EVP_PKEY_CTX_set_signature_md(ctx, md); | |
382 | } | |
383 | return ctx->pmeth->ctrl_str(ctx, name, value); | |
384 | } | |
f5cda4cb | 385 | |
99119000 DSH |
386 | /* Utility functions to send a string of hex string to a ctrl */ |
387 | ||
388 | int EVP_PKEY_CTX_str2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *str) | |
389 | { | |
390 | size_t len; | |
391 | ||
392 | len = strlen(str); | |
393 | if (len > INT_MAX) | |
394 | return -1; | |
395 | return ctx->pmeth->ctrl(ctx, cmd, len, (void *)str); | |
396 | } | |
397 | ||
398 | int EVP_PKEY_CTX_hex2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *hex) | |
399 | { | |
400 | unsigned char *bin; | |
401 | long binlen; | |
402 | int rv = -1; | |
403 | ||
404 | bin = string_to_hex(hex, &binlen); | |
405 | if (bin == NULL) | |
406 | return 0; | |
407 | if (binlen <= INT_MAX) | |
408 | rv = ctx->pmeth->ctrl(ctx, cmd, binlen, bin); | |
409 | OPENSSL_free(bin); | |
410 | return rv; | |
411 | } | |
412 | ||
b28dea4e | 413 | int EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX *ctx) |
0f113f3e MC |
414 | { |
415 | return ctx->operation; | |
416 | } | |
b28dea4e DSH |
417 | |
418 | void EVP_PKEY_CTX_set0_keygen_info(EVP_PKEY_CTX *ctx, int *dat, int datlen) | |
0f113f3e MC |
419 | { |
420 | ctx->keygen_info = dat; | |
421 | ctx->keygen_info_count = datlen; | |
422 | } | |
b28dea4e | 423 | |
f5cda4cb | 424 | void EVP_PKEY_CTX_set_data(EVP_PKEY_CTX *ctx, void *data) |
0f113f3e MC |
425 | { |
426 | ctx->data = data; | |
427 | } | |
f5cda4cb DSH |
428 | |
429 | void *EVP_PKEY_CTX_get_data(EVP_PKEY_CTX *ctx) | |
0f113f3e MC |
430 | { |
431 | return ctx->data; | |
432 | } | |
f5cda4cb | 433 | |
81cebb8b | 434 | EVP_PKEY *EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX *ctx) |
0f113f3e MC |
435 | { |
436 | return ctx->pkey; | |
437 | } | |
81cebb8b | 438 | |
0e1dba93 | 439 | EVP_PKEY *EVP_PKEY_CTX_get0_peerkey(EVP_PKEY_CTX *ctx) |
0f113f3e MC |
440 | { |
441 | return ctx->peerkey; | |
442 | } | |
443 | ||
f5cda4cb | 444 | void EVP_PKEY_CTX_set_app_data(EVP_PKEY_CTX *ctx, void *data) |
0f113f3e MC |
445 | { |
446 | ctx->app_data = data; | |
447 | } | |
f5cda4cb DSH |
448 | |
449 | void *EVP_PKEY_CTX_get_app_data(EVP_PKEY_CTX *ctx) | |
0f113f3e MC |
450 | { |
451 | return ctx->app_data; | |
452 | } | |
ba30bad5 DSH |
453 | |
454 | void EVP_PKEY_meth_set_init(EVP_PKEY_METHOD *pmeth, | |
0f113f3e MC |
455 | int (*init) (EVP_PKEY_CTX *ctx)) |
456 | { | |
457 | pmeth->init = init; | |
458 | } | |
8bdcef40 DSH |
459 | |
460 | void EVP_PKEY_meth_set_copy(EVP_PKEY_METHOD *pmeth, | |
0f113f3e MC |
461 | int (*copy) (EVP_PKEY_CTX *dst, |
462 | EVP_PKEY_CTX *src)) | |
463 | { | |
464 | pmeth->copy = copy; | |
465 | } | |
ba30bad5 DSH |
466 | |
467 | void EVP_PKEY_meth_set_cleanup(EVP_PKEY_METHOD *pmeth, | |
0f113f3e MC |
468 | void (*cleanup) (EVP_PKEY_CTX *ctx)) |
469 | { | |
470 | pmeth->cleanup = cleanup; | |
471 | } | |
ba30bad5 DSH |
472 | |
473 | void EVP_PKEY_meth_set_paramgen(EVP_PKEY_METHOD *pmeth, | |
0f113f3e MC |
474 | int (*paramgen_init) (EVP_PKEY_CTX *ctx), |
475 | int (*paramgen) (EVP_PKEY_CTX *ctx, | |
476 | EVP_PKEY *pkey)) | |
477 | { | |
478 | pmeth->paramgen_init = paramgen_init; | |
479 | pmeth->paramgen = paramgen; | |
480 | } | |
ba30bad5 DSH |
481 | |
482 | void EVP_PKEY_meth_set_keygen(EVP_PKEY_METHOD *pmeth, | |
0f113f3e MC |
483 | int (*keygen_init) (EVP_PKEY_CTX *ctx), |
484 | int (*keygen) (EVP_PKEY_CTX *ctx, | |
485 | EVP_PKEY *pkey)) | |
486 | { | |
487 | pmeth->keygen_init = keygen_init; | |
488 | pmeth->keygen = keygen; | |
489 | } | |
ba30bad5 DSH |
490 | |
491 | void EVP_PKEY_meth_set_sign(EVP_PKEY_METHOD *pmeth, | |
0f113f3e MC |
492 | int (*sign_init) (EVP_PKEY_CTX *ctx), |
493 | int (*sign) (EVP_PKEY_CTX *ctx, | |
494 | unsigned char *sig, size_t *siglen, | |
495 | const unsigned char *tbs, | |
496 | size_t tbslen)) | |
497 | { | |
498 | pmeth->sign_init = sign_init; | |
499 | pmeth->sign = sign; | |
500 | } | |
ba30bad5 DSH |
501 | |
502 | void EVP_PKEY_meth_set_verify(EVP_PKEY_METHOD *pmeth, | |
0f113f3e MC |
503 | int (*verify_init) (EVP_PKEY_CTX *ctx), |
504 | int (*verify) (EVP_PKEY_CTX *ctx, | |
505 | const unsigned char *sig, | |
506 | size_t siglen, | |
507 | const unsigned char *tbs, | |
508 | size_t tbslen)) | |
509 | { | |
510 | pmeth->verify_init = verify_init; | |
511 | pmeth->verify = verify; | |
512 | } | |
ba30bad5 DSH |
513 | |
514 | void EVP_PKEY_meth_set_verify_recover(EVP_PKEY_METHOD *pmeth, | |
0f113f3e MC |
515 | int (*verify_recover_init) (EVP_PKEY_CTX |
516 | *ctx), | |
517 | int (*verify_recover) (EVP_PKEY_CTX | |
518 | *ctx, | |
519 | unsigned char | |
520 | *sig, | |
521 | size_t *siglen, | |
522 | const unsigned | |
523 | char *tbs, | |
524 | size_t tbslen)) | |
525 | { | |
526 | pmeth->verify_recover_init = verify_recover_init; | |
527 | pmeth->verify_recover = verify_recover; | |
528 | } | |
ba30bad5 DSH |
529 | |
530 | void EVP_PKEY_meth_set_signctx(EVP_PKEY_METHOD *pmeth, | |
0f113f3e MC |
531 | int (*signctx_init) (EVP_PKEY_CTX *ctx, |
532 | EVP_MD_CTX *mctx), | |
533 | int (*signctx) (EVP_PKEY_CTX *ctx, | |
534 | unsigned char *sig, | |
535 | size_t *siglen, | |
536 | EVP_MD_CTX *mctx)) | |
537 | { | |
538 | pmeth->signctx_init = signctx_init; | |
539 | pmeth->signctx = signctx; | |
540 | } | |
ba30bad5 DSH |
541 | |
542 | void EVP_PKEY_meth_set_verifyctx(EVP_PKEY_METHOD *pmeth, | |
0f113f3e MC |
543 | int (*verifyctx_init) (EVP_PKEY_CTX *ctx, |
544 | EVP_MD_CTX *mctx), | |
545 | int (*verifyctx) (EVP_PKEY_CTX *ctx, | |
546 | const unsigned char *sig, | |
547 | int siglen, | |
548 | EVP_MD_CTX *mctx)) | |
549 | { | |
550 | pmeth->verifyctx_init = verifyctx_init; | |
551 | pmeth->verifyctx = verifyctx; | |
552 | } | |
ba30bad5 DSH |
553 | |
554 | void EVP_PKEY_meth_set_encrypt(EVP_PKEY_METHOD *pmeth, | |
0f113f3e MC |
555 | int (*encrypt_init) (EVP_PKEY_CTX *ctx), |
556 | int (*encryptfn) (EVP_PKEY_CTX *ctx, | |
557 | unsigned char *out, | |
558 | size_t *outlen, | |
559 | const unsigned char *in, | |
560 | size_t inlen)) | |
561 | { | |
562 | pmeth->encrypt_init = encrypt_init; | |
563 | pmeth->encrypt = encryptfn; | |
564 | } | |
ba30bad5 DSH |
565 | |
566 | void EVP_PKEY_meth_set_decrypt(EVP_PKEY_METHOD *pmeth, | |
0f113f3e MC |
567 | int (*decrypt_init) (EVP_PKEY_CTX *ctx), |
568 | int (*decrypt) (EVP_PKEY_CTX *ctx, | |
569 | unsigned char *out, | |
570 | size_t *outlen, | |
571 | const unsigned char *in, | |
572 | size_t inlen)) | |
573 | { | |
574 | pmeth->decrypt_init = decrypt_init; | |
575 | pmeth->decrypt = decrypt; | |
576 | } | |
ba30bad5 DSH |
577 | |
578 | void EVP_PKEY_meth_set_derive(EVP_PKEY_METHOD *pmeth, | |
0f113f3e MC |
579 | int (*derive_init) (EVP_PKEY_CTX *ctx), |
580 | int (*derive) (EVP_PKEY_CTX *ctx, | |
581 | unsigned char *key, | |
582 | size_t *keylen)) | |
583 | { | |
584 | pmeth->derive_init = derive_init; | |
585 | pmeth->derive = derive; | |
586 | } | |
ba30bad5 DSH |
587 | |
588 | void EVP_PKEY_meth_set_ctrl(EVP_PKEY_METHOD *pmeth, | |
0f113f3e MC |
589 | int (*ctrl) (EVP_PKEY_CTX *ctx, int type, int p1, |
590 | void *p2), | |
591 | int (*ctrl_str) (EVP_PKEY_CTX *ctx, | |
592 | const char *type, | |
593 | const char *value)) | |
594 | { | |
595 | pmeth->ctrl = ctrl; | |
596 | pmeth->ctrl_str = ctrl_str; | |
597 | } | |
e7451ed1 DSH |
598 | |
599 | void EVP_PKEY_meth_get_init(EVP_PKEY_METHOD *pmeth, | |
600 | int (**pinit) (EVP_PKEY_CTX *ctx)) | |
601 | { | |
602 | *pinit = pmeth->init; | |
603 | } | |
604 | ||
605 | void EVP_PKEY_meth_get_copy(EVP_PKEY_METHOD *pmeth, | |
606 | int (**pcopy) (EVP_PKEY_CTX *dst, | |
607 | EVP_PKEY_CTX *src)) | |
608 | { | |
609 | *pcopy = pmeth->copy; | |
610 | } | |
611 | ||
612 | void EVP_PKEY_meth_get_cleanup(EVP_PKEY_METHOD *pmeth, | |
613 | void (**pcleanup) (EVP_PKEY_CTX *ctx)) | |
614 | { | |
615 | *pcleanup = pmeth->cleanup; | |
616 | } | |
617 | ||
618 | void EVP_PKEY_meth_get_paramgen(EVP_PKEY_METHOD *pmeth, | |
619 | int (**pparamgen_init) (EVP_PKEY_CTX *ctx), | |
620 | int (**pparamgen) (EVP_PKEY_CTX *ctx, | |
621 | EVP_PKEY *pkey)) | |
622 | { | |
623 | if (pparamgen_init) | |
624 | *pparamgen_init = pmeth->paramgen_init; | |
625 | if (pparamgen) | |
626 | *pparamgen = pmeth->paramgen; | |
627 | } | |
628 | ||
629 | void EVP_PKEY_meth_get_keygen(EVP_PKEY_METHOD *pmeth, | |
630 | int (**pkeygen_init) (EVP_PKEY_CTX *ctx), | |
631 | int (**pkeygen) (EVP_PKEY_CTX *ctx, | |
632 | EVP_PKEY *pkey)) | |
633 | { | |
634 | if (pkeygen_init) | |
635 | *pkeygen_init = pmeth->keygen_init; | |
636 | if (pkeygen) | |
637 | *pkeygen = pmeth->keygen; | |
638 | } | |
639 | ||
640 | void EVP_PKEY_meth_get_sign(EVP_PKEY_METHOD *pmeth, | |
641 | int (**psign_init) (EVP_PKEY_CTX *ctx), | |
642 | int (**psign) (EVP_PKEY_CTX *ctx, | |
643 | unsigned char *sig, size_t *siglen, | |
644 | const unsigned char *tbs, | |
645 | size_t tbslen)) | |
646 | { | |
647 | if (psign_init) | |
648 | *psign_init = pmeth->sign_init; | |
649 | if (psign) | |
650 | *psign = pmeth->sign; | |
651 | } | |
652 | ||
653 | void EVP_PKEY_meth_get_verify(EVP_PKEY_METHOD *pmeth, | |
654 | int (**pverify_init) (EVP_PKEY_CTX *ctx), | |
655 | int (**pverify) (EVP_PKEY_CTX *ctx, | |
656 | const unsigned char *sig, | |
657 | size_t siglen, | |
658 | const unsigned char *tbs, | |
659 | size_t tbslen)) | |
660 | { | |
661 | if (pverify_init) | |
662 | *pverify_init = pmeth->verify_init; | |
663 | if (pverify) | |
664 | *pverify = pmeth->verify; | |
665 | } | |
666 | ||
667 | void EVP_PKEY_meth_get_verify_recover(EVP_PKEY_METHOD *pmeth, | |
668 | int (**pverify_recover_init) (EVP_PKEY_CTX | |
669 | *ctx), | |
670 | int (**pverify_recover) (EVP_PKEY_CTX | |
671 | *ctx, | |
672 | unsigned char | |
673 | *sig, | |
674 | size_t *siglen, | |
675 | const unsigned | |
676 | char *tbs, | |
677 | size_t tbslen)) | |
678 | { | |
679 | if (pverify_recover_init) | |
680 | *pverify_recover_init = pmeth->verify_recover_init; | |
681 | if (pverify_recover) | |
682 | *pverify_recover = pmeth->verify_recover; | |
683 | } | |
684 | ||
685 | void EVP_PKEY_meth_get_signctx(EVP_PKEY_METHOD *pmeth, | |
686 | int (**psignctx_init) (EVP_PKEY_CTX *ctx, | |
687 | EVP_MD_CTX *mctx), | |
688 | int (**psignctx) (EVP_PKEY_CTX *ctx, | |
689 | unsigned char *sig, | |
690 | size_t *siglen, | |
691 | EVP_MD_CTX *mctx)) | |
692 | { | |
693 | if (psignctx_init) | |
694 | *psignctx_init = pmeth->signctx_init; | |
695 | if (psignctx) | |
696 | *psignctx = pmeth->signctx; | |
697 | } | |
698 | ||
699 | void EVP_PKEY_meth_get_verifyctx(EVP_PKEY_METHOD *pmeth, | |
700 | int (**pverifyctx_init) (EVP_PKEY_CTX *ctx, | |
701 | EVP_MD_CTX *mctx), | |
702 | int (**pverifyctx) (EVP_PKEY_CTX *ctx, | |
703 | const unsigned char *sig, | |
704 | int siglen, | |
705 | EVP_MD_CTX *mctx)) | |
706 | { | |
707 | if (pverifyctx_init) | |
708 | *pverifyctx_init = pmeth->verifyctx_init; | |
709 | if (pverifyctx) | |
710 | *pverifyctx = pmeth->verifyctx; | |
711 | } | |
712 | ||
713 | void EVP_PKEY_meth_get_encrypt(EVP_PKEY_METHOD *pmeth, | |
714 | int (**pencrypt_init) (EVP_PKEY_CTX *ctx), | |
715 | int (**pencryptfn) (EVP_PKEY_CTX *ctx, | |
716 | unsigned char *out, | |
717 | size_t *outlen, | |
718 | const unsigned char *in, | |
719 | size_t inlen)) | |
720 | { | |
721 | if (pencrypt_init) | |
722 | *pencrypt_init = pmeth->encrypt_init; | |
723 | if (pencryptfn) | |
724 | *pencryptfn = pmeth->encrypt; | |
725 | } | |
726 | ||
727 | void EVP_PKEY_meth_get_decrypt(EVP_PKEY_METHOD *pmeth, | |
728 | int (**pdecrypt_init) (EVP_PKEY_CTX *ctx), | |
729 | int (**pdecrypt) (EVP_PKEY_CTX *ctx, | |
730 | unsigned char *out, | |
731 | size_t *outlen, | |
732 | const unsigned char *in, | |
733 | size_t inlen)) | |
734 | { | |
735 | if (pdecrypt_init) | |
736 | *pdecrypt_init = pmeth->decrypt_init; | |
737 | if (pdecrypt) | |
738 | *pdecrypt = pmeth->decrypt; | |
739 | } | |
740 | ||
741 | void EVP_PKEY_meth_get_derive(EVP_PKEY_METHOD *pmeth, | |
742 | int (**pderive_init) (EVP_PKEY_CTX *ctx), | |
743 | int (**pderive) (EVP_PKEY_CTX *ctx, | |
744 | unsigned char *key, | |
745 | size_t *keylen)) | |
746 | { | |
747 | if (pderive_init) | |
748 | *pderive_init = pmeth->derive_init; | |
749 | if (pderive) | |
750 | *pderive = pmeth->derive; | |
751 | } | |
752 | ||
753 | void EVP_PKEY_meth_get_ctrl(EVP_PKEY_METHOD *pmeth, | |
754 | int (**pctrl) (EVP_PKEY_CTX *ctx, int type, int p1, | |
755 | void *p2), | |
756 | int (**pctrl_str) (EVP_PKEY_CTX *ctx, | |
757 | const char *type, | |
758 | const char *value)) | |
759 | { | |
760 | if (pctrl) | |
761 | *pctrl = pmeth->ctrl; | |
762 | if (pctrl_str) | |
763 | *pctrl_str = pmeth->ctrl_str; | |
764 | } |