Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/ecdsa/ellipticcurve.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ def __eq__(self, other):
)
return NotImplemented

def __ne__(self, other):
return not (self == other)

def __hash__(self):
return hash((self.__p, self.__a, self.__b))

Expand Down Expand Up @@ -185,6 +188,19 @@ def __init__(self, curve, x, y, z, order=None, generator=False):
doubler = doubler.double().scale()
self.__precompute.append((doubler.x(), doubler.y()))

def __getstate__(self):
try:
self._scale_lock.reader_acquire()
state = self.__dict__.copy()
finally:
self._scale_lock.reader_release()
del state["_scale_lock"]
return state

def __setstate__(self, state):
self.__dict__.update(state)
self._scale_lock = RWLock()

def __eq__(self, other):
"""Compare two points with each-other."""
try:
Expand Down
2 changes: 1 addition & 1 deletion src/ecdsa/test_ellipticcurve.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,6 @@ def test_inequality_points(self):
p = Point(c, 100, 100, 100)
self.assertNotEqual(self.g_23, p)

def test_inaquality_points_diff_types(self):
def test_inequality_points_diff_types(self):
c = CurveFp(100, -3, 100)
self.assertNotEqual(self.g_23, c)
13 changes: 12 additions & 1 deletion src/ecdsa/test_jacobi.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pickle

try:
import unittest2 as unittest
except ImportError:
Expand All @@ -6,7 +8,7 @@
import hypothesis.strategies as st
from hypothesis import given, assume, settings, example

from .ellipticcurve import Point, PointJacobi, INFINITY
from .ellipticcurve import CurveFp, Point, PointJacobi, INFINITY
from .ecdsa import generator_256, curve_256, generator_224
from .numbertheory import inverse_mod

Expand Down Expand Up @@ -384,3 +386,12 @@ def test_mul_add_large(self):
self.assertEqual(
j_g * (0xFF00 + 255 * 0xF0F0), j_g.mul_add(0xFF00, b, 0xF0F0)
)

def test_equality(self):
pj1 = PointJacobi(curve=CurveFp(23, 1, 1, 1), x=2, y=3, z=1, order=1)
pj2 = PointJacobi(curve=CurveFp(23, 1, 1, 1), x=2, y=3, z=1, order=1)
self.assertEqual(pj1, pj2)

def test_pickle(self):
pj = PointJacobi(curve=CurveFp(23, 1, 1, 1), x=2, y=3, z=1, order=1)
self.assertEqual(pickle.loads(pickle.dumps(pj)), pj)