@@ -163,7 +163,7 @@ def __init__(self, curve, x, y, z, order=None, generator=False):
163
163
self .__curve = curve
164
164
# since it's generally better (faster) to use scaled points vs unscaled
165
165
# ones, use writer-biased RWLock for locking:
166
- self ._scale_lock = RWLock ()
166
+ self ._update_lock = RWLock ()
167
167
if GMPY :
168
168
self .__x = mpz (x )
169
169
self .__y = mpz (y )
@@ -180,16 +180,16 @@ def __init__(self, curve, x, y, z, order=None, generator=False):
180
180
def _maybe_precompute (self ):
181
181
if self .__generator :
182
182
# since we lack promotion of read-locks to write-locks, we do a
183
- # "acquire-read-lock check, acquire-write-lock plus recheck" cycle
183
+ # "acquire-read-lock, check, acquire-write-lock plus recheck" cycle
184
184
try :
185
- self ._scale_lock .reader_acquire ()
185
+ self ._update_lock .reader_acquire ()
186
186
if self .__precompute :
187
187
return
188
188
finally :
189
- self ._scale_lock .reader_release ()
189
+ self ._update_lock .reader_release ()
190
190
191
191
try :
192
- self ._scale_lock .writer_acquire ()
192
+ self ._update_lock .writer_acquire ()
193
193
if self .__precompute :
194
194
return
195
195
order = self .__order
@@ -208,38 +208,38 @@ def _maybe_precompute(self):
208
208
self .__precompute .append ((doubler .x (), doubler .y ()))
209
209
210
210
finally :
211
- self ._scale_lock .writer_release ()
211
+ self ._update_lock .writer_release ()
212
212
213
213
def __getstate__ (self ):
214
214
try :
215
- self ._scale_lock .reader_acquire ()
215
+ self ._update_lock .reader_acquire ()
216
216
state = self .__dict__ .copy ()
217
217
finally :
218
- self ._scale_lock .reader_release ()
219
- del state ["_scale_lock " ]
218
+ self ._update_lock .reader_release ()
219
+ del state ["_update_lock " ]
220
220
return state
221
221
222
222
def __setstate__ (self , state ):
223
223
self .__dict__ .update (state )
224
- self ._scale_lock = RWLock ()
224
+ self ._update_lock = RWLock ()
225
225
226
226
def __eq__ (self , other ):
227
227
"""Compare two points with each-other."""
228
228
try :
229
- self ._scale_lock .reader_acquire ()
229
+ self ._update_lock .reader_acquire ()
230
230
if other is INFINITY :
231
231
return not self .__y or not self .__z
232
232
x1 , y1 , z1 = self .__x , self .__y , self .__z
233
233
finally :
234
- self ._scale_lock .reader_release ()
234
+ self ._update_lock .reader_release ()
235
235
if isinstance (other , Point ):
236
236
x2 , y2 , z2 = other .x (), other .y (), 1
237
237
elif isinstance (other , PointJacobi ):
238
238
try :
239
- other ._scale_lock .reader_acquire ()
239
+ other ._update_lock .reader_acquire ()
240
240
x2 , y2 , z2 = other .__x , other .__y , other .__z
241
241
finally :
242
- other ._scale_lock .reader_release ()
242
+ other ._update_lock .reader_release ()
243
243
else :
244
244
return NotImplemented
245
245
if self .__curve != other .curve ():
@@ -277,13 +277,13 @@ def x(self):
277
277
and then x() and y() on the returned instance.
278
278
"""
279
279
try :
280
- self ._scale_lock .reader_acquire ()
280
+ self ._update_lock .reader_acquire ()
281
281
if self .__z == 1 :
282
282
return self .__x
283
283
x = self .__x
284
284
z = self .__z
285
285
finally :
286
- self ._scale_lock .reader_release ()
286
+ self ._update_lock .reader_release ()
287
287
p = self .__curve .p ()
288
288
z = numbertheory .inverse_mod (z , p )
289
289
return x * z ** 2 % p
@@ -298,13 +298,13 @@ def y(self):
298
298
and then x() and y() on the returned instance.
299
299
"""
300
300
try :
301
- self ._scale_lock .reader_acquire ()
301
+ self ._update_lock .reader_acquire ()
302
302
if self .__z == 1 :
303
303
return self .__y
304
304
y = self .__y
305
305
z = self .__z
306
306
finally :
307
- self ._scale_lock .reader_release ()
307
+ self ._update_lock .reader_release ()
308
308
p = self .__curve .p ()
309
309
z = numbertheory .inverse_mod (z , p )
310
310
return y * z ** 3 % p
@@ -316,14 +316,14 @@ def scale(self):
316
316
Modifies point in place, returns self.
317
317
"""
318
318
try :
319
- self ._scale_lock .reader_acquire ()
319
+ self ._update_lock .reader_acquire ()
320
320
if self .__z == 1 :
321
321
return self
322
322
finally :
323
- self ._scale_lock .reader_release ()
323
+ self ._update_lock .reader_release ()
324
324
325
325
try :
326
- self ._scale_lock .writer_acquire ()
326
+ self ._update_lock .writer_acquire ()
327
327
# scaling already scaled point is safe (as inverse of 1 is 1) and
328
328
# quick so we don't need to optimise for the unlikely event when
329
329
# two threads hit the lock at the same time
@@ -336,7 +336,7 @@ def scale(self):
336
336
# true only after all values were already updated
337
337
self .__z = 1
338
338
finally :
339
- self ._scale_lock .writer_release ()
339
+ self ._update_lock .writer_release ()
340
340
return self
341
341
342
342
def to_affine (self ):
@@ -415,10 +415,10 @@ def double(self):
415
415
p , a = self .__curve .p (), self .__curve .a ()
416
416
417
417
try :
418
- self ._scale_lock .reader_acquire ()
418
+ self ._update_lock .reader_acquire ()
419
419
X1 , Y1 , Z1 = self .__x , self .__y , self .__z
420
420
finally :
421
- self ._scale_lock .reader_release ()
421
+ self ._update_lock .reader_release ()
422
422
423
423
X3 , Y3 , Z3 = self ._double (X1 , Y1 , Z1 , p , a )
424
424
@@ -533,15 +533,15 @@ def __add__(self, other):
533
533
534
534
p = self .__curve .p ()
535
535
try :
536
- self ._scale_lock .reader_acquire ()
536
+ self ._update_lock .reader_acquire ()
537
537
X1 , Y1 , Z1 = self .__x , self .__y , self .__z
538
538
finally :
539
- self ._scale_lock .reader_release ()
539
+ self ._update_lock .reader_release ()
540
540
try :
541
- other ._scale_lock .reader_acquire ()
541
+ other ._update_lock .reader_acquire ()
542
542
X2 , Y2 , Z2 = other .__x , other .__y , other .__z
543
543
finally :
544
- other ._scale_lock .reader_release ()
544
+ other ._update_lock .reader_release ()
545
545
X3 , Y3 , Z3 = self ._add (X1 , Y1 , Z1 , X2 , Y2 , Z2 , p )
546
546
547
547
if not Y3 or not Z3 :
@@ -632,10 +632,10 @@ def _leftmost_bit(x):
632
632
633
633
def mul_add (self , self_mul , other , other_mul ):
634
634
"""
635
- Do two multiplications at the same time, add results.
635
+ Do two multiplications at the same time, add results.
636
636
637
- calculates self*self_mul + other*other_mul
638
- """
637
+ calculates self*self_mul + other*other_mul
638
+ """
639
639
if other is INFINITY or other_mul == 0 :
640
640
return self * self_mul
641
641
if self_mul == 0 :
@@ -688,12 +688,12 @@ def mul_add(self, self_mul, other, other_mul):
688
688
def __neg__ (self ):
689
689
"""Return negated point."""
690
690
try :
691
- self ._scale_lock .reader_acquire ()
691
+ self ._update_lock .reader_acquire ()
692
692
return PointJacobi (
693
693
self .__curve , self .__x , - self .__y , self .__z , self .__order
694
694
)
695
695
finally :
696
- self ._scale_lock .reader_release ()
696
+ self ._update_lock .reader_release ()
697
697
698
698
699
699
class Point (object ):
0 commit comments