blob: e22d05efcd0107fbfa5d319d083c77687a34ec43 [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
7
8class 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