aboutsummaryrefslogtreecommitdiffstats
path: root/tests/primitives/test_block.py
blob: e22d05efcd0107fbfa5d319d083c77687a34ec43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import binascii

import pytest

from cryptography.primitives.block import BlockCipher, ciphers, modes, padding


class TestBlockCipher(object):
    @pytest.mark.parametrize(("key", "iv", "plaintext", "ciphertext"), [
        (
            b"9dc2c84a37850c11699818605f47958c",
            b"256953b2feab2a04ae0180d8335bbed6",
            b"2e586692e647f5028ec6fa47a55a2aab",
            b"1b1ebd1fc45ec43037fd4844241a437f"
        ),
    ])
    def test_aes_cbc_nopadding(self, key, iv, plaintext, ciphertext):
        cipher = BlockCipher(
            ciphers.AES(binascii.unhexlify(key)),
            modes.CBC(binascii.unhexlify(iv), padding.NoPadding())
        )
        actual_ciphertext = cipher.encrypt(plaintext) + cipher.finalize()
        assert binascii.hexlify(actual_ciphertext) == ciphertext