Alex Gaynor | 95b8620 | 2013-08-08 19:36:44 -0700 | [diff] [blame^] | 1 | import binascii |
| 2 | |
| 3 | import pytest |
| 4 | |
| 5 | from cryptography.primitives.block import BlockCipher, ciphers, modes, padding |
| 6 | |
| 7 | |
| 8 | class TestBlockCipher(object): |
| 9 | @pytest.mark.parametrize(("key", "iv", "plaintext", "ciphertext"), [ |
| 10 | ( |
| 11 | b"9dc2c84a37850c11699818605f47958c", |
| 12 | b"256953b2feab2a04ae0180d8335bbed6", |
| 13 | b"2e586692e647f5028ec6fa47a55a2aab", |
| 14 | b"1b1ebd1fc45ec43037fd4844241a437f" |
| 15 | ), |
| 16 | ]) |
| 17 | def test_aes_cbc_nopadding(self, key, iv, plaintext, ciphertext): |
| 18 | cipher = BlockCipher( |
| 19 | ciphers.AES(binascii.unhexlify(key)), |
| 20 | modes.CBC(binascii.unhexlify(iv), padding.NoPadding()) |
| 21 | ) |
| 22 | actual_ciphertext = cipher.encrypt(plaintext) + cipher.finalize() |
| 23 | assert binascii.hexlify(actual_ciphertext) == ciphertext |