From 4f316afb56efb1d331d7defa0b673d68a7b518b1 Mon Sep 17 00:00:00 2001 From: Mike Hamburg Date: Thu, 7 Oct 2010 21:10:46 -0700 Subject: [PATCH] ecdh, ecdsa tests --- core/bn.js | 4 ++-- core/ecc.js | 6 +++--- sjcl.js | 8 ++++---- test/ecdh_test.js | 15 +++++++++++++++ test/ecdsa_test.js | 29 +++++++++++++++++++++++++++++ test/run_tests_browser.js | 4 +++- 6 files changed, 56 insertions(+), 10 deletions(-) create mode 100644 test/ecdh_test.js create mode 100644 test/ecdsa_test.js diff --git a/core/bn.js b/core/bn.js index d7b9d169..7d5dc310 100644 --- a/core/bn.js +++ b/core/bn.js @@ -318,8 +318,8 @@ sjcl.bn.prototype = { toBits: function(len) { this.fullReduce(); len = len || this.exponent || this.limbs.length * this.radix; - var i = Math.floor((len-1)/24), w=sjcl.bitArray, e = (len + 7 & -8) % this.radix || this.radix; - out = [w.partial(e, this.getLimb(i))]; + var i = Math.floor((len-1)/24), w=sjcl.bitArray, e = (len + 7 & -8) % this.radix || this.radix, + out = [w.partial(e, this.getLimb(i))]; for (i--; i >= 0; i--) { out = w.concat(out, [w.partial(this.radix, this.getLimb(i))]); } diff --git a/core/ecc.js b/core/ecc.js index 9e456d03..f392608b 100644 --- a/core/ecc.js +++ b/core/ecc.js @@ -346,9 +346,9 @@ sjcl.ecc.elGamal.secretKey.prototype = { } }; -sjcl.ecc._dh("dsa"); +sjcl.ecc._dh("ecdsa"); -sjcl.ecc.dsa.secretKey.prototype = { +sjcl.ecc.ecdsa.secretKey.prototype = { sign: function(hash, paranoia) { var R = this._curve.r, l = R.bitLength(), @@ -359,7 +359,7 @@ sjcl.ecc.dsa.secretKey.prototype = { } }; -sjcl.ecc.dsa.publicKey.prototype = { +sjcl.ecc.ecdsa.publicKey.prototype = { verify: function(hash, rs) { var w = sjcl.bitArray, R = this._curve.r, diff --git a/sjcl.js b/sjcl.js index 6141fbfa..239515b4 100644 --- a/sjcl.js +++ b/sjcl.js @@ -44,7 +44,7 @@ d[b].toString(16);b=0;b--)out=c.concat(out,[c.partial(this.radix,this.getLimb(b))]);return out},bitLength:function(){this.fullReduce();for(var a=this.radix*(this.limbs.length-1),b=this.limbs[this.limbs.length- +0,b,c=this.ipv,d,e=this.limbs,f=e.length,g=this.radixMask;for(b=0;b=0;b--)a=c.concat(a,[c.partial(this.radix,this.getLimb(b))]);return a},bitLength:function(){this.fullReduce();for(var a=this.radix*(this.limbs.length-1),b=this.limbs[this.limbs.length- 1];b;b>>=1)a++;return a+7&-8}};sjcl.bn.fromBits=function(a){var b=new this,c=[],d=sjcl.bitArray,e=this.prototype,f=Math.min(this.bitLength||0x100000000,d.bitLength(a)),g=f%e.radix||e.radix;for(c[0]=d.extract(a,0,g);gn;){j=l.pop();r=l.length;for(h=0;h