QCryptographicHash: copy SHA-3 context outside sha3Finish()
This matches what other algorithms do. This is in preparation of separating the state copying from the algorithm finishing, to eventually establish code paths that do not need to copy (e.g. static hash()/hashInto()). Pick-to: 6.7 6.5 Change-Id: If674cae6b7b3fc3abd3b72f2162532321decadff Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit 37e360a13f14f19ac0d3ea9ca5d18ca222f3b5a7) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
b88adc1188
commit
27c3f90650
@ -386,7 +386,7 @@ public:
|
||||
SHA3Context sha3Context;
|
||||
|
||||
enum class Sha3Variant { Sha3, Keccak };
|
||||
void sha3Finish(HashResult &result, int bitCount, Sha3Variant sha3Variant);
|
||||
static void sha3Finish(SHA3Context &ctx, HashResult &result, int bitCount, Sha3Variant sha3Variant);
|
||||
blake2b_state blake2bContext;
|
||||
blake2s_state blake2sContext;
|
||||
#endif
|
||||
@ -399,8 +399,8 @@ public:
|
||||
};
|
||||
|
||||
#ifndef QT_CRYPTOGRAPHICHASH_ONLY_SHA1
|
||||
void QCryptographicHashPrivate::State::sha3Finish(HashResult &result, int bitCount,
|
||||
Sha3Variant sha3Variant)
|
||||
void QCryptographicHashPrivate::State::sha3Finish(SHA3Context &ctx, HashResult &result,
|
||||
int bitCount, Sha3Variant sha3Variant)
|
||||
{
|
||||
/*
|
||||
FIPS 202 §6.1 defines SHA-3 in terms of calculating the Keccak function
|
||||
@ -426,17 +426,15 @@ void QCryptographicHashPrivate::State::sha3Finish(HashResult &result, int bitCou
|
||||
|
||||
result.resizeForOverwrite(bitCount / 8);
|
||||
|
||||
SHA3Context copy = sha3Context;
|
||||
|
||||
switch (sha3Variant) {
|
||||
case Sha3Variant::Sha3:
|
||||
sha3Update(©, reinterpret_cast<const BitSequence *>(&sha3FinalSuffix), 2);
|
||||
sha3Update(&ctx, reinterpret_cast<const BitSequence *>(&sha3FinalSuffix), 2);
|
||||
break;
|
||||
case Sha3Variant::Keccak:
|
||||
break;
|
||||
}
|
||||
|
||||
sha3Final(©, result.data());
|
||||
sha3Final(&ctx, result.data());
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1034,7 +1032,8 @@ void QCryptographicHashPrivate::State::finalizeUnchecked(QCryptographicHash::Alg
|
||||
method == QCryptographicHash::Keccak_256 ||
|
||||
method == QCryptographicHash::Keccak_384 ||
|
||||
method == QCryptographicHash::Keccak_512) {
|
||||
sha3Finish(result, 8 * hashLengthInternal(method), Sha3Variant::Keccak);
|
||||
SHA3Context copy = sha3Context;
|
||||
sha3Finish(copy, result, 8 * hashLengthInternal(method), Sha3Variant::Keccak);
|
||||
} else if (method == QCryptographicHash::Blake2b_160 ||
|
||||
method == QCryptographicHash::Blake2b_256 ||
|
||||
method == QCryptographicHash::Blake2b_384) {
|
||||
@ -1123,14 +1122,16 @@ void QCryptographicHashPrivate::State::finalizeUnchecked(QCryptographicHash::Alg
|
||||
case QCryptographicHash::RealSha3_256:
|
||||
case QCryptographicHash::RealSha3_384:
|
||||
case QCryptographicHash::RealSha3_512: {
|
||||
sha3Finish(result, 8 * hashLengthInternal(method), Sha3Variant::Sha3);
|
||||
SHA3Context copy = sha3Context;
|
||||
sha3Finish(copy, result, 8 * hashLengthInternal(method), Sha3Variant::Sha3);
|
||||
break;
|
||||
}
|
||||
case QCryptographicHash::Keccak_224:
|
||||
case QCryptographicHash::Keccak_256:
|
||||
case QCryptographicHash::Keccak_384:
|
||||
case QCryptographicHash::Keccak_512: {
|
||||
sha3Finish(result, 8 * hashLengthInternal(method), Sha3Variant::Keccak);
|
||||
SHA3Context copy = sha3Context;
|
||||
sha3Finish(copy, result, 8 * hashLengthInternal(method), Sha3Variant::Keccak);
|
||||
break;
|
||||
}
|
||||
case QCryptographicHash::Blake2b_160:
|
||||
|
Loading…
x
Reference in New Issue
Block a user