@@ -389,13 +389,35 @@ public boolean equals(Object obj) {
389389 return false ;
390390 }
391391 }
392- FieldElement recip1 = Z .invert ();
393- FieldElement x1 = X .multiply (recip1 );
394- FieldElement y1 = Y .multiply (recip1 );
395- FieldElement recip2 = ge .Z .invert ();
396- FieldElement x2 = ge .X .multiply (recip2 );
397- FieldElement y2 = ge .Y .multiply (recip2 );
398- return x1 .equals (x2 ) && y1 .equals (y2 );
392+ switch (this .repr ) {
393+ case P2 :
394+ case P3 :
395+ FieldElement recip1 = Z .invert ();
396+ FieldElement x1 = X .multiply (recip1 );
397+ FieldElement y1 = Y .multiply (recip1 );
398+ FieldElement recip2 = ge .Z .invert ();
399+ FieldElement x2 = ge .X .multiply (recip2 );
400+ FieldElement y2 = ge .Y .multiply (recip2 );
401+ return x1 .equals (x2 ) && y1 .equals (y2 );
402+ case P1P1 :
403+ return toP2 ().equals (ge );
404+ case PRECOMP :
405+ // Compare directly, PRECOMP is derived directly from x and y
406+ return X .equals (ge .X ) && Y .equals (ge .Y ) && Z .equals (ge .Z );
407+ case CACHED :
408+ // (Y+X)/Z = y+x etc.
409+ FieldElement recip3 = Z .invert ();
410+ FieldElement x3 = X .multiply (recip3 );
411+ FieldElement y3 = Y .multiply (recip3 );
412+ FieldElement t3 = T .multiply (recip3 );
413+ FieldElement recip4 = ge .Z .invert ();
414+ FieldElement x4 = ge .X .multiply (recip4 );
415+ FieldElement y4 = ge .Y .multiply (recip4 );
416+ FieldElement t4 = ge .T .multiply (recip4 );
417+ return x3 .equals (x4 ) && y3 .equals (y4 ) && t3 .equals (t4 );
418+ default :
419+ return false ;
420+ }
399421 }
400422
401423 /**
0 commit comments