From 494786ce736a99d7ea8cc72fa06309ade597dd0e Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 23 Feb 2023 15:45:46 +0100 Subject: [PATCH] QMessageAuthenticationCode: make messageHash a QCryptographicHashPrivate ... avoiding one more memory allocation, and giving us access to QCryptographicHashPrivate::result, for use in subsequent commits. The only real adjustment to users of QMACPrivate::messageHash is that instead of messageHash.result(); they now need to use messageHash.finalizeUnchecked(); messageHash.resultView() // .toByteArray() I.e. explicitly finalize. Pick-to: 6.5 Change-Id: I80b1158b062554bbf8afa7241674a892de27f204 Reviewed-by: Thiago Macieira --- 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 8163ddf216d..6a76c275201 100644 --- a/src/corelib/tools/qcryptographichash.cpp +++ b/src/corelib/tools/qcryptographichash.cpp @@ -996,7 +996,7 @@ public: QByteArray key; QByteArray result; QBasicMutex finalizeMutex; - QCryptographicHash messageHash; + QCryptographicHashPrivate messageHash; const QCryptographicHash::Algorithm method; void initMessageHash(); @@ -1022,7 +1022,8 @@ void QMessageAuthenticationCodePrivate::initMessageHash() if (key.size() > blockSize) { messageHash.addData(key); - key = messageHash.result(); + messageHash.finalizeUnchecked(); + key = messageHash.resultView().toByteArray(); messageHash.reset(); } @@ -1186,6 +1187,7 @@ void QMessageAuthenticationCodePrivate::finalizeUnchecked() { const int blockSize = qt_hash_block_size(method); + messageHash.finalizeUnchecked(); QByteArrayView hashedMessage = messageHash.resultView(); QVarLengthArray oKeyPad(blockSize);