Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unset variables #23

Merged
merged 1 commit into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions ellipticcurve/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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)) {
Expand All @@ -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);
};
Expand Down
21 changes: 10 additions & 11 deletions ellipticcurve/utils/der.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)];
}
Expand Down Expand Up @@ -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];
Expand All @@ -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();
}
Expand All @@ -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");
Expand Down Expand Up @@ -281,7 +280,7 @@ function _encodeNumber (n) {


function _readLength (string) {
num = _extractFirstInt(string);
let num = _extractFirstInt(string);
if (!(num & hex160)) {
return [(num & hex127), 1];
}
Expand Down