mirror of
https://github.com/cmclark00/retro-imager.git
synced 2025-05-18 07:55:21 +01:00
Use accelerated hashing for verification
Modern CPUs have special instructions to accelerate computing SHA hashes. The Qt QCryptographicHash code is standard C, so not taking advantage of those though. Outsource the hashing to OpenSSL that does. Shaves off some seconds during verification stage.
This commit is contained in:
parent
2c5432fe7f
commit
8048b5e47c
6 changed files with 73 additions and 7 deletions
37
acceleratedcryptographichash.cpp
Normal file
37
acceleratedcryptographichash.cpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Use OpenSSL for hashing as their code is more optimized than Qt's
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
* Copyright (C) 2020 Raspberry Pi (Trading) Limited
|
||||
*/
|
||||
|
||||
#include "acceleratedcryptographichash.h"
|
||||
|
||||
AcceleratedCryptographicHash::AcceleratedCryptographicHash(QCryptographicHash::Algorithm method)
|
||||
{
|
||||
if (method != QCryptographicHash::Sha256)
|
||||
throw std::runtime_error("Only sha256 implemented");
|
||||
|
||||
SHA256_Init(&_sha256);
|
||||
}
|
||||
|
||||
AcceleratedCryptographicHash::~AcceleratedCryptographicHash()
|
||||
{
|
||||
}
|
||||
|
||||
void AcceleratedCryptographicHash::addData(const char *data, int length)
|
||||
{
|
||||
SHA256_Update(&_sha256, data, length);
|
||||
}
|
||||
|
||||
void AcceleratedCryptographicHash::addData(const QByteArray &data)
|
||||
{
|
||||
addData(data.constData(), data.size());
|
||||
}
|
||||
|
||||
QByteArray AcceleratedCryptographicHash::result()
|
||||
{
|
||||
unsigned char binhash[SHA256_DIGEST_LENGTH];
|
||||
SHA256_Final(binhash, &_sha256);
|
||||
return QByteArray((char *) binhash, sizeof binhash);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue