diff options
author | tb <> | 2023-12-29 07:09:44 +0000 |
---|---|---|
committer | tb <> | 2023-12-29 07:09:44 +0000 |
commit | 49bdd006c34b7427173db8e17bc4c93ee919d4d4 (patch) | |
tree | af839b2582b7d20f3ab2f76e5c644a7cf5da5e63 /src/lib/libcrypto | |
parent | b5b01d4f751b38fce11616819ef7d485c8a4c5e9 (diff) | |
download | openbsd-49bdd006c34b7427173db8e17bc4c93ee919d4d4.tar.gz openbsd-49bdd006c34b7427173db8e17bc4c93ee919d4d4.tar.bz2 openbsd-49bdd006c34b7427173db8e17bc4c93ee919d4d4.zip |
Hoist EVP_MD_CTX accessors to after EVP_MD_CTX_ctrl
This way the file has EVP_Digest*, then EVP_MD_CTX new/free/clean,
then ctrl then the EVP_MD_CTX accessors, then the EVP_MD accessors
and finally the EVP_MD_meth stuff and the order of things starts
making a wee bit of sense.
Diffstat (limited to 'src/lib/libcrypto')
-rw-r--r-- | src/lib/libcrypto/evp/evp_digest.c | 125 |
1 files changed, 62 insertions, 63 deletions
diff --git a/src/lib/libcrypto/evp/evp_digest.c b/src/lib/libcrypto/evp/evp_digest.c index e29081d337..7c17a09e2a 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.4 2023/12/29 07:02:28 tb Exp $ */ | 1 | /* $OpenBSD: evp_digest.c,v 1.5 2023/12/29 07:09:44 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 | * |
@@ -345,7 +345,6 @@ EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in) | |||
345 | return 1; | 345 | return 1; |
346 | } | 346 | } |
347 | 347 | ||
348 | |||
349 | int | 348 | int |
350 | EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr) | 349 | EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr) |
351 | { | 350 | { |
@@ -369,6 +368,67 @@ EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr) | |||
369 | return ret; | 368 | return ret; |
370 | } | 369 | } |
371 | 370 | ||
371 | const EVP_MD * | ||
372 | EVP_MD_CTX_md(const EVP_MD_CTX *ctx) | ||
373 | { | ||
374 | if (!ctx) | ||
375 | return NULL; | ||
376 | return ctx->digest; | ||
377 | } | ||
378 | |||
379 | void * | ||
380 | EVP_MD_CTX_md_data(const EVP_MD_CTX *ctx) | ||
381 | { | ||
382 | return ctx->md_data; | ||
383 | } | ||
384 | |||
385 | EVP_PKEY_CTX * | ||
386 | EVP_MD_CTX_pkey_ctx(const EVP_MD_CTX *ctx) | ||
387 | { | ||
388 | return ctx->pctx; | ||
389 | } | ||
390 | |||
391 | void | ||
392 | EVP_MD_CTX_set_pkey_ctx(EVP_MD_CTX *ctx, EVP_PKEY_CTX *pctx) | ||
393 | { | ||
394 | if (EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX)) { | ||
395 | EVP_MD_CTX_clear_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX); | ||
396 | } else { | ||
397 | EVP_PKEY_CTX_free(ctx->pctx); | ||
398 | } | ||
399 | |||
400 | ctx->pctx = pctx; | ||
401 | |||
402 | if (pctx != NULL) { | ||
403 | /* | ||
404 | * For unclear reasons it was decided that the caller keeps | ||
405 | * ownership of pctx. So a flag was invented to make sure we | ||
406 | * don't free it in EVP_MD_CTX_cleanup(). We also need to | ||
407 | * unset it in EVP_MD_CTX_copy_ex(). Fortunately, the flag | ||
408 | * isn't public... | ||
409 | */ | ||
410 | EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX); | ||
411 | } | ||
412 | } | ||
413 | |||
414 | void | ||
415 | EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags) | ||
416 | { | ||
417 | ctx->flags |= flags; | ||
418 | } | ||
419 | |||
420 | void | ||
421 | EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags) | ||
422 | { | ||
423 | ctx->flags &= ~flags; | ||
424 | } | ||
425 | |||
426 | int | ||
427 | EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags) | ||
428 | { | ||
429 | return (ctx->flags & flags); | ||
430 | } | ||
431 | |||
372 | int | 432 | int |
373 | EVP_MD_block_size(const EVP_MD *md) | 433 | EVP_MD_block_size(const EVP_MD *md) |
374 | { | 434 | { |
@@ -510,64 +570,3 @@ EVP_MD_meth_set_ctrl(EVP_MD *md, | |||
510 | md->md_ctrl = ctrl; | 570 | md->md_ctrl = ctrl; |
511 | return 1; | 571 | return 1; |
512 | } | 572 | } |
513 | |||
514 | const EVP_MD * | ||
515 | EVP_MD_CTX_md(const EVP_MD_CTX *ctx) | ||
516 | { | ||
517 | if (!ctx) | ||
518 | return NULL; | ||
519 | return ctx->digest; | ||
520 | } | ||
521 | |||
522 | void * | ||
523 | EVP_MD_CTX_md_data(const EVP_MD_CTX *ctx) | ||
524 | { | ||
525 | return ctx->md_data; | ||
526 | } | ||
527 | |||
528 | EVP_PKEY_CTX * | ||
529 | EVP_MD_CTX_pkey_ctx(const EVP_MD_CTX *ctx) | ||
530 | { | ||
531 | return ctx->pctx; | ||
532 | } | ||
533 | |||
534 | void | ||
535 | EVP_MD_CTX_set_pkey_ctx(EVP_MD_CTX *ctx, EVP_PKEY_CTX *pctx) | ||
536 | { | ||
537 | if (EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX)) { | ||
538 | EVP_MD_CTX_clear_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX); | ||
539 | } else { | ||
540 | EVP_PKEY_CTX_free(ctx->pctx); | ||
541 | } | ||
542 | |||
543 | ctx->pctx = pctx; | ||
544 | |||
545 | if (pctx != NULL) { | ||
546 | /* | ||
547 | * For unclear reasons it was decided that the caller keeps | ||
548 | * ownership of pctx. So a flag was invented to make sure we | ||
549 | * don't free it in EVP_MD_CTX_cleanup(). We also need to | ||
550 | * unset it in EVP_MD_CTX_copy_ex(). Fortunately, the flag | ||
551 | * isn't public... | ||
552 | */ | ||
553 | EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX); | ||
554 | } | ||
555 | } | ||
556 | |||
557 | void | ||
558 | EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags) | ||
559 | { | ||
560 | ctx->flags |= flags; | ||
561 | } | ||
562 | |||
563 | void | ||
564 | EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags) | ||
565 | { | ||
566 | ctx->flags &= ~flags; | ||
567 | } | ||
568 | |||
569 | int | ||
570 | EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags) | ||
571 | { | ||
572 | return (ctx->flags & flags); | ||
573 | } | ||