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