summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp/evp_lib.c
diff options
context:
space:
mode:
authortb <>2022-01-09 15:15:25 +0000
committertb <>2022-01-09 15:15:25 +0000
commit12dd2352d38b1ef2237d623bc6b869d169e71567 (patch)
treeb42edbe525fc7c43874d4c14d0981bb1cb4e2d3d /src/lib/libcrypto/evp/evp_lib.c
parent98fb653e64884887dde11a1e705e45a6290548d1 (diff)
downloadopenbsd-12dd2352d38b1ef2237d623bc6b869d169e71567.tar.gz
openbsd-12dd2352d38b1ef2237d623bc6b869d169e71567.tar.bz2
openbsd-12dd2352d38b1ef2237d623bc6b869d169e71567.zip
Prepare to provide EVP_MD_CTX{,_set}_pkey_ctx()
This API with very strange ownership handling is used by Ruby 3.1, unfortunately. For unclear reasons, it was decided that the caller retains ownership of the pctx passed in. EVP_PKEY_CTX aren't refcounted, so a flag was added to make sure that md_ctx->pctx is not freed in EVP_MD_CTX_{cleanup,reset}(). Since EVP_MD_CTX_copy_ex() duplicates the md_ctx->pctx, the flag also needs to be unset on the duplicated EVP_MD_CTX. ok inoguchi jsing
Diffstat (limited to 'src/lib/libcrypto/evp/evp_lib.c')
-rw-r--r--src/lib/libcrypto/evp/evp_lib.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/lib/libcrypto/evp/evp_lib.c b/src/lib/libcrypto/evp/evp_lib.c
index 8070fa45ae..c96813987f 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.22 2022/01/07 11:13:54 tb Exp $ */ 1/* $OpenBSD: evp_lib.c,v 1.23 2022/01/09 15:15:25 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 *
@@ -385,6 +385,35 @@ EVP_MD_CTX_md_data(const EVP_MD_CTX *ctx)
385 return ctx->md_data; 385 return ctx->md_data;
386} 386}
387 387
388EVP_PKEY_CTX *
389EVP_MD_CTX_pkey_ctx(const EVP_MD_CTX *ctx)
390{
391 return ctx->pctx;
392}
393
394void
395EVP_MD_CTX_set_pkey_ctx(EVP_MD_CTX *ctx, EVP_PKEY_CTX *pctx)
396{
397 if (EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX)) {
398 EVP_MD_CTX_clear_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX);
399 } else {
400 EVP_PKEY_CTX_free(ctx->pctx);
401 }
402
403 ctx->pctx = pctx;
404
405 if (pctx != NULL) {
406 /*
407 * For unclear reasons it was decided that the caller keeps
408 * ownership of pctx. So a flag was invented to make sure we
409 * don't free it in EVP_MD_CTX_cleanup(). We also need to
410 * unset it in EVP_MD_CTX_copy_ex(). Fortunately, the flag
411 * isn't public...
412 */
413 EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX);
414 }
415}
416
388void 417void
389EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags) 418EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags)
390{ 419{