| 15 | |
| 16 | @wycheproof_tests("aes_cmac_test.json") |
| 17 | def test_aes_cmac(backend, wycheproof): |
| 18 | key = binascii.unhexlify(wycheproof.testcase["key"]) |
| 19 | msg = binascii.unhexlify(wycheproof.testcase["msg"]) |
| 20 | tag = binascii.unhexlify(wycheproof.testcase["tag"]) |
| 21 | |
| 22 | # skip truncated tags, which we don't support in the API |
| 23 | if wycheproof.valid and len(tag) == 16: |
| 24 | ctx = CMAC(AES(key), backend) |
| 25 | ctx.update(msg) |
| 26 | ctx.verify(tag) |
| 27 | elif len(key) not in [16, 24, 32]: |
| 28 | with pytest.raises(ValueError): |
| 29 | CMAC(AES(key), backend) |
| 30 | else: |
| 31 | ctx = CMAC(AES(key), backend) |
| 32 | ctx.update(msg) |
| 33 | with pytest.raises(InvalidSignature): |
| 34 | ctx.verify(tag) |