summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp/pmeth_lib.c
diff options
context:
space:
mode:
authorjsing <>2014-05-07 17:42:51 +0000
committerjsing <>2014-05-07 17:42:51 +0000
commitdd9b16d5489a1196ae0fcbe4315fe0122b042d7d (patch)
treeb341b2cdc0818410f55d0a4662a40677e4899326 /src/lib/libcrypto/evp/pmeth_lib.c
parent1b7393e13080fa69e951cc4f482e3d5d85639c70 (diff)
downloadopenbsd-dd9b16d5489a1196ae0fcbe4315fe0122b042d7d.tar.gz
openbsd-dd9b16d5489a1196ae0fcbe4315fe0122b042d7d.tar.bz2
openbsd-dd9b16d5489a1196ae0fcbe4315fe0122b042d7d.zip
KNF.
Diffstat (limited to 'src/lib/libcrypto/evp/pmeth_lib.c')
-rw-r--r--src/lib/libcrypto/evp/pmeth_lib.c458
1 files changed, 238 insertions, 220 deletions
diff --git a/src/lib/libcrypto/evp/pmeth_lib.c b/src/lib/libcrypto/evp/pmeth_lib.c
index a9fb15fdfe..e51ae51098 100644
--- a/src/lib/libcrypto/evp/pmeth_lib.c
+++ b/src/lib/libcrypto/evp/pmeth_lib.c
@@ -10,7 +10,7 @@
10 * are met: 10 * are met:
11 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 14 *
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in 16 * notice, this list of conditions and the following disclaimer in
@@ -75,8 +75,7 @@ STACK_OF(EVP_PKEY_METHOD) *app_pkey_methods = NULL;
75extern const EVP_PKEY_METHOD rsa_pkey_meth, dh_pkey_meth, dsa_pkey_meth; 75extern const EVP_PKEY_METHOD rsa_pkey_meth, dh_pkey_meth, dsa_pkey_meth;
76extern const EVP_PKEY_METHOD ec_pkey_meth, hmac_pkey_meth, cmac_pkey_meth; 76extern const EVP_PKEY_METHOD ec_pkey_meth, hmac_pkey_meth, cmac_pkey_meth;
77 77
78static const EVP_PKEY_METHOD *standard_methods[] = 78static const EVP_PKEY_METHOD *standard_methods[] = {
79 {
80#ifndef OPENSSL_NO_RSA 79#ifndef OPENSSL_NO_RSA
81 &rsa_pkey_meth, 80 &rsa_pkey_meth,
82#endif 81#endif
@@ -91,62 +90,61 @@ static const EVP_PKEY_METHOD *standard_methods[] =
91#endif 90#endif
92 &hmac_pkey_meth, 91 &hmac_pkey_meth,
93 &cmac_pkey_meth 92 &cmac_pkey_meth
94 }; 93};
95 94
96DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *, 95DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *,
97 pmeth); 96 pmeth);
98 97
99static int pmeth_cmp(const EVP_PKEY_METHOD * const *a, 98static int
100 const EVP_PKEY_METHOD * const *b) 99pmeth_cmp(const EVP_PKEY_METHOD * const *a, const EVP_PKEY_METHOD * const *b)
101 { 100{
102 return ((*a)->pkey_id - (*b)->pkey_id); 101 return ((*a)->pkey_id - (*b)->pkey_id);
103 } 102}
104 103
105IMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *, 104IMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *,
106 pmeth); 105 pmeth);
107 106
108const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type) 107const EVP_PKEY_METHOD *
109 { 108EVP_PKEY_meth_find(int type)
109{
110 EVP_PKEY_METHOD tmp; 110 EVP_PKEY_METHOD tmp;
111 const EVP_PKEY_METHOD *t = &tmp, **ret; 111 const EVP_PKEY_METHOD *t = &tmp, **ret;
112
112 tmp.pkey_id = type; 113 tmp.pkey_id = type;
113 if (app_pkey_methods) 114 if (app_pkey_methods) {
114 {
115 int idx; 115 int idx;
116 idx = sk_EVP_PKEY_METHOD_find(app_pkey_methods, &tmp); 116 idx = sk_EVP_PKEY_METHOD_find(app_pkey_methods, &tmp);
117 if (idx >= 0) 117 if (idx >= 0)
118 return sk_EVP_PKEY_METHOD_value(app_pkey_methods, idx); 118 return sk_EVP_PKEY_METHOD_value(app_pkey_methods, idx);
119 } 119 }
120 ret = OBJ_bsearch_pmeth(&t, standard_methods, 120 ret = OBJ_bsearch_pmeth(&t, standard_methods,
121 sizeof(standard_methods)/sizeof(EVP_PKEY_METHOD *)); 121 sizeof(standard_methods)/sizeof(EVP_PKEY_METHOD *));
122 if (!ret || !*ret) 122 if (!ret || !*ret)
123 return NULL; 123 return NULL;
124 return *ret; 124 return *ret;
125 } 125}
126 126
127static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id) 127static EVP_PKEY_CTX *
128 { 128int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
129{
129 EVP_PKEY_CTX *ret; 130 EVP_PKEY_CTX *ret;
130 const EVP_PKEY_METHOD *pmeth; 131 const EVP_PKEY_METHOD *pmeth;
131 if (id == -1) 132
132 { 133 if (id == -1) {
133 if (!pkey || !pkey->ameth) 134 if (!pkey || !pkey->ameth)
134 return NULL; 135 return NULL;
135 id = pkey->ameth->pkey_id; 136 id = pkey->ameth->pkey_id;
136 } 137 }
137#ifndef OPENSSL_NO_ENGINE 138#ifndef OPENSSL_NO_ENGINE
138 if (pkey && pkey->engine) 139 if (pkey && pkey->engine)
139 e = pkey->engine; 140 e = pkey->engine;
140 /* Try to find an ENGINE which implements this method */ 141 /* Try to find an ENGINE which implements this method */
141 if (e) 142 if (e) {
142 { 143 if (!ENGINE_init(e)) {
143 if (!ENGINE_init(e)) 144 EVPerr(EVP_F_INT_CTX_NEW, ERR_R_ENGINE_LIB);
144 {
145 EVPerr(EVP_F_INT_CTX_NEW,ERR_R_ENGINE_LIB);
146 return NULL; 145 return NULL;
147 }
148 } 146 }
149 else 147 } else
150 e = ENGINE_get_pkey_meth_engine(id); 148 e = ENGINE_get_pkey_meth_engine(id);
151 149
152 /* If an ENGINE handled this method look it up. Othewise 150 /* If an ENGINE handled this method look it up. Othewise
@@ -159,22 +157,20 @@ static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
159#endif 157#endif
160 pmeth = EVP_PKEY_meth_find(id); 158 pmeth = EVP_PKEY_meth_find(id);
161 159
162 if (pmeth == NULL) 160 if (pmeth == NULL) {
163 { 161 EVPerr(EVP_F_INT_CTX_NEW, EVP_R_UNSUPPORTED_ALGORITHM);
164 EVPerr(EVP_F_INT_CTX_NEW,EVP_R_UNSUPPORTED_ALGORITHM);
165 return NULL; 162 return NULL;
166 } 163 }
167 164
168 ret = malloc(sizeof(EVP_PKEY_CTX)); 165 ret = malloc(sizeof(EVP_PKEY_CTX));
169 if (!ret) 166 if (!ret) {
170 {
171#ifndef OPENSSL_NO_ENGINE 167#ifndef OPENSSL_NO_ENGINE
172 if (e) 168 if (e)
173 ENGINE_finish(e); 169 ENGINE_finish(e);
174#endif 170#endif
175 EVPerr(EVP_F_INT_CTX_NEW,ERR_R_MALLOC_FAILURE); 171 EVPerr(EVP_F_INT_CTX_NEW, ERR_R_MALLOC_FAILURE);
176 return NULL; 172 return NULL;
177 } 173 }
178 ret->engine = e; 174 ret->engine = e;
179 ret->pmeth = pmeth; 175 ret->pmeth = pmeth;
180 ret->operation = EVP_PKEY_OP_UNDEFINED; 176 ret->operation = EVP_PKEY_OP_UNDEFINED;
@@ -182,24 +178,24 @@ static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
182 ret->peerkey = NULL; 178 ret->peerkey = NULL;
183 ret->pkey_gencb = 0; 179 ret->pkey_gencb = 0;
184 if (pkey) 180 if (pkey)
185 CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY); 181 CRYPTO_add(&pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);
186 ret->data = NULL; 182 ret->data = NULL;
187 183
188 if (pmeth->init) 184 if (pmeth->init) {
189 { 185 if (pmeth->init(ret) <= 0) {
190 if (pmeth->init(ret) <= 0)
191 {
192 EVP_PKEY_CTX_free(ret); 186 EVP_PKEY_CTX_free(ret);
193 return NULL; 187 return NULL;
194 }
195 } 188 }
189 }
196 190
197 return ret; 191 return ret;
198 } 192}
199 193
200EVP_PKEY_METHOD* EVP_PKEY_meth_new(int id, int flags) 194EVP_PKEY_METHOD*
201 { 195EVP_PKEY_meth_new(int id, int flags)
196{
202 EVP_PKEY_METHOD *pmeth; 197 EVP_PKEY_METHOD *pmeth;
198
203 pmeth = malloc(sizeof(EVP_PKEY_METHOD)); 199 pmeth = malloc(sizeof(EVP_PKEY_METHOD));
204 if (!pmeth) 200 if (!pmeth)
205 return NULL; 201 return NULL;
@@ -236,20 +232,20 @@ EVP_PKEY_METHOD* EVP_PKEY_meth_new(int id, int flags)
236 pmeth->ctrl_str = 0; 232 pmeth->ctrl_str = 0;
237 233
238 return pmeth; 234 return pmeth;
239 } 235}
240 236
241void EVP_PKEY_meth_get0_info(int *ppkey_id, int *pflags, 237void
242 const EVP_PKEY_METHOD *meth) 238EVP_PKEY_meth_get0_info(int *ppkey_id, int *pflags, const EVP_PKEY_METHOD *meth)
243 { 239{
244 if (ppkey_id) 240 if (ppkey_id)
245 *ppkey_id = meth->pkey_id; 241 *ppkey_id = meth->pkey_id;
246 if (pflags) 242 if (pflags)
247 *pflags = meth->flags; 243 *pflags = meth->flags;
248 } 244}
249
250void EVP_PKEY_meth_copy(EVP_PKEY_METHOD *dst, const EVP_PKEY_METHOD *src)
251 {
252 245
246void
247EVP_PKEY_meth_copy(EVP_PKEY_METHOD *dst, const EVP_PKEY_METHOD *src)
248{
253 dst->init = src->init; 249 dst->init = src->init;
254 dst->copy = src->copy; 250 dst->copy = src->copy;
255 dst->cleanup = src->cleanup; 251 dst->cleanup = src->cleanup;
@@ -286,36 +282,40 @@ void EVP_PKEY_meth_copy(EVP_PKEY_METHOD *dst, const EVP_PKEY_METHOD *src)
286 282
287 dst->ctrl = src->ctrl; 283 dst->ctrl = src->ctrl;
288 dst->ctrl_str = src->ctrl_str; 284 dst->ctrl_str = src->ctrl_str;
289 } 285}
290 286
291void EVP_PKEY_meth_free(EVP_PKEY_METHOD *pmeth) 287void
292 { 288EVP_PKEY_meth_free(EVP_PKEY_METHOD *pmeth)
289{
293 if (pmeth && (pmeth->flags & EVP_PKEY_FLAG_DYNAMIC)) 290 if (pmeth && (pmeth->flags & EVP_PKEY_FLAG_DYNAMIC))
294 free(pmeth); 291 free(pmeth);
295 } 292}
296 293
297EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e) 294EVP_PKEY_CTX *
298 { 295EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e)
296{
299 return int_ctx_new(pkey, e, -1); 297 return int_ctx_new(pkey, e, -1);
300 } 298}
301 299
302EVP_PKEY_CTX *EVP_PKEY_CTX_new_id(int id, ENGINE *e) 300EVP_PKEY_CTX *
303 { 301EVP_PKEY_CTX_new_id(int id, ENGINE *e)
302{
304 return int_ctx_new(NULL, e, id); 303 return int_ctx_new(NULL, e, id);
305 } 304}
306 305
307EVP_PKEY_CTX *EVP_PKEY_CTX_dup(EVP_PKEY_CTX *pctx) 306EVP_PKEY_CTX *
308 { 307EVP_PKEY_CTX_dup(EVP_PKEY_CTX *pctx)
308{
309 EVP_PKEY_CTX *rctx; 309 EVP_PKEY_CTX *rctx;
310
310 if (!pctx->pmeth || !pctx->pmeth->copy) 311 if (!pctx->pmeth || !pctx->pmeth->copy)
311 return NULL; 312 return NULL;
312#ifndef OPENSSL_NO_ENGINE 313#ifndef OPENSSL_NO_ENGINE
313 /* Make sure it's safe to copy a pkey context using an ENGINE */ 314 /* Make sure it's safe to copy a pkey context using an ENGINE */
314 if (pctx->engine && !ENGINE_init(pctx->engine)) 315 if (pctx->engine && !ENGINE_init(pctx->engine)) {
315 { 316 EVPerr(EVP_F_EVP_PKEY_CTX_DUP, ERR_R_ENGINE_LIB);
316 EVPerr(EVP_F_EVP_PKEY_CTX_DUP,ERR_R_ENGINE_LIB);
317 return 0; 317 return 0;
318 } 318 }
319#endif 319#endif
320 rctx = malloc(sizeof(EVP_PKEY_CTX)); 320 rctx = malloc(sizeof(EVP_PKEY_CTX));
321 if (!rctx) 321 if (!rctx)
@@ -327,12 +327,12 @@ EVP_PKEY_CTX *EVP_PKEY_CTX_dup(EVP_PKEY_CTX *pctx)
327#endif 327#endif
328 328
329 if (pctx->pkey) 329 if (pctx->pkey)
330 CRYPTO_add(&pctx->pkey->references,1,CRYPTO_LOCK_EVP_PKEY); 330 CRYPTO_add(&pctx->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);
331 331
332 rctx->pkey = pctx->pkey; 332 rctx->pkey = pctx->pkey;
333 333
334 if (pctx->peerkey) 334 if (pctx->peerkey)
335 CRYPTO_add(&pctx->peerkey->references,1,CRYPTO_LOCK_EVP_PKEY); 335 CRYPTO_add(&pctx->peerkey->references, 1, CRYPTO_LOCK_EVP_PKEY);
336 336
337 rctx->peerkey = pctx->peerkey; 337 rctx->peerkey = pctx->peerkey;
338 338
@@ -345,25 +345,25 @@ EVP_PKEY_CTX *EVP_PKEY_CTX_dup(EVP_PKEY_CTX *pctx)
345 345
346 EVP_PKEY_CTX_free(rctx); 346 EVP_PKEY_CTX_free(rctx);
347 return NULL; 347 return NULL;
348}
348 349
349 } 350int
350 351EVP_PKEY_meth_add0(const EVP_PKEY_METHOD *pmeth)
351int EVP_PKEY_meth_add0(const EVP_PKEY_METHOD *pmeth) 352{
352 { 353 if (app_pkey_methods == NULL) {
353 if (app_pkey_methods == NULL)
354 {
355 app_pkey_methods = sk_EVP_PKEY_METHOD_new(pmeth_cmp); 354 app_pkey_methods = sk_EVP_PKEY_METHOD_new(pmeth_cmp);
356 if (!app_pkey_methods) 355 if (!app_pkey_methods)
357 return 0; 356 return 0;
358 } 357 }
359 if (!sk_EVP_PKEY_METHOD_push(app_pkey_methods, pmeth)) 358 if (!sk_EVP_PKEY_METHOD_push(app_pkey_methods, pmeth))
360 return 0; 359 return 0;
361 sk_EVP_PKEY_METHOD_sort(app_pkey_methods); 360 sk_EVP_PKEY_METHOD_sort(app_pkey_methods);
362 return 1; 361 return 1;
363 } 362}
364 363
365void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx) 364void
366 { 365EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx)
366{
367 if (ctx == NULL) 367 if (ctx == NULL)
368 return; 368 return;
369 if (ctx->pmeth && ctx->pmeth->cleanup) 369 if (ctx->pmeth && ctx->pmeth->cleanup)
@@ -373,37 +373,36 @@ void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx)
373 if (ctx->peerkey) 373 if (ctx->peerkey)
374 EVP_PKEY_free(ctx->peerkey); 374 EVP_PKEY_free(ctx->peerkey);
375#ifndef OPENSSL_NO_ENGINE 375#ifndef OPENSSL_NO_ENGINE
376 if(ctx->engine) 376 if (ctx->engine)
377 /* The EVP_PKEY_CTX we used belongs to an ENGINE, release the 377 /* The EVP_PKEY_CTX we used belongs to an ENGINE, release the
378 * functional reference we held for this reason. */ 378 * functional reference we held for this reason. */
379 ENGINE_finish(ctx->engine); 379 ENGINE_finish(ctx->engine);
380#endif 380#endif
381 free(ctx); 381 free(ctx);
382 } 382}
383 383
384int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype, 384int
385 int cmd, int p1, void *p2) 385EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype, int cmd,
386 { 386 int p1, void *p2)
387{
387 int ret; 388 int ret;
388 if (!ctx || !ctx->pmeth || !ctx->pmeth->ctrl) 389
389 { 390 if (!ctx || !ctx->pmeth || !ctx->pmeth->ctrl) {
390 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_COMMAND_NOT_SUPPORTED); 391 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_COMMAND_NOT_SUPPORTED);
391 return -2; 392 return -2;
392 } 393 }
393 if ((keytype != -1) && (ctx->pmeth->pkey_id != keytype)) 394 if ((keytype != -1) && (ctx->pmeth->pkey_id != keytype))
394 return -1; 395 return -1;
395 396
396 if (ctx->operation == EVP_PKEY_OP_UNDEFINED) 397 if (ctx->operation == EVP_PKEY_OP_UNDEFINED) {
397 {
398 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_NO_OPERATION_SET); 398 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_NO_OPERATION_SET);
399 return -1; 399 return -1;
400 } 400 }
401 401
402 if ((optype != -1) && !(ctx->operation & optype)) 402 if ((optype != -1) && !(ctx->operation & optype)) {
403 {
404 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_INVALID_OPERATION); 403 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_INVALID_OPERATION);
405 return -1; 404 return -1;
406 } 405 }
407 406
408 ret = ctx->pmeth->ctrl(ctx, cmd, p1, p2); 407 ret = ctx->pmeth->ctrl(ctx, cmd, p1, p2);
409 408
@@ -412,182 +411,201 @@ int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype,
412 411
413 return ret; 412 return ret;
414 413
415 } 414}
416 415
417int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx, 416int
418 const char *name, const char *value) 417EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx, const char *name, const char *value)
419 { 418{
420 if (!ctx || !ctx->pmeth || !ctx->pmeth->ctrl_str) 419 if (!ctx || !ctx->pmeth || !ctx->pmeth->ctrl_str) {
421 {
422 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR, 420 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR,
423 EVP_R_COMMAND_NOT_SUPPORTED); 421 EVP_R_COMMAND_NOT_SUPPORTED);
424 return -2; 422 return -2;
425 } 423 }
426 if (!strcmp(name, "digest")) 424 if (!strcmp(name, "digest")) {
427 {
428 const EVP_MD *md; 425 const EVP_MD *md;
429 if (!value || !(md = EVP_get_digestbyname(value))) 426 if (!value || !(md = EVP_get_digestbyname(value))) {
430 {
431 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR, 427 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR,
432 EVP_R_INVALID_DIGEST); 428 EVP_R_INVALID_DIGEST);
433 return 0; 429 return 0;
434 }
435 return EVP_PKEY_CTX_set_signature_md(ctx, md);
436 } 430 }
437 return ctx->pmeth->ctrl_str(ctx, name, value); 431 return EVP_PKEY_CTX_set_signature_md(ctx, md);
438 } 432 }
433 return ctx->pmeth->ctrl_str(ctx, name, value);
434}
439 435
440int EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX *ctx) 436int
441 { 437EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX *ctx)
438{
442 return ctx->operation; 439 return ctx->operation;
443 } 440}
444 441
445void EVP_PKEY_CTX_set0_keygen_info(EVP_PKEY_CTX *ctx, int *dat, int datlen) 442void
446 { 443EVP_PKEY_CTX_set0_keygen_info(EVP_PKEY_CTX *ctx, int *dat, int datlen)
444{
447 ctx->keygen_info = dat; 445 ctx->keygen_info = dat;
448 ctx->keygen_info_count = datlen; 446 ctx->keygen_info_count = datlen;
449 } 447}
450 448
451void EVP_PKEY_CTX_set_data(EVP_PKEY_CTX *ctx, void *data) 449void
452 { 450EVP_PKEY_CTX_set_data(EVP_PKEY_CTX *ctx, void *data)
451{
453 ctx->data = data; 452 ctx->data = data;
454 } 453}
455 454
456void *EVP_PKEY_CTX_get_data(EVP_PKEY_CTX *ctx) 455void *
457 { 456EVP_PKEY_CTX_get_data(EVP_PKEY_CTX *ctx)
457{
458 return ctx->data; 458 return ctx->data;
459 } 459}
460 460
461EVP_PKEY *EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX *ctx) 461EVP_PKEY *
462 { 462EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX *ctx)
463{
463 return ctx->pkey; 464 return ctx->pkey;
464 } 465}
465 466
466EVP_PKEY *EVP_PKEY_CTX_get0_peerkey(EVP_PKEY_CTX *ctx) 467EVP_PKEY *
467 { 468EVP_PKEY_CTX_get0_peerkey(EVP_PKEY_CTX *ctx)
469{
468 return ctx->peerkey; 470 return ctx->peerkey;
469 } 471}
470 472
471void EVP_PKEY_CTX_set_app_data(EVP_PKEY_CTX *ctx, void *data) 473void
472 { 474EVP_PKEY_CTX_set_app_data(EVP_PKEY_CTX *ctx, void *data)
475{
473 ctx->app_data = data; 476 ctx->app_data = data;
474 } 477}
475 478
476void *EVP_PKEY_CTX_get_app_data(EVP_PKEY_CTX *ctx) 479void *
477 { 480EVP_PKEY_CTX_get_app_data(EVP_PKEY_CTX *ctx)
481{
478 return ctx->app_data; 482 return ctx->app_data;
479 } 483}
480 484
481void EVP_PKEY_meth_set_init(EVP_PKEY_METHOD *pmeth, 485void
482 int (*init)(EVP_PKEY_CTX *ctx)) 486EVP_PKEY_meth_set_init(EVP_PKEY_METHOD *pmeth,
483 { 487 int (*init)(EVP_PKEY_CTX *ctx))
488{
484 pmeth->init = init; 489 pmeth->init = init;
485 } 490}
486 491
487void EVP_PKEY_meth_set_copy(EVP_PKEY_METHOD *pmeth, 492void
488 int (*copy)(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)) 493EVP_PKEY_meth_set_copy(EVP_PKEY_METHOD *pmeth,
489 { 494 int (*copy)(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src))
495{
490 pmeth->copy = copy; 496 pmeth->copy = copy;
491 } 497}
492 498
493void EVP_PKEY_meth_set_cleanup(EVP_PKEY_METHOD *pmeth, 499void
494 void (*cleanup)(EVP_PKEY_CTX *ctx)) 500EVP_PKEY_meth_set_cleanup(EVP_PKEY_METHOD *pmeth,
495 { 501 void (*cleanup)(EVP_PKEY_CTX *ctx))
502{
496 pmeth->cleanup = cleanup; 503 pmeth->cleanup = cleanup;
497 } 504}
498 505
499void EVP_PKEY_meth_set_paramgen(EVP_PKEY_METHOD *pmeth, 506void
500 int (*paramgen_init)(EVP_PKEY_CTX *ctx), 507EVP_PKEY_meth_set_paramgen(EVP_PKEY_METHOD *pmeth,
501 int (*paramgen)(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)) 508 int (*paramgen_init)(EVP_PKEY_CTX *ctx),
502 { 509 int (*paramgen)(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey))
510{
503 pmeth->paramgen_init = paramgen_init; 511 pmeth->paramgen_init = paramgen_init;
504 pmeth->paramgen = paramgen; 512 pmeth->paramgen = paramgen;
505 } 513}
506 514
507void EVP_PKEY_meth_set_keygen(EVP_PKEY_METHOD *pmeth, 515void
508 int (*keygen_init)(EVP_PKEY_CTX *ctx), 516EVP_PKEY_meth_set_keygen(EVP_PKEY_METHOD *pmeth,
509 int (*keygen)(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)) 517 int (*keygen_init)(EVP_PKEY_CTX *ctx),
510 { 518 int (*keygen)(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey))
519{
511 pmeth->keygen_init = keygen_init; 520 pmeth->keygen_init = keygen_init;
512 pmeth->keygen = keygen; 521 pmeth->keygen = keygen;
513 } 522}
514 523
515void EVP_PKEY_meth_set_sign(EVP_PKEY_METHOD *pmeth, 524void
516 int (*sign_init)(EVP_PKEY_CTX *ctx), 525EVP_PKEY_meth_set_sign(EVP_PKEY_METHOD *pmeth,
517 int (*sign)(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, 526 int (*sign_init)(EVP_PKEY_CTX *ctx),
518 const unsigned char *tbs, size_t tbslen)) 527 int (*sign)(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
519 { 528 const unsigned char *tbs, size_t tbslen))
529{
520 pmeth->sign_init = sign_init; 530 pmeth->sign_init = sign_init;
521 pmeth->sign = sign; 531 pmeth->sign = sign;
522 } 532}
523 533
524void EVP_PKEY_meth_set_verify(EVP_PKEY_METHOD *pmeth, 534void
525 int (*verify_init)(EVP_PKEY_CTX *ctx), 535EVP_PKEY_meth_set_verify(EVP_PKEY_METHOD *pmeth,
526 int (*verify)(EVP_PKEY_CTX *ctx, const unsigned char *sig, size_t siglen, 536 int (*verify_init)(EVP_PKEY_CTX *ctx),
527 const unsigned char *tbs, size_t tbslen)) 537 int (*verify)(EVP_PKEY_CTX *ctx, const unsigned char *sig, size_t siglen,
528 { 538 const unsigned char *tbs, size_t tbslen))
539{
529 pmeth->verify_init = verify_init; 540 pmeth->verify_init = verify_init;
530 pmeth->verify = verify; 541 pmeth->verify = verify;
531 } 542}
532 543
533void EVP_PKEY_meth_set_verify_recover(EVP_PKEY_METHOD *pmeth, 544void
534 int (*verify_recover_init)(EVP_PKEY_CTX *ctx), 545EVP_PKEY_meth_set_verify_recover(EVP_PKEY_METHOD *pmeth,
535 int (*verify_recover)(EVP_PKEY_CTX *ctx, 546 int (*verify_recover_init)(EVP_PKEY_CTX *ctx),
536 unsigned char *sig, size_t *siglen, 547 int (*verify_recover)(EVP_PKEY_CTX *ctx,
537 const unsigned char *tbs, size_t tbslen)) 548 unsigned char *sig, size_t *siglen,
538 { 549 const unsigned char *tbs, size_t tbslen))
550{
539 pmeth->verify_recover_init = verify_recover_init; 551 pmeth->verify_recover_init = verify_recover_init;
540 pmeth->verify_recover = verify_recover; 552 pmeth->verify_recover = verify_recover;
541 } 553}
542 554
543void EVP_PKEY_meth_set_signctx(EVP_PKEY_METHOD *pmeth, 555void
544 int (*signctx_init)(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx), 556EVP_PKEY_meth_set_signctx(EVP_PKEY_METHOD *pmeth,
545 int (*signctx)(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, 557 int (*signctx_init)(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx),
546 EVP_MD_CTX *mctx)) 558 int (*signctx)(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
547 { 559 EVP_MD_CTX *mctx))
560{
548 pmeth->signctx_init = signctx_init; 561 pmeth->signctx_init = signctx_init;
549 pmeth->signctx = signctx; 562 pmeth->signctx = signctx;
550 } 563}
551 564
552void EVP_PKEY_meth_set_verifyctx(EVP_PKEY_METHOD *pmeth, 565void
553 int (*verifyctx_init)(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx), 566EVP_PKEY_meth_set_verifyctx(EVP_PKEY_METHOD *pmeth,
554 int (*verifyctx)(EVP_PKEY_CTX *ctx, const unsigned char *sig,int siglen, 567 int (*verifyctx_init)(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx),
555 EVP_MD_CTX *mctx)) 568 int (*verifyctx)(EVP_PKEY_CTX *ctx, const unsigned char *sig, int siglen,
556 { 569 EVP_MD_CTX *mctx))
570{
557 pmeth->verifyctx_init = verifyctx_init; 571 pmeth->verifyctx_init = verifyctx_init;
558 pmeth->verifyctx = verifyctx; 572 pmeth->verifyctx = verifyctx;
559 } 573}
560 574
561void EVP_PKEY_meth_set_encrypt(EVP_PKEY_METHOD *pmeth, 575void
562 int (*encrypt_init)(EVP_PKEY_CTX *ctx), 576EVP_PKEY_meth_set_encrypt(EVP_PKEY_METHOD *pmeth,
563 int (*encryptfn)(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen, 577 int (*encrypt_init)(EVP_PKEY_CTX *ctx),
564 const unsigned char *in, size_t inlen)) 578 int (*encryptfn)(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
565 { 579 const unsigned char *in, size_t inlen))
580{
566 pmeth->encrypt_init = encrypt_init; 581 pmeth->encrypt_init = encrypt_init;
567 pmeth->encrypt = encryptfn; 582 pmeth->encrypt = encryptfn;
568 } 583}
569 584
570void EVP_PKEY_meth_set_decrypt(EVP_PKEY_METHOD *pmeth, 585void
571 int (*decrypt_init)(EVP_PKEY_CTX *ctx), 586EVP_PKEY_meth_set_decrypt(EVP_PKEY_METHOD *pmeth,
572 int (*decrypt)(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen, 587 int (*decrypt_init)(EVP_PKEY_CTX *ctx),
573 const unsigned char *in, size_t inlen)) 588 int (*decrypt)(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
574 { 589 const unsigned char *in, size_t inlen))
590{
575 pmeth->decrypt_init = decrypt_init; 591 pmeth->decrypt_init = decrypt_init;
576 pmeth->decrypt = decrypt; 592 pmeth->decrypt = decrypt;
577 } 593}
578 594
579void EVP_PKEY_meth_set_derive(EVP_PKEY_METHOD *pmeth, 595void
580 int (*derive_init)(EVP_PKEY_CTX *ctx), 596EVP_PKEY_meth_set_derive(EVP_PKEY_METHOD *pmeth,
581 int (*derive)(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen)) 597 int (*derive_init)(EVP_PKEY_CTX *ctx),
582 { 598 int (*derive)(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen))
599{
583 pmeth->derive_init = derive_init; 600 pmeth->derive_init = derive_init;
584 pmeth->derive = derive; 601 pmeth->derive = derive;
585 } 602}
586 603
587void EVP_PKEY_meth_set_ctrl(EVP_PKEY_METHOD *pmeth, 604void
588 int (*ctrl)(EVP_PKEY_CTX *ctx, int type, int p1, void *p2), 605EVP_PKEY_meth_set_ctrl(EVP_PKEY_METHOD *pmeth,
589 int (*ctrl_str)(EVP_PKEY_CTX *ctx, const char *type, const char *value)) 606 int (*ctrl)(EVP_PKEY_CTX *ctx, int type, int p1, void *p2),
590 { 607 int (*ctrl_str)(EVP_PKEY_CTX *ctx, const char *type, const char *value))
608{
591 pmeth->ctrl = ctrl; 609 pmeth->ctrl = ctrl;
592 pmeth->ctrl_str = ctrl_str; 610 pmeth->ctrl_str = ctrl_str;
593 } 611}