QMessageAuthenticationCode: statically assert HMAC works for all algorithms
... by checking that for each algorithm, that the algorithm's result size is not larger than the algorithm's block size. Pick-to: 6.5 Change-Id: I4daf7900e72766d180954b15edb06687a57f939f Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
1fb0dca140
commit
c1e2ec16db
@ -1150,7 +1150,14 @@ void QMessageAuthenticationCodePrivate::setKey(const QByteArray &newKey)
|
|||||||
if (newKey.size() > blockSize) {
|
if (newKey.size() > blockSize) {
|
||||||
messageHash.addData(newKey);
|
messageHash.addData(newKey);
|
||||||
messageHash.finalizeUnchecked();
|
messageHash.finalizeUnchecked();
|
||||||
static_assert(maxHashLength() <= maxHashBlockSize());
|
static_assert([] {
|
||||||
|
using A = QCryptographicHash::Algorithm;
|
||||||
|
for (int i = 0; i < A::NumAlgorithms; ++i) {
|
||||||
|
if (hashLengthInternal(A(i)) > qt_hash_block_size(A(i)))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}(), "this code assumes that a hash's result always fits into that hash's block size");
|
||||||
key = messageHash.result;
|
key = messageHash.result;
|
||||||
messageHash.reset();
|
messageHash.reset();
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user