]>
Commit | Line | Data |
---|---|---|
0f113f3e | 1 | /* |
b0edda11 | 2 | * Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved. |
0b6f3c66 | 3 | * |
4a8b0c55 | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
62867571 RS |
5 | * this file except in compliance with the License. You can obtain a copy |
6 | * in the file LICENSE in the source distribution or at | |
7 | * https://www.openssl.org/source/license.html | |
0b6f3c66 DSH |
8 | */ |
9 | ||
10 | #include <stdio.h> | |
11 | #include <stdlib.h> | |
3c27208f | 12 | #include <openssl/engine.h> |
33bed28b | 13 | #include <openssl/evp.h> |
99119000 | 14 | #include <openssl/x509v3.h> |
35aca9ec MC |
15 | #include <openssl/core_names.h> |
16 | #include <openssl/dh.h> | |
17 | #include "internal/cryptlib.h" | |
5fe736e5 | 18 | #include "internal/asn1_int.h" |
27af42f9 | 19 | #include "internal/evp_int.h" |
99119000 | 20 | #include "internal/numbers.h" |
ff64702b | 21 | #include "evp_locl.h" |
0b6f3c66 | 22 | |
0f113f3e | 23 | typedef int sk_cmp_fn_type(const char *const *a, const char *const *b); |
5ce278a7 | 24 | |
df2ee0e2 | 25 | static STACK_OF(EVP_PKEY_METHOD) *app_pkey_methods = NULL; |
0b6f3c66 | 26 | |
cefa762e | 27 | /* This array needs to be in order of NIDs */ |
0f113f3e | 28 | static const EVP_PKEY_METHOD *standard_methods[] = { |
d4f0339c | 29 | #ifndef OPENSSL_NO_RSA |
0f113f3e | 30 | &rsa_pkey_meth, |
d4f0339c DSH |
31 | #endif |
32 | #ifndef OPENSSL_NO_DH | |
0f113f3e | 33 | &dh_pkey_meth, |
d4f0339c DSH |
34 | #endif |
35 | #ifndef OPENSSL_NO_DSA | |
0f113f3e | 36 | &dsa_pkey_meth, |
d4f0339c | 37 | #endif |
ef236ec3 | 38 | #ifndef OPENSSL_NO_EC |
0f113f3e | 39 | &ec_pkey_meth, |
ef236ec3 | 40 | #endif |
0f113f3e | 41 | &hmac_pkey_meth, |
b4a3aeeb | 42 | #ifndef OPENSSL_NO_CMAC |
0f113f3e | 43 | &cmac_pkey_meth, |
b4a3aeeb | 44 | #endif |
6577e008 DSH |
45 | #ifndef OPENSSL_NO_RSA |
46 | &rsa_pss_pkey_meth, | |
47 | #endif | |
afb14cda | 48 | #ifndef OPENSSL_NO_DH |
1eff3485 | 49 | &dhx_pkey_meth, |
cefa762e JB |
50 | #endif |
51 | #ifndef OPENSSL_NO_SCRYPT | |
52 | &scrypt_pkey_meth, | |
afb14cda | 53 | #endif |
aacfb134 | 54 | &tls1_prf_pkey_meth, |
262bd85f DSH |
55 | #ifndef OPENSSL_NO_EC |
56 | &ecx25519_pkey_meth, | |
13735cfe | 57 | &ecx448_pkey_meth, |
262bd85f | 58 | #endif |
52ad5b60 TS |
59 | &hkdf_pkey_meth, |
60 | #ifndef OPENSSL_NO_POLY1305 | |
61 | &poly1305_pkey_meth, | |
62 | #endif | |
3f5616d7 TS |
63 | #ifndef OPENSSL_NO_SIPHASH |
64 | &siphash_pkey_meth, | |
65 | #endif | |
42a3008a DSH |
66 | #ifndef OPENSSL_NO_EC |
67 | &ed25519_pkey_meth, | |
13735cfe | 68 | &ed448_pkey_meth, |
42a3008a | 69 | #endif |
ddb634fe JL |
70 | #ifndef OPENSSL_NO_SM2 |
71 | &sm2_pkey_meth, | |
72 | #endif | |
0f113f3e | 73 | }; |
0b6f3c66 | 74 | |
606f6c47 | 75 | DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *, |
0f113f3e | 76 | pmeth); |
babb3798 | 77 | |
0f113f3e MC |
78 | static int pmeth_cmp(const EVP_PKEY_METHOD *const *a, |
79 | const EVP_PKEY_METHOD *const *b) | |
80 | { | |
81 | return ((*a)->pkey_id - (*b)->pkey_id); | |
82 | } | |
0b6f3c66 | 83 | |
606f6c47 | 84 | IMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *, |
0f113f3e | 85 | pmeth); |
babb3798 | 86 | |
c9777d26 | 87 | const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type) |
0f113f3e MC |
88 | { |
89 | EVP_PKEY_METHOD tmp; | |
90 | const EVP_PKEY_METHOD *t = &tmp, **ret; | |
91 | tmp.pkey_id = type; | |
92 | if (app_pkey_methods) { | |
93 | int idx; | |
94 | idx = sk_EVP_PKEY_METHOD_find(app_pkey_methods, &tmp); | |
95 | if (idx >= 0) | |
96 | return sk_EVP_PKEY_METHOD_value(app_pkey_methods, idx); | |
97 | } | |
98 | ret = OBJ_bsearch_pmeth(&t, standard_methods, | |
99 | sizeof(standard_methods) / | |
100 | sizeof(EVP_PKEY_METHOD *)); | |
101 | if (!ret || !*ret) | |
102 | return NULL; | |
103 | return *ret; | |
104 | } | |
0b6f3c66 | 105 | |
f5cda4cb | 106 | static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id) |
0f113f3e MC |
107 | { |
108 | EVP_PKEY_CTX *ret; | |
109 | const EVP_PKEY_METHOD *pmeth; | |
2f2e6b62 | 110 | |
0f113f3e | 111 | if (id == -1) { |
a6465b3f P |
112 | if (pkey == NULL) |
113 | return 0; | |
2f2e6b62 | 114 | id = pkey->type; |
0f113f3e | 115 | } |
a63bf2c5 | 116 | #ifndef OPENSSL_NO_ENGINE |
c2976edf | 117 | if (e == NULL && pkey != NULL) |
d19b01ad | 118 | e = pkey->pmeth_engine != NULL ? pkey->pmeth_engine : pkey->engine; |
0f113f3e MC |
119 | /* Try to find an ENGINE which implements this method */ |
120 | if (e) { | |
121 | if (!ENGINE_init(e)) { | |
122 | EVPerr(EVP_F_INT_CTX_NEW, ERR_R_ENGINE_LIB); | |
123 | return NULL; | |
124 | } | |
c2976edf | 125 | } else { |
0f113f3e | 126 | e = ENGINE_get_pkey_meth_engine(id); |
c2976edf | 127 | } |
0f113f3e MC |
128 | |
129 | /* | |
0d4fb843 | 130 | * If an ENGINE handled this method look it up. Otherwise use internal |
0f113f3e MC |
131 | * tables. |
132 | */ | |
0f113f3e MC |
133 | if (e) |
134 | pmeth = ENGINE_get_pkey_meth(e, id); | |
135 | else | |
a63bf2c5 | 136 | #endif |
0f113f3e | 137 | pmeth = EVP_PKEY_meth_find(id); |
c9777d26 | 138 | |
0f113f3e | 139 | if (pmeth == NULL) { |
918a27fa DSH |
140 | #ifndef OPENSSL_NO_ENGINE |
141 | ENGINE_finish(e); | |
142 | #endif | |
0f113f3e MC |
143 | EVPerr(EVP_F_INT_CTX_NEW, EVP_R_UNSUPPORTED_ALGORITHM); |
144 | return NULL; | |
145 | } | |
c9777d26 | 146 | |
64b25758 | 147 | ret = OPENSSL_zalloc(sizeof(*ret)); |
90945fa3 | 148 | if (ret == NULL) { |
a63bf2c5 | 149 | #ifndef OPENSSL_NO_ENGINE |
7c96dbcd | 150 | ENGINE_finish(e); |
a63bf2c5 | 151 | #endif |
0f113f3e MC |
152 | EVPerr(EVP_F_INT_CTX_NEW, ERR_R_MALLOC_FAILURE); |
153 | return NULL; | |
154 | } | |
155 | ret->engine = e; | |
156 | ret->pmeth = pmeth; | |
157 | ret->operation = EVP_PKEY_OP_UNDEFINED; | |
158 | ret->pkey = pkey; | |
a6465b3f | 159 | if (pkey != NULL) |
03273d61 | 160 | EVP_PKEY_up_ref(pkey); |
0f113f3e MC |
161 | |
162 | if (pmeth->init) { | |
163 | if (pmeth->init(ret) <= 0) { | |
83b4049a | 164 | ret->pmeth = NULL; |
0f113f3e MC |
165 | EVP_PKEY_CTX_free(ret); |
166 | return NULL; | |
167 | } | |
168 | } | |
169 | ||
170 | return ret; | |
171 | } | |
172 | ||
173 | EVP_PKEY_METHOD *EVP_PKEY_meth_new(int id, int flags) | |
174 | { | |
175 | EVP_PKEY_METHOD *pmeth; | |
b4faea50 | 176 | |
b51bce94 | 177 | pmeth = OPENSSL_zalloc(sizeof(*pmeth)); |
3484236d F |
178 | if (pmeth == NULL) { |
179 | EVPerr(EVP_F_EVP_PKEY_METH_NEW, ERR_R_MALLOC_FAILURE); | |
0f113f3e | 180 | return NULL; |
3484236d | 181 | } |
0f113f3e | 182 | |
0f113f3e MC |
183 | pmeth->pkey_id = id; |
184 | pmeth->flags = flags | EVP_PKEY_FLAG_DYNAMIC; | |
0f113f3e MC |
185 | return pmeth; |
186 | } | |
ba30bad5 | 187 | |
f830c68f | 188 | void EVP_PKEY_meth_get0_info(int *ppkey_id, int *pflags, |
0f113f3e MC |
189 | const EVP_PKEY_METHOD *meth) |
190 | { | |
191 | if (ppkey_id) | |
192 | *ppkey_id = meth->pkey_id; | |
193 | if (pflags) | |
194 | *pflags = meth->flags; | |
195 | } | |
f830c68f DSH |
196 | |
197 | void EVP_PKEY_meth_copy(EVP_PKEY_METHOD *dst, const EVP_PKEY_METHOD *src) | |
0f113f3e | 198 | { |
f830c68f | 199 | |
0f113f3e MC |
200 | dst->init = src->init; |
201 | dst->copy = src->copy; | |
202 | dst->cleanup = src->cleanup; | |
f830c68f | 203 | |
0f113f3e MC |
204 | dst->paramgen_init = src->paramgen_init; |
205 | dst->paramgen = src->paramgen; | |
f830c68f | 206 | |
0f113f3e MC |
207 | dst->keygen_init = src->keygen_init; |
208 | dst->keygen = src->keygen; | |
f830c68f | 209 | |
0f113f3e MC |
210 | dst->sign_init = src->sign_init; |
211 | dst->sign = src->sign; | |
f830c68f | 212 | |
0f113f3e MC |
213 | dst->verify_init = src->verify_init; |
214 | dst->verify = src->verify; | |
f830c68f | 215 | |
0f113f3e MC |
216 | dst->verify_recover_init = src->verify_recover_init; |
217 | dst->verify_recover = src->verify_recover; | |
f830c68f | 218 | |
0f113f3e MC |
219 | dst->signctx_init = src->signctx_init; |
220 | dst->signctx = src->signctx; | |
f830c68f | 221 | |
0f113f3e MC |
222 | dst->verifyctx_init = src->verifyctx_init; |
223 | dst->verifyctx = src->verifyctx; | |
f830c68f | 224 | |
0f113f3e MC |
225 | dst->encrypt_init = src->encrypt_init; |
226 | dst->encrypt = src->encrypt; | |
f830c68f | 227 | |
0f113f3e MC |
228 | dst->decrypt_init = src->decrypt_init; |
229 | dst->decrypt = src->decrypt; | |
f830c68f | 230 | |
0f113f3e MC |
231 | dst->derive_init = src->derive_init; |
232 | dst->derive = src->derive; | |
f830c68f | 233 | |
0f113f3e MC |
234 | dst->ctrl = src->ctrl; |
235 | dst->ctrl_str = src->ctrl_str; | |
2aee35d3 PY |
236 | |
237 | dst->check = src->check; | |
0f113f3e | 238 | } |
f830c68f | 239 | |
ba30bad5 | 240 | void EVP_PKEY_meth_free(EVP_PKEY_METHOD *pmeth) |
0f113f3e MC |
241 | { |
242 | if (pmeth && (pmeth->flags & EVP_PKEY_FLAG_DYNAMIC)) | |
243 | OPENSSL_free(pmeth); | |
244 | } | |
ba30bad5 | 245 | |
f5cda4cb | 246 | EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e) |
0f113f3e MC |
247 | { |
248 | return int_ctx_new(pkey, e, -1); | |
249 | } | |
f5cda4cb DSH |
250 | |
251 | EVP_PKEY_CTX *EVP_PKEY_CTX_new_id(int id, ENGINE *e) | |
0f113f3e MC |
252 | { |
253 | return int_ctx_new(NULL, e, id); | |
254 | } | |
f5cda4cb | 255 | |
9fdcc21f | 256 | EVP_PKEY_CTX *EVP_PKEY_CTX_dup(const EVP_PKEY_CTX *pctx) |
0f113f3e MC |
257 | { |
258 | EVP_PKEY_CTX *rctx; | |
ff64702b MC |
259 | |
260 | if (((pctx->pmeth == NULL) || (pctx->pmeth->copy == NULL)) | |
261 | && pctx->exchprovctx == NULL) | |
0f113f3e | 262 | return NULL; |
c9777d26 | 263 | #ifndef OPENSSL_NO_ENGINE |
0f113f3e MC |
264 | /* Make sure it's safe to copy a pkey context using an ENGINE */ |
265 | if (pctx->engine && !ENGINE_init(pctx->engine)) { | |
266 | EVPerr(EVP_F_EVP_PKEY_CTX_DUP, ERR_R_ENGINE_LIB); | |
267 | return 0; | |
268 | } | |
c9777d26 | 269 | #endif |
ff64702b | 270 | rctx = OPENSSL_zalloc(sizeof(*rctx)); |
3484236d F |
271 | if (rctx == NULL) { |
272 | EVPerr(EVP_F_EVP_PKEY_CTX_DUP, ERR_R_MALLOC_FAILURE); | |
0f113f3e | 273 | return NULL; |
3484236d | 274 | } |
8bdcef40 | 275 | |
ff64702b MC |
276 | if (pctx->pkey != NULL) |
277 | EVP_PKEY_up_ref(pctx->pkey); | |
278 | rctx->pkey = pctx->pkey; | |
279 | rctx->operation = pctx->operation; | |
280 | ||
281 | if (pctx->exchprovctx != NULL) { | |
282 | if (!ossl_assert(pctx->exchange != NULL)) | |
283 | return NULL; | |
284 | rctx->exchange = pctx->exchange; | |
285 | if (!EVP_KEYEXCH_up_ref(rctx->exchange)) { | |
286 | OPENSSL_free(rctx); | |
287 | return NULL; | |
288 | } | |
289 | rctx->exchprovctx = pctx->exchange->dupctx(pctx->exchprovctx); | |
290 | if (rctx->exchprovctx == NULL) { | |
291 | EVP_KEYEXCH_free(rctx->exchange); | |
292 | OPENSSL_free(rctx); | |
293 | return NULL; | |
294 | } | |
295 | return rctx; | |
296 | } | |
297 | ||
0f113f3e | 298 | rctx->pmeth = pctx->pmeth; |
c9777d26 | 299 | #ifndef OPENSSL_NO_ENGINE |
0f113f3e | 300 | rctx->engine = pctx->engine; |
c9777d26 | 301 | #endif |
8bdcef40 | 302 | |
0f113f3e | 303 | if (pctx->peerkey) |
03273d61 | 304 | EVP_PKEY_up_ref(pctx->peerkey); |
0f113f3e | 305 | rctx->peerkey = pctx->peerkey; |
8bdcef40 | 306 | |
0f113f3e MC |
307 | if (pctx->pmeth->copy(rctx, pctx) > 0) |
308 | return rctx; | |
8bdcef40 | 309 | |
83b4049a | 310 | rctx->pmeth = NULL; |
0f113f3e MC |
311 | EVP_PKEY_CTX_free(rctx); |
312 | return NULL; | |
8bdcef40 | 313 | |
0f113f3e | 314 | } |
8bdcef40 | 315 | |
ba30bad5 | 316 | int EVP_PKEY_meth_add0(const EVP_PKEY_METHOD *pmeth) |
0f113f3e MC |
317 | { |
318 | if (app_pkey_methods == NULL) { | |
319 | app_pkey_methods = sk_EVP_PKEY_METHOD_new(pmeth_cmp); | |
3484236d F |
320 | if (app_pkey_methods == NULL){ |
321 | EVPerr(EVP_F_EVP_PKEY_METH_ADD0, ERR_R_MALLOC_FAILURE); | |
0f113f3e | 322 | return 0; |
3484236d | 323 | } |
0f113f3e | 324 | } |
3484236d F |
325 | if (!sk_EVP_PKEY_METHOD_push(app_pkey_methods, pmeth)) { |
326 | EVPerr(EVP_F_EVP_PKEY_METH_ADD0, ERR_R_MALLOC_FAILURE); | |
0f113f3e | 327 | return 0; |
3484236d | 328 | } |
0f113f3e MC |
329 | sk_EVP_PKEY_METHOD_sort(app_pkey_methods); |
330 | return 1; | |
331 | } | |
ba30bad5 | 332 | |
0822e89a PY |
333 | void evp_app_cleanup_int(void) |
334 | { | |
335 | if (app_pkey_methods != NULL) | |
336 | sk_EVP_PKEY_METHOD_pop_free(app_pkey_methods, EVP_PKEY_meth_free); | |
337 | } | |
338 | ||
339 | int EVP_PKEY_meth_remove(const EVP_PKEY_METHOD *pmeth) | |
340 | { | |
341 | const EVP_PKEY_METHOD *ret; | |
342 | ||
343 | ret = sk_EVP_PKEY_METHOD_delete_ptr(app_pkey_methods, pmeth); | |
344 | ||
345 | return ret == NULL ? 0 : 1; | |
346 | } | |
347 | ||
48ed9c23 DSH |
348 | size_t EVP_PKEY_meth_get_count(void) |
349 | { | |
350 | size_t rv = OSSL_NELEM(standard_methods); | |
351 | ||
352 | if (app_pkey_methods) | |
353 | rv += sk_EVP_PKEY_METHOD_num(app_pkey_methods); | |
354 | return rv; | |
355 | } | |
356 | ||
357 | const EVP_PKEY_METHOD *EVP_PKEY_meth_get0(size_t idx) | |
358 | { | |
359 | if (idx < OSSL_NELEM(standard_methods)) | |
360 | return standard_methods[idx]; | |
361 | if (app_pkey_methods == NULL) | |
362 | return NULL; | |
363 | idx -= OSSL_NELEM(standard_methods); | |
364 | if (idx >= (size_t)sk_EVP_PKEY_METHOD_num(app_pkey_methods)) | |
365 | return NULL; | |
366 | return sk_EVP_PKEY_METHOD_value(app_pkey_methods, idx); | |
367 | } | |
368 | ||
5da98aa6 | 369 | void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx) |
0f113f3e MC |
370 | { |
371 | if (ctx == NULL) | |
372 | return; | |
373 | if (ctx->pmeth && ctx->pmeth->cleanup) | |
374 | ctx->pmeth->cleanup(ctx); | |
ff64702b MC |
375 | |
376 | if (ctx->exchprovctx != NULL && ctx->exchange != NULL) | |
377 | ctx->exchange->freectx(ctx->exchprovctx); | |
378 | ||
379 | EVP_KEYEXCH_free(ctx->exchange); | |
380 | ||
c5ba2d99 RS |
381 | EVP_PKEY_free(ctx->pkey); |
382 | EVP_PKEY_free(ctx->peerkey); | |
c9777d26 | 383 | #ifndef OPENSSL_NO_ENGINE |
7c96dbcd | 384 | ENGINE_finish(ctx->engine); |
c9777d26 | 385 | #endif |
0f113f3e MC |
386 | OPENSSL_free(ctx); |
387 | } | |
5da98aa6 | 388 | |
35aca9ec MC |
389 | int EVP_PKEY_CTX_set_params(EVP_PKEY_CTX *ctx, OSSL_PARAM *params) |
390 | { | |
391 | if (ctx->exchprovctx != NULL && ctx->exchange != NULL) | |
392 | return ctx->exchange->set_params(ctx->exchprovctx, params); | |
393 | return 0; | |
394 | } | |
395 | ||
76ca35e7 | 396 | #ifndef OPENSSL_NO_DH |
35aca9ec MC |
397 | int EVP_PKEY_CTX_set_dh_pad(EVP_PKEY_CTX *ctx, int pad) |
398 | { | |
399 | OSSL_PARAM dh_pad_params[2]; | |
400 | ||
401 | /* TODO(3.0): Remove this eventually when no more legacy */ | |
402 | if (ctx->exchprovctx == NULL) | |
403 | return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DH, EVP_PKEY_OP_DERIVE, | |
404 | EVP_PKEY_CTRL_DH_PAD, pad, NULL); | |
405 | ||
406 | dh_pad_params[0] = OSSL_PARAM_construct_int(OSSL_EXCHANGE_PARAM_PAD, &pad); | |
407 | dh_pad_params[1] = OSSL_PARAM_construct_end(); | |
408 | ||
409 | return EVP_PKEY_CTX_set_params(ctx, dh_pad_params); | |
410 | } | |
76ca35e7 | 411 | #endif |
35aca9ec MC |
412 | |
413 | static int legacy_ctrl_to_param(EVP_PKEY_CTX *ctx, int keytype, int optype, | |
414 | int cmd, int p1, void *p2) | |
415 | { | |
416 | switch (cmd) { | |
76ca35e7 | 417 | #ifndef OPENSSL_NO_DH |
35aca9ec MC |
418 | case EVP_PKEY_CTRL_DH_PAD: |
419 | return EVP_PKEY_CTX_set_dh_pad(ctx, p1); | |
76ca35e7 | 420 | #endif |
35aca9ec MC |
421 | } |
422 | return 0; | |
423 | } | |
424 | ||
0b6f3c66 | 425 | int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype, |
0f113f3e MC |
426 | int cmd, int p1, void *p2) |
427 | { | |
428 | int ret; | |
4803717f | 429 | |
35aca9ec MC |
430 | if (ctx == NULL) { |
431 | EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_COMMAND_NOT_SUPPORTED); | |
432 | return -2; | |
433 | } | |
434 | ||
435 | if (ctx->exchprovctx != NULL) | |
436 | return legacy_ctrl_to_param(ctx, keytype, optype, cmd, p1, p2); | |
437 | ||
438 | if (ctx->pmeth == NULL || ctx->pmeth->ctrl == NULL) { | |
0f113f3e MC |
439 | EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_COMMAND_NOT_SUPPORTED); |
440 | return -2; | |
441 | } | |
442 | if ((keytype != -1) && (ctx->pmeth->pkey_id != keytype)) | |
443 | return -1; | |
444 | ||
4803717f PY |
445 | /* Skip the operation checks since this is called in a very early stage */ |
446 | if (ctx->pmeth->digest_custom != NULL) | |
447 | goto doit; | |
448 | ||
0f113f3e MC |
449 | if (ctx->operation == EVP_PKEY_OP_UNDEFINED) { |
450 | EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_NO_OPERATION_SET); | |
451 | return -1; | |
452 | } | |
453 | ||
454 | if ((optype != -1) && !(ctx->operation & optype)) { | |
455 | EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_INVALID_OPERATION); | |
456 | return -1; | |
457 | } | |
458 | ||
4803717f | 459 | doit: |
0f113f3e MC |
460 | ret = ctx->pmeth->ctrl(ctx, cmd, p1, p2); |
461 | ||
462 | if (ret == -2) | |
463 | EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_COMMAND_NOT_SUPPORTED); | |
464 | ||
465 | return ret; | |
0f113f3e | 466 | } |
0b6f3c66 | 467 | |
cefa762e | 468 | int EVP_PKEY_CTX_ctrl_uint64(EVP_PKEY_CTX *ctx, int keytype, int optype, |
64bf1016 | 469 | int cmd, uint64_t value) |
cefa762e JB |
470 | { |
471 | return EVP_PKEY_CTX_ctrl(ctx, keytype, optype, cmd, 0, &value); | |
472 | } | |
473 | ||
35aca9ec MC |
474 | static int legacy_ctrl_str_to_param(EVP_PKEY_CTX *ctx, const char *name, |
475 | const char *value) | |
476 | { | |
76ca35e7 | 477 | #ifndef OPENSSL_NO_DH |
35aca9ec MC |
478 | if (strcmp(name, "dh_pad") == 0) { |
479 | int pad; | |
480 | ||
481 | pad = atoi(value); | |
482 | return EVP_PKEY_CTX_set_dh_pad(ctx, pad); | |
483 | } | |
76ca35e7 | 484 | #endif |
35aca9ec MC |
485 | return 0; |
486 | } | |
487 | ||
4a3dc3c0 | 488 | int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx, |
0f113f3e MC |
489 | const char *name, const char *value) |
490 | { | |
35aca9ec MC |
491 | if (ctx == NULL) { |
492 | EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR, EVP_R_COMMAND_NOT_SUPPORTED); | |
493 | return -2; | |
494 | } | |
495 | ||
496 | if (ctx->exchprovctx != NULL) | |
497 | return legacy_ctrl_str_to_param(ctx, name, value); | |
498 | ||
0f113f3e MC |
499 | if (!ctx || !ctx->pmeth || !ctx->pmeth->ctrl_str) { |
500 | EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR, EVP_R_COMMAND_NOT_SUPPORTED); | |
501 | return -2; | |
502 | } | |
410877ba DSH |
503 | if (strcmp(name, "digest") == 0) |
504 | return EVP_PKEY_CTX_md(ctx, EVP_PKEY_OP_TYPE_SIG, EVP_PKEY_CTRL_MD, | |
505 | value); | |
0f113f3e MC |
506 | return ctx->pmeth->ctrl_str(ctx, name, value); |
507 | } | |
f5cda4cb | 508 | |
99119000 DSH |
509 | /* Utility functions to send a string of hex string to a ctrl */ |
510 | ||
511 | int EVP_PKEY_CTX_str2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *str) | |
512 | { | |
513 | size_t len; | |
514 | ||
515 | len = strlen(str); | |
516 | if (len > INT_MAX) | |
517 | return -1; | |
518 | return ctx->pmeth->ctrl(ctx, cmd, len, (void *)str); | |
519 | } | |
520 | ||
521 | int EVP_PKEY_CTX_hex2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *hex) | |
522 | { | |
523 | unsigned char *bin; | |
524 | long binlen; | |
525 | int rv = -1; | |
526 | ||
14f051a0 | 527 | bin = OPENSSL_hexstr2buf(hex, &binlen); |
99119000 DSH |
528 | if (bin == NULL) |
529 | return 0; | |
530 | if (binlen <= INT_MAX) | |
531 | rv = ctx->pmeth->ctrl(ctx, cmd, binlen, bin); | |
532 | OPENSSL_free(bin); | |
533 | return rv; | |
534 | } | |
52ad523c | 535 | |
410877ba DSH |
536 | /* Pass a message digest to a ctrl */ |
537 | int EVP_PKEY_CTX_md(EVP_PKEY_CTX *ctx, int optype, int cmd, const char *md) | |
538 | { | |
539 | const EVP_MD *m; | |
c82bafc5 | 540 | |
410877ba DSH |
541 | if (md == NULL || (m = EVP_get_digestbyname(md)) == NULL) { |
542 | EVPerr(EVP_F_EVP_PKEY_CTX_MD, EVP_R_INVALID_DIGEST); | |
543 | return 0; | |
544 | } | |
545 | return EVP_PKEY_CTX_ctrl(ctx, -1, optype, cmd, 0, (void *)m); | |
546 | } | |
99119000 | 547 | |
b28dea4e | 548 | int EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX *ctx) |
0f113f3e MC |
549 | { |
550 | return ctx->operation; | |
551 | } | |
b28dea4e DSH |
552 | |
553 | void EVP_PKEY_CTX_set0_keygen_info(EVP_PKEY_CTX *ctx, int *dat, int datlen) | |
0f113f3e MC |
554 | { |
555 | ctx->keygen_info = dat; | |
556 | ctx->keygen_info_count = datlen; | |
557 | } | |
b28dea4e | 558 | |
f5cda4cb | 559 | void EVP_PKEY_CTX_set_data(EVP_PKEY_CTX *ctx, void *data) |
0f113f3e MC |
560 | { |
561 | ctx->data = data; | |
562 | } | |
f5cda4cb | 563 | |
9fdcc21f | 564 | void *EVP_PKEY_CTX_get_data(const EVP_PKEY_CTX *ctx) |
0f113f3e MC |
565 | { |
566 | return ctx->data; | |
567 | } | |
f5cda4cb | 568 | |
81cebb8b | 569 | EVP_PKEY *EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX *ctx) |
0f113f3e MC |
570 | { |
571 | return ctx->pkey; | |
572 | } | |
81cebb8b | 573 | |
0e1dba93 | 574 | EVP_PKEY *EVP_PKEY_CTX_get0_peerkey(EVP_PKEY_CTX *ctx) |
0f113f3e MC |
575 | { |
576 | return ctx->peerkey; | |
577 | } | |
578 | ||
f5cda4cb | 579 | void EVP_PKEY_CTX_set_app_data(EVP_PKEY_CTX *ctx, void *data) |
0f113f3e MC |
580 | { |
581 | ctx->app_data = data; | |
582 | } | |
f5cda4cb DSH |
583 | |
584 | void *EVP_PKEY_CTX_get_app_data(EVP_PKEY_CTX *ctx) | |
0f113f3e MC |
585 | { |
586 | return ctx->app_data; | |
587 | } | |
ba30bad5 DSH |
588 | |
589 | void EVP_PKEY_meth_set_init(EVP_PKEY_METHOD *pmeth, | |
0f113f3e MC |
590 | int (*init) (EVP_PKEY_CTX *ctx)) |
591 | { | |
592 | pmeth->init = init; | |
593 | } | |
8bdcef40 DSH |
594 | |
595 | void EVP_PKEY_meth_set_copy(EVP_PKEY_METHOD *pmeth, | |
0f113f3e | 596 | int (*copy) (EVP_PKEY_CTX *dst, |
9fdcc21f | 597 | const EVP_PKEY_CTX *src)) |
0f113f3e MC |
598 | { |
599 | pmeth->copy = copy; | |
600 | } | |
ba30bad5 DSH |
601 | |
602 | void EVP_PKEY_meth_set_cleanup(EVP_PKEY_METHOD *pmeth, | |
0f113f3e MC |
603 | void (*cleanup) (EVP_PKEY_CTX *ctx)) |
604 | { | |
605 | pmeth->cleanup = cleanup; | |
606 | } | |
ba30bad5 DSH |
607 | |
608 | void EVP_PKEY_meth_set_paramgen(EVP_PKEY_METHOD *pmeth, | |
0f113f3e MC |
609 | int (*paramgen_init) (EVP_PKEY_CTX *ctx), |
610 | int (*paramgen) (EVP_PKEY_CTX *ctx, | |
611 | EVP_PKEY *pkey)) | |
612 | { | |
613 | pmeth->paramgen_init = paramgen_init; | |
614 | pmeth->paramgen = paramgen; | |
615 | } | |
ba30bad5 DSH |
616 | |
617 | void EVP_PKEY_meth_set_keygen(EVP_PKEY_METHOD *pmeth, | |
0f113f3e MC |
618 | int (*keygen_init) (EVP_PKEY_CTX *ctx), |
619 | int (*keygen) (EVP_PKEY_CTX *ctx, | |
620 | EVP_PKEY *pkey)) | |
621 | { | |
622 | pmeth->keygen_init = keygen_init; | |
623 | pmeth->keygen = keygen; | |
624 | } | |
ba30bad5 DSH |
625 | |
626 | void EVP_PKEY_meth_set_sign(EVP_PKEY_METHOD *pmeth, | |
0f113f3e MC |
627 | int (*sign_init) (EVP_PKEY_CTX *ctx), |
628 | int (*sign) (EVP_PKEY_CTX *ctx, | |
629 | unsigned char *sig, size_t *siglen, | |
630 | const unsigned char *tbs, | |
631 | size_t tbslen)) | |
632 | { | |
633 | pmeth->sign_init = sign_init; | |
634 | pmeth->sign = sign; | |
635 | } | |
ba30bad5 DSH |
636 | |
637 | void EVP_PKEY_meth_set_verify(EVP_PKEY_METHOD *pmeth, | |
0f113f3e MC |
638 | int (*verify_init) (EVP_PKEY_CTX *ctx), |
639 | int (*verify) (EVP_PKEY_CTX *ctx, | |
640 | const unsigned char *sig, | |
641 | size_t siglen, | |
642 | const unsigned char *tbs, | |
643 | size_t tbslen)) | |
644 | { | |
645 | pmeth->verify_init = verify_init; | |
646 | pmeth->verify = verify; | |
647 | } | |
ba30bad5 DSH |
648 | |
649 | void EVP_PKEY_meth_set_verify_recover(EVP_PKEY_METHOD *pmeth, | |
0f113f3e MC |
650 | int (*verify_recover_init) (EVP_PKEY_CTX |
651 | *ctx), | |
652 | int (*verify_recover) (EVP_PKEY_CTX | |
653 | *ctx, | |
654 | unsigned char | |
655 | *sig, | |
656 | size_t *siglen, | |
657 | const unsigned | |
658 | char *tbs, | |
659 | size_t tbslen)) | |
660 | { | |
661 | pmeth->verify_recover_init = verify_recover_init; | |
662 | pmeth->verify_recover = verify_recover; | |
663 | } | |
ba30bad5 DSH |
664 | |
665 | void EVP_PKEY_meth_set_signctx(EVP_PKEY_METHOD *pmeth, | |
0f113f3e MC |
666 | int (*signctx_init) (EVP_PKEY_CTX *ctx, |
667 | EVP_MD_CTX *mctx), | |
668 | int (*signctx) (EVP_PKEY_CTX *ctx, | |
669 | unsigned char *sig, | |
670 | size_t *siglen, | |
671 | EVP_MD_CTX *mctx)) | |
672 | { | |
673 | pmeth->signctx_init = signctx_init; | |
674 | pmeth->signctx = signctx; | |
675 | } | |
ba30bad5 DSH |
676 | |
677 | void EVP_PKEY_meth_set_verifyctx(EVP_PKEY_METHOD *pmeth, | |
0f113f3e MC |
678 | int (*verifyctx_init) (EVP_PKEY_CTX *ctx, |
679 | EVP_MD_CTX *mctx), | |
680 | int (*verifyctx) (EVP_PKEY_CTX *ctx, | |
681 | const unsigned char *sig, | |
682 | int siglen, | |
683 | EVP_MD_CTX *mctx)) | |
684 | { | |
685 | pmeth->verifyctx_init = verifyctx_init; | |
686 | pmeth->verifyctx = verifyctx; | |
687 | } | |
ba30bad5 DSH |
688 | |
689 | void EVP_PKEY_meth_set_encrypt(EVP_PKEY_METHOD *pmeth, | |
0f113f3e MC |
690 | int (*encrypt_init) (EVP_PKEY_CTX *ctx), |
691 | int (*encryptfn) (EVP_PKEY_CTX *ctx, | |
692 | unsigned char *out, | |
693 | size_t *outlen, | |
694 | const unsigned char *in, | |
695 | size_t inlen)) | |
696 | { | |
697 | pmeth->encrypt_init = encrypt_init; | |
698 | pmeth->encrypt = encryptfn; | |
699 | } | |
ba30bad5 DSH |
700 | |
701 | void EVP_PKEY_meth_set_decrypt(EVP_PKEY_METHOD *pmeth, | |
0f113f3e MC |
702 | int (*decrypt_init) (EVP_PKEY_CTX *ctx), |
703 | int (*decrypt) (EVP_PKEY_CTX *ctx, | |
704 | unsigned char *out, | |
705 | size_t *outlen, | |
706 | const unsigned char *in, | |
707 | size_t inlen)) | |
708 | { | |
709 | pmeth->decrypt_init = decrypt_init; | |
710 | pmeth->decrypt = decrypt; | |
711 | } | |
ba30bad5 DSH |
712 | |
713 | void EVP_PKEY_meth_set_derive(EVP_PKEY_METHOD *pmeth, | |
0f113f3e MC |
714 | int (*derive_init) (EVP_PKEY_CTX *ctx), |
715 | int (*derive) (EVP_PKEY_CTX *ctx, | |
716 | unsigned char *key, | |
717 | size_t *keylen)) | |
718 | { | |
719 | pmeth->derive_init = derive_init; | |
720 | pmeth->derive = derive; | |
721 | } | |
ba30bad5 DSH |
722 | |
723 | void EVP_PKEY_meth_set_ctrl(EVP_PKEY_METHOD *pmeth, | |
0f113f3e MC |
724 | int (*ctrl) (EVP_PKEY_CTX *ctx, int type, int p1, |
725 | void *p2), | |
726 | int (*ctrl_str) (EVP_PKEY_CTX *ctx, | |
727 | const char *type, | |
728 | const char *value)) | |
729 | { | |
730 | pmeth->ctrl = ctrl; | |
731 | pmeth->ctrl_str = ctrl_str; | |
732 | } | |
e7451ed1 | 733 | |
2aee35d3 PY |
734 | void EVP_PKEY_meth_set_check(EVP_PKEY_METHOD *pmeth, |
735 | int (*check) (EVP_PKEY *pkey)) | |
736 | { | |
737 | pmeth->check = check; | |
738 | } | |
739 | ||
b0004708 PY |
740 | void EVP_PKEY_meth_set_public_check(EVP_PKEY_METHOD *pmeth, |
741 | int (*check) (EVP_PKEY *pkey)) | |
742 | { | |
743 | pmeth->public_check = check; | |
744 | } | |
745 | ||
746 | void EVP_PKEY_meth_set_param_check(EVP_PKEY_METHOD *pmeth, | |
747 | int (*check) (EVP_PKEY *pkey)) | |
748 | { | |
749 | pmeth->param_check = check; | |
750 | } | |
751 | ||
0a8fdef7 PY |
752 | void EVP_PKEY_meth_set_digest_custom(EVP_PKEY_METHOD *pmeth, |
753 | int (*digest_custom) (EVP_PKEY_CTX *ctx, | |
754 | EVP_MD_CTX *mctx)) | |
755 | { | |
756 | pmeth->digest_custom = digest_custom; | |
757 | } | |
758 | ||
693be9a2 | 759 | void EVP_PKEY_meth_get_init(const EVP_PKEY_METHOD *pmeth, |
e7451ed1 DSH |
760 | int (**pinit) (EVP_PKEY_CTX *ctx)) |
761 | { | |
762 | *pinit = pmeth->init; | |
763 | } | |
764 | ||
693be9a2 | 765 | void EVP_PKEY_meth_get_copy(const EVP_PKEY_METHOD *pmeth, |
e7451ed1 | 766 | int (**pcopy) (EVP_PKEY_CTX *dst, |
9fdcc21f | 767 | const EVP_PKEY_CTX *src)) |
e7451ed1 DSH |
768 | { |
769 | *pcopy = pmeth->copy; | |
770 | } | |
771 | ||
693be9a2 | 772 | void EVP_PKEY_meth_get_cleanup(const EVP_PKEY_METHOD *pmeth, |
e7451ed1 DSH |
773 | void (**pcleanup) (EVP_PKEY_CTX *ctx)) |
774 | { | |
775 | *pcleanup = pmeth->cleanup; | |
776 | } | |
777 | ||
693be9a2 | 778 | void EVP_PKEY_meth_get_paramgen(const EVP_PKEY_METHOD *pmeth, |
e7451ed1 DSH |
779 | int (**pparamgen_init) (EVP_PKEY_CTX *ctx), |
780 | int (**pparamgen) (EVP_PKEY_CTX *ctx, | |
781 | EVP_PKEY *pkey)) | |
782 | { | |
783 | if (pparamgen_init) | |
784 | *pparamgen_init = pmeth->paramgen_init; | |
785 | if (pparamgen) | |
786 | *pparamgen = pmeth->paramgen; | |
787 | } | |
788 | ||
693be9a2 | 789 | void EVP_PKEY_meth_get_keygen(const EVP_PKEY_METHOD *pmeth, |
e7451ed1 DSH |
790 | int (**pkeygen_init) (EVP_PKEY_CTX *ctx), |
791 | int (**pkeygen) (EVP_PKEY_CTX *ctx, | |
792 | EVP_PKEY *pkey)) | |
793 | { | |
794 | if (pkeygen_init) | |
795 | *pkeygen_init = pmeth->keygen_init; | |
796 | if (pkeygen) | |
797 | *pkeygen = pmeth->keygen; | |
798 | } | |
799 | ||
693be9a2 | 800 | void EVP_PKEY_meth_get_sign(const EVP_PKEY_METHOD *pmeth, |
e7451ed1 DSH |
801 | int (**psign_init) (EVP_PKEY_CTX *ctx), |
802 | int (**psign) (EVP_PKEY_CTX *ctx, | |
803 | unsigned char *sig, size_t *siglen, | |
804 | const unsigned char *tbs, | |
805 | size_t tbslen)) | |
806 | { | |
807 | if (psign_init) | |
808 | *psign_init = pmeth->sign_init; | |
809 | if (psign) | |
810 | *psign = pmeth->sign; | |
811 | } | |
812 | ||
693be9a2 | 813 | void EVP_PKEY_meth_get_verify(const EVP_PKEY_METHOD *pmeth, |
e7451ed1 DSH |
814 | int (**pverify_init) (EVP_PKEY_CTX *ctx), |
815 | int (**pverify) (EVP_PKEY_CTX *ctx, | |
816 | const unsigned char *sig, | |
817 | size_t siglen, | |
818 | const unsigned char *tbs, | |
819 | size_t tbslen)) | |
820 | { | |
821 | if (pverify_init) | |
822 | *pverify_init = pmeth->verify_init; | |
823 | if (pverify) | |
824 | *pverify = pmeth->verify; | |
825 | } | |
826 | ||
693be9a2 | 827 | void EVP_PKEY_meth_get_verify_recover(const EVP_PKEY_METHOD *pmeth, |
e7451ed1 DSH |
828 | int (**pverify_recover_init) (EVP_PKEY_CTX |
829 | *ctx), | |
830 | int (**pverify_recover) (EVP_PKEY_CTX | |
831 | *ctx, | |
832 | unsigned char | |
833 | *sig, | |
834 | size_t *siglen, | |
835 | const unsigned | |
836 | char *tbs, | |
837 | size_t tbslen)) | |
838 | { | |
839 | if (pverify_recover_init) | |
840 | *pverify_recover_init = pmeth->verify_recover_init; | |
841 | if (pverify_recover) | |
842 | *pverify_recover = pmeth->verify_recover; | |
843 | } | |
844 | ||
693be9a2 | 845 | void EVP_PKEY_meth_get_signctx(const EVP_PKEY_METHOD *pmeth, |
e7451ed1 DSH |
846 | int (**psignctx_init) (EVP_PKEY_CTX *ctx, |
847 | EVP_MD_CTX *mctx), | |
848 | int (**psignctx) (EVP_PKEY_CTX *ctx, | |
849 | unsigned char *sig, | |
850 | size_t *siglen, | |
851 | EVP_MD_CTX *mctx)) | |
852 | { | |
853 | if (psignctx_init) | |
854 | *psignctx_init = pmeth->signctx_init; | |
855 | if (psignctx) | |
856 | *psignctx = pmeth->signctx; | |
857 | } | |
858 | ||
693be9a2 | 859 | void EVP_PKEY_meth_get_verifyctx(const EVP_PKEY_METHOD *pmeth, |
e7451ed1 DSH |
860 | int (**pverifyctx_init) (EVP_PKEY_CTX *ctx, |
861 | EVP_MD_CTX *mctx), | |
862 | int (**pverifyctx) (EVP_PKEY_CTX *ctx, | |
863 | const unsigned char *sig, | |
864 | int siglen, | |
865 | EVP_MD_CTX *mctx)) | |
866 | { | |
867 | if (pverifyctx_init) | |
868 | *pverifyctx_init = pmeth->verifyctx_init; | |
869 | if (pverifyctx) | |
870 | *pverifyctx = pmeth->verifyctx; | |
871 | } | |
872 | ||
693be9a2 | 873 | void EVP_PKEY_meth_get_encrypt(const EVP_PKEY_METHOD *pmeth, |
e7451ed1 DSH |
874 | int (**pencrypt_init) (EVP_PKEY_CTX *ctx), |
875 | int (**pencryptfn) (EVP_PKEY_CTX *ctx, | |
876 | unsigned char *out, | |
877 | size_t *outlen, | |
878 | const unsigned char *in, | |
879 | size_t inlen)) | |
880 | { | |
881 | if (pencrypt_init) | |
882 | *pencrypt_init = pmeth->encrypt_init; | |
883 | if (pencryptfn) | |
884 | *pencryptfn = pmeth->encrypt; | |
885 | } | |
886 | ||
693be9a2 | 887 | void EVP_PKEY_meth_get_decrypt(const EVP_PKEY_METHOD *pmeth, |
e7451ed1 DSH |
888 | int (**pdecrypt_init) (EVP_PKEY_CTX *ctx), |
889 | int (**pdecrypt) (EVP_PKEY_CTX *ctx, | |
890 | unsigned char *out, | |
891 | size_t *outlen, | |
892 | const unsigned char *in, | |
893 | size_t inlen)) | |
894 | { | |
895 | if (pdecrypt_init) | |
896 | *pdecrypt_init = pmeth->decrypt_init; | |
897 | if (pdecrypt) | |
898 | *pdecrypt = pmeth->decrypt; | |
899 | } | |
900 | ||
693be9a2 | 901 | void EVP_PKEY_meth_get_derive(const EVP_PKEY_METHOD *pmeth, |
e7451ed1 DSH |
902 | int (**pderive_init) (EVP_PKEY_CTX *ctx), |
903 | int (**pderive) (EVP_PKEY_CTX *ctx, | |
904 | unsigned char *key, | |
905 | size_t *keylen)) | |
906 | { | |
907 | if (pderive_init) | |
908 | *pderive_init = pmeth->derive_init; | |
909 | if (pderive) | |
910 | *pderive = pmeth->derive; | |
911 | } | |
912 | ||
693be9a2 | 913 | void EVP_PKEY_meth_get_ctrl(const EVP_PKEY_METHOD *pmeth, |
e7451ed1 DSH |
914 | int (**pctrl) (EVP_PKEY_CTX *ctx, int type, int p1, |
915 | void *p2), | |
916 | int (**pctrl_str) (EVP_PKEY_CTX *ctx, | |
917 | const char *type, | |
918 | const char *value)) | |
919 | { | |
920 | if (pctrl) | |
921 | *pctrl = pmeth->ctrl; | |
922 | if (pctrl_str) | |
923 | *pctrl_str = pmeth->ctrl_str; | |
924 | } | |
2aee35d3 | 925 | |
693be9a2 | 926 | void EVP_PKEY_meth_get_check(const EVP_PKEY_METHOD *pmeth, |
2aee35d3 PY |
927 | int (**pcheck) (EVP_PKEY *pkey)) |
928 | { | |
34f5c8b1 | 929 | if (pcheck != NULL) |
2aee35d3 PY |
930 | *pcheck = pmeth->check; |
931 | } | |
b0004708 | 932 | |
693be9a2 | 933 | void EVP_PKEY_meth_get_public_check(const EVP_PKEY_METHOD *pmeth, |
b0004708 PY |
934 | int (**pcheck) (EVP_PKEY *pkey)) |
935 | { | |
34f5c8b1 | 936 | if (pcheck != NULL) |
b0004708 PY |
937 | *pcheck = pmeth->public_check; |
938 | } | |
939 | ||
693be9a2 | 940 | void EVP_PKEY_meth_get_param_check(const EVP_PKEY_METHOD *pmeth, |
b0004708 PY |
941 | int (**pcheck) (EVP_PKEY *pkey)) |
942 | { | |
34f5c8b1 | 943 | if (pcheck != NULL) |
b0004708 PY |
944 | *pcheck = pmeth->param_check; |
945 | } | |
0a8fdef7 PY |
946 | |
947 | void EVP_PKEY_meth_get_digest_custom(EVP_PKEY_METHOD *pmeth, | |
948 | int (**pdigest_custom) (EVP_PKEY_CTX *ctx, | |
949 | EVP_MD_CTX *mctx)) | |
950 | { | |
675f4cee | 951 | if (pdigest_custom != NULL) |
0a8fdef7 PY |
952 | *pdigest_custom = pmeth->digest_custom; |
953 | } |