ecdsa: remove unused verifyRaw
This commit is contained in:
parent
a221bd142c
commit
4c030be343
3 changed files with 9 additions and 18 deletions
17
src/ecdsa.js
17
src/ecdsa.js
|
@ -104,7 +104,7 @@ function sign (curve, hash, d) {
|
||||||
return new ECSignature(r, s)
|
return new ECSignature(r, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
function verifyRaw (curve, e, signature, Q) {
|
function verify (curve, hash, signature, Q) {
|
||||||
var n = curve.n
|
var n = curve.n
|
||||||
var G = curve.G
|
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 (r.signum() <= 0 || r.compareTo(n) >= 0) return false
|
||||||
if (s.signum() <= 0 || s.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
|
// Compute s^-1
|
||||||
var sInv = s.modInverse(n)
|
var sInv = s.modInverse(n)
|
||||||
|
|
||||||
|
@ -140,14 +144,6 @@ function verifyRaw (curve, e, signature, Q) {
|
||||||
return v.equals(r)
|
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.
|
* Recover a public key from a signature.
|
||||||
*
|
*
|
||||||
|
@ -227,6 +223,5 @@ module.exports = {
|
||||||
deterministicGenerateK: deterministicGenerateK,
|
deterministicGenerateK: deterministicGenerateK,
|
||||||
recoverPubKey: recoverPubKey,
|
recoverPubKey: recoverPubKey,
|
||||||
sign: sign,
|
sign: sign,
|
||||||
verify: verify,
|
verify: verify
|
||||||
verifyRaw: verifyRaw
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,30 +158,26 @@ describe('ecdsa', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('verify/verifyRaw', function () {
|
describe('verify', function () {
|
||||||
fixtures.valid.ecdsa.forEach(function (f) {
|
fixtures.valid.ecdsa.forEach(function (f) {
|
||||||
it('verifies a valid signature for "' + f.message + '"', function () {
|
it('verifies a valid signature for "' + f.message + '"', function () {
|
||||||
var d = BigInteger.fromHex(f.d)
|
var d = BigInteger.fromHex(f.d)
|
||||||
var H = crypto.sha256(f.message)
|
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 signature = new ECSignature(new BigInteger(f.signature.r), new BigInteger(f.signature.s))
|
||||||
var Q = curve.G.multiply(d)
|
var Q = curve.G.multiply(d)
|
||||||
|
|
||||||
assert(ecdsa.verify(curve, H, signature, Q))
|
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 () {
|
it('fails to verify with ' + f.description, function () {
|
||||||
var H = crypto.sha256(f.message)
|
var H = crypto.sha256(f.message)
|
||||||
var e = BigInteger.fromBuffer(H)
|
|
||||||
var d = BigInteger.fromHex(f.d)
|
var d = BigInteger.fromHex(f.d)
|
||||||
var signature = new ECSignature(new BigInteger(f.signature.r), new BigInteger(f.signature.s))
|
var signature = new ECSignature(new BigInteger(f.signature.r), new BigInteger(f.signature.s))
|
||||||
var Q = curve.G.multiply(d)
|
var Q = curve.G.multiply(d)
|
||||||
|
|
||||||
assert.equal(ecdsa.verify(curve, H, signature, Q), false)
|
assert.equal(ecdsa.verify(curve, H, signature, Q), false)
|
||||||
assert.equal(ecdsa.verifyRaw(curve, e, signature, Q), false)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
2
test/fixtures/ecdsa.json
vendored
2
test/fixtures/ecdsa.json
vendored
|
@ -218,7 +218,7 @@
|
||||||
"i": 4
|
"i": 4
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"verifyRaw": [
|
"verify": [
|
||||||
{
|
{
|
||||||
"description": "The wrong signature",
|
"description": "The wrong signature",
|
||||||
"d": "01",
|
"d": "01",
|
||||||
|
|
Loading…
Add table
Reference in a new issue