@@ -84,6 +84,17 @@ class PointJacobi(object):
8484 """
8585 def __init__ (self , curve , x , y , z , order = None , generator = False ):
8686 """
87+ Initialise a point that uses Jacobi representation internally.
88+
89+ :param CurveFp curve: curve on which the point resides
90+ :param int x: the X parameter of Jacobi representation (equal to x when
91+ converting from affine coordinates
92+ :param int y: the Y parameter of Jacobi representation (equal to y when
93+ converting from affine coordinates
94+ :param int z: the Z parameter of Jacobi representation (equal to 1 when
95+ converting from affine coordinates
96+ :param int order: the point order, must be non zero when using
97+ generator=True
8798 :param bool generator: the point provided is a curve generator, as
8899 such, it will be commonly used with scalar multiplication. This will
89100 cause to precompute multiplication table for it
@@ -133,9 +144,14 @@ def __eq__(self, other):
133144 (y1 * zz2 * z2 - y2 * zz1 * z1 ) % p == 0
134145
135146 def order (self ):
147+ """Return the order of the point.
148+
149+ None if it is undefined.
150+ """
136151 return self .__order
137152
138153 def curve (self ):
154+ """Return curve over which the point is defined."""
139155 return self .__curve
140156
141157 def x (self ):
@@ -144,7 +160,8 @@ def x(self):
144160
145161 This method should be used only when the 'y' coordinate is not needed.
146162 It's computationally more efficient to use `to_affine()` and then
147- call x() and y() on the returned instance.
163+ call x() and y() on the returned instance. Or call `scale()`
164+ and then x() and y() on the returned instance.
148165 """
149166 if self .__z == 1 :
150167 return self .__x
@@ -158,7 +175,8 @@ def y(self):
158175
159176 This method should be used only when the 'x' coordinate is not needed.
160177 It's computationally more efficient to use `to_affine()` and then
161- call x() and y() on the returned instance.
178+ call x() and y() on the returned instance. Or call `scale()`
179+ and then x() and y() on the returned instance.
162180 """
163181 if self .__z == 1 :
164182 return self .__y
@@ -190,7 +208,12 @@ def to_affine(self):
190208
191209 @staticmethod
192210 def from_affine (point , generator = False ):
193- """Create from an affine point."""
211+ """Create from an affine point.
212+
213+ :param bool generator: set to True to make the point to precalculate
214+ multiplication table - useful for public point when verifying many
215+ signatures (around 100 or so) or for generator points of a curve.
216+ """
194217 return PointJacobi (point .curve (), point .x (), point .y (), 1 ,
195218 point .order (), generator )
196219
@@ -292,6 +315,7 @@ def _add_with_z2_1(self, X1, Y1, Z1, X2, Y2):
292315 return PointJacobi (self .__curve , X3 , Y3 , Z3 , self .__order )
293316
294317 def __radd__ (self , other ):
318+ """Add other to self."""
295319 return self + other
296320
297321 def __add__ (self , other ):
@@ -346,6 +370,7 @@ def __rmul__(self, other):
346370 return self * other
347371
348372 def _mul_precompute (self , other ):
373+ """Multiply point by integer with precomputation table."""
349374 result = INFINITY
350375 for precomp in self .__precompute :
351376 if other % 2 :
@@ -357,7 +382,9 @@ def _mul_precompute(self, other):
357382 other //= 2
358383 return result
359384
360- def _naf (self , mult ):
385+ @staticmethod
386+ def _naf (mult ):
387+ """Calculate non-adjacent form of number."""
361388 ret = []
362389 while mult :
363390 if mult % 2 :
@@ -397,11 +424,12 @@ def __mul__(self, other):
397424
398425 @staticmethod
399426 def _leftmost_bit (x ):
400- assert x > 0
401- result = 1
402- while result <= x :
403- result = 2 * result
404- return result // 2
427+ """Return integer with the same magnitude as x but hamming weight of 1"""
428+ assert x > 0
429+ result = 1
430+ while result <= x :
431+ result = 2 * result
432+ return result // 2
405433
406434 def mul_add (self , self_mul , other , other_mul ):
407435 """
@@ -433,6 +461,7 @@ def mul_add(self, self_mul, other, other_mul):
433461 return result
434462
435463 def __neg__ (self ):
464+ """Return negated point."""
436465 return PointJacobi (self .__curve , self .__x , - self .__y , self .__z ,
437466 self .__order )
438467
0 commit comments