diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2021-07-06 16:16:06 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2021-07-08 01:49:26 +0200 |
commit | 28fbed2f5cfa311067ed42268302c15b99769876 (patch) | |
tree | e21e3461aed6214ca6b88e67d99124ca952acd14 /src/corelib/tools/qcryptographichash.cpp | |
parent | e9fffbaf81ec81685cb6a5d75844cd700183ab9e (diff) |
QCryptographicHash: share more code between switch cases
Now that calling hashLengthInternal() is cheap, use it to factor
common code in switch statements. For sha3, that would have been
possible before, too. Reason for duplicating the case bodies is
unclear.
Change-Id: I281617546e0b3e701315eee2f10df8d26ada92ae
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/tools/qcryptographichash.cpp')
-rw-r--r-- | src/corelib/tools/qcryptographichash.cpp | 40 |
1 files changed, 8 insertions, 32 deletions
diff --git a/src/corelib/tools/qcryptographichash.cpp b/src/corelib/tools/qcryptographichash.cpp index f5c5cbb204..512d38b02b 100644 --- a/src/corelib/tools/qcryptographichash.cpp +++ b/src/corelib/tools/qcryptographichash.cpp @@ -480,16 +480,10 @@ void QCryptographicHashPrivate::addData(QByteArrayView bytes) noexcept break; case QCryptographicHash::RealSha3_224: case QCryptographicHash::Keccak_224: - sha3Update(&sha3Context, reinterpret_cast<const BitSequence *>(data), uint64_t(length) * 8); - break; case QCryptographicHash::RealSha3_256: case QCryptographicHash::Keccak_256: - sha3Update(&sha3Context, reinterpret_cast<const BitSequence *>(data), uint64_t(length) * 8); - break; case QCryptographicHash::RealSha3_384: case QCryptographicHash::Keccak_384: - sha3Update(&sha3Context, reinterpret_cast<const BitSequence *>(data), uint64_t(length) * 8); - break; case QCryptographicHash::RealSha3_512: case QCryptographicHash::Keccak_512: sha3Update(&sha3Context, reinterpret_cast<const BitSequence *>(data), uint64_t(length) * 8); @@ -600,36 +594,18 @@ QByteArray QCryptographicHashPrivate::finalize() SHA512Result(©, reinterpret_cast<unsigned char *>(result.data())); break; } - case QCryptographicHash::RealSha3_224: { - sha3Finish(224, QCryptographicHashPrivate::Sha3Variant::Sha3); - break; - } - case QCryptographicHash::RealSha3_256: { - sha3Finish(256, QCryptographicHashPrivate::Sha3Variant::Sha3); - break; - } - case QCryptographicHash::RealSha3_384: { - sha3Finish(384, QCryptographicHashPrivate::Sha3Variant::Sha3); - break; - } + case QCryptographicHash::RealSha3_224: + case QCryptographicHash::RealSha3_256: + case QCryptographicHash::RealSha3_384: case QCryptographicHash::RealSha3_512: { - sha3Finish(512, QCryptographicHashPrivate::Sha3Variant::Sha3); - break; - } - case QCryptographicHash::Keccak_224: { - sha3Finish(224, QCryptographicHashPrivate::Sha3Variant::Keccak); - break; - } - case QCryptographicHash::Keccak_256: { - sha3Finish(256, QCryptographicHashPrivate::Sha3Variant::Keccak); - break; - } - case QCryptographicHash::Keccak_384: { - sha3Finish(384, QCryptographicHashPrivate::Sha3Variant::Keccak); + sha3Finish(8 * hashLengthInternal(method), Sha3Variant::Sha3); break; } + case QCryptographicHash::Keccak_224: + case QCryptographicHash::Keccak_256: + case QCryptographicHash::Keccak_384: case QCryptographicHash::Keccak_512: { - sha3Finish(512, QCryptographicHashPrivate::Sha3Variant::Keccak); + sha3Finish(8 * hashLengthInternal(method), Sha3Variant::Keccak); break; } case QCryptographicHash::Blake2b_160: |