Use QCryptographicHash::hash() more widely
... instead of the "usual" rule of three: ctor, addData(), result(). Not only does it generate less code in the caller, it's now also faster. Change-Id: I67c7eeb01f527b90e80a08f60c1c7f2ec1e49dd4 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
parent
bd62dc1391
commit
e9fffbaf81
@ -122,10 +122,7 @@ void QMessageAuthenticationCodePrivate::initMessageHash()
|
|||||||
const int blockSize = qt_hash_block_size(method);
|
const int blockSize = qt_hash_block_size(method);
|
||||||
|
|
||||||
if (key.size() > blockSize) {
|
if (key.size() > blockSize) {
|
||||||
QCryptographicHash hash(method);
|
key = QCryptographicHash::hash(key, method);
|
||||||
hash.addData(key);
|
|
||||||
key = hash.result();
|
|
||||||
hash.reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key.size() < blockSize) {
|
if (key.size() < blockSize) {
|
||||||
|
@ -594,10 +594,9 @@ QString QNetworkDiskCachePrivate::uniqueFileName(const QUrl &url)
|
|||||||
cleanUrl.setPassword(QString());
|
cleanUrl.setPassword(QString());
|
||||||
cleanUrl.setFragment(QString());
|
cleanUrl.setFragment(QString());
|
||||||
|
|
||||||
QCryptographicHash hash(QCryptographicHash::Sha1);
|
const QByteArray hash = QCryptographicHash::hash(cleanUrl.toEncoded(), QCryptographicHash::Sha1);
|
||||||
hash.addData(cleanUrl.toEncoded());
|
|
||||||
// convert sha1 to base36 form and return first 8 bytes for use as string
|
// convert sha1 to base36 form and return first 8 bytes for use as string
|
||||||
const QByteArray id = QByteArray::number(*(qlonglong*)hash.result().constData(), 36).left(8);
|
const QByteArray id = QByteArray::number(*(qlonglong*)hash.data(), 36).left(8);
|
||||||
// generates <one-char subdir>/<8-char filname.d>
|
// generates <one-char subdir>/<8-char filname.d>
|
||||||
uint code = (uint)id.at(id.length()-1) % 16;
|
uint code = (uint)id.at(id.length()-1) % 16;
|
||||||
QString pathFragment = QString::number(code, 16) + QLatin1Char('/')
|
QString pathFragment = QString::number(code, 16) + QLatin1Char('/')
|
||||||
|
@ -109,15 +109,11 @@ static QByteArray _q_PKCS12_keygen(char id, const QByteArray &salt, const QStrin
|
|||||||
QByteArray A;
|
QByteArray A;
|
||||||
QByteArray B;
|
QByteArray B;
|
||||||
B.resize(v);
|
B.resize(v);
|
||||||
QCryptographicHash hash(QCryptographicHash::Sha1);
|
|
||||||
for (int i = 0; i < c; ++i) {
|
for (int i = 0; i < c; ++i) {
|
||||||
// hash r iterations
|
// hash r iterations
|
||||||
QByteArray Ai = D + I;
|
QByteArray Ai = D + I;
|
||||||
for (int j = 0; j < r; ++j) {
|
for (int j = 0; j < r; ++j)
|
||||||
hash.reset();
|
Ai = QCryptographicHash::hash(Ai, QCryptographicHash::Sha1);
|
||||||
hash.addData(Ai);
|
|
||||||
Ai = hash.result();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int j = 0; j < v; ++j)
|
for (int j = 0; j < v; ++j)
|
||||||
B[j] = Ai[j % u];
|
B[j] = Ai[j % u];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user