From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: deepak1556 <hop2deep@gmail.com>
Date: Wed, 19 Dec 2018 08:54:45 +0530
Subject: fix: use bssl BN_bn2bin_padded for ossl's BN_bn2binpad

Also note that BN_bn2bin_padded returns 1 on success instead of size

diff --git a/src/node_crypto.cc b/src/node_crypto.cc
index a5710dc33b62b9b53174318aed62d8e7fe3a52b9..2143117ec3b782ce307bcb3c7183594bc233d5e8 100644
--- a/src/node_crypto.cc
+++ b/src/node_crypto.cc
@@ -5404,9 +5404,9 @@ void DiffieHellman::GenerateKeys(const FunctionCallbackInfo<Value>& args) {
   const int size = BN_num_bytes(pub_key);
   CHECK_GE(size, 0);
   AllocatedBuffer data = env->AllocateManaged(size);
-  CHECK_EQ(size,
-           BN_bn2binpad(
-               pub_key, reinterpret_cast<unsigned char*>(data.data()), size));
+  CHECK_EQ(
+      1,
+      BN_bn2bin_padded(reinterpret_cast<unsigned char*>(data.data()), size, pub_key));
   args.GetReturnValue().Set(data.ToBuffer().ToLocalChecked());
 }
 
@@ -5426,8 +5426,8 @@ void DiffieHellman::GetField(const FunctionCallbackInfo<Value>& args,
   CHECK_GE(size, 0);
   AllocatedBuffer data = env->AllocateManaged(size);
   CHECK_EQ(
-      size,
-      BN_bn2binpad(num, reinterpret_cast<unsigned char*>(data.data()), size));
+      1,
+      BN_bn2bin_padded(reinterpret_cast<unsigned char*>(data.data()), size, num));
   args.GetReturnValue().Set(data.ToBuffer().ToLocalChecked());
 }
 
@@ -5750,9 +5750,9 @@ void ECDH::GetPrivateKey(const FunctionCallbackInfo<Value>& args) {
 
   const int size = BN_num_bytes(b);
   AllocatedBuffer out = env->AllocateManaged(size);
-  CHECK_EQ(size, BN_bn2binpad(b,
-                              reinterpret_cast<unsigned char*>(out.data()),
-                              size));
+  CHECK_EQ(1, BN_bn2bin_padded(reinterpret_cast<unsigned char*>(out.data()),
+                                  size,
+                                  b));
 
   Local<Object> buf = out.ToBuffer().ToLocalChecked();
   args.GetReturnValue().Set(buf);
