@@ -44,6 +44,8 @@ function BaseCurve(type, conf) {
44
44
this . _wnafT3 = new Array ( 4 ) ;
45
45
this . _wnafT4 = new Array ( 4 ) ;
46
46
47
+ this . _bitLength = this . n ? this . n . bitLength ( ) : 0 ;
48
+
47
49
// Generalized Greg Maxwell's trick
48
50
var adjustCount = this . n && this . p . div ( this . n ) ;
49
51
if ( ! adjustCount || adjustCount . cmpn ( 100 ) > 0 ) {
@@ -67,7 +69,7 @@ BaseCurve.prototype._fixedNafMul = function _fixedNafMul(p, k) {
67
69
assert ( p . precomputed ) ;
68
70
var doubles = p . _getDoubles ( ) ;
69
71
70
- var naf = getNAF ( k , 1 ) ;
72
+ var naf = getNAF ( k , 1 , this . _bitLength ) ;
71
73
var I = ( 1 << ( doubles . step + 1 ) ) - ( doubles . step % 2 === 0 ? 2 : 1 ) ;
72
74
I /= 3 ;
73
75
@@ -104,7 +106,7 @@ BaseCurve.prototype._wnafMul = function _wnafMul(p, k) {
104
106
var wnd = nafPoints . points ;
105
107
106
108
// Get NAF form
107
- var naf = getNAF ( k , w ) ;
109
+ var naf = getNAF ( k , w , this . _bitLength ) ;
108
110
109
111
// Add `this`*(N+1) for every w-NAF index
110
112
var acc = this . jpoint ( null , null , null ) ;
@@ -160,8 +162,8 @@ BaseCurve.prototype._wnafMulAdd = function _wnafMulAdd(defW,
160
162
var a = i - 1 ;
161
163
var b = i ;
162
164
if ( wndWidth [ a ] !== 1 || wndWidth [ b ] !== 1 ) {
163
- naf [ a ] = getNAF ( coeffs [ a ] , wndWidth [ a ] ) ;
164
- naf [ b ] = getNAF ( coeffs [ b ] , wndWidth [ b ] ) ;
165
+ naf [ a ] = getNAF ( coeffs [ a ] , wndWidth [ a ] , this . _bitLength ) ;
166
+ naf [ b ] = getNAF ( coeffs [ b ] , wndWidth [ b ] , this . _bitLength ) ;
165
167
max = Math . max ( naf [ a ] . length , max ) ;
166
168
max = Math . max ( naf [ b ] . length , max ) ;
167
169
continue ;
@@ -3740,14 +3742,17 @@ utils.toHex = minUtils.toHex;
3740
3742
utils . encode = minUtils . encode ;
3741
3743
3742
3744
// Represent num in a w-NAF form
3743
- function getNAF ( num , w ) {
3744
- var naf = [ ] ;
3745
+ function getNAF ( num , w , bits ) {
3746
+ var naf = new Array ( Math . max ( num . bitLength ( ) , bits ) + 1 ) ;
3747
+ naf . fill ( 0 ) ;
3748
+
3745
3749
var ws = 1 << ( w + 1 ) ;
3746
3750
var k = num . clone ( ) ;
3747
- while ( k . cmpn ( 1 ) >= 0 ) {
3751
+
3752
+ for ( var i = 0 ; i < naf . length ; i ++ ) {
3748
3753
var z ;
3754
+ var mod = k . andln ( ws - 1 ) ;
3749
3755
if ( k . isOdd ( ) ) {
3750
- var mod = k . andln ( ws - 1 ) ;
3751
3756
if ( mod > ( ws >> 1 ) - 1 )
3752
3757
z = ( ws >> 1 ) - mod ;
3753
3758
else
@@ -3756,13 +3761,9 @@ function getNAF(num, w) {
3756
3761
} else {
3757
3762
z = 0 ;
3758
3763
}
3759
- naf . push ( z ) ;
3760
3764
3761
- // Optimization, shift by word if possible
3762
- var shift = ( k . cmpn ( 0 ) !== 0 && k . andln ( ws - 1 ) === 0 ) ? ( w + 1 ) : 1 ;
3763
- for ( var i = 1 ; i < shift ; i ++ )
3764
- naf . push ( 0 ) ;
3765
- k . iushrn ( shift ) ;
3765
+ naf [ i ] = z ;
3766
+ k . iushrn ( 1 ) ;
3766
3767
}
3767
3768
3768
3769
return naf ;
@@ -8797,7 +8798,7 @@ utils.encode = function encode(arr, enc) {
8797
8798
} , { } ] , 35 :[ function ( require , module , exports ) {
8798
8799
module . exports = {
8799
8800
"name" : "elliptic" ,
8800
- "version" : "6.5.1 " ,
8801
+ "version" : "6.5.2 " ,
8801
8802
"description" : "EC cryptography" ,
8802
8803
"main" : "lib/elliptic.js" ,
8803
8804
"files" : [
@@ -8829,7 +8830,7 @@ module.exports={
8829
8830
"homepage" : "https://github.com/indutny/elliptic" ,
8830
8831
"devDependencies" : {
8831
8832
"brfs" : "^1.4.3" ,
8832
- "coveralls" : "^3.0.4 " ,
8833
+ "coveralls" : "^3.0.8 " ,
8833
8834
"grunt" : "^1.0.4" ,
8834
8835
"grunt-browserify" : "^5.0.0" ,
8835
8836
"grunt-cli" : "^1.2.0" ,
@@ -8840,8 +8841,8 @@ module.exports={
8840
8841
"grunt-saucelabs" : "^9.0.1" ,
8841
8842
"istanbul" : "^0.4.2" ,
8842
8843
"jscs" : "^3.0.7" ,
8843
- "jshint" : "^2.6.0 " ,
8844
- "mocha" : "^6.1.4 "
8844
+ "jshint" : "^2.10.3 " ,
8845
+ "mocha" : "^6.2.2 "
8845
8846
} ,
8846
8847
"dependencies" : {
8847
8848
"bn.js" : "^4.4.0" ,
0 commit comments