Skip to content

Commit d13fd93

Browse files
alexreaperhulk
authored andcommitted
Support compressed points in the wycheproof tests (pyca#4648)
* Support compressed points in the wycheproof tests * Handle entries with no public key * Ok, let's try this
1 parent 7deaf5a commit d13fd93

1 file changed

Lines changed: 5 additions & 15 deletions

File tree

tests/wycheproof/test_ecdh.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,28 +97,18 @@ def test_ecdh_ecpoint(backend, wycheproof):
9797
private_key = ec.derive_private_key(
9898
int(wycheproof.testcase["private"], 16), curve, backend
9999
)
100-
# We don't support compressed points
101-
if (
102-
wycheproof.has_flag("CompressedPoint") or
103-
not wycheproof.testcase["public"]
104-
):
100+
101+
if wycheproof.invalid:
105102
with pytest.raises(ValueError):
106-
ec.EllipticCurvePublicNumbers.from_encoded_point(
103+
ec.EllipticCurvePublicKey.from_encoded_point(
107104
curve, binascii.unhexlify(wycheproof.testcase["public"])
108105
)
109106
return
110107

111-
public_numbers = ec.EllipticCurvePublicNumbers.from_encoded_point(
108+
assert wycheproof.valid or wycheproof.acceptable
109+
public_key = ec.EllipticCurvePublicKey.from_encoded_point(
112110
curve, binascii.unhexlify(wycheproof.testcase["public"])
113111
)
114-
if wycheproof.testcase["comment"] == "point is not on curve":
115-
assert wycheproof.invalid
116-
with pytest.raises(ValueError):
117-
public_numbers.public_key(backend)
118-
return
119-
120-
assert wycheproof.valid or wycheproof.acceptable
121-
public_key = public_numbers.public_key(backend)
122112
computed_shared = private_key.exchange(ec.ECDH(), public_key)
123113
expected_shared = binascii.unhexlify(wycheproof.testcase["shared"])
124114
assert computed_shared == expected_shared

0 commit comments

Comments
 (0)