blob: b976e2173efdd23899d8f6b2e2df7f7c0f7a0956 [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 )
19 actual_ciphertext = cipher.encrypt(plaintext) + cipher.finalize()
20 assert binascii.hexlify(actual_ciphertext) == ciphertext