From 8785692dcbcce7bcacc18da80dee041e33827990 Mon Sep 17 00:00:00 2001 From: Mateus Xavier Date: Wed, 31 Aug 2022 17:34:16 -0300 Subject: [PATCH] Fix unset variables according to @giogiannichi --- CHANGELOG.md | 2 ++ ellipticcurve/math.js | 26 +++++++++++++------------- ellipticcurve/utils/der.js | 21 ++++++++++----------- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44e84c7..ba18b96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ Given a version number MAJOR.MINOR.PATCH, increment: ## [Unreleased] +### Fixed +unset variables on math and der files ## [1.1.4] - 2021-11-09 ### Fixed diff --git a/ellipticcurve/math.js b/ellipticcurve/math.js index 9775f0c..a85fe7d 100644 --- a/ellipticcurve/math.js +++ b/ellipticcurve/math.js @@ -81,7 +81,7 @@ var fromJacobian = function (p, P) { // :param P: Prime number in the module of the equation Y^2 = X^3 + A*X + B (mod p) // :return: Point in default coordinates - z = inv(p.z, P); + var z = inv(p.z, P); var point = new Point( modulo(p.x.multiply(z.pow(2)), P), @@ -130,10 +130,10 @@ var jacobianAdd = function (p, q, A, P) { return p; }; - U1 = modulo(p.x.multiply(q.z.pow(2)), P); - U2 = modulo(q.x.multiply(p.z.pow(2)), P); - S1 = modulo(p.y.multiply(q.z.pow(3)), P); - S2 = modulo(q.y.multiply(p.z.pow(3)), P); + let U1 = modulo(p.x.multiply(q.z.pow(2)), P); + let U2 = modulo(q.x.multiply(p.z.pow(2)), P); + let S1 = modulo(p.y.multiply(q.z.pow(3)), P); + let S2 = modulo(q.y.multiply(p.z.pow(3)), P); if (U1.eq(U2)) { if (S1.neq(S2)) { @@ -142,14 +142,14 @@ var jacobianAdd = function (p, q, A, P) { return jacobianDouble(p, A, P); }; - H = U2.minus(U1); - R = S2.minus(S1); - H2 = modulo((H.multiply(H)), P); - H3 = modulo((H.multiply(H2)), P); - U1H2 = modulo((U1.multiply(H2)), P); - nx = modulo(((R.pow(2)).minus(H3).minus(U1H2.multiply(2))), P); - ny = modulo((R.multiply(U1H2.minus(nx)).minus(S1.multiply(H3))), P); - nz = modulo((H.multiply(p.z).multiply(q.z)), P); + let H = U2.minus(U1); + let R = S2.minus(S1); + let H2 = modulo((H.multiply(H)), P); + let H3 = modulo((H.multiply(H2)), P); + let U1H2 = modulo((U1.multiply(H2)), P); + let nx = modulo(((R.pow(2)).minus(H3).minus(U1H2.multiply(2))), P); + let ny = modulo((R.multiply(U1H2.minus(nx)).minus(S1.multiply(H3))), P); + let nz = modulo((H.multiply(p.z).multiply(q.z)), P); return new Point(nx, ny, nz); }; diff --git a/ellipticcurve/utils/der.js b/ellipticcurve/utils/der.js index 9171cdb..284021e 100644 --- a/ellipticcurve/utils/der.js +++ b/ellipticcurve/utils/der.js @@ -27,7 +27,7 @@ const bytesHexF = Buffer.from(hexF).toString('binary'); exports.encodeSequence = function () { let sequence = []; let totalLengthLen = 0; - for (i=0; i < arguments.length; i++) { + for (let i = 0; i < arguments.length; i++) { sequence.push(arguments[i]); totalLengthLen += arguments[i].length; } @@ -105,7 +105,7 @@ exports.removeSequence = function (string) { let length = result[0]; let lengthLen = result[1]; - endSeq = 1 + lengthLen + length; + let endSeq = 1 + lengthLen + length; return [string.slice(1 + lengthLen, endSeq), string.slice(endSeq)]; } @@ -185,20 +185,20 @@ exports.removeOctetString = function (string) { let length = result[0]; let lengthLen = result[1]; - body = string.slice(1 + lengthLen, 1 + lengthLen + length); - rest = string.slice(1 + lengthLen + length); + let body = string.slice(1 + lengthLen, 1 + lengthLen + length); + let rest = string.slice(1 + lengthLen + length); return [body, rest]; } exports.removeConstructed = function (string) { - s0 = _extractFirstInt(string); + let s0 = _extractFirstInt(string); if ((s0 & hex224) != hex129) { throw new Error("wanted constructed tag (0xa0-0xbf), got 0x" + s0); } - tag = s0 & hex31 + let tag = s0 & hex31 let result = _readLength(string.slice(1)); let length = result[0]; let lengthLen = result[1]; @@ -214,8 +214,7 @@ exports.fromPem = function (pem) { let split = pem.split("\n"); let stripped = ""; - let i; - for (i = 0; i < split.length; i++) { + for (let i = 0; i < split.length; i++) { if (!split[i].startsWith("-----")) { stripped += split[i].trim(); } @@ -227,9 +226,9 @@ exports.fromPem = function (pem) { exports.toPem = function (der, name) { let b64 = Base64.encode(der); - lines = [("-----BEGIN " + name + "-----\n")]; + let lines = [("-----BEGIN " + name + "-----\n")]; - for (start = 0; start <= b64.length; start += 64) { + for (let start = 0; start <= b64.length; start += 64) { lines.push(b64.slice(start, start + 64) + "\n") } lines.push("-----END " + name + "-----\n"); @@ -281,7 +280,7 @@ function _encodeNumber (n) { function _readLength (string) { - num = _extractFirstInt(string); + let num = _extractFirstInt(string); if (!(num & hex160)) { return [(num & hex127), 1]; }