MCPcopy
hub / github.com/pyca/cryptography / test_ecdh_ecpoint

Function test_ecdh_ecpoint

tests/wycheproof/test_ecdh.py:91–117  ·  view source on GitHub ↗
(backend, wycheproof)

Source from the content-addressed store, hash-verified

89 "ecdh_secp521r1_ecpoint_test.json",
90)
91def test_ecdh_ecpoint(backend, wycheproof):
92 curve = _CURVES[wycheproof.testgroup["curve"]]
93 assert isinstance(curve, ec.EllipticCurve)
94 _skip_exchange_algorithm_unsupported(backend, ec.ECDH(), curve)
95
96 private_key = wycheproof.cache_value_to_group(
97 f"private_key_{wycheproof.testcase['private']}",
98 lambda: ec.derive_private_key(
99 int(wycheproof.testcase["private"], 16), curve
100 ),
101 )
102
103 if wycheproof.invalid:
104 with pytest.raises(ValueError):
105 ec.EllipticCurvePublicKey.from_encoded_point(
106 curve, binascii.unhexlify(wycheproof.testcase["public"])
107 )
108 return
109
110 assert wycheproof.valid or wycheproof.acceptable
111 # caching these values shows no performance improvement
112 public_key = ec.EllipticCurvePublicKey.from_encoded_point(
113 curve, binascii.unhexlify(wycheproof.testcase["public"])
114 )
115 computed_shared = private_key.exchange(ec.ECDH(), public_key)
116 expected_shared = binascii.unhexlify(wycheproof.testcase["shared"])
117 assert computed_shared == expected_shared

Callers

nothing calls this directly

Calls 5

cache_value_to_groupMethod · 0.80
from_encoded_pointMethod · 0.80
unhexlifyMethod · 0.80
exchangeMethod · 0.45

Tested by

no test coverage detected