blob: 5e342d2f1024c2029a52625b8b5110fbae8171f4 [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"),
Alex Gaynorde9a3ee2013-08-09 10:42:44 -070012 load_nist_vectors_from_file(
13 "AES/KAT/CBCGFSbox256.rsp",
14 "ENCRYPT",
15 ["key", "iv", "plaintext", "ciphertext"]
16 )
Alex Gaynorcd95f3c2013-08-08 22:08:26 -070017 )
Alex Gaynor95b86202013-08-08 19:36:44 -070018 def test_aes_cbc_nopadding(self, key, iv, plaintext, ciphertext):
19 cipher = BlockCipher(
Alex Gaynorde9a3ee2013-08-09 10:42:44 -070020 ciphers.AES(binascii.unhexlify(key)),
21 modes.CBC(binascii.unhexlify(iv), padding.NoPadding())
Alex Gaynor95b86202013-08-08 19:36:44 -070022 )
Donald Stufft5de03922013-08-09 07:28:31 -040023 actual_ciphertext = cipher.encrypt(binascii.unhexlify(plaintext))
24 actual_ciphertext += cipher.finalize()
Alex Gaynorde9a3ee2013-08-09 10:42:44 -070025 assert binascii.hexlify(actual_ciphertext)