aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/primitives/test_ciphers.py17
-rw-r--r--tests/primitives/test_nist.py90
2 files changed, 106 insertions, 1 deletions
diff --git a/tests/primitives/test_ciphers.py b/tests/primitives/test_ciphers.py
index 27d35850..17fcdbaf 100644
--- a/tests/primitives/test_ciphers.py
+++ b/tests/primitives/test_ciphers.py
@@ -17,7 +17,7 @@ import binascii
import pytest
-from cryptography.primitives.block.ciphers import AES, Camellia
+from cryptography.primitives.block.ciphers import AES, Camellia, TripleDES
class TestAES(object):
@@ -48,3 +48,18 @@ class TestCamellia(object):
def test_invalid_key_size(self):
with pytest.raises(ValueError):
Camellia(binascii.unhexlify(b"0" * 12))
+
+
+class TestTripleDES(object):
+ @pytest.mark.parametrize("key", [
+ b"0" * 16,
+ b"0" * 32,
+ b"0" * 48,
+ ])
+ def test_key_size(self, key):
+ cipher = TripleDES(binascii.unhexlify(key))
+ assert cipher.key_size == 192
+
+ def test_invalid_key_size(self):
+ with pytest.raises(ValueError):
+ TripleDES(binascii.unhexlify(b"0" * 12))
diff --git a/tests/primitives/test_nist.py b/tests/primitives/test_nist.py
index d97b207b..2a32d1bc 100644
--- a/tests/primitives/test_nist.py
+++ b/tests/primitives/test_nist.py
@@ -164,3 +164,93 @@ class TestAES_CFB(object):
lambda key, iv: ciphers.AES(binascii.unhexlify(key)),
lambda key, iv: modes.CFB(binascii.unhexlify(iv)),
)
+
+
+class TestTripleDES_CBC(object):
+ test_KAT = generate_encrypt_test(
+ lambda path: load_nist_vectors_from_file(path, "ENCRYPT"),
+ os.path.join("3DES", "KAT"),
+ [
+ "TCBCinvperm.rsp",
+ "TCBCpermop.rsp",
+ "TCBCsubtab.rsp",
+ "TCBCvarkey.rsp",
+ "TCBCvartext.rsp",
+ ],
+ lambda keys, iv: ciphers.TripleDES(binascii.unhexlify(keys)),
+ lambda keys, iv: modes.CBC(binascii.unhexlify(iv)),
+ )
+
+ test_MMT = generate_encrypt_test(
+ lambda path: load_nist_vectors_from_file(path, "ENCRYPT"),
+ os.path.join("3DES", "MMT"),
+ [
+ "TCBCMMT1.rsp",
+ "TCBCMMT2.rsp",
+ "TCBCMMT3.rsp",
+ ],
+ lambda key1, key2, key3, iv: (
+ ciphers.TripleDES(binascii.unhexlify(key1 + key2 + key3))
+ ),
+ lambda key1, key2, key3, iv: modes.CBC(binascii.unhexlify(iv)),
+ )
+
+
+class TestTripleDES_OFB(object):
+ test_KAT = generate_encrypt_test(
+ lambda path: load_nist_vectors_from_file(path, "ENCRYPT"),
+ os.path.join("3DES", "KAT"),
+ [
+ "TOFBpermop.rsp",
+ "TOFBsubtab.rsp",
+ "TOFBvarkey.rsp",
+ "TOFBvartext.rsp",
+ "TOFBinvperm.rsp",
+ ],
+ lambda keys, iv: ciphers.TripleDES(binascii.unhexlify(keys)),
+ lambda keys, iv: modes.OFB(binascii.unhexlify(iv)),
+ )
+
+ test_MMT = generate_encrypt_test(
+ lambda path: load_nist_vectors_from_file(path, "ENCRYPT"),
+ os.path.join("3DES", "MMT"),
+ [
+ "TOFBMMT1.rsp",
+ "TOFBMMT2.rsp",
+ "TOFBMMT3.rsp",
+ ],
+ lambda key1, key2, key3, iv: (
+ ciphers.TripleDES(binascii.unhexlify(key1 + key2 + key3))
+ ),
+ lambda key1, key2, key3, iv: modes.OFB(binascii.unhexlify(iv)),
+ )
+
+
+class TestTripleDES_CFB(object):
+ test_KAT = generate_encrypt_test(
+ lambda path: load_nist_vectors_from_file(path, "ENCRYPT"),
+ os.path.join("3DES", "KAT"),
+ [
+ "TCFB64invperm.rsp",
+ "TCFB64permop.rsp",
+ "TCFB64subtab.rsp",
+ "TCFB64varkey.rsp",
+ "TCFB64vartext.rsp",
+ ],
+ lambda keys, iv: ciphers.TripleDES(binascii.unhexlify(keys)),
+ lambda keys, iv: modes.CFB(binascii.unhexlify(iv)),
+ )
+
+ test_MMT = generate_encrypt_test(
+ lambda path: load_nist_vectors_from_file(path, "ENCRYPT"),
+ os.path.join("3DES", "MMT"),
+ [
+ "TCFB64MMT1.rsp",
+ "TCFB64MMT2.rsp",
+ "TCFB64MMT3.rsp",
+ ],
+ lambda key1, key2, key3, iv: (
+ ciphers.TripleDES(binascii.unhexlify(key1 + key2 + key3))
+ ),
+ lambda key1, key2, key3, iv: modes.CFB(binascii.unhexlify(iv)),
+ )