aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/primitives/test_block.py11
-rw-r--r--tests/primitives/utils.py12
-rw-r--r--tests/test_utils.py14
-rw-r--r--tests/utils.py2
4 files changed, 33 insertions, 6 deletions
diff --git a/tests/primitives/test_block.py b/tests/primitives/test_block.py
index f4d3f467..9f5905bf 100644
--- a/tests/primitives/test_block.py
+++ b/tests/primitives/test_block.py
@@ -63,3 +63,14 @@ class TestBlockCipher(object):
with pytest.raises(ValueError):
cipher.finalize()
+
+ def test_unaligned_block_encryption(self, api):
+ cipher = BlockCipher(
+ ciphers.AES(binascii.unhexlify(b"0" * 32)),
+ modes.ECB(),
+ api
+ )
+ ct = cipher.encrypt(b"a" * 15)
+ assert ct == b""
+ ct += cipher.encrypt(b"a" * 65)
+ assert len(ct) == 80
diff --git a/tests/primitives/utils.py b/tests/primitives/utils.py
index 8b32700b..a3759b03 100644
--- a/tests/primitives/utils.py
+++ b/tests/primitives/utils.py
@@ -43,7 +43,7 @@ def encrypt_test(api, cipher_factory, mode_factory, params, only_if,
def generate_hash_test(param_loader, path, file_names, hash_cls,
- only_if=lambda api: True, skip_message=None):
+ only_if=None, skip_message=None):
def test_hash(self):
for api in _ALL_APIS:
for file_name in file_names:
@@ -60,7 +60,7 @@ def generate_hash_test(param_loader, path, file_names, hash_cls,
def hash_test(api, hash_cls, params, only_if, skip_message):
- if not only_if(api):
+ if only_if is not None and not only_if(api):
pytest.skip(skip_message)
msg = params[0]
md = params[1]
@@ -70,7 +70,7 @@ def hash_test(api, hash_cls, params, only_if, skip_message):
def generate_base_hash_test(hash_cls, digest_size, block_size,
- only_if=lambda api: True, skip_message=None):
+ only_if=None, skip_message=None):
def test_base_hash(self):
for api in _ALL_APIS:
yield (
@@ -87,7 +87,7 @@ def generate_base_hash_test(hash_cls, digest_size, block_size,
def base_hash_test(api, hash_cls, digest_size, block_size, only_if,
skip_message):
- if not only_if(api):
+ if only_if is not None and not only_if(api):
pytest.skip(skip_message)
m = hash_cls(api=api)
assert m.digest_size == digest_size
@@ -97,7 +97,7 @@ def base_hash_test(api, hash_cls, digest_size, block_size, only_if,
assert m._ctx != m_copy._ctx
-def generate_long_string_hash_test(hash_factory, md, only_if=lambda api: True,
+def generate_long_string_hash_test(hash_factory, md, only_if=None,
skip_message=None):
def test_long_string_hash(self):
for api in _ALL_APIS:
@@ -113,7 +113,7 @@ def generate_long_string_hash_test(hash_factory, md, only_if=lambda api: True,
def long_string_hash_test(api, hash_factory, md, only_if, skip_message):
- if not only_if(api):
+ if only_if is not None and not only_if(api):
pytest.skip(skip_message)
m = hash_factory(api)
m.update(b"a" * 1000000)
diff --git a/tests/test_utils.py b/tests/test_utils.py
index a9bb6a87..3fe9e570 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -269,6 +269,20 @@ def test_load_cryptrec_vectors():
]
+def test_load_cryptrec_vectors_invalid():
+ vector_data = textwrap.dedent("""
+ # Vectors taken from http://info.isl.ntt.co.jp/crypt/eng/camellia/
+ # Download is t_camelia.txt
+
+ # Camellia with 128-bit key
+
+ E No.001 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ """).splitlines()
+
+ with pytest.raises(ValueError):
+ load_cryptrec_vectors(vector_data)
+
+
def test_load_cryptrec_vectors_from_file_encrypt():
test_set = load_cryptrec_vectors_from_file(
"Camellia/NTT/camellia-128-ecb.txt"
diff --git a/tests/utils.py b/tests/utils.py
index 03b780f8..fa7cc68d 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -90,6 +90,8 @@ def load_cryptrec_vectors(vector_data):
"plaintext": pt,
"ciphertext": ct
})
+ else:
+ raise ValueError("Invalid line in file '{}'".format(line))
return cryptrec_list