summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto
diff options
context:
space:
mode:
authortb <>2023-12-29 07:09:44 +0000
committertb <>2023-12-29 07:09:44 +0000
commit49bdd006c34b7427173db8e17bc4c93ee919d4d4 (patch)
treeaf839b2582b7d20f3ab2f76e5c644a7cf5da5e63 /src/lib/libcrypto
parentb5b01d4f751b38fce11616819ef7d485c8a4c5e9 (diff)
downloadopenbsd-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.c125
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
349int 348int
350EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr) 349EVP_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
371const EVP_MD *
372EVP_MD_CTX_md(const EVP_MD_CTX *ctx)
373{
374 if (!ctx)
375 return NULL;
376 return ctx->digest;
377}
378
379void *
380EVP_MD_CTX_md_data(const EVP_MD_CTX *ctx)
381{
382 return ctx->md_data;
383}
384
385EVP_PKEY_CTX *
386EVP_MD_CTX_pkey_ctx(const EVP_MD_CTX *ctx)
387{
388 return ctx->pctx;
389}
390
391void
392EVP_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
414void
415EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags)
416{
417 ctx->flags |= flags;
418}
419
420void
421EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags)
422{
423 ctx->flags &= ~flags;
424}
425
426int
427EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags)
428{
429 return (ctx->flags & flags);
430}
431
372int 432int
373EVP_MD_block_size(const EVP_MD *md) 433EVP_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
514const EVP_MD *
515EVP_MD_CTX_md(const EVP_MD_CTX *ctx)
516{
517 if (!ctx)
518 return NULL;
519 return ctx->digest;
520}
521
522void *
523EVP_MD_CTX_md_data(const EVP_MD_CTX *ctx)
524{
525 return ctx->md_data;
526}
527
528EVP_PKEY_CTX *
529EVP_MD_CTX_pkey_ctx(const EVP_MD_CTX *ctx)
530{
531 return ctx->pctx;
532}
533
534void
535EVP_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
557void
558EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags)
559{
560 ctx->flags |= flags;
561}
562
563void
564EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags)
565{
566 ctx->flags &= ~flags;
567}
568
569int
570EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags)
571{
572 return (ctx->flags & flags);
573}