Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

Commit

Permalink
fix: BN_bn2bin_padded returns 1 on success instead of size
Browse files Browse the repository at this point in the history
fixup! fix: update with BORINGSSL api for node_crypto.cc
  • Loading branch information
nornagon authored and nitsakh committed Mar 18, 2019
1 parent 6f2df27 commit e56bc4f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4221,7 +4221,7 @@ void DiffieHellman::GenerateKeys(const FunctionCallbackInfo<Value>& args) {
auto* allocator = env->isolate()->GetArrayBufferAllocator();
char* data = static_cast<char*>(allocator->AllocateUninitialized(size));
CHECK_EQ(
size,
1,
BN_bn2bin_padded(reinterpret_cast<unsigned char*>(data), size, pub_key));
args.GetReturnValue().Set(Buffer::New(env, data, size).ToLocalChecked());
}
Expand All @@ -4242,7 +4242,7 @@ void DiffieHellman::GetField(const FunctionCallbackInfo<Value>& args,
CHECK_GE(size, 0);
auto* allocator = env->isolate()->GetArrayBufferAllocator();
char* data = static_cast<char*>(allocator->AllocateUninitialized(size));
CHECK_EQ(size,
CHECK_EQ(1,
BN_bn2bin_padded(reinterpret_cast<unsigned char*>(data), size, num));
args.GetReturnValue().Set(Buffer::New(env, data, size).ToLocalChecked());
}
Expand Down Expand Up @@ -4588,7 +4588,7 @@ void ECDH::GetPrivateKey(const FunctionCallbackInfo<Value>& args) {
unsigned char* out =
static_cast<unsigned char*>(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");
}
Expand Down

0 comments on commit e56bc4f

Please sign in to comment.