From 5f677a86a7811596ee2c5b693de2e9591d4ec377 Mon Sep 17 00:00:00 2001 From: Stefan Thomas Date: Thu, 20 Mar 2014 17:22:10 -0700 Subject: [PATCH] [CHORE] Update SJCL. --- build/sjcl.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/build/sjcl.js b/build/sjcl.js index 8e2c9a2a..b2c436dc 100644 --- a/build/sjcl.js +++ b/build/sjcl.js @@ -4043,6 +4043,24 @@ sjcl.ecc.ecdsa.publicKey.prototype = { } }; +sjcl.ecc.ecdsa.secretKey.prototype.canonicalizeSignature = function(rs) { + var w = sjcl.bitArray, + R = this._curve.r, + l = R.bitLength(); + + var r = sjcl.bn.fromBits(w.bitSlice(rs,0,l)), + s = sjcl.bn.fromBits(w.bitSlice(rs,l,2*l)); + + // For a canonical signature we want the lower of two possible values for s + // 0 < s <= n/2 + if (!R.copy().halveM().greaterEquals(s)) { + s = R.sub(s); + } + + return w.concat(r.toBits(l), s.toBits(l)); +}; + + sjcl.ecc.ecdsa.secretKey.prototype.signDER = function(hash, paranoia) { return this.encodeDER(this.sign(hash, paranoia)); };