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

import pytest

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

from ..utils import load_nist_vectors_from_file


class TestBlockCipher(object):
    @pytest.mark.parametrize(("key", "iv", "plaintext", "ciphertext"),
        load_nist_vectors_from_file(
            "AES/KAT/CBCGFSbox256.rsp",
            "ENCRYPT",
            ["key", "iv", "plaintext", "ciphertext"]
        )
    )
    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(binascii.unhexlify(plaintext))
        actual_ciphertext += cipher.finalize()
        assert binascii.hexlify(actual_ciphertext)