aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/primitives/test_block.py12
-rw-r--r--tests/test_utils.py112
-rw-r--r--tests/utils.py2
3 files changed, 65 insertions, 61 deletions
diff --git a/tests/primitives/test_block.py b/tests/primitives/test_block.py
index 8c311d5c..5e342d2f 100644
--- a/tests/primitives/test_block.py
+++ b/tests/primitives/test_block.py
@@ -9,13 +9,17 @@ 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"])
+ 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.encode("ascii"))),
- modes.CBC(binascii.unhexlify(iv.encode("ascii")), padding.NoPadding())
+ 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) == ciphertext
+ assert binascii.hexlify(actual_ciphertext)
diff --git a/tests/test_utils.py b/tests/test_utils.py
index acb36d4c..2822eb15 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -45,16 +45,16 @@ def test_load_nist_vectors_encrypt():
["key", "iv", "plaintext", "ciphertext"],
) == [
(
- "00000000000000000000000000000000",
- "00000000000000000000000000000000",
- "f34481ec3cc627bacd5dc3fb08f273e6",
- "0336763e966d92595a567cc9ce537f5e",
+ b"00000000000000000000000000000000",
+ b"00000000000000000000000000000000",
+ b"f34481ec3cc627bacd5dc3fb08f273e6",
+ b"0336763e966d92595a567cc9ce537f5e",
),
(
- "00000000000000000000000000000000",
- "00000000000000000000000000000000",
- "9798c4640bad75c7c3227db910174e72",
- "a9a1631bf4996954ebc093957b234589",
+ b"00000000000000000000000000000000",
+ b"00000000000000000000000000000000",
+ b"9798c4640bad75c7c3227db910174e72",
+ b"a9a1631bf4996954ebc093957b234589",
),
]
@@ -101,16 +101,16 @@ def test_load_nist_vectors_decrypt():
["key", "iv", "ciphertext", "plaintext"],
) == [
(
- "00000000000000000000000000000000",
- "00000000000000000000000000000000",
- "0336763e966d92595a567cc9ce537f5e",
- "f34481ec3cc627bacd5dc3fb08f273e6",
+ b"00000000000000000000000000000000",
+ b"00000000000000000000000000000000",
+ b"0336763e966d92595a567cc9ce537f5e",
+ b"f34481ec3cc627bacd5dc3fb08f273e6",
),
(
- "00000000000000000000000000000000",
- "00000000000000000000000000000000",
- "a9a1631bf4996954ebc093957b234589",
- "9798c4640bad75c7c3227db910174e72",
+ b"00000000000000000000000000000000",
+ b"00000000000000000000000000000000",
+ b"a9a1631bf4996954ebc093957b234589",
+ b"9798c4640bad75c7c3227db910174e72",
),
]
@@ -122,34 +122,34 @@ def test_load_nist_vectors_from_file_encrypt():
["key", "iv", "plaintext", "ciphertext"],
) == [
(
- "0000000000000000000000000000000000000000000000000000000000000000",
- "00000000000000000000000000000000",
- "014730f80ac625fe84f026c60bfd547d",
- "5c9d844ed46f9885085e5d6a4f94c7d7",
+ b"0000000000000000000000000000000000000000000000000000000000000000",
+ b"00000000000000000000000000000000",
+ b"014730f80ac625fe84f026c60bfd547d",
+ b"5c9d844ed46f9885085e5d6a4f94c7d7",
),
(
- "0000000000000000000000000000000000000000000000000000000000000000",
- "00000000000000000000000000000000",
- "0b24af36193ce4665f2825d7b4749c98",
- "a9ff75bd7cf6613d3731c77c3b6d0c04",
+ b"0000000000000000000000000000000000000000000000000000000000000000",
+ b"00000000000000000000000000000000",
+ b"0b24af36193ce4665f2825d7b4749c98",
+ b"a9ff75bd7cf6613d3731c77c3b6d0c04",
),
(
- "0000000000000000000000000000000000000000000000000000000000000000",
- "00000000000000000000000000000000",
- "761c1fe41a18acf20d241650611d90f1",
- "623a52fcea5d443e48d9181ab32c7421",
+ b"0000000000000000000000000000000000000000000000000000000000000000",
+ b"00000000000000000000000000000000",
+ b"761c1fe41a18acf20d241650611d90f1",
+ b"623a52fcea5d443e48d9181ab32c7421",
),
(
- "0000000000000000000000000000000000000000000000000000000000000000",
- "00000000000000000000000000000000",
- "8a560769d605868ad80d819bdba03771",
- "38f2c7ae10612415d27ca190d27da8b4",
+ b"0000000000000000000000000000000000000000000000000000000000000000",
+ b"00000000000000000000000000000000",
+ b"8a560769d605868ad80d819bdba03771",
+ b"38f2c7ae10612415d27ca190d27da8b4",
),
(
- "0000000000000000000000000000000000000000000000000000000000000000",
- "00000000000000000000000000000000",
- "91fbef2d15a97816060bee1feaa49afe",
- "1bc704f1bce135ceb810341b216d7abe",
+ b"0000000000000000000000000000000000000000000000000000000000000000",
+ b"00000000000000000000000000000000",
+ b"91fbef2d15a97816060bee1feaa49afe",
+ b"1bc704f1bce135ceb810341b216d7abe",
),
]
@@ -161,33 +161,33 @@ def test_load_nist_vectors_from_file_decypt():
["key", "iv", "ciphertext", "plaintext"],
) == [
(
- "0000000000000000000000000000000000000000000000000000000000000000",
- "00000000000000000000000000000000",
- "5c9d844ed46f9885085e5d6a4f94c7d7",
- "014730f80ac625fe84f026c60bfd547d",
+ b"0000000000000000000000000000000000000000000000000000000000000000",
+ b"00000000000000000000000000000000",
+ b"5c9d844ed46f9885085e5d6a4f94c7d7",
+ b"014730f80ac625fe84f026c60bfd547d",
),
(
- "0000000000000000000000000000000000000000000000000000000000000000",
- "00000000000000000000000000000000",
- "a9ff75bd7cf6613d3731c77c3b6d0c04",
- "0b24af36193ce4665f2825d7b4749c98",
+ b"0000000000000000000000000000000000000000000000000000000000000000",
+ b"00000000000000000000000000000000",
+ b"a9ff75bd7cf6613d3731c77c3b6d0c04",
+ b"0b24af36193ce4665f2825d7b4749c98",
),
(
- "0000000000000000000000000000000000000000000000000000000000000000",
- "00000000000000000000000000000000",
- "623a52fcea5d443e48d9181ab32c7421",
- "761c1fe41a18acf20d241650611d90f1",
+ b"0000000000000000000000000000000000000000000000000000000000000000",
+ b"00000000000000000000000000000000",
+ b"623a52fcea5d443e48d9181ab32c7421",
+ b"761c1fe41a18acf20d241650611d90f1",
),
(
- "0000000000000000000000000000000000000000000000000000000000000000",
- "00000000000000000000000000000000",
- "38f2c7ae10612415d27ca190d27da8b4",
- "8a560769d605868ad80d819bdba03771",
+ b"0000000000000000000000000000000000000000000000000000000000000000",
+ b"00000000000000000000000000000000",
+ b"38f2c7ae10612415d27ca190d27da8b4",
+ b"8a560769d605868ad80d819bdba03771",
),
(
- "0000000000000000000000000000000000000000000000000000000000000000",
- "00000000000000000000000000000000",
- "1bc704f1bce135ceb810341b216d7abe",
- "91fbef2d15a97816060bee1feaa49afe",
+ b"0000000000000000000000000000000000000000000000000000000000000000",
+ b"00000000000000000000000000000000",
+ b"1bc704f1bce135ceb810341b216d7abe",
+ b"91fbef2d15a97816060bee1feaa49afe",
),
]
diff --git a/tests/utils.py b/tests/utils.py
index 9fe35311..60e7caab 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -35,7 +35,7 @@ def load_nist_vectors(vector_data, op, fields):
# We want to test only for a particular operation
return [
- tuple(vector[1][f] for f in fields)
+ tuple(vector[1][f].encode("ascii") for f in fields)
for vector in sorted(data[op].items(), key=lambda v: v[0])
]