8000 curves: optimize Maxwell's trick · etherscan-io/elliptic@e102a69 · GitHub
[go: up one dir, main page]

Skip to content

Commit e102a69

Browse files
committed
curves: optimize Maxwell's trick
1 parent 7b1c732 commit e102a69

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/elliptic/curve/edwards.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,13 @@ Point.prototype.eqXToP = function eqXToP(x) {
414414
if (this.x.cmp(rx) === 0)
415415
return true;
416416

417+
var xc = x.clone();
417418
var t = this.curve.redN.redMul(this.z);
418419
for (var i = 1; i <= this.curve._maxwellAdjust; i++) {
420+
xc.iadd(this.curve.n);
421+
if (xc.cmp(this.curve.p) >= 0)
422+
return false;
423+
419424
rx.redIAdd(t);
420425
if (this.x.cmp(rx) === 0)
421426
return true;

lib/elliptic/curve/short.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,8 +910,13 @@ JPoint.prototype.eqXToP = function eqXToP(x) {
910910
if (this.x.cmp(rx) === 0)
911911
return true;
912912

913+
var xc = x.clone();
913914
var t = this.curve.redN.redMul(zs);
914915
for (var i = 1; i <= this.curve._maxwellAdjust; i++) {
916+
xc.iadd(this.curve.n);
917+
if (xc.cmp(this.curve.p) >= 0)
918+
return false;
919+
915920
rx.redIAdd(t);
916921
if (this.x.cmp(rx) === 0)
917922
return true;

0 commit comments

Comments
 (0)
0