Skip to content

Commit 7db74ba

Browse files
committed
more documentation
1 parent 416c19a commit 7db74ba

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

src/ecdsa/ellipticcurve.py

+30-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#! /usr/bin/env python
2+
# -*- coding: utf-8 -*-
23
#
34
# Implementation of elliptic curves, for cryptographic applications.
45
#
@@ -78,8 +79,21 @@ def __str__(self):
7879

7980

8081
class PointJacobi(object):
81-
"""Point on an elliptic curve. Uses Jacobi representation"""
82+
"""
83+
Point on an elliptic curve. Uses Jacobi representation
84+
85+
In Jacobian coordinates, there are three parameters, X, Y and Z.
86+
They correspond to Weierstrass representation points 'x' and 'y' like so:
87+
88+
x = X / Z²
89+
y = Y / Z³
90+
"""
8291
def __init__(self, curve, x, y, z, order=None, generator=False):
92+
"""
93+
:param bool generator: the point provided is a curve generator, as
94+
such, it will be commonly used with scalar multiplication. This will
95+
cause to precompute multiplication table for it
96+
"""
8397
self.__curve = curve
8498
self.__x = x
8599
self.__y = y
@@ -106,19 +120,31 @@ def curve(self):
106120
return self.__curve
107121

108122
def x(self):
109-
"""Return x coordinate in Weierstrass form"""
123+
"""
124+
Return x coordinate in Weierstrass form.
125+
126+
This method should be used only when the 'y' coordinate is not needed.
127+
It's computationally more efficient to use `to_weierstrass()` and then
128+
call x() and y() on the returned instance.
129+
"""
110130
p = self.__curve.p()
111131
z = numbertheory.inverse_mod(self.__z, p)
112132
return self.__x * z**2 % p
113133

114134
def y(self):
115-
"""Return y coordinate in Weierstrass form"""
135+
"""
136+
Return y coordinate in Weierstrass form.
137+
138+
This method should be used only when the 'x' coordinate is not needed.
139+
It's computationally more efficient to use `to_weierstrass()` and then
140+
call x() and y() on the returned instance.
141+
"""
116142
p = self.__curve.p()
117143
z = numbertheory.inverse_mod(self.__z, p)
118144
return self.__y * z**3 % p
119145

120146
def normalise(self):
121-
"""Return point with z == 1."""
147+
"""Return point scaled so that z == 1."""
122148
if self.__z == 1:
123149
return self
124150
return self.from_weierstrass(self.to_weierstrass())

0 commit comments

Comments
 (0)