Skip to content

Commit

Permalink
better test coverage for ellipticcurve
Browse files Browse the repository at this point in the history
  • Loading branch information
tomato42 committed Aug 16, 2024
1 parent 3d00b32 commit 7426df8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/ecdsa/test_ellipticcurve.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ def test_inequality_curves(self):
c192 = CurveFp(p, -3, b)
self.assertNotEqual(self.c_23, c192)

def test_inequality_curves_by_b_only(self):
a = CurveFp(23, 1, 0)
b = CurveFp(23, 1, 1)
self.assertNotEqual(a, b)

def test_usability_in_a_hashed_collection_curves(self):
{self.c_23: None}

Expand Down
27 changes: 27 additions & 0 deletions src/ecdsa/test_pyecdsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,22 @@ def test_hybrid_decoding_with_blocked_format(self):

self.assertIn("Invalid X9.62 encoding", str(exp.exception))

def test_hybrid_decoding_with_inconsistent_encoding_and_no_validation(self):
sk = SigningKey.from_secret_exponent(123456789)
vk = sk.verifying_key

enc = vk.to_string("hybrid")
self.assertEqual(enc[:1], b'\x06')
enc = b'\x07' + enc[1:]

b = VerifyingKey.from_string(
enc,
valid_encodings=("hybrid",),
validate_point=False
)

self.assertEqual(vk, b)

def test_compressed_decoding_with_blocked_format(self):
enc = (
b"\x02"
Expand Down Expand Up @@ -898,6 +914,17 @@ def test_decoding_with_inconsistent_hybrid(self):
with self.assertRaises(MalformedPointError):
VerifyingKey.from_string(b"\x07" + enc)

def test_decoding_with_inconsistent_hybrid_odd_point(self):
sk = SigningKey.from_secret_exponent(123456791)
vk = sk.verifying_key

enc = vk.to_string("hybrid")
self.assertEqual(enc[:1], b'\x07')
enc = b'\x06' + enc[1:]

with self.assertRaises(MalformedPointError):
b = VerifyingKey.from_string(enc, valid_encodings=("hybrid",))

Check notice

Code scanning / CodeQL

Unused local variable Note test

Variable b is not used.

def test_decoding_with_point_not_on_curve(self):
enc = (
b"\x0c\xe0\x1d\xe0d\x1c\x8eS\x8a\xc0\x9eK\xa8x !\xd5\xc2\xc3"
Expand Down

0 comments on commit 7426df8

Please sign in to comment.