Skip to content

Commit

Permalink
fixup! crypto: add optional callback to crypto.sign and crypto.verify
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Mar 8, 2021
1 parent 2a4990a commit 5673dcb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
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' });

0 comments on commit 5673dcb

Please sign in to comment.