fixtures: ECDSA signatures should be DER encoded if possible
This commit is contained in:
parent
5b95fd6ae3
commit
b5ff9db8fd
2 changed files with 35 additions and 53 deletions
test
|
@ -89,7 +89,7 @@ describe('ecdsa', function () {
|
|||
it('recovers the pubKey for ' + f.d, function () {
|
||||
var d = BigInteger.fromHex(f.d)
|
||||
var Q = curve.G.multiply(d)
|
||||
var signature = new ECSignature(new BigInteger(f.signature.r), new BigInteger(f.signature.s))
|
||||
var signature = ECSignature.fromDER(new Buffer(f.signature, 'hex'))
|
||||
var h1 = crypto.sha256(f.message)
|
||||
var e = BigInteger.fromBuffer(h1)
|
||||
var Qprime = ecdsa.recoverPubKey(curve, e, signature, f.i)
|
||||
|
@ -124,7 +124,7 @@ describe('ecdsa', function () {
|
|||
fixtures.invalid.recoverPubKey.forEach(function (f) {
|
||||
it('throws on ' + f.description + ' (' + f.exception + ')', function () {
|
||||
var e = BigInteger.fromHex(f.e)
|
||||
var signature = new ECSignature(new BigInteger(f.signature.r, 16), new BigInteger(f.signature.s, 16))
|
||||
var signature = new ECSignature(new BigInteger(f.signatureRaw.r, 16), new BigInteger(f.signatureRaw.s, 16))
|
||||
|
||||
assert.throws(function () {
|
||||
ecdsa.recoverPubKey(curve, e, signature, f.i)
|
||||
|
@ -138,10 +138,9 @@ describe('ecdsa', function () {
|
|||
it('produces a deterministic signature for "' + f.message + '"', function () {
|
||||
var d = BigInteger.fromHex(f.d)
|
||||
var hash = crypto.sha256(f.message)
|
||||
var signature = ecdsa.sign(curve, hash, d)
|
||||
var signature = ecdsa.sign(curve, hash, d).toDER()
|
||||
|
||||
assert.strictEqual(signature.r.toString(), f.signature.r)
|
||||
assert.strictEqual(signature.s.toString(), f.signature.s)
|
||||
assert.strictEqual(signature.toString('hex'), f.signature)
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -160,7 +159,7 @@ describe('ecdsa', function () {
|
|||
it('verifies a valid signature for "' + f.message + '"', function () {
|
||||
var d = BigInteger.fromHex(f.d)
|
||||
var H = crypto.sha256(f.message)
|
||||
var signature = new ECSignature(new BigInteger(f.signature.r), new BigInteger(f.signature.s))
|
||||
var signature = ECSignature.fromDER(new Buffer(f.signature, 'hex'))
|
||||
var Q = curve.G.multiply(d)
|
||||
|
||||
assert(ecdsa.verify(curve, H, signature, Q))
|
||||
|
@ -171,7 +170,14 @@ describe('ecdsa', function () {
|
|||
it('fails to verify with ' + f.description, function () {
|
||||
var H = crypto.sha256(f.message)
|
||||
var d = BigInteger.fromHex(f.d)
|
||||
var signature = new ECSignature(new BigInteger(f.signature.r, 16), new BigInteger(f.signature.s, 16))
|
||||
|
||||
var signature
|
||||
if (f.signature) {
|
||||
signature = ECSignature.fromDER(new Buffer(f.signature, 'hex'))
|
||||
|
||||
} else if (f.signatureRaw) {
|
||||
signature = new ECSignature(new BigInteger(f.signatureRaw.r, 16), new BigInteger(f.signatureRaw.s, 16))
|
||||
}
|
||||
|
||||
var Q = curve.G.multiply(d)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue