From a011e47f3d2980e9d550aa865acc211899828ad3 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 19 Mar 2023 15:42:57 +0100 Subject: [PATCH] QMessageAuthenticatonCode: re-use QCryptographicHash's result buffer QMessageAuthenticationCodePrivate::result always mirrored QCryptographicHash's, so we only need one, greatly reducing sizeof(QMessageAuthentcationCodePrivate) and avoiding unnecessary copies. Pick-to: 6.5 Change-Id: I56365b29bd9e096a4582b1764b6fef4c5243735b Reviewed-by: Thiago Macieira Reviewed-by: Qt CI Bot --- src/corelib/tools/qcryptographichash.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/corelib/tools/qcryptographichash.cpp b/src/corelib/tools/qcryptographichash.cpp index 1fecf2ee6a..72c13d247b 100644 --- a/src/corelib/tools/qcryptographichash.cpp +++ b/src/corelib/tools/qcryptographichash.cpp @@ -1308,7 +1308,6 @@ public: } HashBlock key; - HashResult result; QCryptographicHashPrivate messageHash; void setKey(QByteArrayView k) noexcept; @@ -1464,7 +1463,6 @@ QMessageAuthenticationCode::~QMessageAuthenticationCode() */ void QMessageAuthenticationCode::reset() noexcept { - d->result.clear(); d->messageHash.reset(); d->initMessageHash(); } @@ -1503,7 +1501,6 @@ void QMessageAuthenticationCode::reset() noexcept */ void QMessageAuthenticationCode::setKey(QByteArrayView key) noexcept { - d->result.clear(); d->messageHash.reset(); d->setKey(key); d->initMessageHash(); @@ -1554,7 +1551,7 @@ bool QMessageAuthenticationCode::addData(QIODevice *device) QByteArrayView QMessageAuthenticationCode::resultView() const noexcept { d->finalize(); - return d->result.toByteArrayView(); + return d->messageHash.resultView(); } /*! @@ -1570,7 +1567,7 @@ QByteArray QMessageAuthenticationCode::result() const void QMessageAuthenticationCodePrivate::finalize() { const auto lock = qt_scoped_lock(messageHash.finalizeMutex); - if (!result.isEmpty()) + if (!messageHash.result.isEmpty()) return; finalizeUnchecked(); } @@ -1584,8 +1581,6 @@ void QMessageAuthenticationCodePrivate::finalizeUnchecked() noexcept messageHash.addData(xored(key, 0x5c)); messageHash.addData(hashedMessage); messageHash.finalizeUnchecked(); - - result = messageHash.result; } /*! @@ -1602,7 +1597,7 @@ QByteArray QMessageAuthenticationCode::hash(QByteArrayView message, QByteArrayVi mac.initMessageHash(); mac.messageHash.addData(message); mac.finalizeUnchecked(); - return mac.result.toByteArrayView().toByteArray(); + return mac.messageHash.resultView().toByteArray(); } QT_END_NAMESPACE