diff options
author | Jan Grulich <jgrulich@redhat.com> | 2023-01-11 12:06:16 +0100 |
---|---|---|
committer | Jan Grulich <jgrulich@redhat.com> | 2023-01-12 16:33:56 +0100 |
commit | 698c7696ebff4868c695bb6d7ca66ed17b5c2f3b (patch) | |
tree | 503ce1b10138410bfd3b31415eedb1b52dd06ee4 /src | |
parent | 94e474b48e9d3c6434339afe166c2329f8c36ea2 (diff) |
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 <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/tools/qcryptographichash.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/corelib/tools/qcryptographichash.cpp b/src/corelib/tools/qcryptographichash.cpp index 39a7e0824a..1c3fea079c 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) { |