ecdsa: remove unused verifyRaw

This commit is contained in:
Daniel Cousens 2015-04-10 17:22:00 +10:00
parent a221bd142c
commit 4c030be343
3 changed files with 9 additions and 18 deletions

View file

@ -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
}

View file

@ -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)
})
})
})

View file

@ -218,7 +218,7 @@
"i": 4
}
],
"verifyRaw": [
"verify": [
{
"description": "The wrong signature",
"d": "01",