ecdsa: add invalid test fixtures for recoverPubKey
This commit is contained in:
parent
8c5c0a13a6
commit
4f8040f8d4
3 changed files with 39 additions and 2 deletions
|
@ -186,7 +186,7 @@ function parseSigCompact(buffer) {
|
||||||
* http://www.secg.org/download/aid-780/sec1-v2.pdf
|
* http://www.secg.org/download/aid-780/sec1-v2.pdf
|
||||||
*/
|
*/
|
||||||
function recoverPubKey(curve, e, signature, i) {
|
function recoverPubKey(curve, e, signature, i) {
|
||||||
assert.strictEqual(i & 3, i, 'The recovery param is more than two bits')
|
assert.strictEqual(i & 3, i, 'Recovery param is more than two bits')
|
||||||
|
|
||||||
var r = signature.r
|
var r = signature.r
|
||||||
var s = signature.s
|
var s = signature.s
|
||||||
|
@ -223,7 +223,8 @@ function recoverPubKey(curve, e, signature, i) {
|
||||||
|
|
||||||
// 1.4 Check that nR isn't at infinity
|
// 1.4 Check that nR isn't at infinity
|
||||||
var R = Point.fromAffine(curve, x, y)
|
var R = Point.fromAffine(curve, x, y)
|
||||||
curve.validate(R)
|
var nR = R.multiply(n)
|
||||||
|
assert(curve.isInfinity(nR), 'nR is not a valid curve point')
|
||||||
|
|
||||||
// 1.5 Compute -e from e
|
// 1.5 Compute -e from e
|
||||||
var eNeg = e.negate().mod(n)
|
var eNeg = e.negate().mod(n)
|
||||||
|
|
|
@ -37,6 +37,20 @@ describe('ecdsa', function() {
|
||||||
var Qprime = ecdsa.recoverPubKey(curve, e, parsed.signature, parsed.i)
|
var Qprime = ecdsa.recoverPubKey(curve, e, parsed.signature, parsed.i)
|
||||||
assert(Q.equals(Qprime))
|
assert(Q.equals(Qprime))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
fixtures.invalid.recoverPubKey.forEach(function(f) {
|
||||||
|
it('throws on ' + f.description, function() {
|
||||||
|
var e = BigInteger.fromHex(f.e)
|
||||||
|
var signature = {
|
||||||
|
r: new BigInteger(f.signature.r),
|
||||||
|
s: new BigInteger(f.signature.s)
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.throws(function() {
|
||||||
|
ecdsa.recoverPubKey(curve, e, signature, f.i)
|
||||||
|
}, new RegExp(f.exception))
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('sign', function() {
|
describe('sign', function() {
|
||||||
|
|
22
test/fixtures/ecdsa.json
vendored
22
test/fixtures/ecdsa.json
vendored
|
@ -143,6 +143,28 @@
|
||||||
"hex": "300c0204ffffffff0202ffffffff"
|
"hex": "300c0204ffffffff0202ffffffff"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"recoverPubKey": [
|
||||||
|
{
|
||||||
|
"description": "Invalid r value (== 0)",
|
||||||
|
"exception": "nR is not a valid curve point",
|
||||||
|
"e": "01",
|
||||||
|
"signature": {
|
||||||
|
"r": "00",
|
||||||
|
"s": "02"
|
||||||
|
},
|
||||||
|
"i": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Invalid i value (> 3)",
|
||||||
|
"exception": "Recovery param is more than two bits",
|
||||||
|
"e": "01",
|
||||||
|
"signature": {
|
||||||
|
"r": "00",
|
||||||
|
"s": "02"
|
||||||
|
},
|
||||||
|
"i": 4
|
||||||
|
}
|
||||||
|
],
|
||||||
"verifyRaw": [
|
"verifyRaw": [
|
||||||
{
|
{
|
||||||
"description": "The wrong signature",
|
"description": "The wrong signature",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue