From dc7527be04699eb0bf010db9b92e717219b4d39f Mon Sep 17 00:00:00 2001 From: Jeremy Apthorp Date: Mon, 4 Mar 2019 11:25:56 -0800 Subject: [PATCH] fix: BN_bn2bin_padded returns 1 on success instead of size fixup! fix: update with BORINGSSL api for node_crypto.cc --- src/node_crypto.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index aedabce2e07..3563eb141af 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -4221,7 +4221,7 @@ void DiffieHellman::GenerateKeys(const FunctionCallbackInfo& args) { auto* allocator = env->isolate()->GetArrayBufferAllocator(); char* data = static_cast(allocator->AllocateUninitialized(size)); CHECK_EQ( - size, + 1, BN_bn2bin_padded(reinterpret_cast(data), size, pub_key)); args.GetReturnValue().Set(Buffer::New(env, data, size).ToLocalChecked()); } @@ -4242,7 +4242,7 @@ void DiffieHellman::GetField(const FunctionCallbackInfo& args, CHECK_GE(size, 0); auto* allocator = env->isolate()->GetArrayBufferAllocator(); char* data = static_cast(allocator->AllocateUninitialized(size)); - CHECK_EQ(size, + CHECK_EQ(1, BN_bn2bin_padded(reinterpret_cast(data), size, num)); args.GetReturnValue().Set(Buffer::New(env, data, size).ToLocalChecked()); } @@ -4588,7 +4588,7 @@ void ECDH::GetPrivateKey(const FunctionCallbackInfo& args) { unsigned char* out = static_cast(allocator->AllocateUninitialized(size)); - if (size != BN_bn2bin_padded(out, size, b)) { + if (!BN_bn2bin_padded(out, size, b)) { allocator->Free(out, size); return env->ThrowError("Failed to convert ECDH private key to Buffer"); }