blob: f2da583081b5b5f1c51cde0ffe3edc31204796ee [file] [log] [blame]
Alex Gaynor95b86202013-08-08 19:36:44 -07001import binascii
2
3import pytest
4
5from cryptography.primitives.block import BlockCipher, ciphers, modes, padding
6
Alex Gaynorcd95f3c2013-08-08 22:08:26 -07007from ..utils import load_nist_vectors_from_file
8
Alex Gaynor95b86202013-08-08 19:36:44 -07009
10class TestBlockCipher(object):
Alex Gaynorcd95f3c2013-08-08 22:08:26 -070011 @pytest.mark.parametrize(("key", "iv", "plaintext", "ciphertext"),
12 load_nist_vectors_from_file("AES/KAT/CBCGFSbox256.rsp", "ENCRYPT", ["key", "iv", "plaintext", "ciphertext"])
13 )
Alex Gaynor95b86202013-08-08 19:36:44 -070014 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 )
Donald Stufft5de03922013-08-09 07:28:31 -040019 actual_ciphertext = cipher.encrypt(binascii.unhexlify(plaintext))
20 actual_ciphertext += cipher.finalize()
Alex Gaynor95b86202013-08-08 19:36:44 -070021 assert binascii.hexlify(actual_ciphertext) == ciphertext