2525# Signature checking (5.4.2):
2626# - Verify that r and s are in [1,n-1].
2727#
28- # Version of 2008.11.25.
29- #
3028# Revision history:
3129# 2005.12.31 - Initial version.
3230# 2008.11.25 - Change CurveFp.is_on to contains_point.
3331#
3432# Written in 2005 by Peter Pearson and placed in the public domain.
33+ # Modified extensively as part of python-ecdsa.
3534
3635from __future__ import division
3736
@@ -92,8 +91,14 @@ def __init__(self, p, a, b, h=None):
9291 self .__h = h
9392
9493 def __eq__ (self , other ):
94+ """Return True if other is an identical curve, False otherwise.
95+
96+ Note: the value of the cofactor of the curve is not taken into account
97+ when comparing curves, as it's derived from the base point and
98+ intrinsic curve characteristic (but it's complex to compute),
99+ only the prime and curve parameters are considered.
100+ """
95101 if isinstance (other , CurveFp ):
96- """Return True if the curves are identical, False otherwise."""
97102 return (
98103 self .__p == other .__p
99104 and self .__a == other .__a
@@ -102,7 +107,8 @@ def __eq__(self, other):
102107 return NotImplemented
103108
104109 def __ne__ (self , other ):
105- return not (self == other )
110+ """Return False if other is an identical curve, True otherwise."""
111+ return not self == other
106112
107113 def __hash__ (self ):
108114 return hash ((self .__p , self .__a , self .__b ))
@@ -158,7 +164,7 @@ def __init__(self, curve, x, y, z, order=None, generator=False):
158164 generator=True
159165 :param bool generator: the point provided is a curve generator, as
160166 such, it will be commonly used with scalar multiplication. This will
161- cause to precompute multiplication table for it
167+ cause to precompute multiplication table generation for it
162168 """
163169 self .__curve = curve
164170 # since it's generally better (faster) to use scaled points vs unscaled
@@ -224,7 +230,10 @@ def __setstate__(self, state):
224230 self ._update_lock = RWLock ()
225231
226232 def __eq__ (self , other ):
227- """Compare two points with each-other."""
233+ """Compare for equality two points with each-other.
234+
235+ Note: only points that lie on the same curve can be equal.
236+ """
228237 try :
229238 self ._update_lock .reader_acquire ()
230239 if other is INFINITY :
@@ -256,6 +265,10 @@ def __eq__(self, other):
256265 y1 * zz2 * z2 - y2 * zz1 * z1
257266 ) % p == 0
258267
268+ def __ne__ (self , other ):
269+ """Compare for inequality two points with each-other."""
270+ return not self == other
271+
259272 def order (self ):
260273 """Return the order of the point.
261274
@@ -757,7 +770,10 @@ def __init__(self, curve, x, y, order=None):
757770 assert self * order == INFINITY
758771
759772 def __eq__ (self , other ):
760- """Return True if the points are identical, False otherwise."""
773+ """Return True if the points are identical, False otherwise.
774+
775+ Note: only points that lie on the same curve can be equal.
776+ """
761777 if isinstance (other , Point ):
762778 return (
763779 self .__curve == other .__curve
@@ -766,6 +782,10 @@ def __eq__(self, other):
766782 )
767783 return NotImplemented
768784
785+ def __ne__ (self , other ):
786+ """Returns False if points are identical, True otherwise."""
787+ return not self == other
788+
769789 def __neg__ (self ):
770790 return Point (self .__curve , self .__x , self .__curve .p () - self .__y )
771791
0 commit comments