summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoshua <joshua@cvs.openbsd.org>2024-01-13 13:59:19 +0000
committerjoshua <joshua@cvs.openbsd.org>2024-01-13 13:59:19 +0000
commit08d6e9d73435379d13f8ab6f0066fd6b3fb2a620 (patch)
tree44524426c320e7513ee799403929426c3a144f1c
parentd35bc4e76072b847f44e9727c5a1cd65b6c6857d (diff)
Clean up EVP_MD_CTX_init() usage in ASN1_item_sign()
ok tb@
-rw-r--r--lib/libcrypto/asn1/asn1_item.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/lib/libcrypto/asn1/asn1_item.c b/lib/libcrypto/asn1/asn1_item.c
index 3f67e3fc36c..18da77433e9 100644
--- a/lib/libcrypto/asn1/asn1_item.c
+++ b/lib/libcrypto/asn1/asn1_item.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: asn1_item.c,v 1.18 2023/11/09 11:36:39 tb Exp $ */
+/* $OpenBSD: asn1_item.c,v 1.19 2024/01/13 13:59:18 joshua Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -222,13 +222,20 @@ int
ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2,
ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey, const EVP_MD *type)
{
- EVP_MD_CTX ctx;
- EVP_MD_CTX_init(&ctx);
- if (!EVP_DigestSignInit(&ctx, NULL, type, NULL, pkey)) {
- EVP_MD_CTX_cleanup(&ctx);
- return 0;
- }
- return ASN1_item_sign_ctx(it, algor1, algor2, signature, asn, &ctx);
+ EVP_MD_CTX *md_ctx = NULL;
+ int ret = 0;
+
+ if ((md_ctx = EVP_MD_CTX_new()) == NULL)
+ goto err;
+ if (!EVP_DigestSignInit(md_ctx, NULL, type, NULL, pkey))
+ goto err;
+
+ ret = ASN1_item_sign_ctx(it, algor1, algor2, signature, asn, md_ctx);
+
+ err:
+ EVP_MD_CTX_free(md_ctx);
+
+ return ret;
}
static int