Skip to content

Commit cb2149d

Browse files
committed
fixup! crypto: add signDigest/verifyDigest and Ed25519ctx support
1 parent 2b883c3 commit cb2149d

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,11 @@ if (hasOpenSSL(3, 2)) {
252252
// Different domain separation means cross-verify must fail.
253253
assert.strictEqual(crypto.verify(null, data, pubKey, sig), false);
254254

255+
// Ed25519 pure signatures are NOT compatible with Ed25519ph.
256+
// sign() output cannot be verified by verifyDigest().
257+
const pureSig = crypto.sign(null, data, privKey);
258+
assert.strictEqual(crypto.verifyDigest(null, digest, pubKey, pureSig), false);
259+
255260
// KeyObject forms
256261
const privKeyObj = crypto.createPrivateKey(privKey);
257262
const pubKeyObj = crypto.createPublicKey(pubKey);
@@ -271,6 +276,9 @@ if (hasOpenSSL(3, 2)) {
271276
key: pubKey,
272277
context: Buffer.from('other'),
273278
}, sig3), false);
279+
280+
// Ed25519ph+context signatures are NOT compatible with verify(ctx).
281+
assert.strictEqual(crypto.verify(null, data, { key: pubKey, context }, sig3), false);
274282
}
275283
}
276284

@@ -297,6 +305,11 @@ if (hasOpenSSL(3, 2)) {
297305
// Different domain separation means cross-verify must fail.
298306
assert.strictEqual(crypto.verify(null, data, pubKey, sig), false);
299307

308+
// Ed448 pure signatures are NOT compatible with Ed448ph.
309+
// sign() output cannot be verified by verifyDigest().
310+
const pureSig = crypto.sign(null, data, privKey);
311+
assert.strictEqual(crypto.verifyDigest(null, digest, pubKey, pureSig), false);
312+
300313
// Ed448ph with context string
301314
{
302315
const context = Buffer.from('my context');
@@ -309,6 +322,17 @@ if (hasOpenSSL(3, 2)) {
309322
key: pubKey,
310323
context: Buffer.from('other'),
311324
}, sig2), false);
325+
326+
// Ed448ph+context signatures are NOT compatible with verify(ctx).
327+
assert.strictEqual(crypto.verify(null, data, { key: pubKey, context }, sig2), false);
328+
}
329+
330+
// Ed448+context signatures are NOT compatible with Ed448ph.
331+
// sign(ctx) output cannot be verified by verifyDigest(ctx).
332+
{
333+
const context = Buffer.from('my context');
334+
const ctxSig = crypto.sign(null, data, { key: privKey, context });
335+
assert.strictEqual(crypto.verifyDigest(null, digest, { key: pubKey, context }, ctxSig), false);
312336
}
313337

314338
// Ed448ph with empty context string

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,10 @@ if (hasOpenSSL(3, 2)) {
547547
key: pubKey,
548548
context: Buffer.from('wrong'),
549549
}, sig), false);
550+
551+
// Ed25519ctx signatures are NOT compatible with Ed25519ph (verifyDigest).
552+
const digest = crypto.createHash('sha512').update(data).digest();
553+
assert.strictEqual(crypto.verifyDigest(null, digest, { key: pubKey, context }, sig), false);
550554
}
551555

552556
{

0 commit comments

Comments
 (0)