From dd5ef21473d490f2ee4a9f251aecd014e95da0ba Mon Sep 17 00:00:00 2001 From: "max.moreau" Date: Sun, 29 Nov 2020 20:32:06 +0100 Subject: [PATCH] Fix fedora33 compiration use of opaque EVP_MD_CTX Add macro switch for openssl version --- src/crypto/include/scy/crypto/hash.h | 2 +- src/crypto/src/hash.cpp | 25 +++++++++++-------------- src/crypto/src/x509certificate.cpp | 10 +++++++--- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/crypto/include/scy/crypto/hash.h b/src/crypto/include/scy/crypto/hash.h index a93fdde9c..80873bc37 100644 --- a/src/crypto/include/scy/crypto/hash.h +++ b/src/crypto/include/scy/crypto/hash.h @@ -53,7 +53,7 @@ class Crypto_API Hash protected: Hash& operator=(Hash const&); - EVP_MD_CTX _ctx; + EVP_MD_CTX* _ctx; const EVP_MD* _md; crypto::ByteVec _digest; std::string _algorithm; diff --git a/src/crypto/src/hash.cpp b/src/crypto/src/hash.cpp index 1a0fad345..ccbae6ea9 100644 --- a/src/crypto/src/hash.cpp +++ b/src/crypto/src/hash.cpp @@ -20,11 +20,12 @@ using std::endl; namespace scy { namespace crypto { - - + Hash::Hash(const std::string& algorithm) - : _algorithm(algorithm) - //, _ctx(EVP_MD_CTX_new()) + : _ctx(EVP_MD_CTX_new()) + , _md(nullptr) + , _digest() + , _algorithm(algorithm) { crypto::initializeEngine(); @@ -32,32 +33,28 @@ Hash::Hash(const std::string& algorithm) if (!_md) throw std::runtime_error("Algorithm not supported: " + algorithm); - EVP_DigestInit(&_ctx, _md); + EVP_DigestInit(_ctx, _md); } Hash::~Hash() { crypto::uninitializeEngine(); - - EVP_MD_CTX_cleanup(&_ctx); - //EVP_MD_CTX_free(_ctx); + EVP_MD_CTX_free(_ctx); } void Hash::reset() { - //EVP_MD_CTX_free(_ctx); - //_ctx = EVP_MD_CTX_new(); - internal::api(EVP_MD_CTX_cleanup(&_ctx)); - internal::api(EVP_DigestInit(&_ctx, _md)); + internal::api(EVP_MD_CTX_reset(_ctx)); + internal::api(EVP_DigestInit(_ctx, _md)); _digest.clear(); } void Hash::update(const void* data, size_t length) { - internal::api(EVP_DigestUpdate(&_ctx, data, length)); + internal::api(EVP_DigestUpdate(_ctx, data, length)); } @@ -79,7 +76,7 @@ const ByteVec& Hash::digest() if (_digest.size() == 0) { _digest.resize(EVP_MAX_MD_SIZE); // TODO: Get actual algorithm size unsigned int len = 0; - internal::api(EVP_DigestFinal(&_ctx, &_digest[0], &len)); + internal::api(EVP_DigestFinal(_ctx, &_digest[0], &len)); _digest.resize(len); } return _digest; diff --git a/src/crypto/src/x509certificate.cpp b/src/crypto/src/x509certificate.cpp index 76f5e799b..ba87a400b 100644 --- a/src/crypto/src/x509certificate.cpp +++ b/src/crypto/src/x509certificate.cpp @@ -11,6 +11,7 @@ #include "scy/crypto/x509certificate.h" #include +#include #include #include #include @@ -58,10 +59,13 @@ X509Certificate::X509Certificate(X509* pCert, bool shared) { assert(_certificate); - if (shared) + if (shared){ +#if OPENSSL_VERSION_NUMBER >= 0x1010000fL + X509_up_ref(_certificate); +#else _certificate->references++; - // X509_up_ref(_certificate); // OpenSSL >= 1.1.0 - +#endif + } init(); }