1
1
#! /usr/bin/env python
2
+ # -*- coding: utf-8 -*-
2
3
#
3
4
# Implementation of elliptic curves, for cryptographic applications.
4
5
#
@@ -78,8 +79,21 @@ def __str__(self):
78
79
79
80
80
81
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
+ """
82
91
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
+ """
83
97
self .__curve = curve
84
98
self .__x = x
85
99
self .__y = y
@@ -106,19 +120,31 @@ def curve(self):
106
120
return self .__curve
107
121
108
122
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
+ """
110
130
p = self .__curve .p ()
111
131
z = numbertheory .inverse_mod (self .__z , p )
112
132
return self .__x * z ** 2 % p
113
133
114
134
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
+ """
116
142
p = self .__curve .p ()
117
143
z = numbertheory .inverse_mod (self .__z , p )
118
144
return self .__y * z ** 3 % p
119
145
120
146
def normalise (self ):
121
- """Return point with z == 1."""
147
+ """Return point scaled so that z == 1."""
122
148
if self .__z == 1 :
123
149
return self
124
150
return self .from_weierstrass (self .to_weierstrass ())
0 commit comments