diff --git a/src/ecdsa.js b/src/ecdsa.js index 71f0bbd..549eedb 100644 --- a/src/ecdsa.js +++ b/src/ecdsa.js @@ -104,7 +104,7 @@ function sign (curve, hash, d) { return new ECSignature(r, s) } -function verifyRaw (curve, e, signature, Q) { +function verify (curve, hash, signature, Q) { var n = curve.n var G = curve.G @@ -115,6 +115,10 @@ function verifyRaw (curve, e, signature, Q) { if (r.signum() <= 0 || r.compareTo(n) >= 0) return false if (s.signum() <= 0 || s.compareTo(n) >= 0) return false + // 1.4.2 H = Hash(M), already done by the user + // 1.4.3 e = H + var e = BigInteger.fromBuffer(hash) + // Compute s^-1 var sInv = s.modInverse(n) @@ -140,14 +144,6 @@ function verifyRaw (curve, e, signature, Q) { return v.equals(r) } -function verify (curve, hash, signature, Q) { - // 1.4.2 H = Hash(M), already done by the user - // 1.4.3 e = H - var e = BigInteger.fromBuffer(hash) - - return verifyRaw(curve, e, signature, Q) -} - /** * Recover a public key from a signature. * @@ -227,6 +223,5 @@ module.exports = { deterministicGenerateK: deterministicGenerateK, recoverPubKey: recoverPubKey, sign: sign, - verify: verify, - verifyRaw: verifyRaw + verify: verify } diff --git a/test/ecdsa.js b/test/ecdsa.js index a5ff8a5..94f0f40 100644 --- a/test/ecdsa.js +++ b/test/ecdsa.js @@ -158,30 +158,26 @@ describe('ecdsa', function () { }) }) - describe('verify/verifyRaw', function () { + describe('verify', function () { fixtures.valid.ecdsa.forEach(function (f) { it('verifies a valid signature for "' + f.message + '"', function () { var d = BigInteger.fromHex(f.d) var H = crypto.sha256(f.message) - var e = BigInteger.fromBuffer(H) var signature = new ECSignature(new BigInteger(f.signature.r), new BigInteger(f.signature.s)) var Q = curve.G.multiply(d) assert(ecdsa.verify(curve, H, signature, Q)) - assert(ecdsa.verifyRaw(curve, e, signature, Q)) }) }) - fixtures.invalid.verifyRaw.forEach(function (f) { + fixtures.invalid.verify.forEach(function (f) { it('fails to verify with ' + f.description, function () { var H = crypto.sha256(f.message) - var e = BigInteger.fromBuffer(H) var d = BigInteger.fromHex(f.d) var signature = new ECSignature(new BigInteger(f.signature.r), new BigInteger(f.signature.s)) var Q = curve.G.multiply(d) assert.equal(ecdsa.verify(curve, H, signature, Q), false) - assert.equal(ecdsa.verifyRaw(curve, e, signature, Q), false) }) }) }) diff --git a/test/fixtures/ecdsa.json b/test/fixtures/ecdsa.json index 57814c2..7bbcc85 100644 --- a/test/fixtures/ecdsa.json +++ b/test/fixtures/ecdsa.json @@ -218,7 +218,7 @@ "i": 4 } ], - "verifyRaw": [ + "verify": [ { "description": "The wrong signature", "d": "01",