Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d0e94fc

Browse filesBrowse files
tniessencodebytere
authored andcommitted
crypto: fix ieee-p1363 for createVerify
Fixes: #31866 PR-URL: #31876 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 61a0d8b commit d0e94fc
Copy full SHA for d0e94fc

File tree

Expand file treeCollapse file tree

3 files changed

+16
-10
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+16
-10
lines changed
Open diff view settings
Collapse file

‎src/node_crypto.cc‎

Copy file name to clipboardExpand all lines: src/node_crypto.cc
+4-8Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5323,8 +5323,7 @@ void Verify::VerifyUpdate(const FunctionCallbackInfo<Value>& args) {
53235323

53245324

53255325
SignBase::Error Verify::VerifyFinal(const ManagedEVPPKey& pkey,
5326-
const char* sig,
5327-
int siglen,
5326+
const ByteSource& sig,
53285327
int padding,
53295328
const Maybe<int>& saltlen,
53305329
bool* verify_result) {
@@ -5345,11 +5344,8 @@ SignBase::Error Verify::VerifyFinal(const ManagedEVPPKey& pkey,
53455344
ApplyRSAOptions(pkey, pkctx.get(), padding, saltlen) &&
53465345
EVP_PKEY_CTX_set_signature_md(pkctx.get(),
53475346
EVP_MD_CTX_md(mdctx.get())) > 0) {
5348-
const int r = EVP_PKEY_verify(pkctx.get(),
5349-
reinterpret_cast<const unsigned char*>(sig),
5350-
siglen,
5351-
m,
5352-
m_len);
5347+
const unsigned char* s = reinterpret_cast<const unsigned char*>(sig.get());
5348+
const int r = EVP_PKEY_verify(pkctx.get(), s, sig.size(), m, m_len);
53535349
*verify_result = r == 1;
53545350
}
53555351

@@ -5394,7 +5390,7 @@ void Verify::VerifyFinal(const FunctionCallbackInfo<Value>& args) {
53945390
}
53955391

53965392
bool verify_result;
5397-
Error err = verify->VerifyFinal(pkey, hbuf.data(), hbuf.length(), padding,
5393+
Error err = verify->VerifyFinal(pkey, signature, padding,
53985394
salt_len, &verify_result);
53995395
if (err != kSignOk)
54005396
return verify->CheckThrow(err);
Collapse file

‎src/node_crypto.h‎

Copy file name to clipboardExpand all lines: src/node_crypto.h
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,8 +700,7 @@ class Verify : public SignBase {
700700
static void Initialize(Environment* env, v8::Local<v8::Object> target);
701701

702702
Error VerifyFinal(const ManagedEVPPKey& key,
703-
const char* sig,
704-
int siglen,
703+
const ByteSource& sig,
705704
int padding,
706705
const v8::Maybe<int>& saltlen,
707706
bool* verify_result);
Collapse file

‎test/parallel/test-crypto-sign-verify.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-crypto-sign-verify.js
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,9 @@ assert.throws(
527527
// Unlike DER signatures, IEEE P1363 signatures have a predictable length.
528528
assert.strictEqual(sig.length, length);
529529
assert.strictEqual(crypto.verify('sha1', data, opts, sig), true);
530+
assert.strictEqual(crypto.createVerify('sha1')
531+
.update(data)
532+
.verify(opts, sig), true);
530533

531534
// Test invalid signature lengths.
532535
for (const i of [-2, -1, 1, 2, 4, 8]) {
@@ -552,6 +555,14 @@ assert.throws(
552555
ok
553556
);
554557

558+
assert.strictEqual(
559+
crypto.createVerify('sha256').update(data).verify({
560+
key: fixtures.readKey('ec-key.pem'),
561+
dsaEncoding: 'ieee-p1363'
562+
}, extSig),
563+
ok
564+
);
565+
555566
extSig[Math.floor(Math.random() * extSig.length)] ^= 1;
556567
}
557568

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.