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

Function test_aes_cbc_pkcs5

tests/wycheproof/test_aes.py:19–42  ·  view source on GitHub ↗
(backend, wycheproof)

Source from the content-addressed store, hash-verified

17
18@wycheproof_tests("aes_cbc_pkcs5_test.json")
19def test_aes_cbc_pkcs5(backend, wycheproof):
20 key = binascii.unhexlify(wycheproof.testcase["key"])
21 iv = binascii.unhexlify(wycheproof.testcase["iv"])
22 msg = binascii.unhexlify(wycheproof.testcase["msg"])
23 ct = binascii.unhexlify(wycheproof.testcase["ct"])
24
25 padder = padding.PKCS7(128).padder()
26
27 cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend)
28 enc = cipher.encryptor()
29 computed_ct = (
30 enc.update(padder.update(msg) + padder.finalize()) + enc.finalize()
31 )
32 dec = cipher.decryptor()
33 padded_msg = dec.update(ct) + dec.finalize()
34 unpadder = padding.PKCS7(128).unpadder()
35 if wycheproof.valid or wycheproof.acceptable:
36 assert computed_ct == ct
37 computed_msg = unpadder.update(padded_msg) + unpadder.finalize()
38 assert computed_msg == msg
39 else:
40 assert computed_ct != ct
41 with pytest.raises(ValueError):
42 unpadder.update(padded_msg) + unpadder.finalize()
43
44
45@wycheproof_tests("aes_gcm_test.json")

Callers

nothing calls this directly

Calls 8

encryptorMethod · 0.95
decryptorMethod · 0.95
CipherClass · 0.90
unhexlifyMethod · 0.80
padderMethod · 0.45
updateMethod · 0.45
finalizeMethod · 0.45
unpadderMethod · 0.45

Tested by

no test coverage detected