tests: add tests for ecdsa.verify

This commit is contained in:
Daniel Cousens 2014-10-11 13:47:32 +11:00
parent 98bc1685b3
commit 10630873eb
3 changed files with 24 additions and 20 deletions

View file

@ -115,31 +115,35 @@ describe('ecdsa', function() {
})
})
describe('verifyRaw', function() {
describe('verify/verifyRaw', function() {
fixtures.valid.forEach(function(f) {
it('verifies a valid signature for \"' + f.message + '\"', function() {
var d = BigInteger.fromHex(f.d)
var e = BigInteger.fromBuffer(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 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) {
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 e = BigInteger.fromHex(f.e)
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)
})
})