(backend, wycheproof)
| 36 | "hmac_sha512_test.json", |
| 37 | ) |
| 38 | def test_hmac(backend, wycheproof): |
| 39 | hash_algo = _HMAC_ALGORITHMS[wycheproof.testfiledata["algorithm"]] |
| 40 | if wycheproof.testgroup["tagSize"] // 8 != hash_algo.digest_size: |
| 41 | pytest.skip("Truncated HMAC not supported") |
| 42 | if not backend.hmac_supported(hash_algo): |
| 43 | pytest.skip(f"Hash {hash_algo.name} not supported") |
| 44 | |
| 45 | h = hmac.HMAC( |
| 46 | key=binascii.unhexlify(wycheproof.testcase["key"]), |
| 47 | algorithm=hash_algo, |
| 48 | backend=backend, |
| 49 | ) |
| 50 | h.update(binascii.unhexlify(wycheproof.testcase["msg"])) |
| 51 | |
| 52 | if wycheproof.invalid: |
| 53 | with pytest.raises(InvalidSignature): |
| 54 | h.verify(binascii.unhexlify(wycheproof.testcase["tag"])) |
| 55 | else: |
| 56 | tag = h.finalize() |
| 57 | assert tag == binascii.unhexlify(wycheproof.testcase["tag"]) |
| 58 | |
| 59 | h = hmac.HMAC( |
| 60 | key=binascii.unhexlify(wycheproof.testcase["key"]), |
| 61 | algorithm=hash_algo, |
| 62 | backend=backend, |
| 63 | ) |
| 64 | h.update(binascii.unhexlify(wycheproof.testcase["msg"])) |
| 65 | h.verify(binascii.unhexlify(wycheproof.testcase["tag"])) |
nothing calls this directly
no test coverage detected