From 54fbf153ab0454deb6c4d82a775a5bc91f0b7765 Mon Sep 17 00:00:00 2001 From: tb Date: Wed, 27 Mar 2024 07:36:59 +0000 Subject: [PATCH] Explain the weird copy dance in EVP_DigestSignFinal() with jsing --- lib/libcrypto/evp/m_sigver.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/libcrypto/evp/m_sigver.c b/lib/libcrypto/evp/m_sigver.c index 090134c40c0..d427e05db0d 100644 --- a/lib/libcrypto/evp/m_sigver.c +++ b/lib/libcrypto/evp/m_sigver.c @@ -1,4 +1,4 @@ -/* $OpenBSD: m_sigver.c,v 1.25 2024/03/27 06:53:15 tb Exp $ */ +/* $OpenBSD: m_sigver.c,v 1.26 2024/03/27 07:36:59 tb Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006. */ @@ -191,7 +191,7 @@ EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, size_t *siglen) return 1; } - + /* Use a copy since EVP_DigestFinal_ex() clears secrets. */ if ((md_ctx = EVP_MD_CTX_new()) == NULL) goto err; if (!EVP_MD_CTX_copy_ex(md_ctx, ctx)) @@ -203,6 +203,7 @@ EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, size_t *siglen) } else { if (!EVP_DigestFinal_ex(md_ctx, md, &mdlen)) goto err; + /* Use the original ctx since secrets were cleared. */ if (EVP_PKEY_sign(ctx->pctx, sigret, siglen, md, mdlen) <= 0) goto err; } -- 2.20.1