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

create Points with not only hex strings #200

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
18 changes: 9 additions & 9 deletions lib/elliptic/curve/edwards.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ EdwardsCurve.prototype.jpoint = function jpoint(x, y, z, t) {
return this.point(x, y, z, t);
};

EdwardsCurve.prototype.pointFromX = function pointFromX(x, odd) {
x = new BN(x, 16);
EdwardsCurve.prototype.pointFromX = function pointFromX(x, odd, base = 16) {
x = new BN(x, base);
if (!x.red)
x = x.toRed(this.red);

Expand All @@ -68,8 +68,8 @@ EdwardsCurve.prototype.pointFromX = function pointFromX(x, odd) {
return this.point(x, y);
};

EdwardsCurve.prototype.pointFromY = function pointFromY(y, odd) {
y = new BN(y, 16);
EdwardsCurve.prototype.pointFromY = function pointFromY(y, odd, base = 16) {
y = new BN(y, base);
if (!y.red)
y = y.toRed(this.red);

Expand Down Expand Up @@ -111,7 +111,7 @@ EdwardsCurve.prototype.validate = function validate(point) {
return lhs.cmp(rhs) === 0;
};

function Point(curve, x, y, z, t) {
function Point(curve, x, y, z, t, base = 16) {
Base.BasePoint.call(this, curve, 'projective');
if (x === null && y === null && z === null) {
this.x = this.curve.zero;
Expand All @@ -120,10 +120,10 @@ function Point(curve, x, y, z, t) {
this.t = this.curve.zero;
this.zOne = true;
} else {
this.x = new BN(x, 16);
this.y = new BN(y, 16);
this.z = z ? new BN(z, 16) : this.curve.one;
this.t = t && new BN(t, 16);
this.x = new BN(x, base);
this.y = new BN(y, base);
this.z = z ? new BN(z, base) : this.curve.one;
this.t = t && new BN(t, base);
if (!this.x.red)
this.x = this.x.toRed(this.curve.red);
if (!this.y.red)
Expand Down
6 changes: 3 additions & 3 deletions lib/elliptic/curve/mont.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ MontCurve.prototype.validate = function validate(point) {
return y.redSqr().cmp(rhs) === 0;
};

function Point(curve, x, z) {
function Point(curve, x, z, base = 16) {
Base.BasePoint.call(this, curve, 'projective');
if (x === null && z === null) {
this.x = this.curve.one;
this.z = this.curve.zero;
} else {
this.x = new BN(x, 16);
this.z = new BN(z, 16);
this.x = new BN(x, base);
this.z = new BN(z, base);
if (!this.x.red)
this.x = this.x.toRed(this.curve.red);
if (!this.z.red)
Expand Down
22 changes: 11 additions & 11 deletions lib/elliptic/curve/short.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ ShortCurve.prototype._endoSplit = function _endoSplit(k) {
return { k1: k1, k2: k2 };
};

ShortCurve.prototype.pointFromX = function pointFromX(x, odd) {
x = new BN(x, 16);
ShortCurve.prototype.pointFromX = function pointFromX(x, odd, base = 16) {
x = new BN(x, base);
if (!x.red)
x = x.toRed(this.red);

Expand Down Expand Up @@ -248,15 +248,15 @@ ShortCurve.prototype._endoWnafMulAdd =
return res;
};

function Point(curve, x, y, isRed) {
function Point(curve, x, y, isRed, base = 16) {
Base.BasePoint.call(this, curve, 'affine');
if (x === null && y === null) {
this.x = null;
this.y = null;
this.inf = true;
} else {
this.x = new BN(x, 16);
this.y = new BN(y, 16);
this.x = new BN(x, base);
this.y = new BN(y, base);
// Force redgomery representation when loading from JSON
if (isRed) {
this.x.forceRed(this.curve.red);
Expand Down Expand Up @@ -419,8 +419,8 @@ Point.prototype.getY = function getY() {
return this.y.fromRed();
};

Point.prototype.mul = function mul(k) {
k = new BN(k, 16);
Point.prototype.mul = function mul(k, base = 16) {
k = new BN(k, base);
if (this.isInfinity())
return this;
else if (this._hasDoubles(k))
Expand Down Expand Up @@ -487,16 +487,16 @@ Point.prototype.toJ = function toJ() {
return res;
};

function JPoint(curve, x, y, z) {
function JPoint(curve, x, y, z, base = 16) {
Base.BasePoint.call(this, curve, 'jacobian');
if (x === null && y === null && z === null) {
this.x = this.curve.one;
this.y = this.curve.one;
this.z = new BN(0);
} else {
this.x = new BN(x, 16);
this.y = new BN(y, 16);
this.z = new BN(z, 16);
this.x = new BN(x, base);
this.y = new BN(y, base);
this.z = new BN(z, base);
}
if (!this.x.red)
this.x = this.x.toRed(this.curve.red);
Expand Down