Skip to content

Commit 79bc0c5

Browse files
committed
more test coverage for ellipticurve module
1 parent 304263b commit 79bc0c5

File tree

5 files changed

+62
-2
lines changed

5 files changed

+62
-2
lines changed

src/ecdsa/ellipticcurve.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1532,7 +1532,9 @@ def double(self):
15321532

15331533
X3, Y3, Z3, T3 = self._double(X1, Y1, Z1, T1, p, a)
15341534

1535-
if not X3 or not T3:
1535+
# both Ed25519 and Ed448 have prime order, so no point added to
1536+
# itself will equal zero
1537+
if not X3 or not T3: # pragma: no branch
15361538
return INFINITY
15371539
return PointEdwards(self.__curve, X3, Y3, Z3, T3, self.__order)
15381540

src/ecdsa/test_ecdh.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from .ellipticcurve import CurveEdTw
3333

3434

35-
if "--fast" in sys.argv:
35+
if "--fast" in sys.argv: # pragma: no cover
3636
curves = [SECP112r2, SECP128r1]
3737

3838

src/ecdsa/test_eddsa.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,27 @@ def test_ed25519_eq_x_different_y():
163163
assert a != b
164164

165165

166+
def test_ed25519_mul_by_order():
167+
g = PointEdwards(
168+
curve_ed25519,
169+
generator_ed25519.x(),
170+
generator_ed25519.y(),
171+
1,
172+
generator_ed25519.x() * generator_ed25519.y(),
173+
)
174+
175+
assert g * generator_ed25519.order() == INFINITY
176+
177+
178+
def test_radd():
179+
180+
a = PointEdwards(curve_ed25519, 1, 1, 1, 1)
181+
182+
p = INFINITY + a
183+
184+
assert p == a
185+
186+
166187
def test_ed25519_test_normalisation_and_scaling():
167188
x = generator_ed25519.x()
168189
y = generator_ed25519.y()

src/ecdsa/test_ellipticcurve.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,34 @@ def test_inequality_points(self):
223223
def test_inequality_points_diff_types(self):
224224
c = CurveFp(100, -3, 100)
225225
self.assertNotEqual(self.g_23, c)
226+
227+
def test_to_bytes_from_bytes(self):
228+
p = Point(self.c_23, 3, 10)
229+
230+
self.assertEqual(p, Point.from_bytes(self.c_23, p.to_bytes()))
231+
232+
def test_add_to_neg_self(self):
233+
p = Point(self.c_23, 3, 10)
234+
235+
self.assertEqual(INFINITY, p + (-p))
236+
237+
def test_add_to_infinity(self):
238+
p = Point(self.c_23, 3, 10)
239+
240+
self.assertIs(p, p + INFINITY)
241+
242+
def test_mul_infinity_by_scalar(self):
243+
self.assertIs(INFINITY, INFINITY * 10)
244+
245+
def test_mul_by_negative(self):
246+
p = Point(self.c_23, 3, 10)
247+
248+
self.assertEqual(p * -5, (-p) * 5)
249+
250+
def test_str_infinity(self):
251+
self.assertEqual(str(INFINITY), "infinity")
252+
253+
def test_str_point(self):
254+
p = Point(self.c_23, 3, 10)
255+
256+
self.assertEqual(str(p), "(3,10)")

src/ecdsa/test_jacobi.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,12 @@ def test_equality_with_wrong_curves(self):
635635

636636
self.assertNotEqual(p_a, p_b)
637637

638+
def test_add_with_point_at_infinity(self):
639+
pj1 = PointJacobi(curve=CurveFp(23, 1, 1, 1), x=2, y=3, z=1, order=1)
640+
x, y, z = pj1._add(2, 3, 1, 5, 5, 0, 23)
641+
642+
self.assertEqual((x, y, z), (2, 3, 1))
643+
638644
def test_pickle(self):
639645
pj = PointJacobi(curve=CurveFp(23, 1, 1, 1), x=2, y=3, z=1, order=1)
640646
self.assertEqual(pickle.loads(pickle.dumps(pj)), pj)

0 commit comments

Comments
 (0)