diff options
author | tb <> | 2023-12-29 06:08:01 +0000 |
---|---|---|
committer | tb <> | 2023-12-29 06:08:01 +0000 |
commit | b1150f6e908de063136ab31bd074926d0a966d5e (patch) | |
tree | 2f04a5e51430f5cc8d529123b6fee7cf4fad4f9a /src/lib/libcrypto/evp/evp_digest.c | |
parent | 55b5efee44a1a983840a2ae8e17bca6699ea0eb5 (diff) | |
download | openbsd-b1150f6e908de063136ab31bd074926d0a966d5e.tar.gz openbsd-b1150f6e908de063136ab31bd074926d0a966d5e.tar.bz2 openbsd-b1150f6e908de063136ab31bd074926d0a966d5e.zip |
Move the middle part of evp_lib.c to evp_digest.c
These are ~200 lines of EVP_MD API that separated two parts of the file
dedicated to EVP_CIPHER thingies.
Diffstat (limited to 'src/lib/libcrypto/evp/evp_digest.c')
-rw-r--r-- | src/lib/libcrypto/evp/evp_digest.c | 205 |
1 files changed, 204 insertions, 1 deletions
diff --git a/src/lib/libcrypto/evp/evp_digest.c b/src/lib/libcrypto/evp/evp_digest.c index deb282e4ec..583c454845 100644 --- a/src/lib/libcrypto/evp/evp_digest.c +++ b/src/lib/libcrypto/evp/evp_digest.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: evp_digest.c,v 1.1 2023/12/29 05:57:24 tb Exp $ */ | 1 | /* $OpenBSD: evp_digest.c,v 1.2 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 | * |
@@ -367,3 +367,206 @@ EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr) | |||
367 | } | 367 | } |
368 | return ret; | 368 | return ret; |
369 | } | 369 | } |
370 | |||
371 | int | ||
372 | EVP_MD_block_size(const EVP_MD *md) | ||
373 | { | ||
374 | return md->block_size; | ||
375 | } | ||
376 | |||
377 | int | ||
378 | EVP_MD_type(const EVP_MD *md) | ||
379 | { | ||
380 | return md->type; | ||
381 | } | ||
382 | |||
383 | int | ||
384 | EVP_MD_pkey_type(const EVP_MD *md) | ||
385 | { | ||
386 | return md->pkey_type; | ||
387 | } | ||
388 | |||
389 | int | ||
390 | EVP_MD_size(const EVP_MD *md) | ||
391 | { | ||
392 | if (!md) { | ||
393 | EVPerror(EVP_R_MESSAGE_DIGEST_IS_NULL); | ||
394 | return -1; | ||
395 | } | ||
396 | return md->md_size; | ||
397 | } | ||
398 | |||
399 | unsigned long | ||
400 | EVP_MD_flags(const EVP_MD *md) | ||
401 | { | ||
402 | return md->flags; | ||
403 | } | ||
404 | |||
405 | EVP_MD * | ||
406 | EVP_MD_meth_new(int md_type, int pkey_type) | ||
407 | { | ||
408 | EVP_MD *md; | ||
409 | |||
410 | if ((md = calloc(1, sizeof(*md))) == NULL) | ||
411 | return NULL; | ||
412 | |||
413 | md->type = md_type; | ||
414 | md->pkey_type = pkey_type; | ||
415 | |||
416 | return md; | ||
417 | } | ||
418 | |||
419 | EVP_MD * | ||
420 | EVP_MD_meth_dup(const EVP_MD *md) | ||
421 | { | ||
422 | EVP_MD *to; | ||
423 | |||
424 | if ((to = EVP_MD_meth_new(md->type, md->pkey_type)) == NULL) | ||
425 | return NULL; | ||
426 | |||
427 | memcpy(to, md, sizeof(*to)); | ||
428 | |||
429 | return to; | ||
430 | } | ||
431 | |||
432 | void | ||
433 | EVP_MD_meth_free(EVP_MD *md) | ||
434 | { | ||
435 | freezero(md, sizeof(*md)); | ||
436 | } | ||
437 | |||
438 | int | ||
439 | EVP_MD_meth_set_input_blocksize(EVP_MD *md, int blocksize) | ||
440 | { | ||
441 | md->block_size = blocksize; | ||
442 | return 1; | ||
443 | } | ||
444 | |||
445 | int | ||
446 | EVP_MD_meth_set_result_size(EVP_MD *md, int result_size) | ||
447 | { | ||
448 | md->md_size = result_size; | ||
449 | return 1; | ||
450 | } | ||
451 | |||
452 | int | ||
453 | EVP_MD_meth_set_app_datasize(EVP_MD *md, int datasize) | ||
454 | { | ||
455 | md->ctx_size = datasize; | ||
456 | return 1; | ||
457 | } | ||
458 | |||
459 | int | ||
460 | EVP_MD_meth_set_flags(EVP_MD *md, unsigned long flags) | ||
461 | { | ||
462 | md->flags = flags; | ||
463 | return 1; | ||
464 | } | ||
465 | |||
466 | int | ||
467 | EVP_MD_meth_set_init(EVP_MD *md, int (*init)(EVP_MD_CTX *ctx)) | ||
468 | { | ||
469 | md->init = init; | ||
470 | return 1; | ||
471 | } | ||
472 | |||
473 | int | ||
474 | EVP_MD_meth_set_update(EVP_MD *md, | ||
475 | int (*update)(EVP_MD_CTX *ctx, const void *data, size_t count)) | ||
476 | { | ||
477 | md->update = update; | ||
478 | return 1; | ||
479 | } | ||
480 | |||
481 | int | ||
482 | EVP_MD_meth_set_final(EVP_MD *md, | ||
483 | int (*final)(EVP_MD_CTX *ctx, unsigned char *md)) | ||
484 | { | ||
485 | md->final = final; | ||
486 | return 1; | ||
487 | } | ||
488 | |||
489 | int | ||
490 | EVP_MD_meth_set_copy(EVP_MD *md, | ||
491 | int (*copy)(EVP_MD_CTX *to, const EVP_MD_CTX *from)) | ||
492 | { | ||
493 | md->copy = copy; | ||
494 | return 1; | ||
495 | } | ||
496 | |||
497 | int | ||
498 | EVP_MD_meth_set_cleanup(EVP_MD *md, | ||
499 | int (*cleanup)(EVP_MD_CTX *ctx)) | ||
500 | { | ||
501 | md->cleanup = cleanup; | ||
502 | return 1; | ||
503 | } | ||
504 | |||
505 | int | ||
506 | EVP_MD_meth_set_ctrl(EVP_MD *md, | ||
507 | int (*ctrl)(EVP_MD_CTX *ctx, int cmd, int p1, void *p2)) | ||
508 | { | ||
509 | md->md_ctrl = ctrl; | ||
510 | return 1; | ||
511 | } | ||
512 | |||
513 | const EVP_MD * | ||
514 | EVP_MD_CTX_md(const EVP_MD_CTX *ctx) | ||
515 | { | ||
516 | if (!ctx) | ||
517 | return NULL; | ||
518 | return ctx->digest; | ||
519 | } | ||
520 | |||
521 | void * | ||
522 | EVP_MD_CTX_md_data(const EVP_MD_CTX *ctx) | ||
523 | { | ||
524 | return ctx->md_data; | ||
525 | } | ||
526 | |||
527 | EVP_PKEY_CTX * | ||
528 | EVP_MD_CTX_pkey_ctx(const EVP_MD_CTX *ctx) | ||
529 | { | ||
530 | return ctx->pctx; | ||
531 | } | ||
532 | |||
533 | void | ||
534 | EVP_MD_CTX_set_pkey_ctx(EVP_MD_CTX *ctx, EVP_PKEY_CTX *pctx) | ||
535 | { | ||
536 | if (EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX)) { | ||
537 | EVP_MD_CTX_clear_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX); | ||
538 | } else { | ||
539 | EVP_PKEY_CTX_free(ctx->pctx); | ||
540 | } | ||
541 | |||
542 | ctx->pctx = pctx; | ||
543 | |||
544 | if (pctx != NULL) { | ||
545 | /* | ||
546 | * For unclear reasons it was decided that the caller keeps | ||
547 | * ownership of pctx. So a flag was invented to make sure we | ||
548 | * don't free it in EVP_MD_CTX_cleanup(). We also need to | ||
549 | * unset it in EVP_MD_CTX_copy_ex(). Fortunately, the flag | ||
550 | * isn't public... | ||
551 | */ | ||
552 | EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX); | ||
553 | } | ||
554 | } | ||
555 | |||
556 | void | ||
557 | EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags) | ||
558 | { | ||
559 | ctx->flags |= flags; | ||
560 | } | ||
561 | |||
562 | void | ||
563 | EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags) | ||
564 | { | ||
565 | ctx->flags &= ~flags; | ||
566 | } | ||
567 | |||
568 | int | ||
569 | EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags) | ||
570 | { | ||
571 | return (ctx->flags & flags); | ||
572 | } | ||