From 6a1b165c7ec1d27633c0d4ed1a840357b834e127 Mon Sep 17 00:00:00 2001 From: J08nY Date: Mon, 31 Mar 2025 10:56:03 +0200 Subject: Better is_neutral test in curve. --- pyecsca/ec/curve.py | 6 +++++- pyecsca/ec/point.py | 8 ++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'pyecsca/ec') diff --git a/pyecsca/ec/curve.py b/pyecsca/ec/curve.py index 2e08abb..18d7e65 100644 --- a/pyecsca/ec/curve.py +++ b/pyecsca/ec/curve.py @@ -257,7 +257,11 @@ class EllipticCurve: :param point: The point to test. :return: Whether it is the neutral point. """ - return self.neutral == point + # Neutral is either InfinityPoint or Point in either affine or some other coord system. + if isinstance(point.coordinate_model, AffineCoordinateModel): + return self.neutral_is_affine and self.affine_neutral == point + else: + return self.neutral.equals_homog(point) def is_on_curve(self, point: Point) -> bool: """ diff --git a/pyecsca/ec/point.py b/pyecsca/ec/point.py index 1833f46..5a486bc 100644 --- a/pyecsca/ec/point.py +++ b/pyecsca/ec/point.py @@ -169,7 +169,9 @@ class Point: if not isinstance(other, Point) or isinstance(other, InfinityPoint): return False if self.coordinate_model.curve_model != other.coordinate_model.curve_model: - return False + raise ValueError("Can only compare points with the same curve model.") + if self.coordinate_model != other.coordinate_model: + raise ValueError("Can only compare points with the same coordinate model.") if "z" in self.coordinate_model.formulas: formula = self.coordinate_model.formulas["z"] self_mapped = formula(self.field, self) @@ -188,7 +190,9 @@ class Point: if not isinstance(other, Point) or isinstance(other, InfinityPoint): return False if self.coordinate_model.curve_model != other.coordinate_model.curve_model: - return False + raise ValueError("Can only compare points with the same curve model.") + if self.coordinate_model != other.coordinate_model: + raise ValueError("Can only compare points with the same coordinate model.") weights = sorted(self.coordinate_model.homogweights.items(), key=itemgetter(1)) lambdas: Set[Mod] = set() for var, weight in weights: -- cgit v1.2.3-70-g09d2