Skip to content

Commit

Permalink
lib: relint using eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny committed Aug 2, 2020
1 parent 8421a01 commit e71b2d9
Show file tree
Hide file tree
Showing 23 changed files with 6,283 additions and 7,080 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test/lib
68 changes: 68 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
module.exports = {
"env": {
"node": true,
"es6": true
},
"extends": [
"eslint:recommended",
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly",
"BigInt": "readonly",
},
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"rules": {
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
],
"array-bracket-spacing": [ "error", "always" ],
"brace-style": [ "error" ],
"camelcase": [ "error" ],
"comma-spacing": [ "error" ],
"comma-style": [ "error" ],
"eol-last": [ "error" ],
"func-call-spacing": [ "error" ],
"func-name-matching": [ "error" ],
"no-multiple-empty-lines": [ "error" ],
"no-tabs": [ "error" ],
"no-trailing-spaces": [ "error" ],
"no-whitespace-before-property": [ "error" ],
"object-curly-newline": [ "error" ],
"object-curly-spacing": [ "error", "always" ],
"padded-blocks": [ "error", "never" ],
"quotes": [ "error", "single", { "avoidEscape": true } ],
"semi-spacing": [ "error" ],
"semi-style": [ "error" ],
"space-before-blocks": [ "error" ],
"space-in-parens": [ "error" ],
"space-infix-ops": [ "error" ],
"space-unary-ops": [ "error" ],
"switch-colon-spacing": [ "error" ],
"comma-dangle": [ "error", "always-multiline" ],
},
"settings": {
"react": {
"version": "detect",
},
}
};
46 changes: 0 additions & 46 deletions .jscsrc

This file was deleted.

89 changes: 0 additions & 89 deletions .jshintrc

This file was deleted.

65 changes: 35 additions & 30 deletions lib/elliptic/curve/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,20 @@ BaseCurve.prototype._fixedNafMul = function _fixedNafMul(p, k) {

// Translate into more windowed form
var repr = [];
for (var j = 0; j < naf.length; j += doubles.step) {
var nafW = 0;
for (var k = j + doubles.step - 1; k >= j; k--)
nafW = (nafW << 1) + naf[k];
var j;
var nafW;
for (j = 0; j < naf.length; j += doubles.step) {
nafW = 0;
for (var l = j + doubles.step - 1; l >= j; l--)
nafW = (nafW << 1) + naf[l];
repr.push(nafW);
}

var a = this.jpoint(null, null, null);
var b = this.jpoint(null, null, null);
for (var i = I; i > 0; i--) {
for (var j = 0; j < repr.length; j++) {
var nafW = repr[j];
for (j = 0; j < repr.length; j++) {
nafW = repr[j];
if (nafW === i)
b = b.mixedAdd(doubles.points[j]);
else if (nafW === -i)
Expand All @@ -96,11 +98,11 @@ BaseCurve.prototype._wnafMul = function _wnafMul(p, k) {
var acc = this.jpoint(null, null, null);
for (var i = naf.length - 1; i >= 0; i--) {
// Count zeroes
for (var k = 0; i >= 0 && naf[i] === 0; i--)
k++;
for (var l = 0; i >= 0 && naf[i] === 0; i--)
l++;
if (i >= 0)
k++;
acc = acc.dblp(k);
l++;
acc = acc.dblp(l);

if (i < 0)
break;
Expand All @@ -124,25 +126,28 @@ BaseCurve.prototype._wnafMul = function _wnafMul(p, k) {
};

BaseCurve.prototype._wnafMulAdd = function _wnafMulAdd(defW,
points,
coeffs,
len,
jacobianResult) {
points,
coeffs,
len,
jacobianResult) {
var wndWidth = this._wnafT1;
var wnd = this._wnafT2;
var naf = this._wnafT3;

// Fill all arrays
var max = 0;
for (var i = 0; i < len; i++) {
var p = points[i];
var i;
var j;
var p;
for (i = 0; i < len; i++) {
p = points[i];
var nafPoints = p._getNAFPoints(defW);
wndWidth[i] = nafPoints.wnd;
wnd[i] = nafPoints.points;
}

// Comb small window NAFs
for (var i = len - 1; i >= 1; i -= 2) {
for (i = len - 1; i >= 1; i -= 2) {
var a = i - 1;
var b = i;
if (wndWidth[a] !== 1 || wndWidth[b] !== 1) {
Expand All @@ -157,7 +162,7 @@ BaseCurve.prototype._wnafMulAdd = function _wnafMulAdd(defW,
points[a], /* 1 */
null, /* 3 */
null, /* 5 */
points[b] /* 7 */
points[b], /* 7 */
];

// Try to avoid Projective points, if possible
Expand All @@ -181,14 +186,14 @@ BaseCurve.prototype._wnafMulAdd = function _wnafMulAdd(defW,
7, /* 0 1 */
5, /* 1 -1 */
1, /* 1 0 */
3 /* 1 1 */
3, /* 1 1 */
];

var jsf = getJSF(coeffs[a], coeffs[b]);
max = Math.max(jsf[0].length, max);
naf[a] = new Array(max);
naf[b] = new Array(max);
for (var j = 0; j < max; j++) {
for (j = 0; j < max; j++) {
var ja = jsf[0][j] | 0;
var jb = jsf[1][j] | 0;

Expand All @@ -200,12 +205,12 @@ BaseCurve.prototype._wnafMulAdd = function _wnafMulAdd(defW,

var acc = this.jpoint(null, null, null);
var tmp = this._wnafT4;
for (var i = max; i >= 0; i--) {
for (i = max; i >= 0; i--) {
var k = 0;

while (i >= 0) {
var zero = true;
for (var j = 0; j < len; j++) {
for (j = 0; j < len; j++) {
tmp[j] = naf[j][i] | 0;
if (tmp[j] !== 0)
zero = false;
Expand All @@ -221,9 +226,9 @@ BaseCurve.prototype._wnafMulAdd = function _wnafMulAdd(defW,
if (i < 0)
break;

for (var j = 0; j < len; j++) {
for (j = 0; j < len; j++) {
var z = tmp[j];
var p;
p;
if (z === 0)
continue;
else if (z > 0)
Expand All @@ -238,7 +243,7 @@ BaseCurve.prototype._wnafMulAdd = function _wnafMulAdd(defW,
}
}
// Zeroify references
for (var i = 0; i < len; i++)
for (i = 0; i < len; i++)
wnd[i] = null;

if (jacobianResult)
Expand Down Expand Up @@ -276,7 +281,7 @@ BaseCurve.prototype.decodePoint = function decodePoint(bytes, enc) {
assert(bytes[bytes.length - 1] % 2 === 1);

var res = this.point(bytes.slice(1, 1 + len),
bytes.slice(1 + len, 1 + 2 * len));
bytes.slice(1 + len, 1 + 2 * len));

return res;
} else if ((bytes[0] === 0x02 || bytes[0] === 0x03) &&
Expand All @@ -297,7 +302,7 @@ BasePoint.prototype._encode = function _encode(compact) {
if (compact)
return [ this.getY().isEven() ? 0x02 : 0x03 ].concat(x);

return [ 0x04 ].concat(x, this.getY().toArray('be', len)) ;
return [ 0x04 ].concat(x, this.getY().toArray('be', len));
};

BasePoint.prototype.encode = function encode(enc, compact) {
Expand All @@ -311,7 +316,7 @@ BasePoint.prototype.precompute = function precompute(power) {
var precomputed = {
doubles: null,
naf: null,
beta: null
beta: null,
};
precomputed.naf = this._getNAFPoints(8);
precomputed.doubles = this._getDoubles(4, power);
Expand Down Expand Up @@ -345,7 +350,7 @@ BasePoint.prototype._getDoubles = function _getDoubles(step, power) {
}
return {
step: step,
points: doubles
points: doubles,
};
};

Expand All @@ -360,7 +365,7 @@ BasePoint.prototype._getNAFPoints = function _getNAFPoints(wnd) {
res[i] = res[i - 1].add(dbl);
return {
wnd: wnd,
points: res
points: res,
};
};

Expand Down
Loading

0 comments on commit e71b2d9

Please sign in to comment.