(backend, wycheproof)
| 58 | "ecdsa_secp192r1_sha256_test.json", |
| 59 | ) |
| 60 | def test_ecdsa_signature(backend, wycheproof): |
| 61 | try: |
| 62 | key = wycheproof.cache_value_to_group( |
| 63 | "cache_key", |
| 64 | lambda: serialization.load_der_public_key( |
| 65 | binascii.unhexlify(wycheproof.testgroup["publicKeyDer"]) |
| 66 | ), |
| 67 | ) |
| 68 | assert isinstance(key, ec.EllipticCurvePublicKey) |
| 69 | except UnsupportedAlgorithm: |
| 70 | pytest.skip( |
| 71 | "unable to load key (curve {})".format( |
| 72 | wycheproof.testgroup["publicKey"]["curve"] |
| 73 | ) |
| 74 | ) |
| 75 | digest = _DIGESTS[wycheproof.testgroup["sha"]] |
| 76 | |
| 77 | alg = ec.ECDSA(digest) |
| 78 | if not backend.elliptic_curve_signature_algorithm_supported( |
| 79 | alg, key.curve |
| 80 | ): |
| 81 | pytest.skip(f"Signature with {digest} and {key.curve} not supported") |
| 82 | |
| 83 | if wycheproof.valid or ( |
| 84 | wycheproof.acceptable and not wycheproof.has_flag("MissingZero") |
| 85 | ): |
| 86 | key.verify( |
| 87 | binascii.unhexlify(wycheproof.testcase["sig"]), |
| 88 | binascii.unhexlify(wycheproof.testcase["msg"]), |
| 89 | alg, |
| 90 | ) |
| 91 | else: |
| 92 | with pytest.raises(InvalidSignature): |
| 93 | key.verify( |
| 94 | binascii.unhexlify(wycheproof.testcase["sig"]), |
| 95 | binascii.unhexlify(wycheproof.testcase["msg"]), |
| 96 | alg, |
| 97 | ) |
nothing calls this directly
no test coverage detected