Blame SOURCES/0002-Remove-OpenSSL-1.0.2-features.patch

6261c9
From 356ece933457ff7216658236ec5cf05f906e8f69 Mon Sep 17 00:00:00 2001
6261c9
From: Your Name <you@example.com>
6261c9
Date: Fri, 14 Sep 2018 13:39:05 +0000
6261c9
Subject: [PATCH 2/2] Remove OpenSSL 1.0.2 features
6261c9
6261c9
---
6261c9
 src/node_crypto.cc                         | 150 ++++++++++++++++++++---------
6261c9
 src/node_crypto.h                          |  28 ++++--
6261c9
 test/parallel/test-crypto-authenticated.js |   6 +-
6261c9
 3 files changed, 128 insertions(+), 56 deletions(-)
6261c9
6261c9
diff --git a/src/node_crypto.cc b/src/node_crypto.cc
6261c9
index 7bdb1b1..6111e2e 100644
6261c9
--- a/src/node_crypto.cc
6261c9
+++ b/src/node_crypto.cc
6261c9
@@ -1077,8 +1077,8 @@ void SecureContext::SetECDHCurve(const FunctionCallbackInfo<Value>& args) {
6261c9
   node::Utf8Value curve(env->isolate(), args[0]);
6261c9
 
6261c9
 #if OPENSSL_VERSION_NUMBER < 0x10100000L
6261c9
-  SSL_CTX_set_options(sc->ctx_, SSL_OP_SINGLE_ECDH_USE);
6261c9
-  SSL_CTX_set_ecdh_auto(sc->ctx_, 1);
6261c9
+  SSL_CTX_set_options(sc->ctx_.get(), SSL_OP_SINGLE_ECDH_USE);
6261c9
+  SSL_CTX_set_ecdh_auto(sc->ctx_.get(), 1);
6261c9
 #endif
6261c9
 
6261c9
   if (strcmp(*curve, "auto") == 0)
6261c9
@@ -1340,7 +1340,7 @@ void SecureContext::GetTicketKeys(const FunctionCallbackInfo<Value>& args) {
6261c9
   memcpy(Buffer::Data(buff) + 16, wrap->ticket_key_hmac_, 16);
6261c9
   memcpy(Buffer::Data(buff) + 32, wrap->ticket_key_aes_, 16);
6261c9
 #else
6261c9
-  if (SSL_CTX_get_tlsext_ticket_keys(wrap->ctx_,
6261c9
+  if (SSL_CTX_get_tlsext_ticket_keys(wrap->ctx_.get(),
6261c9
                                      Buffer::Data(buff),
6261c9
                                      Buffer::Length(buff)) != 1) {
6261c9
     return wrap->env()->ThrowError("Failed to fetch tls ticket keys");
6261c9
@@ -1374,7 +1374,7 @@ void SecureContext::SetTicketKeys(const FunctionCallbackInfo<Value>& args) {
6261c9
   memcpy(wrap->ticket_key_hmac_, Buffer::Data(args[0]) + 16, 16);
6261c9
   memcpy(wrap->ticket_key_aes_, Buffer::Data(args[0]) + 32, 16);
6261c9
 #else
6261c9
-  if (SSL_CTX_set_tlsext_ticket_keys(wrap->ctx_,
6261c9
+  if (SSL_CTX_set_tlsext_ticket_keys(wrap->ctx_.get(),
6261c9
                                      Buffer::Data(args[0]),
6261c9
                                      Buffer::Length(args[0])) != 1) {
6261c9
     return env->ThrowError("Failed to fetch tls ticket keys");
6261c9
@@ -2804,14 +2804,14 @@ void CipherBase::Init(const char* cipher_type,
6261c9
                                iv);
6261c9
   CHECK_NE(key_len, 0);
6261c9
 
6261c9
-  ctx_.reset(EVP_CIPHER_CTX_new());
6261c9
+  ctx_ = EVP_CIPHER_CTX_new();
6261c9
 
6261c9
   const int mode = EVP_CIPHER_mode(cipher);
6261c9
   if (mode == EVP_CIPH_WRAP_MODE)
6261c9
-    EVP_CIPHER_CTX_set_flags(ctx_.get(), EVP_CIPHER_CTX_FLAG_WRAP_ALLOW);
6261c9
+    EVP_CIPHER_CTX_set_flags(ctx_, EVP_CIPHER_CTX_FLAG_WRAP_ALLOW);
6261c9
 
6261c9
   const bool encrypt = (kind_ == kCipher);
6261c9
-  if (1 != EVP_CipherInit_ex(ctx_.get(), cipher, nullptr,
6261c9
+  if (1 != EVP_CipherInit_ex(ctx_, cipher, nullptr,
6261c9
                              nullptr, nullptr, encrypt)) {
6261c9
     return ThrowCryptoError(env(), ERR_get_error(),
6261c9
                             "Failed to initialize cipher");
6261c9
@@ -2832,9 +2832,9 @@ void CipherBase::Init(const char* cipher_type,
6261c9
       return;
6261c9
   }
6261c9
 
6261c9
-  CHECK_EQ(1, EVP_CIPHER_CTX_set_key_length(ctx_.get(), key_len));
6261c9
+  CHECK_EQ(1, EVP_CIPHER_CTX_set_key_length(ctx_, key_len));
6261c9
 
6261c9
-  if (1 != EVP_CipherInit_ex(ctx_.get(),
6261c9
+  if (1 != EVP_CipherInit_ex(ctx_,
6261c9
                              nullptr,
6261c9
                              nullptr,
6261c9
                              reinterpret_cast<unsigned char*>(key),
6261c9
@@ -2871,8 +2871,8 @@ void CipherBase::Init(const FunctionCallbackInfo<Value>& args) {
6261c9
 
6261c9
 static bool IsSupportedAuthenticatedMode(int mode) {
6261c9
   return mode == EVP_CIPH_CCM_MODE ||
6261c9
-         mode == EVP_CIPH_GCM_MODE ||
6261c9
-         mode == EVP_CIPH_OCB_MODE;
6261c9
+         mode == EVP_CIPH_GCM_MODE;
6261c9
+         // mode == EVP_CIPH_OCB_MODE;
6261c9
 }
6261c9
 
6261c9
 void CipherBase::InitIv(const char* cipher_type,
6261c9
@@ -2906,13 +2906,13 @@ void CipherBase::InitIv(const char* cipher_type,
6261c9
     return env()->ThrowError("Invalid IV length");
6261c9
   }
6261c9
 
6261c9
-  ctx_.reset(EVP_CIPHER_CTX_new());
6261c9
+  ctx_ = EVP_CIPHER_CTX_new();
6261c9
 
6261c9
   if (mode == EVP_CIPH_WRAP_MODE)
6261c9
-    EVP_CIPHER_CTX_set_flags(ctx_.get(), EVP_CIPHER_CTX_FLAG_WRAP_ALLOW);
6261c9
+    EVP_CIPHER_CTX_set_flags(ctx_, EVP_CIPHER_CTX_FLAG_WRAP_ALLOW);
6261c9
 
6261c9
   const bool encrypt = (kind_ == kCipher);
6261c9
-  if (1 != EVP_CipherInit_ex(ctx_.get(), cipher, nullptr,
6261c9
+  if (1 != EVP_CipherInit_ex(ctx_, cipher, nullptr,
6261c9
                              nullptr, nullptr, encrypt)) {
6261c9
     return ThrowCryptoError(env(), ERR_get_error(),
6261c9
                             "Failed to initialize cipher");
6261c9
@@ -2924,12 +2924,13 @@ void CipherBase::InitIv(const char* cipher_type,
6261c9
       return;
6261c9
   }
6261c9
 
6261c9
-  if (!EVP_CIPHER_CTX_set_key_length(ctx_.get(), key_len)) {
6261c9
-    ctx_.reset();
6261c9
+  if (!EVP_CIPHER_CTX_set_key_length(ctx_, key_len)) {
6261c9
+    EVP_CIPHER_CTX_free(ctx_);
6261c9
+    ctx_ = nullptr;
6261c9
     return env()->ThrowError("Invalid key length");
6261c9
   }
6261c9
 
6261c9
-  if (1 != EVP_CipherInit_ex(ctx_.get(),
6261c9
+  if (1 != EVP_CipherInit_ex(ctx_,
6261c9
                              nullptr,
6261c9
                              nullptr,
6261c9
                              reinterpret_cast<const unsigned char*>(key),
6261c9
@@ -2992,8 +2993,8 @@ bool CipherBase::InitAuthenticated(const char* cipher_type, int iv_len,
6261c9
     return false;
6261c9
   }
6261c9
 
6261c9
-  const int mode = EVP_CIPHER_CTX_mode(ctx_.get());
6261c9
-  if (mode == EVP_CIPH_CCM_MODE || mode == EVP_CIPH_OCB_MODE) {
6261c9
+  const int mode = EVP_CIPHER_CTX_mode(ctx_);
6261c9
+  if (mode == EVP_CIPH_CCM_MODE) {
6261c9
     if (auth_tag_len == kNoAuthTagLength) {
6261c9
       char msg[128];
6261c9
       snprintf(msg, sizeof(msg), "authTagLength required for %s", cipher_type);
6261c9
@@ -3010,7 +3011,8 @@ bool CipherBase::InitAuthenticated(const char* cipher_type, int iv_len,
6261c9
 #endif
6261c9
 
6261c9
     // Tell OpenSSL about the desired length.
6261c9
-    if (!EVP_CIPHER_CTX_ctrl(ctx_.get(), EVP_CTRL_AEAD_SET_TAG, auth_tag_len,
6261c9
+     if (!EVP_CIPHER_CTX_ctrl(ctx_, EVP_CTRL_CCM_SET_TAG, auth_tag_len,
6261c9
+    // if (!EVP_CIPHER_CTX_ctrl(ctx_, EVP_CTRL_AEAD_SET_TAG, auth_tag_len,
6261c9
                              nullptr)) {
6261c9
       env()->ThrowError("Invalid authentication tag length");
6261c9
       return false;
6261c9
@@ -3049,7 +3051,7 @@ bool CipherBase::InitAuthenticated(const char* cipher_type, int iv_len,
6261c9
 
6261c9
 bool CipherBase::CheckCCMMessageLength(int message_len) {
6261c9
   CHECK(ctx_);
6261c9
-  CHECK(EVP_CIPHER_CTX_mode(ctx_.get()) == EVP_CIPH_CCM_MODE);
6261c9
+  CHECK(EVP_CIPHER_CTX_mode(ctx_) == EVP_CIPH_CCM_MODE);
6261c9
 
6261c9
   if (message_len > max_message_size_) {
6261c9
     env()->ThrowError("Message exceeds maximum size");
6261c9
@@ -3063,7 +3065,7 @@ bool CipherBase::CheckCCMMessageLength(int message_len) {
6261c9
 bool CipherBase::IsAuthenticatedMode() const {
6261c9
   // Check if this cipher operates in an AEAD mode that we support.
6261c9
   CHECK(ctx_);
6261c9
-  const int mode = EVP_CIPHER_CTX_mode(ctx_.get());
6261c9
+  const int mode = EVP_CIPHER_CTX_mode(ctx_);
6261c9
   return IsSupportedAuthenticatedMode(mode);
6261c9
 }
6261c9
 
6261c9
@@ -3098,7 +3100,7 @@ void CipherBase::SetAuthTag(const FunctionCallbackInfo<Value>& args) {
6261c9
   }
6261c9
 
6261c9
   unsigned int tag_len = Buffer::Length(args[0]);
6261c9
-  const int mode = EVP_CIPHER_CTX_mode(cipher->ctx_.get());
6261c9
+  const int mode = EVP_CIPHER_CTX_mode(cipher->ctx_);
6261c9
   if (mode == EVP_CIPH_GCM_MODE) {
6261c9
     if (cipher->auth_tag_len_ != kNoAuthTagLength &&
6261c9
         cipher->auth_tag_len_ != tag_len) {
6261c9
@@ -3114,6 +3116,7 @@ void CipherBase::SetAuthTag(const FunctionCallbackInfo<Value>& args) {
6261c9
           "Valid GCM tag lengths are 4, 8, 12, 13, 14, 15, 16.", tag_len);
6261c9
       ProcessEmitDeprecationWarning(cipher->env(), msg, "DEP0090");
6261c9
     }
6261c9
+/*
6261c9
   } else if (mode == EVP_CIPH_OCB_MODE) {
6261c9
     // At this point, the tag length is already known and must match the
6261c9
     // length of the given authentication tag.
6261c9
@@ -3125,6 +3128,7 @@ void CipherBase::SetAuthTag(const FunctionCallbackInfo<Value>& args) {
6261c9
           "Invalid authentication tag length: %u", tag_len);
6261c9
       return cipher->env()->ThrowError(msg);
6261c9
     }
6261c9
+*/
6261c9
   }
6261c9
 
6261c9
   // Note: we don't use std::min() here to work around a header conflict.
6261c9
@@ -3141,8 +3145,8 @@ void CipherBase::SetAuthTag(const FunctionCallbackInfo<Value>& args) {
6261c9
 
6261c9
 bool CipherBase::MaybePassAuthTagToOpenSSL() {
6261c9
   if (!auth_tag_set_ && auth_tag_len_ != kNoAuthTagLength) {
6261c9
-    if (!EVP_CIPHER_CTX_ctrl(ctx_.get(),
6261c9
-                             EVP_CTRL_AEAD_SET_TAG,
6261c9
+    if (!EVP_CIPHER_CTX_ctrl(ctx_,
6261c9
+                             EVP_CTRL_CCM_SET_TAG,
6261c9
                              auth_tag_len_,
6261c9
                              reinterpret_cast<unsigned char*>(auth_tag_))) {
6261c9
       return false;
6261c9
@@ -3159,7 +3163,7 @@ bool CipherBase::SetAAD(const char* data, unsigned int len, int plaintext_len) {
6261c9
   MarkPopErrorOnReturn mark_pop_error_on_return;
6261c9
 
6261c9
   int outlen;
6261c9
-  const int mode = EVP_CIPHER_CTX_mode(ctx_.get());
6261c9
+  const int mode = EVP_CIPHER_CTX_mode(ctx_);
6261c9
 
6261c9
   // When in CCM mode, we need to set the authentication tag and the plaintext
6261c9
   // length in advance.
6261c9
@@ -3178,11 +3182,11 @@ bool CipherBase::SetAAD(const char* data, unsigned int len, int plaintext_len) {
6261c9
     }
6261c9
 
6261c9
     // Specify the plaintext length.
6261c9
-    if (!EVP_CipherUpdate(ctx_.get(), nullptr, &outlen, nullptr, plaintext_len))
6261c9
+    if (!EVP_CipherUpdate(ctx_, nullptr, &outlen, nullptr, plaintext_len))
6261c9
       return false;
6261c9
   }
6261c9
 
6261c9
-  return 1 == EVP_CipherUpdate(ctx_.get(),
6261c9
+  return 1 == EVP_CipherUpdate(ctx_,
6261c9
                                nullptr,
6261c9
                                &outlen,
6261c9
                                reinterpret_cast<const unsigned char*>(data),
6261c9
@@ -3212,7 +3216,7 @@ CipherBase::UpdateResult CipherBase::Update(const char* data,
6261c9
     return kErrorState;
6261c9
   MarkPopErrorOnReturn mark_pop_error_on_return;
6261c9
 
6261c9
-  const int mode = EVP_CIPHER_CTX_mode(ctx_.get());
6261c9
+  const int mode = EVP_CIPHER_CTX_mode(ctx_);
6261c9
 
6261c9
   if (mode == EVP_CIPH_CCM_MODE) {
6261c9
     if (!CheckCCMMessageLength(len))
6261c9
@@ -3226,11 +3230,11 @@ CipherBase::UpdateResult CipherBase::Update(const char* data,
6261c9
   }
6261c9
 
6261c9
   *out_len = 0;
6261c9
-  int buff_len = len + EVP_CIPHER_CTX_block_size(ctx_.get());
6261c9
+  int buff_len = len + EVP_CIPHER_CTX_block_size(ctx_);
6261c9
   // For key wrapping algorithms, get output size by calling
6261c9
   // EVP_CipherUpdate() with null output.
6261c9
   if (kind_ == kCipher && mode == EVP_CIPH_WRAP_MODE &&
6261c9
-      EVP_CipherUpdate(ctx_.get(),
6261c9
+      EVP_CipherUpdate(ctx_,
6261c9
                        nullptr,
6261c9
                        &buff_len,
6261c9
                        reinterpret_cast<const unsigned char*>(data),
6261c9
@@ -3239,7 +3243,7 @@ CipherBase::UpdateResult CipherBase::Update(const char* data,
6261c9
   }
6261c9
 
6261c9
   *out = Malloc<unsigned char>(buff_len);
6261c9
-  int r = EVP_CipherUpdate(ctx_.get(),
6261c9
+  int r = EVP_CipherUpdate(ctx_,
6261c9
                            *out,
6261c9
                            out_len,
6261c9
                            reinterpret_cast<const unsigned char*>(data),
6261c9
@@ -3301,7 +3305,7 @@ bool CipherBase::SetAutoPadding(bool auto_padding) {
6261c9
   if (!ctx_)
6261c9
     return false;
6261c9
   MarkPopErrorOnReturn mark_pop_error_on_return;
6261c9
-  return EVP_CIPHER_CTX_set_padding(ctx_.get(), auto_padding);
6261c9
+  return EVP_CIPHER_CTX_set_padding(ctx_, auto_padding);
6261c9
 }
6261c9
 
6261c9
 
6261c9
@@ -3318,10 +3322,10 @@ bool CipherBase::Final(unsigned char** out, int* out_len) {
6261c9
   if (!ctx_)
6261c9
     return false;
6261c9
 
6261c9
-  const int mode = EVP_CIPHER_CTX_mode(ctx_.get());
6261c9
+  const int mode = EVP_CIPHER_CTX_mode(ctx_);
6261c9
 
6261c9
   *out = Malloc<unsigned char>(
6261c9
-      static_cast<size_t>(EVP_CIPHER_CTX_block_size(ctx_.get())));
6261c9
+      static_cast<size_t>(EVP_CIPHER_CTX_block_size(ctx_)));
6261c9
 
6261c9
   if (kind_ == kDecipher && IsSupportedAuthenticatedMode(mode)) {
6261c9
     MaybePassAuthTagToOpenSSL();
6261c9
@@ -3333,7 +3337,7 @@ bool CipherBase::Final(unsigned char** out, int* out_len) {
6261c9
   if (kind_ == kDecipher && mode == EVP_CIPH_CCM_MODE) {
6261c9
     ok = !pending_auth_failed_;
6261c9
   } else {
6261c9
-    ok = EVP_CipherFinal_ex(ctx_.get(), *out, out_len) == 1;
6261c9
+    ok = EVP_CipherFinal_ex(ctx_, *out, out_len) == 1;
6261c9
 
6261c9
     if (ok && kind_ == kCipher && IsAuthenticatedMode()) {
6261c9
       // In GCM mode, the authentication tag length can be specified in advance,
6261c9
@@ -3351,7 +3355,8 @@ bool CipherBase::Final(unsigned char** out, int* out_len) {
6261c9
     }
6261c9
   }
6261c9
 
6261c9
-  ctx_.reset();
6261c9
+  EVP_CIPHER_CTX_free(ctx_);
6261c9
+  ctx_ = nullptr;
6261c9
 
6261c9
   return ok;
6261c9
 }
6261c9
@@ -3394,6 +3399,11 @@ void CipherBase::Final(const FunctionCallbackInfo<Value>& args) {
6261c9
 }
6261c9
 
6261c9
 
6261c9
+Hmac::~Hmac() {
6261c9
+  HMAC_CTX_free(ctx_);
6261c9
+}
6261c9
+
6261c9
+
6261c9
 void Hmac::Initialize(Environment* env, v8::Local<Object> target) {
6261c9
   Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
6261c9
 
6261c9
@@ -3423,9 +3433,16 @@ void Hmac::HmacInit(const char* hash_type, const char* key, int key_len) {
6261c9
   if (key_len == 0) {
6261c9
     key = "";
6261c9
   }
6261c9
+/*
6261c9
   ctx_.reset(HMAC_CTX_new());
6261c9
   if (!ctx_ || !HMAC_Init_ex(ctx_.get(), key, key_len, md, nullptr)) {
6261c9
     ctx_.reset();
6261c9
+*/
6261c9
+  ctx_ = HMAC_CTX_new();
6261c9
+  if (ctx_ == nullptr ||
6261c9
+      !HMAC_Init_ex(ctx_, key, key_len, md, nullptr)) {
6261c9
+    HMAC_CTX_free(ctx_);
6261c9
+    ctx_ = nullptr;
6261c9
     return ThrowCryptoError(env(), ERR_get_error());
6261c9
   }
6261c9
 }
6261c9
@@ -3446,7 +3463,7 @@ void Hmac::HmacInit(const FunctionCallbackInfo<Value>& args) {
6261c9
 bool Hmac::HmacUpdate(const char* data, int len) {
6261c9
   if (!ctx_)
6261c9
     return false;
6261c9
-  int r = HMAC_Update(ctx_.get(),
6261c9
+  int r = HMAC_Update(ctx_,
6261c9
                       reinterpret_cast<const unsigned char*>(data),
6261c9
                       len);
6261c9
   return r == 1;
6261c9
@@ -3493,10 +3510,17 @@ void Hmac::HmacDigest(const FunctionCallbackInfo<Value>& args) {
6261c9
   unsigned char md_value[EVP_MAX_MD_SIZE];
6261c9
   unsigned int md_len = 0;
6261c9
 
6261c9
+/*
6261c9
   if (hmac->ctx_) {
6261c9
     HMAC_Final(hmac->ctx_.get(), md_value, &md_len);
6261c9
     hmac->ctx_.reset();
6261c9
   }
6261c9
+*/
6261c9
+  if (hmac->ctx_ != nullptr) {
6261c9
+    HMAC_Final(hmac->ctx_, md_value, &md_len);
6261c9
+    HMAC_CTX_free(hmac->ctx_);
6261c9
+    hmac->ctx_ = nullptr;
6261c9
+  }
6261c9
 
6261c9
   Local<Value> error;
6261c9
   MaybeLocal<Value> rc =
6261c9
@@ -3514,6 +3538,11 @@ void Hmac::HmacDigest(const FunctionCallbackInfo<Value>& args) {
6261c9
 }
6261c9
 
6261c9
 
6261c9
+Hash::~Hash() {
6261c9
+  EVP_MD_CTX_free(mdctx_);
6261c9
+}
6261c9
+
6261c9
+
6261c9
 void Hash::Initialize(Environment* env, v8::Local<Object> target) {
6261c9
   Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
6261c9
 
6261c9
@@ -3543,9 +3572,16 @@ bool Hash::HashInit(const char* hash_type) {
6261c9
   const EVP_MD* md = EVP_get_digestbyname(hash_type);
6261c9
   if (md == nullptr)
6261c9
     return false;
6261c9
+/*
6261c9
   mdctx_.reset(EVP_MD_CTX_new());
6261c9
   if (!mdctx_ || EVP_DigestInit_ex(mdctx_.get(), md, nullptr) <= 0) {
6261c9
     mdctx_.reset();
6261c9
+*/
6261c9
+  mdctx_ = EVP_MD_CTX_new();
6261c9
+  if (mdctx_ == nullptr ||
6261c9
+      EVP_DigestInit_ex(mdctx_, md, nullptr) <= 0) {
6261c9
+    EVP_MD_CTX_free(mdctx_);
6261c9
+    mdctx_ = nullptr;
6261c9
     return false;
6261c9
   }
6261c9
   finalized_ = false;
6261c9
@@ -3556,7 +3592,7 @@ bool Hash::HashInit(const char* hash_type) {
6261c9
 bool Hash::HashUpdate(const char* data, int len) {
6261c9
   if (!mdctx_)
6261c9
     return false;
6261c9
-  EVP_DigestUpdate(mdctx_.get(), data, len);
6261c9
+  EVP_DigestUpdate(mdctx_, data, len);
6261c9
   return true;
6261c9
 }
6261c9
 
6261c9
@@ -3601,7 +3637,7 @@ void Hash::HashDigest(const FunctionCallbackInfo<Value>& args) {
6261c9
   unsigned char md_value[EVP_MAX_MD_SIZE];
6261c9
   unsigned int md_len;
6261c9
 
6261c9
-  EVP_DigestFinal_ex(hash->mdctx_.get(), md_value, &md_len);
6261c9
+  EVP_DigestFinal_ex(hash->mdctx_, md_value, &md_len);
6261c9
   hash->finalized_ = true;
6261c9
 
6261c9
   Local<Value> error;
6261c9
@@ -3620,6 +3656,11 @@ void Hash::HashDigest(const FunctionCallbackInfo<Value>& args) {
6261c9
 }
6261c9
 
6261c9
 
6261c9
+SignBase::~SignBase() {
6261c9
+  EVP_MD_CTX_free(mdctx_);
6261c9
+}
6261c9
+
6261c9
+
6261c9
 SignBase::Error SignBase::Init(const char* sign_type) {
6261c9
   CHECK_NULL(mdctx_);
6261c9
 #if OPENSSL_VERSION_NUMBER >= 0x10100000L
6261c9
@@ -3634,9 +3675,16 @@ SignBase::Error SignBase::Init(const char* sign_type) {
6261c9
   if (md == nullptr)
6261c9
     return kSignUnknownDigest;
6261c9
 
6261c9
+/*
6261c9
   mdctx_.reset(EVP_MD_CTX_new());
6261c9
   if (!mdctx_ || !EVP_DigestInit_ex(mdctx_.get(), md, nullptr)) {
6261c9
     mdctx_.reset();
6261c9
+*/
6261c9
+  mdctx_ = EVP_MD_CTX_new();
6261c9
+  if (mdctx_ == nullptr ||
6261c9
+      !EVP_DigestInit_ex(mdctx_, md, nullptr)) {
6261c9
+    EVP_MD_CTX_free(mdctx_);
6261c9
+    mdctx_ = nullptr;
6261c9
     return kSignInit;
6261c9
   }
6261c9
 
6261c9
@@ -3647,7 +3695,7 @@ SignBase::Error SignBase::Init(const char* sign_type) {
6261c9
 SignBase::Error SignBase::Update(const char* data, int len) {
6261c9
   if (mdctx_ == nullptr)
6261c9
     return kSignNotInitialised;
6261c9
-  if (!EVP_DigestUpdate(mdctx_.get(), data, len))
6261c9
+  if (!EVP_DigestUpdate(mdctx_, data, len))
6261c9
     return kSignUpdate;
6261c9
   return kSignOk;
6261c9
 }
6261c9
@@ -3749,7 +3797,8 @@ void Sign::SignUpdate(const FunctionCallbackInfo<Value>& args) {
6261c9
   sign->CheckThrow(err);
6261c9
 }
6261c9
 
6261c9
-static int Node_SignFinal(EVPMDPointer&& mdctx, unsigned char* md,
6261c9
+// static int Node_SignFinal(EVPMDPointer&& mdctx, unsigned char* md,
6261c9
+static int Node_SignFinal(EVP_MD_CTX* mdctx, unsigned char* md,
6261c9
                           unsigned int* sig_len,
6261c9
                           const EVPKeyPointer& pkey, int padding,
6261c9
                           int pss_salt_len) {
6261c9
@@ -3757,7 +3806,7 @@ static int Node_SignFinal(EVPMDPointer&& mdctx, unsigned char* md,
6261c9
   unsigned int m_len;
6261c9
 
6261c9
   *sig_len = 0;
6261c9
-  if (!EVP_DigestFinal_ex(mdctx.get(), m, &m_len))
6261c9
+  if (!EVP_DigestFinal_ex(mdctx, m, &m_len))
6261c9
     return 0;
6261c9
 
6261c9
   size_t sltmp = static_cast<size_t>(EVP_PKEY_size(pkey.get()));
6261c9
@@ -3766,7 +3815,7 @@ static int Node_SignFinal(EVPMDPointer&& mdctx, unsigned char* md,
6261c9
       EVP_PKEY_sign_init(pkctx.get()) > 0 &&
6261c9
       ApplyRSAOptions(pkey, pkctx.get(), padding, pss_salt_len) &&
6261c9
       EVP_PKEY_CTX_set_signature_md(pkctx.get(),
6261c9
-                                    EVP_MD_CTX_md(mdctx.get())) > 0 &&
6261c9
+                                    EVP_MD_CTX_md(mdctx)) > 0 &&
6261c9
       EVP_PKEY_sign(pkctx.get(), md, &sltmp, m, m_len) > 0) {
6261c9
     *sig_len = sltmp;
6261c9
     return 1;
6261c9
@@ -3784,7 +3833,8 @@ SignBase::Error Sign::SignFinal(const char* key_pem,
6261c9
   if (!mdctx_)
6261c9
     return kSignNotInitialised;
6261c9
 
6261c9
-  EVPMDPointer mdctx = std::move(mdctx_);
6261c9
+  // EVPMDPointer mdctx = std::move(mdctx_);
6261c9
+  EVP_MD_CTX* mdctx = std::move(mdctx_);
6261c9
 
6261c9
   BIOPointer bp(BIO_new_mem_buf(const_cast<char*>(key_pem), key_pem_len));
6261c9
   if (!bp)
6261c9
@@ -3967,12 +4017,12 @@ SignBase::Error Verify::VerifyFinal(const char* key_pem,
6261c9
   unsigned int m_len;
6261c9
   int r = 0;
6261c9
   *verify_result = false;
6261c9
-  EVPMDPointer mdctx = std::move(mdctx_);
6261c9
+  EVP_MD_CTX* mdctx = std::move(mdctx_);
6261c9
 
6261c9
   if (ParsePublicKey(&pkey, key_pem, key_pem_len) != kParsePublicOk)
6261c9
     return kSignPublicKey;
6261c9
 
6261c9
-  if (!EVP_DigestFinal_ex(mdctx.get(), m, &m_len))
6261c9
+  if (!EVP_DigestFinal_ex(mdctx, m, &m_len))
6261c9
     return kSignPublicKey;
6261c9
 
6261c9
   EVPKeyCtxPointer pkctx(EVP_PKEY_CTX_new(pkey.get(), nullptr));
6261c9
@@ -3980,7 +4030,7 @@ SignBase::Error Verify::VerifyFinal(const char* key_pem,
6261c9
       EVP_PKEY_verify_init(pkctx.get()) > 0 &&
6261c9
       ApplyRSAOptions(pkey, pkctx.get(), padding, saltlen) &&
6261c9
       EVP_PKEY_CTX_set_signature_md(pkctx.get(),
6261c9
-                                    EVP_MD_CTX_md(mdctx.get())) > 0) {
6261c9
+                                    EVP_MD_CTX_md(mdctx)) > 0) {
6261c9
     r = EVP_PKEY_verify(pkctx.get(),
6261c9
                         reinterpret_cast<const unsigned char*>(sig),
6261c9
                         siglen,
6261c9
@@ -4948,6 +4998,7 @@ inline void PBKDF2(const FunctionCallbackInfo<Value>& args) {
6261c9
 }
6261c9
 
6261c9
 
6261c9
+/*
6261c9
 #ifndef OPENSSL_NO_SCRYPT
6261c9
 struct ScryptJob : public CryptoJob {
6261c9
   unsigned char* keybuf_data;
6261c9
@@ -5038,6 +5089,7 @@ void Scrypt(const FunctionCallbackInfo<Value>& args) {
6261c9
   args.GetReturnValue().Set(job->ToResult());
6261c9
 }
6261c9
 #endif  // OPENSSL_NO_SCRYPT
6261c9
+*/
6261c9
 
6261c9
 
6261c9
 void GetSSLCiphers(const FunctionCallbackInfo<Value>& args) {
6261c9
@@ -5478,9 +5530,11 @@ void Initialize(Local<Object> target,
6261c9
                  PublicKeyCipher::Cipher
6261c9
                                          EVP_PKEY_verify_recover_init,
6261c9
                                          EVP_PKEY_verify_recover>);
6261c9
+/*
6261c9
 #ifndef OPENSSL_NO_SCRYPT
6261c9
   env->SetMethod(target, "scrypt", Scrypt);
6261c9
 #endif  // OPENSSL_NO_SCRYPT
6261c9
+*/
6261c9
 }
6261c9
 
6261c9
 }  // namespace crypto
6261c9
diff --git a/src/node_crypto.h b/src/node_crypto.h
6261c9
index e850358..49eb078 100644
6261c9
--- a/src/node_crypto.h
6261c9
+++ b/src/node_crypto.h
6261c9
@@ -81,7 +81,7 @@ using SSLSessionPointer = DeleteFnPtr<SSL_SESSION, SSL_SESSION_free>;
6261c9
 using SSLPointer = DeleteFnPtr<SSL, SSL_free>;
6261c9
 using EVPKeyPointer = DeleteFnPtr<EVP_PKEY, EVP_PKEY_free>;
6261c9
 using EVPKeyCtxPointer = DeleteFnPtr<EVP_PKEY_CTX, EVP_PKEY_CTX_free>;
6261c9
-using EVPMDPointer = DeleteFnPtr<EVP_MD_CTX, EVP_MD_CTX_free>;
6261c9
+// using EVPMDPointer = DeleteFnPtr<EVP_MD_CTX, EVP_MD_CTX_free>;
6261c9
 using RSAPointer = DeleteFnPtr<RSA, RSA_free>;
6261c9
 using BignumPointer = DeleteFnPtr<BIGNUM, BN_free>;
6261c9
 using NetscapeSPKIPointer = DeleteFnPtr<NETSCAPE_SPKI, NETSCAPE_SPKI_free>;
6261c9
@@ -347,6 +347,10 @@ class SSLWrap {
6261c9
 
6261c9
 class CipherBase : public BaseObject {
6261c9
  public:
6261c9
+//  ~CipherBase() override {
6261c9
+//    EVP_CIPHER_CTX_cleanup(ctx_);
6261c9
+//  }
6261c9
+
6261c9
   static void Initialize(Environment* env, v8::Local<v8::Object> target);
6261c9
 
6261c9
   void MemoryInfo(MemoryTracker* tracker) const override {
6261c9
@@ -413,7 +417,9 @@ class CipherBase : public BaseObject {
6261c9
   }
6261c9
 
6261c9
  private:
6261c9
-  DeleteFnPtr<EVP_CIPHER_CTX, EVP_CIPHER_CTX_free> ctx_;
6261c9
+  EVP_CIPHER_CTX* ctx_;
6261c9
+  // DeleteFnPtr<EVP_CIPHER_CTX, EVP_CIPHER_CTX_free> ctx_;
6261c9
+  // DeleteFnPtr<EVP_CIPHER_CTX, EVP_CIPHER_CTX_cleanup> ctx_;
6261c9
   const CipherKind kind_;
6261c9
   bool auth_tag_set_;
6261c9
   unsigned int auth_tag_len_;
6261c9
@@ -424,6 +430,8 @@ class CipherBase : public BaseObject {
6261c9
 
6261c9
 class Hmac : public BaseObject {
6261c9
  public:
6261c9
+  ~Hmac() override;
6261c9
+
6261c9
   static void Initialize(Environment* env, v8::Local<v8::Object> target);
6261c9
 
6261c9
   void MemoryInfo(MemoryTracker* tracker) const override {
6261c9
@@ -448,11 +456,14 @@ class Hmac : public BaseObject {
6261c9
   }
6261c9
 
6261c9
  private:
6261c9
-  DeleteFnPtr<HMAC_CTX, HMAC_CTX_free> ctx_;
6261c9
+  // DeleteFnPtr<HMAC_CTX, HMAC_CTX_free> ctx_;
6261c9
+  HMAC_CTX* ctx_;
6261c9
 };
6261c9
 
6261c9
 class Hash : public BaseObject {
6261c9
  public:
6261c9
+  ~Hash() override;
6261c9
+
6261c9
   static void Initialize(Environment* env, v8::Local<v8::Object> target);
6261c9
 
6261c9
   void MemoryInfo(MemoryTracker* tracker) const override {
6261c9
@@ -477,7 +488,8 @@ class Hash : public BaseObject {
6261c9
   }
6261c9
 
6261c9
  private:
6261c9
-  EVPMDPointer mdctx_;
6261c9
+  // EVPMDPointer mdctx_;
6261c9
+  EVP_MD_CTX* mdctx_;
6261c9
   bool finalized_;
6261c9
 };
6261c9
 
6261c9
@@ -494,9 +506,12 @@ class SignBase : public BaseObject {
6261c9
   } Error;
6261c9
 
6261c9
   SignBase(Environment* env, v8::Local<v8::Object> wrap)
6261c9
-      : BaseObject(env, wrap) {
6261c9
+      : BaseObject(env, wrap),
6261c9
+        mdctx_(nullptr) {
6261c9
   }
6261c9
 
6261c9
+  ~SignBase() override;
6261c9
+
6261c9
   Error Init(const char* sign_type);
6261c9
   Error Update(const char* data, int len);
6261c9
 
6261c9
@@ -509,7 +524,8 @@ class SignBase : public BaseObject {
6261c9
  protected:
6261c9
   void CheckThrow(Error error);
6261c9
 
6261c9
-  EVPMDPointer mdctx_;
6261c9
+  // EVPMDPointer mdctx_;
6261c9
+  EVP_MD_CTX* mdctx_;
6261c9
 };
6261c9
 
6261c9
 class Sign : public SignBase {
6261c9
diff --git a/test/parallel/test-crypto-authenticated.js b/test/parallel/test-crypto-authenticated.js
6261c9
index 4b2d852..cb0bc41 100644
6261c9
--- a/test/parallel/test-crypto-authenticated.js
6261c9
+++ b/test/parallel/test-crypto-authenticated.js
6261c9
@@ -99,7 +99,8 @@ for (const test of TEST_CASES) {
6261c9
   const isOCB = /^aes-(128|192|256)-ocb$/.test(test.algo);
6261c9
 
6261c9
   let options;
6261c9
-  if (isCCM || isOCB)
6261c9
+  //if (isCCM || isOCB)
6261c9
+  if (isCCM)
6261c9
     options = { authTagLength: test.tag.length / 2 };
6261c9
 
6261c9
   const inputEncoding = test.plainIsHex ? 'hex' : 'ascii';
6261c9
@@ -425,7 +426,8 @@ for (const test of TEST_CASES) {
6261c9
 // Test that create(De|C)ipher(iv)? throws if the mode is CCM or OCB and no
6261c9
 // authentication tag has been specified.
6261c9
 {
6261c9
-  for (const mode of ['ccm', 'ocb']) {
6261c9
+  // for (const mode of ['ccm', 'ocb']) {
6261c9
+  for (const mode of ['ccm']) {
6261c9
     assert.throws(() => {
6261c9
       crypto.createCipheriv(`aes-256-${mode}`,
6261c9
                             'FxLKsqdmv0E9xrQhp0b1ZgI0K7JFZJM8',
6261c9
-- 
6261c9
1.8.3.1
6261c9