(self, backend, subtests)
| 20 | |
| 21 | class TestAESModeXTS: |
| 22 | def test_xts_vectors(self, backend, subtests): |
| 23 | # This list comprehension excludes any vector that does not have a |
| 24 | # data unit length that is divisible by 8. The NIST vectors include |
| 25 | # tests for implementations that support encryption of data that is |
| 26 | # not divisible modulo 8, but OpenSSL is not such an implementation. |
| 27 | vectors = [ |
| 28 | x |
| 29 | for x in _load_all_params( |
| 30 | os.path.join("ciphers", "AES", "XTS", "tweak-128hexstr"), |
| 31 | ["XTSGenAES128.rsp", "XTSGenAES256.rsp"], |
| 32 | load_nist_vectors, |
| 33 | ) |
| 34 | if int(x["dataunitlen"]) / 8.0 == int(x["dataunitlen"]) // 8 |
| 35 | ] |
| 36 | for vector in vectors: |
| 37 | with subtests.test(): |
| 38 | key = binascii.unhexlify(vector["key"]) |
| 39 | tweak = binascii.unhexlify(vector["i"]) |
| 40 | pt = binascii.unhexlify(vector["pt"]) |
| 41 | ct = binascii.unhexlify(vector["ct"]) |
| 42 | alg = algorithms.AES(key) |
| 43 | mode = modes.XTS(tweak) |
| 44 | if not backend.cipher_supported(alg, mode): |
| 45 | pytest.skip(f"AES-{alg.key_size}-XTS not supported") |
| 46 | cipher = base.Cipher(alg, mode, backend) |
| 47 | enc = cipher.encryptor() |
| 48 | computed_ct = enc.update(pt) + enc.finalize() |
| 49 | assert computed_ct == ct |
| 50 | dec = cipher.decryptor() |
| 51 | computed_pt = dec.update(ct) + dec.finalize() |
| 52 | assert computed_pt == pt |
| 53 | |
| 54 | def test_xts_too_short(self, backend, subtests): |
| 55 | for key in [ |
nothing calls this directly
no test coverage detected