1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
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(plaintext) + cipher.finalize()
assert binascii.hexlify(actual_ciphertext) == ciphertext
|