aboutsummaryrefslogtreecommitdiffstats
path: root/tests/primitives/test_nist.py
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2013-09-10 16:55:52 -0700
committerAlex Gaynor <alex.gaynor@gmail.com>2013-09-10 16:55:52 -0700
commit920e3300c3c58190f853f529c2be8e9e670f7ab5 (patch)
treef84df229ead72aeebf112da3f60d73385ae16e1a /tests/primitives/test_nist.py
parent9f44cabb5010742226e3b429d450fd0b31d020d2 (diff)
downloadcryptography-920e3300c3c58190f853f529c2be8e9e670f7ab5.tar.gz
cryptography-920e3300c3c58190f853f529c2be8e9e670f7ab5.tar.bz2
cryptography-920e3300c3c58190f853f529c2be8e9e670f7ab5.zip
Get tests running (fail miserably)
Diffstat (limited to 'tests/primitives/test_nist.py')
-rw-r--r--tests/primitives/test_nist.py157
1 files changed, 109 insertions, 48 deletions
diff --git a/tests/primitives/test_nist.py b/tests/primitives/test_nist.py
index 50aee310..55756682 100644
--- a/tests/primitives/test_nist.py
+++ b/tests/primitives/test_nist.py
@@ -28,13 +28,13 @@ from cryptography.primitives.block import BlockCipher, ciphers, modes
from ..utils import load_nist_vectors_from_file
-def parameterize_encrypt_test(cipher, vector_type, fnames):
- return pytest.mark.parametrize(("key", "iv", "plaintext", "ciphertext"),
+def parameterize_encrypt_test(cipher, vector_type, params, fnames):
+ return pytest.mark.parametrize(params,
list(itertools.chain.from_iterable(
load_nist_vectors_from_file(
os.path.join(cipher, vector_type, fname),
"ENCRYPT",
- ["key", "iv", "plaintext", "ciphertext"],
+ params
)
for fname in fnames
))
@@ -42,20 +42,24 @@ def parameterize_encrypt_test(cipher, vector_type, fnames):
class TestAES_CBC(object):
- @parameterize_encrypt_test("AES", "KAT", [
- "CBCGFSbox128.rsp",
- "CBCGFSbox192.rsp",
- "CBCGFSbox256.rsp",
- "CBCKeySbox128.rsp",
- "CBCKeySbox192.rsp",
- "CBCKeySbox256.rsp",
- "CBCVarKey128.rsp",
- "CBCVarKey192.rsp",
- "CBCVarKey256.rsp",
- "CBCVarTxt128.rsp",
- "CBCVarTxt192.rsp",
- "CBCVarTxt256.rsp",
- ])
+ @parameterize_encrypt_test(
+ "AES", "KAT",
+ ["key", "iv", "plaintext", "ciphertext"],
+ [
+ "CBCGFSbox128.rsp",
+ "CBCGFSbox192.rsp",
+ "CBCGFSbox256.rsp",
+ "CBCKeySbox128.rsp",
+ "CBCKeySbox192.rsp",
+ "CBCKeySbox256.rsp",
+ "CBCVarKey128.rsp",
+ "CBCVarKey192.rsp",
+ "CBCVarKey256.rsp",
+ "CBCVarTxt128.rsp",
+ "CBCVarTxt192.rsp",
+ "CBCVarTxt256.rsp",
+ ]
+ )
def test_KAT(self, key, iv, plaintext, ciphertext):
cipher = BlockCipher(
ciphers.AES(binascii.unhexlify(key)),
@@ -65,11 +69,15 @@ class TestAES_CBC(object):
actual_ciphertext += cipher.finalize()
assert binascii.hexlify(actual_ciphertext) == ciphertext
- @parameterize_encrypt_test("AES", "MMT", [
- "CBCMMT128.rsp",
- "CBCMMT192.rsp",
- "CBCMMT256.rsp",
- ])
+ @parameterize_encrypt_test(
+ "AES", "MMT",
+ ["key", "iv", "plaintext", "ciphertext"],
+ [
+ "CBCMMT128.rsp",
+ "CBCMMT192.rsp",
+ "CBCMMT256.rsp",
+ ]
+ )
def test_MMT(self, key, iv, plaintext, ciphertext):
cipher = BlockCipher(
ciphers.AES(binascii.unhexlify(key)),
@@ -81,39 +89,92 @@ class TestAES_CBC(object):
class TestTripleDES_CBC(object):
- @parameterize_encrypt_test("3DES", "KAT", [
- "TCBCIinvperm.rsp",
- "TCBCIpermop.rsp",
- "TCBCIsubtab.rsp",
- "TCBCIvarkey.rsp",
- "TCBCIvartext.rsp",
- "TCBCinvperm.rsp",
- "TCBCpermop.rsp",
- "TCBCsubtab.rsp",
- "TCBCvarkey.rsp",
- "TCBCvartext.rsp",
- ])
- def test_KAT(self, key, iv, plaintext, ciphertext):
+ @parameterize_encrypt_test(
+ "3DES", "KAT",
+ ["keys", "iv", "plaintext", "ciphertext"],
+ [
+ "TCBCinvperm.rsp",
+ "TCBCpermop.rsp",
+ "TCBCsubtab.rsp",
+ "TCBCvarkey.rsp",
+ "TCBCvartext.rsp",
+ ]
+ )
+ def test_KAT_1(self, keys, iv, plaintext, ciphertext):
cipher = BlockCipher(
- ciphers.TripleDES(binascii.unhexlify(key)),
- modes.CBC(binascii.unhexlify(iv))
+ ciphers.TripleDES(binascii.unhexlify(keys)),
+ modes.CBC(binascii.unhexlify(iv)),
)
actual_ciphertext = cipher.encrypt(binascii.unhexlify(plaintext))
actual_ciphertext += cipher.finalize()
assert binascii.hexlify(actual_ciphertext) == ciphertext
- @parameterize_encrypt_test("3DES", "MMT", [
- "TCBCIMMT1.rsp",
- "TCBCIMMT2.rsp",
- "TCBCIMMT3.rsp",
- "TCBCMMT1.rsp",
- "TCBCMMT2.rsp",
- "TCBCMMT3.rsp",
- ])
- def test_MMT(self, key, iv, plaintext, ciphertext):
+ @parameterize_encrypt_test(
+ "3DES", "KAT",
+ ["keys", "iv1", "iv2", "iv3", "plaintext", "ciphertext3"],
+ [
+ "TCBCIpermop.rsp",
+ "TCBCIsubtab.rsp",
+ "TCBCIvarkey.rsp",
+ "TCBCIvartext.rsp",
+ ]
+ )
+ def test_KAT_2(self, keys, iv1, iv2, iv3, plaintext, ciphertext3):
+ cipher = BlockCipher(
+ ciphers.TripleDES(binascii.unhexlify(keys)),
+ modes.CBC(binascii.unhexlify(iv1 + iv2 + iv3)),
+ )
+ actual_ciphertext = cipher.encrypt(binascii.unhexlify(plaintext))
+ actual_ciphertext += cipher.finalize()
+ assert binascii.hexlify(actual_ciphertext) == ciphertext3
+
+ @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(key)),
- modes.CBC(binascii.unhexlify(iv))
+ 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
+
+ @parameterize_encrypt_test(
+ "3DES", "MMT",
+ ["key1", "key2", "key3", "iv1", "iv2", "iv3", "plaintext", "ciphertext"],
+ [
+ "TCBCIMMT1.rsp",
+ "TCBCIMMT2.rsp",
+ "TCBCIMMT3.rsp",
+ ]
+ )
+ def test_MMT_1(self, key1, key2, key3, iv1, iv2, iv3, plaintext, ciphertext):
+ cipher = BlockCipher(
+ ciphers.TripleDES(binascii.unhexlify(key1 + key2 + key3)),
+ modes.CBC(binascii.unhexlify(iv1 + iv2 + iv3)),
+ )
+ actual_ciphertext = cipher.encrypt(binascii.unhexlify(plaintext))
+ actual_ciphertext += cipher.finalize()
+ assert binascii.hexlify(actual_ciphertext) == ciphertext
+
+ @parameterize_encrypt_test(
+ "3DES", "MMT",
+ ["key1", "key2", "key3", "iv", "plaintext", "ciphertext"],
+ [
+ "TCBCMMT1.rsp",
+ "TCBCMMT2.rsp",
+ "TCBCMMT3.rsp",
+ ]
+ )
+ def test_MMT_2(self, key1, key2, key3, iv, plaintext, ciphertext):
+ cipher = BlockCipher(
+ ciphers.TripleDES(binascii.unhexlify(key1 + key2 + key3)),
+ modes.CBC(binascii.unhexlify(iv)),
)
actual_ciphertext = cipher.encrypt(binascii.unhexlify(plaintext))
actual_ciphertext += cipher.finalize()