(backend, wycheproof)
| 89 | "ecdh_secp521r1_ecpoint_test.json", |
| 90 | ) |
| 91 | def 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 |
nothing calls this directly
no test coverage detected