From: joshua Date: Mon, 25 Mar 2024 03:41:16 +0000 (+0000) Subject: Clean up EVP_MD_CTX_{legacy_clear,cleanup}() usage in x509/x509_cmp.c X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=dc7f9f7d3b3921adfdac0230b7b5d865cf70577c;p=openbsd Clean up EVP_MD_CTX_{legacy_clear,cleanup}() usage in x509/x509_cmp.c ok tb@ --- diff --git a/lib/libcrypto/x509/x509_cmp.c b/lib/libcrypto/x509/x509_cmp.c index 6098b6e7e80..2c1e4270930 100644 --- a/lib/libcrypto/x509/x509_cmp.c +++ b/lib/libcrypto/x509/x509_cmp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: x509_cmp.c,v 1.43 2024/02/18 15:45:42 tb Exp $ */ +/* $OpenBSD: x509_cmp.c,v 1.44 2024/03/25 03:41:16 joshua Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -91,34 +91,35 @@ unsigned long X509_issuer_and_serial_hash(X509 *a) { unsigned long ret = 0; - EVP_MD_CTX ctx; + EVP_MD_CTX *md_ctx; unsigned char md[16]; - char *f; + char *f = NULL; - EVP_MD_CTX_legacy_clear(&ctx); - f = X509_NAME_oneline(a->cert_info->issuer, NULL, 0); - if (f == NULL) + if ((md_ctx = EVP_MD_CTX_new()) == NULL) goto err; - if (!EVP_DigestInit_ex(&ctx, EVP_md5(), NULL)) + + if ((f = X509_NAME_oneline(a->cert_info->issuer, NULL, 0)) == NULL) goto err; - if (!EVP_DigestUpdate(&ctx, (unsigned char *)f, strlen(f))) + if (!EVP_DigestInit_ex(md_ctx, EVP_md5(), NULL)) goto err; - free(f); - f = NULL; - if (!EVP_DigestUpdate(&ctx, + if (!EVP_DigestUpdate(md_ctx, (unsigned char *)f, strlen(f))) + goto err; + if (!EVP_DigestUpdate(md_ctx, (unsigned char *)a->cert_info->serialNumber->data, (unsigned long)a->cert_info->serialNumber->length)) goto err; - if (!EVP_DigestFinal_ex(&ctx, &(md[0]), NULL)) + if (!EVP_DigestFinal_ex(md_ctx, &(md[0]), NULL)) goto err; + ret = (((unsigned long)md[0]) | ((unsigned long)md[1] << 8L) | ((unsigned long)md[2] << 16L) | ((unsigned long)md[3] << 24L)) & 0xffffffffL; err: - EVP_MD_CTX_cleanup(&ctx); + EVP_MD_CTX_free(md_ctx); free(f); - return (ret); + + return ret; } LCRYPTO_ALIAS(X509_issuer_and_serial_hash); #endif @@ -285,24 +286,27 @@ LCRYPTO_ALIAS(X509_NAME_hash); unsigned long X509_NAME_hash_old(X509_NAME *x) { - EVP_MD_CTX md_ctx; + EVP_MD_CTX *md_ctx; unsigned long ret = 0; unsigned char md[16]; + if ((md_ctx = EVP_MD_CTX_new()) == NULL) + return ret; + /* Make sure X509_NAME structure contains valid cached encoding */ i2d_X509_NAME(x, NULL); - EVP_MD_CTX_legacy_clear(&md_ctx); - if (EVP_DigestInit_ex(&md_ctx, EVP_md5(), NULL) && - EVP_DigestUpdate(&md_ctx, x->bytes->data, x->bytes->length) && - EVP_DigestFinal_ex(&md_ctx, md, NULL)) + if (EVP_DigestInit_ex(md_ctx, EVP_md5(), NULL) && + EVP_DigestUpdate(md_ctx, x->bytes->data, x->bytes->length) && + EVP_DigestFinal_ex(md_ctx, md, NULL)) ret = (((unsigned long)md[0]) | ((unsigned long)md[1] << 8L) | ((unsigned long)md[2] << 16L) | ((unsigned long)md[3] << 24L)) & 0xffffffffL; - EVP_MD_CTX_cleanup(&md_ctx); - return (ret); + EVP_MD_CTX_free(md_ctx); + + return ret; } LCRYPTO_ALIAS(X509_NAME_hash_old); #endif