aboutsummaryrefslogtreecommitdiffstats
path: root/tests/primitives
diff options
context:
space:
mode:
Diffstat (limited to 'tests/primitives')
-rw-r--r--tests/primitives/test_nist.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/primitives/test_nist.py b/tests/primitives/test_nist.py
index d97b207b..ceecd57e 100644
--- a/tests/primitives/test_nist.py
+++ b/tests/primitives/test_nist.py
@@ -164,3 +164,72 @@ 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_KAT1 = 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(iv),
+ )
+
+ test_KAT2 = generate_encrypt_test(
+ lambda path: load_nist_vectors_from_file(path, "ENCRYPT"),
+ os.path.join("3DES", "KAT"),
+ [
+ "TCBCIpermop.rsp",
+ "TCBCIsubtab.rsp",
+ "TCBCIvarkey.rsp",
+ "TCBCIvartext.rsp",
+ ],
+ lambda keys, iv1, iv2, iv3: ciphers.TripleDES(binascii.unhexlify(keys)),
+ lambda keys, iv1, iv2, iv3: modes.CBC(iv1 + iv2 + iv3),
+ )
+
+ @parameterize_encrypt_test(
+ "3DES", "KAT",
+ ("keys", "iv1", "iv2", "iv3", "plaintext1", "ciphertext3"),
+ [
+ "TCBCIinvperm.rsp",
+ ]
+ )
+ def test_KAT_3(self, keys, iv1, iv2, iv3, plaintext1, ciphertext3):
+ cipher = BlockCipher(
+ ciphers.TripleDES(binascii.unhexlify(keys)),
+ modes.CBC(binascii.unhexlify(iv1 + iv2 + iv3)),
+ )
+ actual_ciphertext = cipher.encrypt(binascii.unhexlify(plaintext1))
+ actual_ciphertext += cipher.finalize()
+ assert binascii.hexlify(actual_ciphertext) == ciphertext3
+
+ test_MMT1 = generate_encrypt_test(
+ lambda path: load_nist_vectors_from_file(path, "ENCRYPT"),
+ os.path.join("3DES", "MMT"),
+ [
+ "TCBCIMMT1.rsp",
+ "TCBCIMMT2.rsp",
+ "TCBCIMMT3.rsp",
+ ],
+ lambda key1, key2, key3, iv1, iv2, iv3: ciphers.TripleDES(binascii.unhexlify(key1 + key2 + key3)),
+ lambda key1, key2, key3, iv1, iv2, iv3: modes.CBC(iv1 + iv2 + iv3),
+ )
+
+ test_MMT1 = 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(iv),
+ )