Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fedora33 compilation #289

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/crypto/include/scy/crypto/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 11 additions & 14 deletions src/crypto/src/hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,44 +20,41 @@ 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();

_md = EVP_get_digestbyname(algorithm.data());
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));
}


Expand All @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions src/crypto/src/x509certificate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "scy/crypto/x509certificate.h"
#include <sstream>
#include <openssl/opensslv.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/pem.h>
Expand Down Expand Up @@ -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();
}

Expand Down