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:
Tom Dewey 2024-07-30 15:03:11 +01:00 committed by Tom Dewey
parent 7074a5e389
commit d9082f8abd
7 changed files with 334 additions and 118 deletions

View file

@ -7,37 +7,20 @@
*/
#include <QCryptographicHash>
#include <memory>
#ifdef Q_OS_DARWIN
#include <CommonCrypto/CommonDigest.h>
#define SHA256_CTX CC_SHA256_CTX
#define SHA256_DIGEST_LENGTH CC_SHA256_DIGEST_LENGTH
#define SHA256_Init CC_SHA256_Init
#define SHA256_Update CC_SHA256_Update
#define SHA256_Final CC_SHA256_Final
#else
#ifdef HAVE_GNUTLS
#include "gnutls/crypto.h"
#else
#include "openssl/sha.h"
#endif
#endif
class AcceleratedCryptographicHash
struct AcceleratedCryptographicHash
{
private:
struct impl;
std::unique_ptr<impl> p_Impl;
public:
explicit AcceleratedCryptographicHash(QCryptographicHash::Algorithm method);
virtual ~AcceleratedCryptographicHash();
~AcceleratedCryptographicHash();
void addData(const char *data, int length);
void addData(const QByteArray &data);
QByteArray result();
protected:
#ifdef HAVE_GNUTLS
gnutls_hash_hd_t _sha256;
#else
SHA256_CTX _sha256;
#endif
};
#endif // ACCELERATEDCRYPTOGRAPHICHASH_H