ecdsa: add invalid tests for verifyRaw

This commit is contained in:
Daniel Cousens 2014-05-24 13:40:20 +10:00
parent 1d6b1fe58b
commit 37d5147cac
2 changed files with 61 additions and 2 deletions

View file

@ -62,7 +62,7 @@ describe('ecdsa', function() {
}) })
describe('verifyRaw', function() { describe('verifyRaw', function() {
it('matches the test vectors', function() { it('verifies valid signatures', function() {
fixtures.valid.forEach(function(f) { fixtures.valid.forEach(function(f) {
var D = BigInteger.fromHex(f.D) var D = BigInteger.fromHex(f.D)
var Q = ecparams.getG().multiply(D) var Q = ecparams.getG().multiply(D)
@ -74,6 +74,18 @@ describe('ecdsa', function() {
assert(ecdsa.verifyRaw(ecparams, e, r, s, Q)) assert(ecdsa.verifyRaw(ecparams, e, r, s, Q))
}) })
}) })
fixtures.invalid.verifyRaw.forEach(function(f) {
it('fails to verify with ' + f.description, function() {
var D = BigInteger.fromHex(f.D)
var e = BigInteger.fromHex(f.e)
var r = new BigInteger(f.signature.r)
var s = new BigInteger(f.signature.s)
var Q = ecparams.getG().multiply(D)
assert.equal(ecdsa.verifyRaw(ecparams, e, r, s, Q), false)
})
})
}) })
describe('serializeSig', function() { describe('serializeSig', function() {

View file

@ -1,7 +1,7 @@
{ {
"valid": [ "valid": [
{ {
"D": "0000000000000000000000000000000000000000000000000000000000000001", "D": "01",
"k": "ec633bd56a5774a0940cb97e27a9e4e51dc94af737596a0c5cbb3d30332d92a5", "k": "ec633bd56a5774a0940cb97e27a9e4e51dc94af737596a0c5cbb3d30332d92a5",
"message": "Everything should be made as simple as possible, but not simpler.", "message": "Everything should be made as simple as possible, but not simpler.",
"compact": "1f33a69cd2065432a30f3d1ce4eb0d59b8ab58c74f27c41a7fdb5696ad4e6108c96f807982866f785d3f6418d24163ddae117b7db4d5fdf0071de069fa54342262", "compact": "1f33a69cd2065432a30f3d1ce4eb0d59b8ab58c74f27c41a7fdb5696ad4e6108c96f807982866f785d3f6418d24163ddae117b7db4d5fdf0071de069fa54342262",
@ -132,6 +132,53 @@
"description": "Sequence too long", "description": "Sequence too long",
"hex": "30080304ffffffff0304ffffffffffffff" "hex": "30080304ffffffff0304ffffffffffffff"
} }
],
"verifyRaw": [
{
"description": "The wrong signature",
"D": "01",
"e": "06ef2b193b83b3d701f765f1db34672ab84897e1252343cc2197829af3a30456",
"signature": {
"r": "38341707918488238920692284707283974715538935465589664377561695343399725051885",
"s": "3180566392414476763164587487324397066658063772201694230600609996154610926757"
}
},
{
"description": "Invalid r value (== 0)",
"D": "01",
"e": "01",
"signature": {
"r": "00",
"s": "02"
}
},
{
"description": "Invalid r value (>= n)",
"D": "01",
"e": "01",
"signature": {
"r": "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141",
"s": "02"
}
},
{
"description": "Invalid s value (== 0)",
"D": "01",
"e": "01",
"signature": {
"r": "02",
"s": "00"
}
},
{
"description": "Invalid s value (>= n)",
"D": "01",
"e": "01",
"signature": {
"r": "02",
"s": "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"
}
}
] ]
} }
} }