From b069ed5e7fdab56024bc8e63575d942723b2ce31 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 30 Aug 2017 23:52:52 -0700 Subject: Revert "QCryptographicHash: make SHA3 calculate SHA3, not Keccak" This reverts commit a647004d9f349e0edc4254dcfe672ccf18f98ea7 (which is a backport of 88a8feeacb9bdaff9ee06164424e407eb904cd10). After the 5.9.0 release, we've found that changing the algorithm is a bad idea. It's true that Qt hasn't calculated SHA-3, but it's calculated something and people may be using it. Keeping a consistent calculation is better for the 5.6 LTS. Discussed-on: http://lists.qt-project.org/pipermail/development/2017-August/030786.html Change-Id: I38341f8155354cc4a776fffd14dfdbcdc7d0f039 Reviewed-by: Lars Knoll --- src/corelib/tools/qcryptographichash.cpp | 52 ++++++++------------------------ 1 file changed, 12 insertions(+), 40 deletions(-) (limited to 'src/corelib/tools/qcryptographichash.cpp') diff --git a/src/corelib/tools/qcryptographichash.cpp b/src/corelib/tools/qcryptographichash.cpp index db2ee978e8..d9f59b82fa 100644 --- a/src/corelib/tools/qcryptographichash.cpp +++ b/src/corelib/tools/qcryptographichash.cpp @@ -174,45 +174,9 @@ public: SHA3Context sha3Context; #endif }; -#ifndef QT_CRYPTOGRAPHICHASH_ONLY_SHA1 - void sha3Finish(int bitCount); -#endif QByteArray result; }; -#ifndef QT_CRYPTOGRAPHICHASH_ONLY_SHA1 -void QCryptographicHashPrivate::sha3Finish(int bitCount) -{ - /* - FIPS 202 ยง6.1 defines SHA-3 in terms of calculating the Keccak function - over the original message with the two-bit suffix "01" appended to it. - This variable stores that suffix (and it's fed into the calculations - when the hash is returned to users). - - Only 2 bits of this variable are actually used (see the call to sha3Update - below). The Keccak implementation we're using will actually use the - *leftmost* 2 bits, and interpret them right-to-left. In other words, the - bits must appear in order of *increasing* significance; and as the two most - significant bits of the byte -- the rightmost 6 are ignored. (Yes, this - seems self-contradictory, but it's the way it is...) - - Overall, this means: - * the leftmost two bits must be "10" (not "01"!); - * we don't care what the other six bits are set to (they can be set to - any value), but we arbitrarily set them to 0; - - and for an unsigned char this gives us 0b10'00'00'00, or 0x80. - */ - static const unsigned char sha3FinalSuffix = 0x80; - - result.resize(bitCount / 8); - - SHA3Context copy = sha3Context; - sha3Update(©, reinterpret_cast(&sha3FinalSuffix), 2); - sha3Final(©, reinterpret_cast(result.data())); -} -#endif - /*! \class QCryptographicHash \inmodule QtCore @@ -457,19 +421,27 @@ QByteArray QCryptographicHash::result() const break; } case Sha3_224: { - d->sha3Finish(224); + SHA3Context copy = d->sha3Context; + d->result.resize(224/8); + sha3Final(©, reinterpret_cast(d->result.data())); break; } case Sha3_256: { - d->sha3Finish(256); + SHA3Context copy = d->sha3Context; + d->result.resize(256/8); + sha3Final(©, reinterpret_cast(d->result.data())); break; } case Sha3_384: { - d->sha3Finish(384); + SHA3Context copy = d->sha3Context; + d->result.resize(384/8); + sha3Final(©, reinterpret_cast(d->result.data())); break; } case Sha3_512: { - d->sha3Finish(512); + SHA3Context copy = d->sha3Context; + d->result.resize(512/8); + sha3Final(©, reinterpret_cast(d->result.data())); break; } #endif -- cgit v1.2.3