kea/kea-openssl-1.1.patch

146 lines
3.7 KiB
Diff
Raw Normal View History

2017-04-04 19:34:22 +00:00
Author: Adam Majer <adamm@zombino.com>
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 <cryptolink.h>
#include <cryptolink/crypto_hash.h>
-#include <boost/scoped_ptr.hpp>
+#include <boost/move/unique_ptr.hpp>
#include <openssl/evp.h>
#include <cryptolink/openssl_common.h>
@@ -60,24 +60,17 @@ public:
isc_throw(isc::cryptolink::UnsupportedAlgorithm,
"Unknown hash algorithm: " <<
static_cast<int>(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<uint8_t>(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<EVP_MD_CTX> md_;
+ boost::movelib::unique_ptr<EVP_MD_CTX, EvpDeleter> 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 <cryptolink.h>
#include <cryptolink/crypto_hmac.h>
-#include <boost/scoped_ptr.hpp>
+#include <boost/move/unique_ptr.hpp>
#include <openssl/hmac.h>
#include <cryptolink/openssl_common.h>
@@ -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<int>(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<HMAC_CTX> md_;
+ boost::movelib::unique_ptr<HMAC_CTX, HMAC_Deleter> md_;
};
HMAC::HMAC(const void* secret, size_t secret_length,
const HashAlgorithm hash_algorithm)
{