Comparing version 4.0.0 to 4.1.0
@@ -2352,18 +2352,42 @@ (function (module, exports) { | ||
Red.prototype.pow = function pow(a, num) { | ||
var w = toBitArray(num); | ||
if (w.length === 0) | ||
if (num.cmpn(0) === 0) | ||
return new BN(1); | ||
if (num.cmpn(1) === 0) | ||
return a.clone(); | ||
// Skip leading zeroes | ||
var res = a; | ||
for (var i = 0; i < w.length; i++, res = this.sqr(res)) | ||
if (w[i] !== 0) | ||
break; | ||
var windowSize = 4; | ||
var wnd = new Array(1 << windowSize); | ||
wnd[0] = new BN(1).toRed(this); | ||
wnd[1] = a; | ||
for (var i = 2; i < wnd.length; i++) | ||
wnd[i] = this.mul(wnd[i - 1], a); | ||
if (++i < w.length) { | ||
for (var q = this.sqr(res); i < w.length; i++, q = this.sqr(q)) { | ||
if (w[i] === 0) | ||
var res = wnd[0]; | ||
var current = 0; | ||
var currentLen = 0; | ||
var start = num.bitLength() % 26; | ||
if (start === 0) | ||
start = 26; | ||
for (var i = num.words.length - 1; i >= 0; i--) { | ||
var word = num.words[i]; | ||
for (var j = start - 1; j >= 0; j--) { | ||
var bit = (word >> j) & 1; | ||
if (res !== wnd[0]) | ||
res = this.sqr(res); | ||
if (bit === 0 && current === 0) { | ||
currentLen = 0; | ||
continue; | ||
res = this.mul(res, q); | ||
} | ||
current <<= 1; | ||
current |= bit; | ||
currentLen++; | ||
if (currentLen !== windowSize && (i !== 0 || j !== 0)) | ||
continue; | ||
res = this.mul(res, wnd[current]); | ||
currentLen = 0; | ||
current = 0; | ||
} | ||
start = 26; | ||
} | ||
@@ -2370,0 +2394,0 @@ |
{ | ||
"name": "bn.js", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"description": "Big number implementation in pure javascript", | ||
@@ -5,0 +5,0 @@ "main": "lib/bn.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
122343
3286