Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup! crypto: add optional callback to crypto.sign and crypto.verify
  • Loading branch information
panva committed Mar 10, 2021
commit 670960f48fdd124f76cbb41412cd22f0de1a7a65
9 changes: 7 additions & 2 deletions src/crypto/crypto_ec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <openssl/ec.h>
#include <openssl/ecdh.h>

#include <algorithm>

namespace node {

using v8::Array;
Expand Down Expand Up @@ -959,19 +961,22 @@ ByteSource ConvertToWebCryptoSignature(
return ByteSource();

DSA_SIG_get0(dsasig.get(), &pr, &ps);
len = BN_num_bytes(pr);
len = std::max(BN_num_bytes(pr), BN_num_bytes(ps));
}
}

CHECK_GT(len, 0);

char* outdata = MallocOpenSSL<char>(len * 2);
memset(outdata, 0, len * 2);
ByteSource out = ByteSource::Allocated(outdata, len * 2);
unsigned char* ptr = reinterpret_cast<unsigned char*>(outdata);

if (!BN_bn2binpad(pr, ptr, len) || !BN_bn2binpad(ps, ptr + len, len)) {
if (BN_bn2binpad(pr, ptr, len) <= 0 ||
BN_bn2binpad(ps, ptr + len, len) <= 0) {
return ByteSource();
}

return out;
}

Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-crypto-async-sign-verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ test('ec_secp256k1_public.pem', 'ec_secp256k1_private.pem', 'sha384', false,
{ dsaEncoding: 'ieee-p1363' });

// DSA w/ der signature encoding
test('dsa_public_1025.pem', 'dsa_private_1025.pem', 'sha256',
test('dsa_public.pem', 'dsa_private.pem', 'sha256',
false);
test('dsa_public_1025.pem', 'dsa_private_1025.pem', 'sha256',
test('dsa_public.pem', 'dsa_private.pem', 'sha256',
false, { dsaEncoding: 'der' });

// DSA w/ ieee-p1363 signature encoding
test('dsa_public_1025.pem', 'dsa_private_1025.pem', 'sha256', false,
test('dsa_public.pem', 'dsa_private.pem', 'sha256', false,
{ dsaEncoding: 'ieee-p1363' });