From 698c7696ebff4868c695bb6d7ca66ed17b5c2f3b Mon Sep 17 00:00:00 2001 From: Jan Grulich Date: Wed, 11 Jan 2023 12:06:16 +0100 Subject: [PATCH] QCryptographicHash[OpenSSL]: allow to get intermediary result OpenSSL doesn't allow to add additional data when the hash has been finalized. To fix that, we just make a copy of the current context and call EVP_DigestFinal_ex() on the copy so we can still later add additional data. Pick-to: 6.5 Change-Id: If76d4ec56f8846d6ef55ed7ec7cbab440d43edd0 Reviewed-by: Giuseppe D'Angelo --- src/corelib/tools/qcryptographichash.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/corelib/tools/qcryptographichash.cpp b/src/corelib/tools/qcryptographichash.cpp index 39a7e0824a1..1c3fea079cc 100644 --- a/src/corelib/tools/qcryptographichash.cpp +++ b/src/corelib/tools/qcryptographichash.cpp @@ -752,9 +752,11 @@ void QCryptographicHashPrivate::finalize() noexcept tmpresult.resizeForOverwrite(length); blake2s_final(©, tmpresult.data(), length); } else if (!initializationFailed) { + EVP_MD_CTX_ptr copy = EVP_MD_CTX_ptr(EVP_MD_CTX_new()); + EVP_MD_CTX_copy_ex(copy.get(), context.get()); tmpresult.resizeForOverwrite(EVP_MD_get_size(algorithm.get())); - const int ret = EVP_DigestFinal_ex(context.get(), tmpresult.data(), nullptr); - Q_UNUSED(ret); + const int ret = EVP_DigestFinal_ex(copy.get(), tmpresult.data(), nullptr); + Q_UNUSED(ret) } #else switch (method) {