9#include "openssl/bignum_p.h"
11#include <openssl/err.h>
13bool Verify::verifyECDSA(
14 const openssl::evp_pkey_ptr &pkey,
const EVP_MD *digest,
15 const char *data, std::size_t dataSize,
16 const char *signature, std::size_t signatureSize)
19 qCWarning(
Log) <<
"no key provided";
23 const openssl::ec_key_ptr ecKey(EVP_PKEY_get1_EC_KEY(pkey.get()));
26 uint8_t digestData[EVP_MAX_MD_SIZE];
27 uint32_t digestSize = 0;
28 EVP_Digest(
reinterpret_cast<const uint8_t*
>(data), dataSize, digestData, &digestSize, digest,
nullptr);
29 if (digestSize * 2 != signatureSize || EVP_PKEY_bits(pkey.get()) != 4 * (
int)signatureSize) {
30 qCWarning(
Log) <<
"digest size mismatch!?" << digestSize << signatureSize;
35 auto r = Bignum::fromByteArray(signature, signatureSize / 2);
36 auto s = Bignum::fromByteArray(signature + signatureSize / 2, signatureSize / 2);
39 const openssl::ecdsa_sig_ptr sig(ECDSA_SIG_new());
40 ECDSA_SIG_set0(sig.get(), r.release(), s.release());
41 const auto verifyResult = ECDSA_do_verify(digestData, digestSize, sig.get(), ecKey.get());
42 switch (verifyResult) {
44 qCWarning(
Log) <<
"Failed to verify signature:" << ERR_error_string(ERR_get_error(),
nullptr);
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:01:39 by
doxygen 1.12.0 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.