diff options
Diffstat (limited to 'src/lib/libcrypto/evp/evp_lib.c')
-rw-r--r-- | src/lib/libcrypto/evp/evp_lib.c | 205 |
1 files changed, 1 insertions, 204 deletions
diff --git a/src/lib/libcrypto/evp/evp_lib.c b/src/lib/libcrypto/evp/evp_lib.c index 622d40dbdf..3288129442 100644 --- a/src/lib/libcrypto/evp/evp_lib.c +++ b/src/lib/libcrypto/evp/evp_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: evp_lib.c,v 1.30 2023/12/15 13:28:30 tb Exp $ */ | 1 | /* $OpenBSD: evp_lib.c,v 1.31 2023/12/29 06:08:01 tb Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -343,209 +343,6 @@ EVP_CIPHER_CTX_set_iv(EVP_CIPHER_CTX *ctx, const unsigned char *iv, size_t len) | |||
343 | return 1; | 343 | return 1; |
344 | } | 344 | } |
345 | 345 | ||
346 | int | ||
347 | EVP_MD_block_size(const EVP_MD *md) | ||
348 | { | ||
349 | return md->block_size; | ||
350 | } | ||
351 | |||
352 | int | ||
353 | EVP_MD_type(const EVP_MD *md) | ||
354 | { | ||
355 | return md->type; | ||
356 | } | ||
357 | |||
358 | int | ||
359 | EVP_MD_pkey_type(const EVP_MD *md) | ||
360 | { | ||
361 | return md->pkey_type; | ||
362 | } | ||
363 | |||
364 | int | ||
365 | EVP_MD_size(const EVP_MD *md) | ||
366 | { | ||
367 | if (!md) { | ||
368 | EVPerror(EVP_R_MESSAGE_DIGEST_IS_NULL); | ||
369 | return -1; | ||
370 | } | ||
371 | return md->md_size; | ||
372 | } | ||
373 | |||
374 | unsigned long | ||
375 | EVP_MD_flags(const EVP_MD *md) | ||
376 | { | ||
377 | return md->flags; | ||
378 | } | ||
379 | |||
380 | EVP_MD * | ||
381 | EVP_MD_meth_new(int md_type, int pkey_type) | ||
382 | { | ||
383 | EVP_MD *md; | ||
384 | |||
385 | if ((md = calloc(1, sizeof(*md))) == NULL) | ||
386 | return NULL; | ||
387 | |||
388 | md->type = md_type; | ||
389 | md->pkey_type = pkey_type; | ||
390 | |||
391 | return md; | ||
392 | } | ||
393 | |||
394 | EVP_MD * | ||
395 | EVP_MD_meth_dup(const EVP_MD *md) | ||
396 | { | ||
397 | EVP_MD *to; | ||
398 | |||
399 | if ((to = EVP_MD_meth_new(md->type, md->pkey_type)) == NULL) | ||
400 | return NULL; | ||
401 | |||
402 | memcpy(to, md, sizeof(*to)); | ||
403 | |||
404 | return to; | ||
405 | } | ||
406 | |||
407 | void | ||
408 | EVP_MD_meth_free(EVP_MD *md) | ||
409 | { | ||
410 | freezero(md, sizeof(*md)); | ||
411 | } | ||
412 | |||
413 | int | ||
414 | EVP_MD_meth_set_input_blocksize(EVP_MD *md, int blocksize) | ||
415 | { | ||
416 | md->block_size = blocksize; | ||
417 | return 1; | ||
418 | } | ||
419 | |||
420 | int | ||
421 | EVP_MD_meth_set_result_size(EVP_MD *md, int result_size) | ||
422 | { | ||
423 | md->md_size = result_size; | ||
424 | return 1; | ||
425 | } | ||
426 | |||
427 | int | ||
428 | EVP_MD_meth_set_app_datasize(EVP_MD *md, int datasize) | ||
429 | { | ||
430 | md->ctx_size = datasize; | ||
431 | return 1; | ||
432 | } | ||
433 | |||
434 | int | ||
435 | EVP_MD_meth_set_flags(EVP_MD *md, unsigned long flags) | ||
436 | { | ||
437 | md->flags = flags; | ||
438 | return 1; | ||
439 | } | ||
440 | |||
441 | int | ||
442 | EVP_MD_meth_set_init(EVP_MD *md, int (*init)(EVP_MD_CTX *ctx)) | ||
443 | { | ||
444 | md->init = init; | ||
445 | return 1; | ||
446 | } | ||
447 | |||
448 | int | ||
449 | EVP_MD_meth_set_update(EVP_MD *md, | ||
450 | int (*update)(EVP_MD_CTX *ctx, const void *data, size_t count)) | ||
451 | { | ||
452 | md->update = update; | ||
453 | return 1; | ||
454 | } | ||
455 | |||
456 | int | ||
457 | EVP_MD_meth_set_final(EVP_MD *md, | ||
458 | int (*final)(EVP_MD_CTX *ctx, unsigned char *md)) | ||
459 | { | ||
460 | md->final = final; | ||
461 | return 1; | ||
462 | } | ||
463 | |||
464 | int | ||
465 | EVP_MD_meth_set_copy(EVP_MD *md, | ||
466 | int (*copy)(EVP_MD_CTX *to, const EVP_MD_CTX *from)) | ||
467 | { | ||
468 | md->copy = copy; | ||
469 | return 1; | ||
470 | } | ||
471 | |||
472 | int | ||
473 | EVP_MD_meth_set_cleanup(EVP_MD *md, | ||
474 | int (*cleanup)(EVP_MD_CTX *ctx)) | ||
475 | { | ||
476 | md->cleanup = cleanup; | ||
477 | return 1; | ||
478 | } | ||
479 | |||
480 | int | ||
481 | EVP_MD_meth_set_ctrl(EVP_MD *md, | ||
482 | int (*ctrl)(EVP_MD_CTX *ctx, int cmd, int p1, void *p2)) | ||
483 | { | ||
484 | md->md_ctrl = ctrl; | ||
485 | return 1; | ||
486 | } | ||
487 | |||
488 | const EVP_MD * | ||
489 | EVP_MD_CTX_md(const EVP_MD_CTX *ctx) | ||
490 | { | ||
491 | if (!ctx) | ||
492 | return NULL; | ||
493 | return ctx->digest; | ||
494 | } | ||
495 | |||
496 | void * | ||
497 | EVP_MD_CTX_md_data(const EVP_MD_CTX *ctx) | ||
498 | { | ||
499 | return ctx->md_data; | ||
500 | } | ||
501 | |||
502 | EVP_PKEY_CTX * | ||
503 | EVP_MD_CTX_pkey_ctx(const EVP_MD_CTX *ctx) | ||
504 | { | ||
505 | return ctx->pctx; | ||
506 | } | ||
507 | |||
508 | void | ||
509 | EVP_MD_CTX_set_pkey_ctx(EVP_MD_CTX *ctx, EVP_PKEY_CTX *pctx) | ||
510 | { | ||
511 | if (EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX)) { | ||
512 | EVP_MD_CTX_clear_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX); | ||
513 | } else { | ||
514 | EVP_PKEY_CTX_free(ctx->pctx); | ||
515 | } | ||
516 | |||
517 | ctx->pctx = pctx; | ||
518 | |||
519 | if (pctx != NULL) { | ||
520 | /* | ||
521 | * For unclear reasons it was decided that the caller keeps | ||
522 | * ownership of pctx. So a flag was invented to make sure we | ||
523 | * don't free it in EVP_MD_CTX_cleanup(). We also need to | ||
524 | * unset it in EVP_MD_CTX_copy_ex(). Fortunately, the flag | ||
525 | * isn't public... | ||
526 | */ | ||
527 | EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX); | ||
528 | } | ||
529 | } | ||
530 | |||
531 | void | ||
532 | EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags) | ||
533 | { | ||
534 | ctx->flags |= flags; | ||
535 | } | ||
536 | |||
537 | void | ||
538 | EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags) | ||
539 | { | ||
540 | ctx->flags &= ~flags; | ||
541 | } | ||
542 | |||
543 | int | ||
544 | EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags) | ||
545 | { | ||
546 | return (ctx->flags & flags); | ||
547 | } | ||
548 | |||
549 | void | 346 | void |
550 | EVP_CIPHER_CTX_set_flags(EVP_CIPHER_CTX *ctx, int flags) | 347 | EVP_CIPHER_CTX_set_flags(EVP_CIPHER_CTX *ctx, int flags) |
551 | { | 348 | { |