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 | |
Alex Gaynor | cd95f3c | 2013-08-08 22:08:26 -0700 | [diff] [blame] | 7 | from ..utils import load_nist_vectors_from_file |
| 8 | |
Alex Gaynor | 95b8620 | 2013-08-08 19:36:44 -0700 | [diff] [blame] | 9 | |
| 10 | class TestBlockCipher(object): |
Alex Gaynor | cd95f3c | 2013-08-08 22:08:26 -0700 | [diff] [blame] | 11 | @pytest.mark.parametrize(("key", "iv", "plaintext", "ciphertext"), |
| 12 | load_nist_vectors_from_file("AES/KAT/CBCGFSbox256.rsp", "ENCRYPT", ["key", "iv", "plaintext", "ciphertext"]) |
| 13 | ) |
Alex Gaynor | 95b8620 | 2013-08-08 19:36:44 -0700 | [diff] [blame] | 14 | def test_aes_cbc_nopadding(self, key, iv, plaintext, ciphertext): |
| 15 | cipher = BlockCipher( |
| 16 | ciphers.AES(binascii.unhexlify(key)), |
| 17 | modes.CBC(binascii.unhexlify(iv), padding.NoPadding()) |
| 18 | ) |
| 19 | actual_ciphertext = cipher.encrypt(plaintext) + cipher.finalize() |
| 20 | assert binascii.hexlify(actual_ciphertext) == ciphertext |