diff options
author | Shauren <shauren.trinity@gmail.com> | 2022-09-06 12:51:08 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2024-02-26 12:17:31 +0100 |
commit | 7ff70a6bff86d641c51da46285ff69ca3361cff3 (patch) | |
tree | 109f87a5242dc090a590277d27f835f41a1d10cd | |
parent | 182cf7bc0e9af9785a43890bc3edbe39a9b6021d (diff) |
Core/Crypto: Remove support for OpenSSL 1.0
(cherry picked from commit b8f18fad29df98d5e8dee1ba28cd5f01fbdf9832)
-rw-r--r-- | dep/openssl/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/common/Cryptography/BigNumber.cpp | 32 | ||||
-rw-r--r-- | src/common/Cryptography/CryptoHash.h | 5 | ||||
-rw-r--r-- | src/common/Cryptography/OpenSSLCrypto.cpp | 48 |
4 files changed, 5 insertions, 84 deletions
diff --git a/dep/openssl/CMakeLists.txt b/dep/openssl/CMakeLists.txt index c76fa03dd3f..1282fd32f38 100644 --- a/dep/openssl/CMakeLists.txt +++ b/dep/openssl/CMakeLists.txt @@ -11,9 +11,7 @@ # basic packagesearching and setup # (further support will be needed, this is a preliminary release!) -set(OPENSSL_EXPECTED_VERSION 1.0.0) - -find_package(OpenSSL REQUIRED COMPONENTS Crypto SSL) +find_package(OpenSSL 1.1 REQUIRED COMPONENTS Crypto SSL) add_library(openssl INTERFACE) diff --git a/src/common/Cryptography/BigNumber.cpp b/src/common/Cryptography/BigNumber.cpp index 35bfc91224d..da54cfcb37a 100644 --- a/src/common/Cryptography/BigNumber.cpp +++ b/src/common/Cryptography/BigNumber.cpp @@ -57,20 +57,7 @@ void BigNumber::SetQword(uint64 val) void BigNumber::SetBinary(uint8 const* bytes, int32 len, bool littleEndian) { if (littleEndian) - { -#if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x10100000L - uint8* array = new uint8[len]; - - for (int i = 0; i < len; i++) - array[i] = bytes[len - 1 - i]; - - BN_bin2bn(array, len, _bn); - - delete[] array; -#else BN_lebin2bn(bytes, len, _bn); -#endif - } else BN_bin2bn(bytes, len, _bn); } @@ -197,27 +184,8 @@ bool BigNumber::IsNegative() const void BigNumber::GetBytes(uint8* buf, size_t bufsize, bool littleEndian) const { -#if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x10100000L - int nBytes = GetNumBytes(); - ASSERT(nBytes >= 0, "Bignum has negative number of bytes (%d).", nBytes); - std::size_t numBytes = static_cast<std::size_t>(nBytes); - - // too large to store - ASSERT(numBytes <= bufsize, "Buffer of size %zu is too small to hold bignum with %zu bytes.\n", bufsize, numBytes); - - // If we need more bytes than length of BigNumber set the rest to 0 - if (numBytes < bufsize) - memset((void*)buf, 0, bufsize); - - BN_bn2bin(_bn, buf + (bufsize - numBytes)); - - // openssl's BN stores data internally in big endian format, reverse if little endian desired - if (littleEndian) - std::reverse(buf, buf + bufsize); -#else int res = littleEndian ? BN_bn2lebinpad(_bn, buf, bufsize) : BN_bn2binpad(_bn, buf, bufsize); ASSERT(res > 0, "Buffer of size %zu is too small to hold bignum with %d bytes.\n", bufsize, BN_num_bytes(_bn)); -#endif } std::vector<uint8> BigNumber::ToByteVector(int32 minSize, bool littleEndian) const diff --git a/src/common/Cryptography/CryptoHash.h b/src/common/Cryptography/CryptoHash.h index 49d421c7fb1..19bb776438c 100644 --- a/src/common/Cryptography/CryptoHash.h +++ b/src/common/Cryptography/CryptoHash.h @@ -35,13 +35,8 @@ namespace Trinity::Impl { typedef EVP_MD const* (*HashCreator)(); -#if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x10100000L - static EVP_MD_CTX* MakeCTX() noexcept { return EVP_MD_CTX_create(); } - static void DestroyCTX(EVP_MD_CTX* ctx) { EVP_MD_CTX_destroy(ctx); } -#else static EVP_MD_CTX* MakeCTX() noexcept { return EVP_MD_CTX_new(); } static void DestroyCTX(EVP_MD_CTX* ctx) { EVP_MD_CTX_free(ctx); } -#endif }; template <GenericHashImpl::HashCreator HashCreator, size_t DigestLength> diff --git a/src/common/Cryptography/OpenSSLCrypto.cpp b/src/common/Cryptography/OpenSSLCrypto.cpp index 4b82263c060..e6224d13841 100644 --- a/src/common/Cryptography/OpenSSLCrypto.cpp +++ b/src/common/Cryptography/OpenSSLCrypto.cpp @@ -15,30 +15,10 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include <OpenSSLCrypto.h> +#include "OpenSSLCrypto.h" #include <openssl/crypto.h> -#if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x1010000fL -#include <vector> -#include <thread> -#include <mutex> - -std::vector<std::mutex*> cryptoLocks; - -static void lockingCallback(int mode, int type, char const* /*file*/, int /*line*/) -{ - if (mode & CRYPTO_LOCK) - cryptoLocks[type]->lock(); - else - cryptoLocks[type]->unlock(); -} - -static void threadIdCallback(CRYPTO_THREADID * id) -{ - (void)id; - CRYPTO_THREADID_set_numeric(id, std::hash<std::thread::id>()(std::this_thread::get_id())); -} -#elif OPENSSL_VERSION_NUMBER >= 0x30000000L +#if OPENSSL_VERSION_NUMBER >= 0x30000000L #include <openssl/provider.h> OSSL_PROVIDER* LegacyProvider; OSSL_PROVIDER* DefaultProvider; @@ -46,19 +26,7 @@ OSSL_PROVIDER* DefaultProvider; void OpenSSLCrypto::threadsSetup([[maybe_unused]] boost::filesystem::path const& providerModulePath) { -#if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x1010000fL - cryptoLocks.resize(CRYPTO_num_locks()); - for(int i = 0 ; i < CRYPTO_num_locks(); ++i) - { - cryptoLocks[i] = new std::mutex(); - } - - (void)&threadIdCallback; - CRYPTO_THREADID_set_callback(threadIdCallback); - - (void)&lockingCallback; - CRYPTO_set_locking_callback(lockingCallback); -#elif OPENSSL_VERSION_NUMBER >= 0x30000000L +#if OPENSSL_VERSION_NUMBER >= 0x30000000L #if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS OSSL_PROVIDER_set_default_search_path(nullptr, providerModulePath.string().c_str()); #endif @@ -69,15 +37,7 @@ void OpenSSLCrypto::threadsSetup([[maybe_unused]] boost::filesystem::path const& void OpenSSLCrypto::threadsCleanup() { -#if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x1010000fL - CRYPTO_set_locking_callback(nullptr); - CRYPTO_THREADID_set_callback(nullptr); - for(int i = 0 ; i < CRYPTO_num_locks(); ++i) - { - delete cryptoLocks[i]; - } - cryptoLocks.resize(0); -#elif OPENSSL_VERSION_NUMBER >= 0x30000000L +#if OPENSSL_VERSION_NUMBER >= 0x30000000L OSSL_PROVIDER_unload(LegacyProvider); OSSL_PROVIDER_unload(DefaultProvider); OSSL_PROVIDER_set_default_search_path(nullptr, nullptr); |