MCPcopy
hub / github.com/pyca/cryptography / test_xts_vectors

Method test_xts_vectors

tests/hazmat/primitives/test_aes.py:22–52  ·  view source on GitHub ↗
(self, backend, subtests)

Source from the content-addressed store, hash-verified

20
21class 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 [

Callers

nothing calls this directly

Calls 8

encryptorMethod · 0.95
decryptorMethod · 0.95
_load_all_paramsFunction · 0.85
testMethod · 0.80
unhexlifyMethod · 0.80
cipher_supportedMethod · 0.80
updateMethod · 0.45
finalizeMethod · 0.45

Tested by

no test coverage detected