Enable canonical mode in elliptic

See indutny/elliptic#24 for details.
This commit is contained in:
Kagami Hiiragi 2015-01-21 02:20:28 +03:00
parent 53d878da8e
commit 69745567ff
2 changed files with 2 additions and 1 deletions

View File

@ -78,7 +78,7 @@ var getPublic = exports.getPublic = function(privateKey) {
exports.sign = function(privateKey, msg) { exports.sign = function(privateKey, msg) {
return new Promise(function(resolve) { return new Promise(function(resolve) {
assert(privateKey.length === 32, "Bad private key"); assert(privateKey.length === 32, "Bad private key");
resolve(new Buffer(ec.sign(msg, privateKey).toDER())); resolve(new Buffer(ec.sign(msg, privateKey, {canonical: true}).toDER()));
}); });
}; };

View File

@ -89,6 +89,7 @@ describe("ECDSA", function() {
it("should allow to sign and verify messages less than 32 bytes", function() { it("should allow to sign and verify messages less than 32 bytes", function() {
return eccrypto.sign(privateKey, shortMsg).then(function(sig) { return eccrypto.sign(privateKey, shortMsg).then(function(sig) {
expect(Buffer.isBuffer(sig)).to.be.true; expect(Buffer.isBuffer(sig)).to.be.true;
expect(sig.toString("hex")).to.equal("304402204737396b697e5a3400e3aedd203d8be89879f97708647252bd0c17752ff4c8f302201d52ef234de82ce0719679fa220334c83b80e21b8505a781d32d94a27d9310aa");
return eccrypto.verify(publicKey, shortMsg, sig); return eccrypto.verify(publicKey, shortMsg, sig);
}); });
}); });