Skip to content

Commit 6048941

Browse files
committedNov 22, 2019
6.5.2
1 parent 9984964 commit 6048941

File tree

4 files changed

+26
-25
lines changed

4 files changed

+26
-25
lines changed
 

‎dist/elliptic.js

+19-18
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ function BaseCurve(type, conf) {
4444
this._wnafT3 = new Array(4);
4545
this._wnafT4 = new Array(4);
4646

47+
this._bitLength = this.n ? this.n.bitLength() : 0;
48+
4749
// Generalized Greg Maxwell's trick
4850
var adjustCount = this.n && this.p.div(this.n);
4951
if (!adjustCount || adjustCount.cmpn(100) > 0) {
@@ -67,7 +69,7 @@ BaseCurve.prototype._fixedNafMul = function _fixedNafMul(p, k) {
6769
assert(p.precomputed);
6870
var doubles = p._getDoubles();
6971

70-
var naf = getNAF(k, 1);
72+
var naf = getNAF(k, 1, this._bitLength);
7173
var I = (1 << (doubles.step + 1)) - (doubles.step % 2 === 0 ? 2 : 1);
7274
I /= 3;
7375

@@ -104,7 +106,7 @@ BaseCurve.prototype._wnafMul = function _wnafMul(p, k) {
104106
var wnd = nafPoints.points;
105107

106108
// Get NAF form
107-
var naf = getNAF(k, w);
109+
var naf = getNAF(k, w, this._bitLength);
108110

109111
// Add `this`*(N+1) for every w-NAF index
110112
var acc = this.jpoint(null, null, null);
@@ -160,8 +162,8 @@ BaseCurve.prototype._wnafMulAdd = function _wnafMulAdd(defW,
160162
var a = i - 1;
161163
var b = i;
162164
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);
165167
max = Math.max(naf[a].length, max);
166168
max = Math.max(naf[b].length, max);
167169
continue;
@@ -3740,14 +3742,17 @@ utils.toHex = minUtils.toHex;
37403742
utils.encode = minUtils.encode;
37413743

37423744
// 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+
37453749
var ws = 1 << (w + 1);
37463750
var k = num.clone();
3747-
while (k.cmpn(1) >= 0) {
3751+
3752+
for (var i = 0; i < naf.length; i++) {
37483753
var z;
3754+
var mod = k.andln(ws - 1);
37493755
if (k.isOdd()) {
3750-
var mod = k.andln(ws - 1);
37513756
if (mod > (ws >> 1) - 1)
37523757
z = (ws >> 1) - mod;
37533758
else
@@ -3756,13 +3761,9 @@ function getNAF(num, w) {
37563761
} else {
37573762
z = 0;
37583763
}
3759-
naf.push(z);
37603764

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);
37663767
}
37673768

37683769
return naf;
@@ -8797,7 +8798,7 @@ utils.encode = function encode(arr, enc) {
87978798
},{}],35:[function(require,module,exports){
87988799
module.exports={
87998800
"name": "elliptic",
8800-
"version": "6.5.1",
8801+
"version": "6.5.2",
88018802
"description": "EC cryptography",
88028803
"main": "lib/elliptic.js",
88038804
"files": [
@@ -8829,7 +8830,7 @@ module.exports={
88298830
"homepage": "https://github.com/indutny/elliptic",
88308831
"devDependencies": {
88318832
"brfs": "^1.4.3",
8832-
"coveralls": "^3.0.4",
8833+
"coveralls": "^3.0.8",
88338834
"grunt": "^1.0.4",
88348835
"grunt-browserify": "^5.0.0",
88358836
"grunt-cli": "^1.2.0",
@@ -8840,8 +8841,8 @@ module.exports={
88408841
"grunt-saucelabs": "^9.0.1",
88418842
"istanbul": "^0.4.2",
88428843
"jscs": "^3.0.7",
8843-
"jshint": "^2.6.0",
8844-
"mocha": "^6.1.4"
8844+
"jshint": "^2.10.3",
8845+
"mocha": "^6.2.2"
88458846
},
88468847
"dependencies": {
88478848
"bn.js": "^4.4.0",

‎dist/elliptic.min.js

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "elliptic",
3-
"version": "6.5.1",
3+
"version": "6.5.2",
44
"description": "EC cryptography",
55
"main": "lib/elliptic.js",
66
"files": [

0 commit comments

Comments
 (0)