Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/plugins/qca-ossl/dhkey.cpp b/plugins/qca-ossl/dhkey.cpp
- index 976806e3..89d45bc4 100644
- --- a/plugins/qca-ossl/dhkey.cpp
- +++ b/plugins/qca-ossl/dhkey.cpp
- @@ -33,7 +33,7 @@ class DHKeyMaker : public QThread
- Q_OBJECT
- public:
- DLGroup domain;
- - DH * result;
- + DH *result;
- DHKeyMaker(const DLGroup &_domain, QObject *parent = nullptr)
- : QThread(parent)
- @@ -51,7 +51,7 @@ public:
- void run() override
- {
- - DH * dh = DH_new();
- + DH *dh = DH_new();
- BIGNUM *bnp = bi2bn(domain.p());
- BIGNUM *bng = bi2bn(domain.g());
- if (!DH_set0_pqg(dh, bnp, nullptr, bng) || !DH_generate_key(dh)) {
- @@ -119,8 +119,8 @@ void DHKey::convertToPublic()
- if (!sec)
- return;
- - DH * orig = EVP_PKEY_get0_DH(evp.pkey);
- - DH * dh = DH_new();
- + const DH *orig = EVP_PKEY_get0_DH(evp.pkey);
- + DH *dh = DH_new();
- const BIGNUM *bnp, *bng, *bnpub_key;
- DH_get0_pqg(orig, &bnp, nullptr, &bng);
- DH_get0_key(orig, &bnpub_key, nullptr);
- @@ -142,13 +142,13 @@ int DHKey::bits() const
- SymmetricKey DHKey::deriveKey(const PKeyBase &theirs)
- {
- - DH * dh = EVP_PKEY_get0_DH(evp.pkey);
- - DH * them = EVP_PKEY_get0_DH(static_cast<const DHKey *>(&theirs)->evp.pkey);
- + const DH *dh = EVP_PKEY_get0_DH(evp.pkey);
- + const DH *them = EVP_PKEY_get0_DH(static_cast<const DHKey *>(&theirs)->evp.pkey);
- const BIGNUM *bnpub_key;
- DH_get0_key(them, &bnpub_key, nullptr);
- SecureArray result(DH_size(dh));
- - int ret = DH_compute_key((unsigned char *)result.data(), bnpub_key, dh);
- + int ret = DH_compute_key((unsigned char *)result.data(), bnpub_key, (DH *)dh);
- if (ret <= 0)
- return SymmetricKey();
- result.resize(ret);
- @@ -174,7 +174,7 @@ void DHKey::createPrivate(const DLGroup &domain, const BigInteger &y, const BigI
- {
- evp.reset();
- - DH * dh = DH_new();
- + DH *dh = DH_new();
- BIGNUM *bnp = bi2bn(domain.p());
- BIGNUM *bng = bi2bn(domain.g());
- BIGNUM *bnpub_key = bi2bn(y);
- @@ -194,7 +194,7 @@ void DHKey::createPublic(const DLGroup &domain, const BigInteger &y)
- {
- evp.reset();
- - DH * dh = DH_new();
- + DH *dh = DH_new();
- BIGNUM *bnp = bi2bn(domain.p());
- BIGNUM *bng = bi2bn(domain.g());
- BIGNUM *bnpub_key = bi2bn(y);
- @@ -211,7 +211,7 @@ void DHKey::createPublic(const DLGroup &domain, const BigInteger &y)
- DLGroup DHKey::domain() const
- {
- - DH * dh = EVP_PKEY_get0_DH(evp.pkey);
- + const DH *dh = EVP_PKEY_get0_DH(evp.pkey);
- const BIGNUM *bnp, *bng;
- DH_get0_pqg(dh, &bnp, nullptr, &bng);
- return DLGroup(bn2bi(bnp), bn2bi(bng));
- @@ -219,7 +219,7 @@ DLGroup DHKey::domain() const
- BigInteger DHKey::y() const
- {
- - DH * dh = EVP_PKEY_get0_DH(evp.pkey);
- + const DH *dh = EVP_PKEY_get0_DH(evp.pkey);
- const BIGNUM *bnpub_key;
- DH_get0_key(dh, &bnpub_key, nullptr);
- return bn2bi(bnpub_key);
- @@ -227,7 +227,7 @@ BigInteger DHKey::y() const
- BigInteger DHKey::x() const
- {
- - DH * dh = EVP_PKEY_get0_DH(evp.pkey);
- + const DH *dh = EVP_PKEY_get0_DH(evp.pkey);
- const BIGNUM *bnpriv_key;
- DH_get0_key(dh, nullptr, &bnpriv_key);
- return bn2bi(bnpriv_key);
- diff --git a/plugins/qca-ossl/dsakey.cpp b/plugins/qca-ossl/dsakey.cpp
- index 6dff69c5..8281b775 100644
- --- a/plugins/qca-ossl/dsakey.cpp
- +++ b/plugins/qca-ossl/dsakey.cpp
- @@ -23,6 +23,13 @@
- #include "dsakey.h"
- #include "utils.h"
- +namespace {
- +static const auto DsaDeleter = [](DSA *pointer) {
- + if (pointer)
- + DSA_free((DSA *)pointer);
- +};
- +} // end of anonymous namespace
- +
- namespace opensslQCAPlugin {
- // take lowest bytes of BIGNUM to fit
- @@ -41,7 +48,7 @@ static SecureArray bn2fixedbuf(const BIGNUM *n, int size)
- static SecureArray dsasig_der_to_raw(const SecureArray &in)
- {
- - DSA_SIG * sig = DSA_SIG_new();
- + DSA_SIG *sig = DSA_SIG_new();
- const unsigned char *inp = (const unsigned char *)in.data();
- d2i_DSA_SIG(&sig, &inp, in.size());
- @@ -63,11 +70,11 @@ static SecureArray dsasig_raw_to_der(const SecureArray &in)
- if (in.size() != 40)
- return SecureArray();
- - DSA_SIG * sig = DSA_SIG_new();
- + DSA_SIG *sig = DSA_SIG_new();
- SecureArray part_r(20);
- - BIGNUM * bnr;
- + BIGNUM *bnr;
- SecureArray part_s(20);
- - BIGNUM * bns;
- + BIGNUM *bns;
- memcpy(part_r.data(), in.data(), 20);
- memcpy(part_s.data(), in.data() + 20, 20);
- bnr = BN_bin2bn((const unsigned char *)part_r.data(), part_r.size(), nullptr);
- @@ -94,7 +101,7 @@ class DSAKeyMaker : public QThread
- Q_OBJECT
- public:
- DLGroup domain;
- - DSA * result;
- + DSA *result;
- DSAKeyMaker(const DLGroup &_domain, QObject *parent = nullptr)
- : QThread(parent)
- @@ -112,14 +119,47 @@ public:
- void run() override
- {
- - DSA * dsa = DSA_new();
- + std::unique_ptr<DSA, decltype(DsaDeleter)> dsa(DSA_new(), DsaDeleter);
- BIGNUM *pne = bi2bn(domain.p()), *qne = bi2bn(domain.q()), *gne = bi2bn(domain.g());
- - if (!DSA_set0_pqg(dsa, pne, qne, gne) || !DSA_generate_key(dsa)) {
- - DSA_free(dsa);
- + if (!DSA_set0_pqg(dsa.get(), pne, qne, gne)) {
- + return;
- + }
- + if (!DSA_generate_key(dsa.get())) {
- + // OPENSSL_VERSION_MAJOR is only defined in openssl3
- +#ifdef OPENSSL_VERSION_MAJOR
- + // HACK
- + // in openssl3 there is an internal flag for "legacy" values
- + // bits < 2048 && seed_len <= 20
- + // set in ossl_ffc_params_FIPS186_2_generate (called by DSA_generate_parameters_ex)
- + // that we have no way to get or set, so if the bits are smaller than 2048 we generate
- + // a dsa from a dummy seed and then override the p/q/g with the ones we want
- + // so we can reuse the internal flag
- + if (BN_num_bits(pne) < 2048) {
- + int dummy;
- + dsa.reset(DSA_new());
- + if (DSA_generate_parameters_ex(
- + dsa.get(), 512, (const unsigned char *)"THIS_IS_A_DUMMY_SEED", 20, &dummy, nullptr, nullptr) !=
- + 1) {
- + return;
- + }
- + pne = bi2bn(domain.p());
- + qne = bi2bn(domain.q());
- + gne = bi2bn(domain.g());
- + if (!DSA_set0_pqg(dsa.get(), pne, qne, gne)) {
- + return;
- + }
- + if (!DSA_generate_key(dsa.get())) {
- + return;
- + }
- + } else {
- + return;
- + }
- +#else
- return;
- +#endif
- }
- - result = dsa;
- + result = dsa.release();
- }
- DSA *takeResult()
- @@ -181,7 +221,7 @@ void DSAKey::convertToPublic()
- return;
- // extract the public key into DER format
- - DSA * dsa_pkey = EVP_PKEY_get0_DSA(evp.pkey);
- + const DSA *dsa_pkey = EVP_PKEY_get0_DSA(evp.pkey);
- int len = i2d_DSAPublicKey(dsa_pkey, nullptr);
- SecureArray result(len);
- unsigned char *p = (unsigned char *)result.data();
- @@ -266,7 +306,7 @@ void DSAKey::createPrivate(const DLGroup &domain, const BigInteger &y, const Big
- {
- evp.reset();
- - DSA * dsa = DSA_new();
- + DSA *dsa = DSA_new();
- BIGNUM *bnp = bi2bn(domain.p());
- BIGNUM *bnq = bi2bn(domain.q());
- BIGNUM *bng = bi2bn(domain.g());
- @@ -287,7 +327,7 @@ void DSAKey::createPublic(const DLGroup &domain, const BigInteger &y)
- {
- evp.reset();
- - DSA * dsa = DSA_new();
- + DSA *dsa = DSA_new();
- BIGNUM *bnp = bi2bn(domain.p());
- BIGNUM *bnq = bi2bn(domain.q());
- BIGNUM *bng = bi2bn(domain.g());
- @@ -305,7 +345,7 @@ void DSAKey::createPublic(const DLGroup &domain, const BigInteger &y)
- DLGroup DSAKey::domain() const
- {
- - DSA * dsa = EVP_PKEY_get0_DSA(evp.pkey);
- + const DSA *dsa = EVP_PKEY_get0_DSA(evp.pkey);
- const BIGNUM *bnp, *bnq, *bng;
- DSA_get0_pqg(dsa, &bnp, &bnq, &bng);
- return DLGroup(bn2bi(bnp), bn2bi(bnq), bn2bi(bng));
- @@ -313,7 +353,7 @@ DLGroup DSAKey::domain() const
- BigInteger DSAKey::y() const
- {
- - DSA * dsa = EVP_PKEY_get0_DSA(evp.pkey);
- + const DSA *dsa = EVP_PKEY_get0_DSA(evp.pkey);
- const BIGNUM *bnpub_key;
- DSA_get0_key(dsa, &bnpub_key, nullptr);
- return bn2bi(bnpub_key);
- @@ -321,7 +361,7 @@ BigInteger DSAKey::y() const
- BigInteger DSAKey::x() const
- {
- - DSA * dsa = EVP_PKEY_get0_DSA(evp.pkey);
- + const DSA *dsa = EVP_PKEY_get0_DSA(evp.pkey);
- const BIGNUM *bnpriv_key;
- DSA_get0_key(dsa, nullptr, &bnpriv_key);
- return bn2bi(bnpriv_key);
- diff --git a/plugins/qca-ossl/evpkey.cpp b/plugins/qca-ossl/evpkey.cpp
- index cae1a901..cde5a509 100644
- --- a/plugins/qca-ossl/evpkey.cpp
- +++ b/plugins/qca-ossl/evpkey.cpp
- @@ -111,10 +111,12 @@ SecureArray EVPKey::endSign()
- int type = EVP_PKEY_id(pkey);
- if (type == EVP_PKEY_RSA) {
- - RSA *rsa = EVP_PKEY_get0_RSA(pkey);
- - if (RSA_private_encrypt(
- - raw.size(), (unsigned char *)raw.data(), (unsigned char *)out.data(), rsa, RSA_PKCS1_PADDING) ==
- - -1) {
- + const RSA *rsa = EVP_PKEY_get0_RSA(pkey);
- + if (RSA_private_encrypt(raw.size(),
- + (unsigned char *)raw.data(),
- + (unsigned char *)out.data(),
- + (RSA *)rsa,
- + RSA_PKCS1_PADDING) == -1) {
- state = SignError;
- return SecureArray();
- }
- @@ -148,11 +150,11 @@ bool EVPKey::endVerify(const SecureArray &sig)
- int type = EVP_PKEY_id(pkey);
- if (type == EVP_PKEY_RSA) {
- - RSA *rsa = EVP_PKEY_get0_RSA(pkey);
- + const RSA *rsa = EVP_PKEY_get0_RSA(pkey);
- if ((len = RSA_public_decrypt(sig.size(),
- (unsigned char *)sig.data(),
- (unsigned char *)out.data(),
- - rsa,
- + (RSA *)rsa,
- RSA_PKCS1_PADDING)) == -1) {
- state = VerifyError;
- return false;
- diff --git a/plugins/qca-ossl/qca-ossl.cpp b/plugins/qca-ossl/qca-ossl.cpp
- index 3df47a65..b9602f7f 100644
- --- a/plugins/qca-ossl/qca-ossl.cpp
- +++ b/plugins/qca-ossl/qca-ossl.cpp
- @@ -48,11 +48,15 @@
- #include <memory>
- #include <openssl/err.h>
- +#include <openssl/opensslv.h>
- #include <openssl/pem.h>
- #include <openssl/pkcs12.h>
- #include <openssl/rand.h>
- #include <openssl/ssl.h>
- #include <openssl/x509v3.h>
- +#ifdef OPENSSL_VERSION_MAJOR
- +#include <openssl/provider.h>
- +#endif
- #ifndef LIBRESSL_VERSION_NUMBER
- #include <openssl/kdf.h>
- @@ -447,9 +451,9 @@ public:
- EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, nullptr);
- EVP_PKEY_derive_init(pctx);
- EVP_PKEY_CTX_set_hkdf_md(pctx, EVP_sha256());
- - EVP_PKEY_CTX_set1_hkdf_salt(pctx, salt.data(), int(salt.size()));
- - EVP_PKEY_CTX_set1_hkdf_key(pctx, secret.data(), int(secret.size()));
- - EVP_PKEY_CTX_add1_hkdf_info(pctx, info.data(), int(info.size()));
- + EVP_PKEY_CTX_set1_hkdf_salt(pctx, (const unsigned char *)salt.data(), int(salt.size()));
- + EVP_PKEY_CTX_set1_hkdf_key(pctx, (const unsigned char *)secret.data(), int(secret.size()));
- + EVP_PKEY_CTX_add1_hkdf_info(pctx, (const unsigned char *)info.data(), int(info.size()));
- size_t outlen = out.size();
- EVP_PKEY_derive(pctx, reinterpret_cast<unsigned char *>(out.data()), &outlen);
- EVP_PKEY_CTX_free(pctx);
- diff --git a/plugins/qca-ossl/rsakey.cpp b/plugins/qca-ossl/rsakey.cpp
- index 447e9cdb..a2e26fa7 100644
- --- a/plugins/qca-ossl/rsakey.cpp
- +++ b/plugins/qca-ossl/rsakey.cpp
- @@ -78,8 +78,9 @@ public:
- if (BN_set_word(e.get(), exp) != 1)
- return;
- - if (RSA_generate_key_ex(rsa.get(), bits, e.get(), nullptr) == 0)
- + if (RSA_generate_key_ex(rsa.get(), bits, e.get(), nullptr) == 0) {
- return;
- + }
- result = rsa.release();
- }
- @@ -143,7 +144,7 @@ void RSAKey::convertToPublic()
- return;
- // extract the public key into DER format
- - RSA * rsa_pkey = EVP_PKEY_get0_RSA(evp.pkey);
- + const RSA *rsa_pkey = EVP_PKEY_get0_RSA(evp.pkey);
- int len = i2d_RSAPublicKey(rsa_pkey, nullptr);
- SecureArray result(len);
- unsigned char *p = (unsigned char *)result.data();
- @@ -165,8 +166,8 @@ int RSAKey::bits() const
- int RSAKey::maximumEncryptSize(EncryptionAlgorithm alg) const
- {
- - RSA *rsa = EVP_PKEY_get0_RSA(evp.pkey);
- - int size = 0;
- + const RSA *rsa = EVP_PKEY_get0_RSA(evp.pkey);
- + int size = 0;
- switch (alg) {
- case EME_PKCS1v15:
- size = RSA_size(rsa) - 11 - 1;
- @@ -187,7 +188,7 @@ int RSAKey::maximumEncryptSize(EncryptionAlgorithm alg) const
- SecureArray RSAKey::encrypt(const SecureArray &in, EncryptionAlgorithm alg)
- {
- - RSA * rsa = EVP_PKEY_get0_RSA(evp.pkey);
- + const RSA *rsa = EVP_PKEY_get0_RSA(evp.pkey);
- SecureArray buf = in;
- int max = maximumEncryptSize(alg);
- @@ -203,9 +204,11 @@ SecureArray RSAKey::encrypt(const SecureArray &in, EncryptionAlgorithm alg)
- case EME_PKCS1_OAEP:
- pad = RSA_PKCS1_OAEP_PADDING;
- break;
- +#ifdef RSA_SSLV23_PADDING
- case EME_PKCS1v15_SSL:
- pad = RSA_SSLV23_PADDING;
- break;
- +#endif
- case EME_NO_PADDING:
- pad = RSA_NO_PADDING;
- break;
- @@ -216,9 +219,11 @@ SecureArray RSAKey::encrypt(const SecureArray &in, EncryptionAlgorithm alg)
- int ret;
- if (isPrivate())
- - ret = RSA_private_encrypt(buf.size(), (unsigned char *)buf.data(), (unsigned char *)result.data(), rsa, pad);
- + ret = RSA_private_encrypt(
- + buf.size(), (unsigned char *)buf.data(), (unsigned char *)result.data(), (RSA *)rsa, pad);
- else
- - ret = RSA_public_encrypt(buf.size(), (unsigned char *)buf.data(), (unsigned char *)result.data(), rsa, pad);
- + ret = RSA_public_encrypt(
- + buf.size(), (unsigned char *)buf.data(), (unsigned char *)result.data(), (RSA *)rsa, pad);
- if (ret < 0)
- return SecureArray();
- @@ -229,7 +234,7 @@ SecureArray RSAKey::encrypt(const SecureArray &in, EncryptionAlgorithm alg)
- bool RSAKey::decrypt(const SecureArray &in, SecureArray *out, EncryptionAlgorithm alg)
- {
- - RSA * rsa = EVP_PKEY_get0_RSA(evp.pkey);
- + const RSA *rsa = EVP_PKEY_get0_RSA(evp.pkey);
- SecureArray result(RSA_size(rsa));
- int pad;
- @@ -240,9 +245,11 @@ bool RSAKey::decrypt(const SecureArray &in, SecureArray *out, EncryptionAlgorith
- case EME_PKCS1_OAEP:
- pad = RSA_PKCS1_OAEP_PADDING;
- break;
- +#ifdef RSA_SSLV23_PADDING
- case EME_PKCS1v15_SSL:
- pad = RSA_SSLV23_PADDING;
- break;
- +#endif
- case EME_NO_PADDING:
- pad = RSA_NO_PADDING;
- break;
- @@ -253,9 +260,11 @@ bool RSAKey::decrypt(const SecureArray &in, SecureArray *out, EncryptionAlgorith
- int ret;
- if (isPrivate())
- - ret = RSA_private_decrypt(in.size(), (unsigned char *)in.data(), (unsigned char *)result.data(), rsa, pad);
- + ret =
- + RSA_private_decrypt(in.size(), (unsigned char *)in.data(), (unsigned char *)result.data(), (RSA *)rsa, pad);
- else
- - ret = RSA_public_decrypt(in.size(), (unsigned char *)in.data(), (unsigned char *)result.data(), rsa, pad);
- + ret =
- + RSA_public_decrypt(in.size(), (unsigned char *)in.data(), (unsigned char *)result.data(), (RSA *)rsa, pad);
- if (ret < 0)
- return false;
- @@ -396,7 +405,7 @@ void RSAKey::createPublic(const BigInteger &n, const BigInteger &e)
- BigInteger RSAKey::n() const
- {
- - RSA * rsa = EVP_PKEY_get0_RSA(evp.pkey);
- + const RSA *rsa = EVP_PKEY_get0_RSA(evp.pkey);
- const BIGNUM *bnn;
- RSA_get0_key(rsa, &bnn, nullptr, nullptr);
- return bn2bi(bnn);
- @@ -404,7 +413,7 @@ BigInteger RSAKey::n() const
- BigInteger RSAKey::e() const
- {
- - RSA * rsa = EVP_PKEY_get0_RSA(evp.pkey);
- + const RSA *rsa = EVP_PKEY_get0_RSA(evp.pkey);
- const BIGNUM *bne;
- RSA_get0_key(rsa, nullptr, &bne, nullptr);
- return bn2bi(bne);
- @@ -412,7 +421,7 @@ BigInteger RSAKey::e() const
- BigInteger RSAKey::p() const
- {
- - RSA * rsa = EVP_PKEY_get0_RSA(evp.pkey);
- + const RSA *rsa = EVP_PKEY_get0_RSA(evp.pkey);
- const BIGNUM *bnp;
- RSA_get0_factors(rsa, &bnp, nullptr);
- return bn2bi(bnp);
- @@ -420,7 +429,7 @@ BigInteger RSAKey::p() const
- BigInteger RSAKey::q() const
- {
- - RSA * rsa = EVP_PKEY_get0_RSA(evp.pkey);
- + const RSA *rsa = EVP_PKEY_get0_RSA(evp.pkey);
- const BIGNUM *bnq;
- RSA_get0_factors(rsa, nullptr, &bnq);
- return bn2bi(bnq);
- @@ -428,7 +437,7 @@ BigInteger RSAKey::q() const
- BigInteger RSAKey::d() const
- {
- - RSA * rsa = EVP_PKEY_get0_RSA(evp.pkey);
- + const RSA *rsa = EVP_PKEY_get0_RSA(evp.pkey);
- const BIGNUM *bnd;
- RSA_get0_key(rsa, nullptr, nullptr, &bnd);
- return bn2bi(bnd);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement