Update packages, add lint script, remove useless eslint-plugins

This commit is contained in:
BafS 2018-02-13 23:30:39 +01:00
parent b672f1936a
commit a53f2b3780
4 changed files with 115 additions and 102 deletions

View File

@ -29,7 +29,8 @@
], ],
"scripts": { "scripts": {
"pretest": "grunt", "pretest": "grunt",
"test": "grunt test" "test": "grunt test",
"lint": "eslint src"
}, },
"devDependencies": { "devDependencies": {
"babel-core": "^6.26.0", "babel-core": "^6.26.0",
@ -47,12 +48,10 @@
"chai": "^4.1.2", "chai": "^4.1.2",
"chai-as-promised": "^7.1.1", "chai-as-promised": "^7.1.1",
"core-js": "^2.5.3", "core-js": "^2.5.3",
"eslint": "^4.16.0", "eslint": "^4.17.0",
"eslint-config-airbnb": "^16.1.0", "eslint-config-airbnb": "^16.1.0",
"eslint-config-airbnb-base": "^12.1.0", "eslint-config-airbnb-base": "^12.1.0",
"eslint-plugin-import": "^2.8.0", "eslint-plugin-import": "^2.8.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.6.1",
"grunt": "~1.0.1", "grunt": "~1.0.1",
"grunt-browserify": "~5.2.0", "grunt-browserify": "~5.2.0",
"grunt-contrib-clean": "~1.1.0", "grunt-contrib-clean": "~1.1.0",
@ -69,17 +68,17 @@
"grunt-text-replace": "~0.4.0", "grunt-text-replace": "~0.4.0",
"gruntify-eslint": "^4.0.0", "gruntify-eslint": "^4.0.0",
"istanbul": "^0.4.5", "istanbul": "^0.4.5",
"mocha": "^4.1.0", "mocha": "^5.0.0",
"sinon": "^4.2.2", "sinon": "^4.3.0",
"whatwg-fetch": "^2.0.3", "whatwg-fetch": "^2.0.3",
"zlibjs": "~0.3.1" "zlibjs": "~0.3.1"
}, },
"dependencies": { "dependencies": {
"asmcrypto-lite": "git+https://github.com/openpgpjs/asmcrypto-lite.git", "asmcrypto-lite": "github:openpgpjs/asmcrypto-lite",
"asn1.js": "^5.0.0", "asn1.js": "^5.0.0",
"bn.js": "^4.11.8", "bn.js": "^4.11.8",
"buffer": "^5.0.8", "buffer": "^5.0.8",
"elliptic": "git+https://github.com/openpgpjs/elliptic.git", "elliptic": "github:openpgpjs/elliptic.git",
"jwk-to-pem": "^1.2.6", "jwk-to-pem": "^1.2.6",
"node-fetch": "^1.7.3", "node-fetch": "^1.7.3",
"node-localstorage": "~1.3.0", "node-localstorage": "~1.3.0",

View File

@ -22,6 +22,8 @@
* @module crypto/cipher/twofish * @module crypto/cipher/twofish
*/ */
/* eslint-disable no-mixed-operators */
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Math //Math
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -132,7 +132,7 @@ function hex2binb(str) {
for (let i = 0; i < length; i += 2) { for (let i = 0; i < length; i += 2) {
num = parseInt(str.substr(i, 2), 16); num = parseInt(str.substr(i, 2), 16);
if (!isNaN(num)) { if (!Number.isNaN(num)) {
offset = i >>> 3; offset = i >>> 3;
while (bin.length <= offset) { while (bin.length <= offset) {
bin.push(0); bin.push(0);
@ -216,14 +216,13 @@ function b642binb(str) {
let j; let j;
let tmpInt; let tmpInt;
let strPart; let strPart;
let firstEqual;
let offset; let offset;
const b64Tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; const b64Tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
if (str.search(/^[a-zA-Z0-9=+\/]+$/) === -1) { if (str.search(/^[a-zA-Z0-9=+\/]+$/) === -1) {
throw new Error('Invalid character in base-64 string'); throw new Error('Invalid character in base-64 string');
} }
firstEqual = str.indexOf('='); const firstEqual = str.indexOf('=');
str = str.replace(/\=/g, ''); str = str.replace(/\=/g, '');
if ((firstEqual !== -1) && (firstEqual < str.length)) { if ((firstEqual !== -1) && (firstEqual < str.length)) {
throw new Error('Invalid \'=\' found in base-64 string'); throw new Error('Invalid \'=\' found in base-64 string');
@ -472,7 +471,7 @@ function shr_64(x, n) {
if (n <= 32) { if (n <= 32) {
retVal = new Int_64( retVal = new Int_64(
x.highOrder >>> n, x.highOrder >>> n,
x.lowOrder >>> n | ((x.highOrder << (32 - n)) & 0xFFFFFFFF) (x.lowOrder >>> n) | ((x.highOrder << (32 - n)) & 0xFFFFFFFF)
); );
} else { } else {
retVal = new Int_64( retVal = new Int_64(
@ -1067,7 +1066,7 @@ function coreSHA2(message, messageLen, variant) {
]; ];
} }
} else { } else {
throw "Unexpected error in SHA-2 implementation"; throw new Error("Unexpected error in SHA-2 implementation");
} }
while (message.length <= lengthPosition) { while (message.length <= lengthPosition) {
@ -1148,7 +1147,7 @@ function coreSHA2(message, messageLen, variant) {
H[7].highOrder, H[7].lowOrder H[7].highOrder, H[7].lowOrder
]; ];
} else { /* This should never be reached */ } else { /* This should never be reached */
throw "Unexpected error in SHA-2 implementation"; throw new Error("Unexpected error in SHA-2 implementation");
} }
return retVal; return retVal;
@ -1239,7 +1238,7 @@ const jsSHA = function(srcString, inputFormat, encoding) {
} }
/* Validate the numRounds argument */ /* Validate the numRounds argument */
if ((numRounds !== parseInt(numRounds)) || (numRounds < 1)) { if ((numRounds !== parseInt(numRounds, 10)) || (numRounds < 1)) {
throw new Error('numRounds must a integer >= 1'); throw new Error('numRounds must a integer >= 1');
} }

View File

@ -31,6 +31,11 @@
* and disclaimer. * and disclaimer.
*/ */
/* eslint-disable no-mixed-operators */
/* eslint-disable no-eq-null */
/* eslint-disable eqeqeq */
/* eslint-disable no-cond-assign */
/* eslint-disable one-var */
/** /**
* @requires util * @requires util
@ -84,8 +89,8 @@ function am1(i, x, w, j, c, n) {
// on values up to 2*hdvalue^2-hdvalue-1 (< 2^31) // on values up to 2*hdvalue^2-hdvalue-1 (< 2^31)
function am2(i, x, w, j, c, n) { function am2(i, x, w, j, c, n) {
let xl = x & 0x7fff, const xl = x & 0x7fff;
xh = x >> 15; const xh = x >> 15;
while (--n >= 0) { while (--n >= 0) {
let l = this[i] & 0x7fff; let l = this[i] & 0x7fff;
const h = this[i++] >> 15; const h = this[i++] >> 15;
@ -100,8 +105,8 @@ function am2(i, x, w, j, c, n) {
// browsers slow down when dealing with 32-bit numbers. // browsers slow down when dealing with 32-bit numbers.
function am3(i, x, w, j, c, n) { function am3(i, x, w, j, c, n) {
let xl = x & 0x3fff, const xl = x & 0x3fff;
xh = x >> 14; const xh = x >> 14;
while (--n >= 0) { while (--n >= 0) {
let l = this[i] & 0x3fff; let l = this[i] & 0x3fff;
const h = this[i++] >> 14; const h = this[i++] >> 14;
@ -119,7 +124,7 @@ function am3(i, x, w, j, c, n) {
} }
else if(j_lm && (navigator != undefined && navigator.appName != "Netscape")) {*/ else if(j_lm && (navigator != undefined && navigator.appName != "Netscape")) {*/
BigInteger.prototype.am = am1; BigInteger.prototype.am = am1;
dbits = 26; dbits = 26; // eslint-disable-line
/*} /*}
else { // Mozilla/Netscape seems to prefer am3 else { // Mozilla/Netscape seems to prefer am3
BigInteger.prototype.am = am3; BigInteger.prototype.am = am3;
@ -131,14 +136,15 @@ BigInteger.prototype.DM = ((1 << dbits) - 1);
BigInteger.prototype.DV = (1 << dbits); BigInteger.prototype.DV = (1 << dbits);
const BI_FP = 52; const BI_FP = 52;
BigInteger.prototype.FV = Math.pow(2, BI_FP); BigInteger.prototype.FV = (2 ** BI_FP);
BigInteger.prototype.F1 = BI_FP - dbits; BigInteger.prototype.F1 = BI_FP - dbits;
BigInteger.prototype.F2 = 2 * dbits - BI_FP; BigInteger.prototype.F2 = 2 * dbits - BI_FP;
// Digit conversions // Digit conversions
const BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz"; const BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz";
const BI_RC = new Array(); const BI_RC = new Array();
let rr, vv; let rr;
let vv;
rr = "0".charCodeAt(0); rr = "0".charCodeAt(0);
for (vv = 0; vv <= 9; ++vv) BI_RC[rr++] = vv; for (vv = 0; vv <= 9; ++vv) BI_RC[rr++] = vv;
rr = "a".charCodeAt(0); rr = "a".charCodeAt(0);
@ -197,9 +203,9 @@ function bnpFromString(s, b) {
} }
this.t = 0; this.t = 0;
this.s = 0; this.s = 0;
let i = s.length, let i = s.length;
mi = false, let mi = false;
sh = 0; let sh = 0;
while (--i >= 0) { while (--i >= 0) {
const x = (k == 8) ? s[i] & 0xff : intAt(s, i); const x = (k == 8) ? s[i] & 0xff : intAt(s, i);
if (x < 0) { if (x < 0) {
@ -241,10 +247,11 @@ function bnToString(b) {
else if (b == 32) k = 5; else if (b == 32) k = 5;
else if (b == 4) k = 2; else if (b == 4) k = 2;
else return this.toRadix(b); else return this.toRadix(b);
let km = (1 << k) - 1, const km = (1 << k) - 1;
d, m = false, let d = false;
r = "", let m = false;
i = this.t; let r = "";
let i = this.t;
let p = this.DB - (i * this.DB) % k; let p = this.DB - (i * this.DB) % k;
if (i-- > 0) { if (i-- > 0) {
if (p < this.DB && (d = this[i] >> p) > 0) { if (p < this.DB && (d = this[i] >> p) > 0) {
@ -298,8 +305,8 @@ function bnCompareTo(a) {
// returns bit length of the integer x // returns bit length of the integer x
function nbits(x) { function nbits(x) {
let r = 1, let r = 1;
t; let t;
if ((t = x >>> 16) != 0) { if ((t = x >>> 16) != 0) {
x = t; x = t;
r += 16; r += 16;
@ -354,9 +361,9 @@ function bnpLShiftTo(n, r) {
const bs = n % this.DB; const bs = n % this.DB;
const cbs = this.DB - bs; const cbs = this.DB - bs;
const bm = (1 << cbs) - 1; const bm = (1 << cbs) - 1;
let ds = Math.floor(n / this.DB), const ds = Math.floor(n / this.DB);
c = (this.s << bs) & this.DM, let c = (this.s << bs) & this.DM;
i; let i;
for (i = this.t - 1; i >= 0; --i) { for (i = this.t - 1; i >= 0; --i) {
r[i + ds + 1] = (this[i] >> cbs) | c; r[i + ds + 1] = (this[i] >> cbs) | c;
c = (this[i] & bm) << bs; c = (this[i] & bm) << bs;
@ -393,9 +400,9 @@ function bnpRShiftTo(n, r) {
// (protected) r = this - a // (protected) r = this - a
function bnpSubTo(a, r) { function bnpSubTo(a, r) {
let i = 0, let i = 0;
c = 0, let c = 0;
m = Math.min(a.t, this.t); const m = Math.min(a.t, this.t);
while (i < m) { while (i < m) {
c += this[i] - a[i]; c += this[i] - a[i];
r[i++] = c & this.DM; r[i++] = c & this.DM;
@ -429,8 +436,8 @@ function bnpSubTo(a, r) {
// "this" should be the larger one if appropriate. // "this" should be the larger one if appropriate.
function bnpMultiplyTo(a, r) { function bnpMultiplyTo(a, r) {
let x = this.abs(), const x = this.abs();
y = a.abs(); const y = a.abs();
let i = x.t; let i = x.t;
r.t = i + y.t; r.t = i + y.t;
while (--i >= 0) r[i] = 0; while (--i >= 0) r[i] = 0;
@ -471,9 +478,9 @@ function bnpDivRemTo(m, q, r) {
return; return;
} }
if (r == null) r = nbi(); if (r == null) r = nbi();
let y = nbi(), const y = nbi();
ts = this.s, const ts = this.s;
ms = m.s; const ms = m.s;
const nsh = this.DB - nbits(pm[pm.t - 1]); // normalize modulus const nsh = this.DB - nbits(pm[pm.t - 1]); // normalize modulus
if (nsh > 0) { if (nsh > 0) {
pm.lShiftTo(nsh, y); pm.lShiftTo(nsh, y);
@ -486,12 +493,12 @@ function bnpDivRemTo(m, q, r) {
const y0 = y[ys - 1]; const y0 = y[ys - 1];
if (y0 == 0) return; if (y0 == 0) return;
const yt = y0 * (1 << this.F1) + ((ys > 1) ? y[ys - 2] >> this.F2 : 0); const yt = y0 * (1 << this.F1) + ((ys > 1) ? y[ys - 2] >> this.F2 : 0);
let d1 = this.FV / yt, const d1 = this.FV / yt;
d2 = (1 << this.F1) / yt, const d2 = (1 << this.F1) / yt;
e = 1 << this.F2; const e = 1 << this.F2;
let i = r.t, let i = r.t;
j = i - ys, let j = i - ys;
t = (q == null) ? nbi() : q; const t = (q == null) ? nbi() : q;
y.dlShiftTo(j, t); y.dlShiftTo(j, t);
if (r.compareTo(t) >= 0) { if (r.compareTo(t) >= 0) {
r[r.t++] = 1; r[r.t++] = 1;
@ -672,10 +679,10 @@ function bnpIsEven() {
function bnpExp(e, z) { function bnpExp(e, z) {
if (e > 0xffffffff || e < 1) return BigInteger.ONE; if (e > 0xffffffff || e < 1) return BigInteger.ONE;
let r = nbi(), let r = nbi();
r2 = nbi(), let r2 = nbi();
g = z.convert(this), const g = z.convert(this);
i = nbits(e) - 1; let i = nbits(e) - 1;
g.copyTo(r); g.copyTo(r);
while (--i >= 0) { while (--i >= 0) {
z.sqrTo(r, r2); z.sqrTo(r, r2);
@ -820,11 +827,11 @@ function bnpToRadix(b) {
if (b == null) b = 10; if (b == null) b = 10;
if (this.signum() == 0 || b < 2 || b > 36) return "0"; if (this.signum() == 0 || b < 2 || b > 36) return "0";
const cs = this.chunkSize(b); const cs = this.chunkSize(b);
const a = Math.pow(b, cs); const a = (b ** cs);
let d = nbv(a), const d = nbv(a);
y = nbi(), const y = nbi();
z = nbi(), const z = nbi();
r = ""; let r = "";
this.divRemTo(d, y, z); this.divRemTo(d, y, z);
while (y.signum() > 0) { while (y.signum() > 0) {
r = (a + z.intValue()).toString(b).substr(1) + r; r = (a + z.intValue()).toString(b).substr(1) + r;
@ -839,10 +846,10 @@ function bnpFromRadix(s, b) {
this.fromInt(0); this.fromInt(0);
if (b == null) b = 10; if (b == null) b = 10;
const cs = this.chunkSize(b); const cs = this.chunkSize(b);
let d = Math.pow(b, cs), const d = (b ** cs);
mi = false, let mi = false;
j = 0, let j = 0;
w = 0; let w = 0;
for (let i = 0; i < s.length; ++i) { for (let i = 0; i < s.length; ++i) {
const x = intAt(s, i); const x = intAt(s, i);
if (x < 0) { if (x < 0) {
@ -858,7 +865,7 @@ function bnpFromRadix(s, b) {
} }
} }
if (j > 0) { if (j > 0) {
this.dMultiply(Math.pow(b, j)); this.dMultiply((b ** j));
this.dAddOffset(w, 0); this.dAddOffset(w, 0);
} }
if (mi) BigInteger.ZERO.subTo(this, this); if (mi) BigInteger.ZERO.subTo(this, this);
@ -882,8 +889,8 @@ function bnpFromNumber(a, b, c) {
} }
} else { } else {
// new BigInteger(int,RNG) // new BigInteger(int,RNG)
let x = new Array(), const x = new Array();
t = a & 7; const t = a & 7;
x.length = (a >> 3) + 1; x.length = (a >> 3) + 1;
b.nextBytes(x); b.nextBytes(x);
if (t > 0) x[0] &= ((1 << t) - 1); if (t > 0) x[0] &= ((1 << t) - 1);
@ -895,11 +902,12 @@ function bnpFromNumber(a, b, c) {
// (public) convert to bigendian byte array // (public) convert to bigendian byte array
function bnToByteArray() { function bnToByteArray() {
let i = this.t, let i = this.t;
r = new Array(); const r = new Array();
r[0] = this.s; r[0] = this.s;
let p = this.DB - (i * this.DB) % 8, let p = this.DB - (i * this.DB) % 8;
d, k = 0; let d = 0;
let k = 0;
if (i-- > 0) { if (i-- > 0) {
if (p < this.DB && (d = this[i] >> p) != (this.s & this.DM) >> p) r[k++] = d | (this.s << (this.DB - p)); if (p < this.DB && (d = this[i] >> p) != (this.s & this.DM) >> p) r[k++] = d | (this.s << (this.DB - p));
while (i >= 0) { while (i >= 0) {
@ -936,7 +944,9 @@ function bnMax(a) {
// (protected) r = this op a (bitwise) // (protected) r = this op a (bitwise)
function bnpBitwiseTo(a, op, r) { function bnpBitwiseTo(a, op, r) {
let i, f, m = Math.min(a.t, this.t); let i = Math.min(a.t, this.t);
let f = i;
const m = i;
for (i = 0; i < m; ++i) r[i] = op(this[i], a[i]); for (i = 0; i < m; ++i) r[i] = op(this[i], a[i]);
if (a.t < this.t) { if (a.t < this.t) {
f = a.s & this.DM; f = a.s & this.DM;
@ -1074,8 +1084,8 @@ function cbit(x) {
// (public) return number of set bits // (public) return number of set bits
function bnBitCount() { function bnBitCount() {
let r = 0, let r = 0;
x = this.s & this.DM; const x = this.s & this.DM;
for (let i = 0; i < this.t; ++i) r += cbit(this[i] ^ x); for (let i = 0; i < this.t; ++i) r += cbit(this[i] ^ x);
return r; return r;
} }
@ -1117,9 +1127,9 @@ function bnFlipBit(n) {
// (protected) r = this + a // (protected) r = this + a
function bnpAddTo(a, r) { function bnpAddTo(a, r) {
let i = 0, let i = 0;
c = 0, let c = 0;
m = Math.min(a.t, this.t); const m = Math.min(a.t, this.t);
while (i < m) { while (i < m) {
c += this[i] + a[i]; c += this[i] + a[i];
r[i++] = c & this.DM; r[i++] = c & this.DM;
@ -1200,8 +1210,8 @@ function bnRemainder(a) {
// (public) [this/a,this%a] // (public) [this/a,this%a]
function bnDivideAndRemainder(a) { function bnDivideAndRemainder(a) {
let q = nbi(), const q = nbi();
r = nbi(); const r = nbi();
this.divRemTo(a, q, r); this.divRemTo(a, q, r);
return new Array(q, r); return new Array(q, r);
} }
@ -1345,9 +1355,9 @@ Barrett.prototype.sqrTo = barrettSqrTo;
// (public) this^e % m (HAC 14.85) // (public) this^e % m (HAC 14.85)
function bnModPow(e, m) { function bnModPow(e, m) {
let i = e.bitLength(), let i = e.bitLength();
k, r = nbv(1), let k, r = nbv(1);
z; let z;
if (i <= 0) return r; if (i <= 0) return r;
else if (i < 18) k = 1; else if (i < 18) k = 1;
else if (i < 48) k = 3; else if (i < 48) k = 3;
@ -1359,10 +1369,10 @@ function bnModPow(e, m) {
else z = new Montgomery(m); else z = new Montgomery(m);
// precomputation // precomputation
let g = new Array(), const g = new Array();
n = 3, let n = 3;
k1 = k - 1, const k1 = k - 1;
km = (1 << k) - 1; const km = (1 << k) - 1;
g[1] = z.convert(this); g[1] = z.convert(this);
if (k > 1) { if (k > 1) {
const g2 = nbi(); const g2 = nbi();
@ -1374,10 +1384,10 @@ function bnModPow(e, m) {
} }
} }
let j = e.t - 1, let j = e.t - 1;
w, is1 = true, let w, is1 = true;
r2 = nbi(), let r2 = nbi();
t; let t;
i = nbits(e[j]) - 1; i = nbits(e[j]) - 1;
while (j >= 0) { while (j >= 0) {
if (i >= k1) w = (e[j] >> (i - k1)) & km; if (i >= k1) w = (e[j] >> (i - k1)) & km;
@ -1464,8 +1474,8 @@ function bnGCD(a) {
function bnpModInt(n) { function bnpModInt(n) {
if (n <= 0) return 0; if (n <= 0) return 0;
let d = this.DV % n, const d = this.DV % n;
r = (this.s < 0) ? n - 1 : 0; let r = (this.s < 0) ? n - 1 : 0;
if (this.t > 0) { if (d == 0) r = this[0] % n; if (this.t > 0) { if (d == 0) r = this[0] % n;
else for (let i = this.t - 1; i >= 0; --i) r = (d * r + this[i]) % n; } else for (let i = this.t - 1; i >= 0; --i) r = (d * r + this[i]) % n; }
return r; return r;
@ -1476,12 +1486,12 @@ function bnpModInt(n) {
function bnModInverse(m) { function bnModInverse(m) {
const ac = m.isEven(); const ac = m.isEven();
if ((this.isEven() && ac) || m.signum() == 0) return BigInteger.ZERO; if ((this.isEven() && ac) || m.signum() == 0) return BigInteger.ZERO;
let u = m.clone(), const u = m.clone();
v = this.clone(); const v = this.clone();
let a = nbv(1), const a = nbv(1);
b = nbv(0), const b = nbv(0);
c = nbv(0), const c = nbv(0);
d = nbv(1); const d = nbv(1);
while (u.signum() != 0) { while (u.signum() != 0) {
while (u.isEven()) { while (u.isEven()) {
u.rShiftTo(1, u); u.rShiftTo(1, u);
@ -1536,7 +1546,8 @@ const lplim = (1 << 26) / lowprimes[lowprimes.length - 1];
// (public) test primality with certainty >= 1-.5^t // (public) test primality with certainty >= 1-.5^t
function bnIsProbablePrime(t) { function bnIsProbablePrime(t) {
let i, x = this.abs(); let i;
const x = this.abs();
if (x.t == 1 && x[0] <= lowprimes[lowprimes.length - 1]) { if (x.t == 1 && x[0] <= lowprimes[lowprimes.length - 1]) {
for (i = 0; i < lowprimes.length; ++i) if (x[0] == lowprimes[i]) return true; for (i = 0; i < lowprimes.length; ++i) if (x[0] == lowprimes[i]) return true;
return false; return false;
@ -1544,8 +1555,8 @@ function bnIsProbablePrime(t) {
if (x.isEven()) return false; if (x.isEven()) return false;
i = 1; i = 1;
while (i < lowprimes.length) { while (i < lowprimes.length) {
let m = lowprimes[i], let m = lowprimes[i];
j = i + 1; let j = i + 1;
while (j < lowprimes.length && m < lplim) m *= lowprimes[j++]; while (j < lowprimes.length && m < lplim) m *= lowprimes[j++];
m = x.modInt(m); m = x.modInt(m);
while (i < j) if (m % lowprimes[i++] == 0) return false; while (i < j) if (m % lowprimes[i++] == 0) return false;
@ -1555,9 +1566,10 @@ function bnIsProbablePrime(t) {
/* added by Recurity Labs */ /* added by Recurity Labs */
/* eslint-disable no-redeclare */
function nbits(x) { function nbits(x) {
let n = 1, let n = 1;
t; let t;
if ((t = x >>> 16) != 0) { if ((t = x >>> 16) != 0) {
x = t; x = t;
n += 16; n += 16;
@ -1601,7 +1613,8 @@ function bnpMillerRabin(t) {
t = (t + 1) >> 1; t = (t + 1) >> 1;
if (t > lowprimes.length) t = lowprimes.length; if (t > lowprimes.length) t = lowprimes.length;
const a = nbi(); const a = nbi();
var j, bases = []; let j;
const bases = [];
for (let i = 0; i < t; ++i) { for (let i = 0; i < t; ++i) {
//Pick bases at random, instead of starting at 2 //Pick bases at random, instead of starting at 2
for (;;) { for (;;) {
@ -1612,7 +1625,7 @@ function bnpMillerRabin(t) {
a.fromInt(j); a.fromInt(j);
let y = a.modPow(r, this); let y = a.modPow(r, this);
if (y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) { if (y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) {
var j = 1; let j = 1;
while (j++ < k && y.compareTo(n1) != 0) { while (j++ < k && y.compareTo(n1) != 0) {
y = y.modPowInt(2, this); y = y.modPowInt(2, this);
if (y.compareTo(BigInteger.ONE) == 0) return false; if (y.compareTo(BigInteger.ONE) == 0) return false;