Fixed compilation for older (pre-3.0.0) OpenSSL versions

This commit is contained in:
Vasily Nemkov 2020-08-31 18:06:33 +03:00
parent 7cc4118dab
commit bdaa012239
2 changed files with 19 additions and 2 deletions

View File

@ -7,6 +7,18 @@
#include <string>
namespace
{
void CipherDeleter(const EVP_CIPHER * cipher [[maybe_unused]])
{
#if OPENSSL_VERSION_NUMBER >= 0x03 << 28
// Used to free EVP_CIPHER poniter obtained with EVP_CIPHER_fetch,
// available only since OpenSSL ver 3.0.0.
EVP_CIPHER_free(const_cast<EVP_CIPHER*>(cipher));
#endif
}
}
namespace DB
{
namespace ErrorCodes
@ -49,10 +61,14 @@ CipherPtr getCipherByName(const StringRef & cipher_name)
evp_cipher = EVP_aes_256_cfb128();
}
#if OPENSSL_VERSION_NUMBER < 0x03 << 28
return CipherPtr{evp_cipher, CipherDeleter};
#else
// HACK: To speed up context initialization with EVP_EncryptInit_ex (which is called at least once per row)
// Apparently cipher from EVP_get_cipherbyname may require additional initialization of context,
// while cipher from EVP_CIPHER_fetch causes less operations => faster context initialization.
return CipherPtr{EVP_CIPHER_fetch(nullptr, EVP_CIPHER_name(evp_cipher), nullptr), &EVP_CIPHER_free};
return CipherPtr{EVP_CIPHER_fetch(nullptr, EVP_CIPHER_name(evp_cipher), nullptr), &CipherDeleter};
#endif
}
}

View File

@ -36,7 +36,8 @@ namespace OpenSSLDetails
[[noreturn]] void onError(std::string error_message);
StringRef foldEncryptionKeyInMySQLCompatitableMode(size_t cipher_key_size, const StringRef & key, std::array<char, EVP_MAX_KEY_LENGTH> & folded_key);
using CipherPtr = std::unique_ptr<EVP_CIPHER, decltype(&::EVP_CIPHER_free)>;
using CipherDeleterType = void (*) (const EVP_CIPHER *cipher);
using CipherPtr = std::unique_ptr<const EVP_CIPHER, CipherDeleterType>;
CipherPtr getCipherByName(const StringRef & name);
enum class CompatibilityMode