mirror of
https://github.com/cmclark00/retro-imager.git
synced 2025-05-18 16:05:21 +01:00
AcceleratedCryptographicHash: Use platform capabilities
Introduce a CNG version for Windows, a CommonCrypto version for macOS and a GnuTLS version for Linux, as we're using gnutls _anyway_.
This commit is contained in:
parent
7074a5e389
commit
d9082f8abd
7 changed files with 334 additions and 118 deletions
53
src/mac/acceleratedcryptographichash_commoncrypto.cpp
Normal file
53
src/mac/acceleratedcryptographichash_commoncrypto.cpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Use CommonCrypto on macOS for SHA256
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
* Copyright (C) 2024 Raspberry Pi Ltd
|
||||
*/
|
||||
|
||||
#include "acceleratedcryptographichash.h"
|
||||
|
||||
#include <CommonCrypto/CommonDigest.h>
|
||||
|
||||
struct AcceleratedCryptographicHash::Impl {
|
||||
explicit Impl(QCryptographicHash::Algorithm algo) {
|
||||
if (method != QCryptographicHash::Sha256)
|
||||
throw std::runtime_error("Only sha256 implemented");
|
||||
|
||||
CC_SHA256_Init(&_sha256);
|
||||
}
|
||||
|
||||
void addData(const char *data, int length)
|
||||
{
|
||||
CC_SHA256_Update(&_sha256, data, length);
|
||||
}
|
||||
|
||||
void addData(const QByteArray &data)
|
||||
{
|
||||
addData(data.constData(), data.size());
|
||||
}
|
||||
|
||||
QByteArray result() {
|
||||
unsigned char binhash[CC_SHA256_DIGEST_LENGTH];
|
||||
CC_SHA256_Final(binhash, &_sha256);
|
||||
return QByteArray((char *) binhash, sizeof binhash);
|
||||
}
|
||||
|
||||
private:
|
||||
CC_SHA256_CTX _sha256;
|
||||
};
|
||||
|
||||
AcceleratedCryptographicHash::AcceleratedCryptographicHash(QCryptographicHash::Algorithm method)
|
||||
: p_Impl(std::make_unique<impl>(method)) {}
|
||||
|
||||
AcceleratedCryptographicHash::~AcceleratedCryptographicHash() = default;
|
||||
|
||||
void AcceleratedCryptographicHash::addData(const char *data, int length) {
|
||||
p_Impl->addData(data, length);
|
||||
}
|
||||
void AcceleratedCryptographicHash::addData(const QByteArray &data) {
|
||||
p_Impl->addData(data);
|
||||
}
|
||||
QByteArray AcceleratedCryptographicHash::result() {
|
||||
return p_Impl->result();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue