Author: Adam Majer Summary: Add OpenSSL 1.1 support. PR: https://github.com/isc-projects/kea/pull/34 --- a/src/lib/cryptolink/openssl_hash.cc +++ b/src/lib/cryptolink/openssl_hash.cc @@ -5,11 +5,11 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. #include #include -#include +#include #include #include @@ -60,24 +60,17 @@ public: isc_throw(isc::cryptolink::UnsupportedAlgorithm, "Unknown hash algorithm: " << static_cast(hash_algorithm)); } - md_.reset(new EVP_MD_CTX); + md_.reset(EVP_MD_CTX_new()); EVP_MD_CTX_init(md_.get()); EVP_DigestInit_ex(md_.get(), algo, NULL); } - /// @brief Destructor - ~HashImpl() { - if (md_) { - EVP_MD_CTX_cleanup(md_.get()); - } - } - /// @brief Returns the output size of the digest /// /// @return output size of the digest size_t getOutputLength() const { return (EVP_MD_CTX_size(md_.get())); @@ -128,12 +121,25 @@ public: } return (std::vector(digest.begin(), digest.end())); } private: + class EvpDeleter { + public: + void operator()(EVP_MD_CTX *ptr) {EVP_MD_CTX_free(ptr);} + }; + +#if OPENSSL_VERSION_NUMBER < 0x10100000L + static EVP_MD_CTX* EVP_MD_CTX_new() { return new EVP_MD_CTX; } + static void EVP_MD_CTX_free(EVP_MD_CTX *ptr) { + EVP_MD_CTX_cleanup(ptr); + delete ptr; + } +#endif + /// @brief The protected pointer to the OpenSSL EVP_MD_CTX structure - boost::scoped_ptr md_; + boost::movelib::unique_ptr md_; }; Hash::Hash(const HashAlgorithm hash_algorithm) { impl_ = new HashImpl(hash_algorithm); --- a/src/lib/cryptolink/openssl_hmac.cc +++ b/src/lib/cryptolink/openssl_hmac.cc @@ -5,11 +5,11 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. #include #include -#include +#include #include #include @@ -39,25 +39,16 @@ public: } if (secret_len == 0) { isc_throw(BadKey, "Bad HMAC secret length: 0"); } - md_.reset(new HMAC_CTX); - HMAC_CTX_init(md_.get()); - + md_.reset(HMAC_CTX_new()); HMAC_Init_ex(md_.get(), secret, static_cast(secret_len), algo, NULL); } - /// @brief Destructor - ~HMACImpl() { - if (md_) { - HMAC_CTX_cleanup(md_.get()); - } - } - /// @brief Returns the output size of the digest /// /// @return output size of the digest size_t getOutputLength() const { int size = HMAC_size(md_.get()); @@ -128,13 +119,29 @@ public: } return (digest.same(sig, len)); } private: + class HMAC_Deleter { + public: + void operator()(HMAC_CTX *ptr) { HMAC_CTX_free(ptr); } + }; + +#if OPENSSL_VERSION_NUMBER < 0x10100000L + static HMAC_CTX* HMAC_CTX_new() { + HMAC_CTX *ptr = new HMAC_CTX; + HMAC_CTX_init(ptr); + return ptr; + } + static void HMAC_CTX_free(HMAC_CTX *ptr) { + HMAC_CTX_cleanup(ptr); + delete ptr; + } +#endif /// @brief The protected pointer to the OpenSSL HMAC_CTX structure - boost::scoped_ptr md_; + boost::movelib::unique_ptr md_; }; HMAC::HMAC(const void* secret, size_t secret_length, const HashAlgorithm hash_algorithm) {