aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2013-11-11 14:46:20 -0800
committerAlex Gaynor <alex.gaynor@gmail.com>2013-11-11 14:46:20 -0800
commitd3ce70317016791079212d7256c3b7f195b4a375 (patch)
tree729747ea4a7d6c7e4e7e316f99317b4150c814d6
parenta3d71d471856e6c76cc1cc543efecb504dbe5c33 (diff)
downloadcryptography-d3ce70317016791079212d7256c3b7f195b4a375.tar.gz
cryptography-d3ce70317016791079212d7256c3b7f195b4a375.tar.bz2
cryptography-d3ce70317016791079212d7256c3b7f195b4a375.zip
Ignore the sections of the NIST files
-rw-r--r--tests/hazmat/primitives/test_3des.py12
-rw-r--r--tests/hazmat/primitives/test_aes.py8
-rw-r--r--tests/hazmat/primitives/test_arc4.py4
-rw-r--r--tests/hazmat/primitives/test_blowfish.py8
-rw-r--r--tests/hazmat/primitives/test_cast5.py6
-rw-r--r--tests/test_utils.py116
-rw-r--r--tests/utils.py13
7 files changed, 134 insertions, 33 deletions
diff --git a/tests/hazmat/primitives/test_3des.py b/tests/hazmat/primitives/test_3des.py
index af6bdc04..1543cfd7 100644
--- a/tests/hazmat/primitives/test_3des.py
+++ b/tests/hazmat/primitives/test_3des.py
@@ -28,7 +28,7 @@ from ...utils import load_nist_vectors_from_file
class TestTripleDES_CBC(object):
test_KAT = generate_encrypt_test(
- lambda path: load_nist_vectors_from_file(path, "ENCRYPT"),
+ lambda path: load_nist_vectors_from_file(path),
os.path.join("ciphers", "3DES", "CBC"),
[
"TCBCinvperm.rsp",
@@ -42,7 +42,7 @@ class TestTripleDES_CBC(object):
)
test_MMT = generate_encrypt_test(
- lambda path: load_nist_vectors_from_file(path, "ENCRYPT"),
+ lambda path: load_nist_vectors_from_file(path),
os.path.join("ciphers", "3DES", "CBC"),
[
"TCBCMMT1.rsp",
@@ -58,7 +58,7 @@ class TestTripleDES_CBC(object):
class TestTripleDES_OFB(object):
test_KAT = generate_encrypt_test(
- lambda path: load_nist_vectors_from_file(path, "ENCRYPT"),
+ lambda path: load_nist_vectors_from_file(path),
os.path.join("ciphers", "3DES", "OFB"),
[
"TOFBpermop.rsp",
@@ -72,7 +72,7 @@ class TestTripleDES_OFB(object):
)
test_MMT = generate_encrypt_test(
- lambda path: load_nist_vectors_from_file(path, "ENCRYPT"),
+ lambda path: load_nist_vectors_from_file(path),
os.path.join("ciphers", "3DES", "OFB"),
[
"TOFBMMT1.rsp",
@@ -88,7 +88,7 @@ class TestTripleDES_OFB(object):
class TestTripleDES_CFB(object):
test_KAT = generate_encrypt_test(
- lambda path: load_nist_vectors_from_file(path, "ENCRYPT"),
+ lambda path: load_nist_vectors_from_file(path),
os.path.join("ciphers", "3DES", "CFB"),
[
"TCFB64invperm.rsp",
@@ -102,7 +102,7 @@ class TestTripleDES_CFB(object):
)
test_MMT = generate_encrypt_test(
- lambda path: load_nist_vectors_from_file(path, "ENCRYPT"),
+ lambda path: load_nist_vectors_from_file(path),
os.path.join("ciphers", "3DES", "CFB"),
[
"TCFB64MMT1.rsp",
diff --git a/tests/hazmat/primitives/test_aes.py b/tests/hazmat/primitives/test_aes.py
index 66471fac..c4818409 100644
--- a/tests/hazmat/primitives/test_aes.py
+++ b/tests/hazmat/primitives/test_aes.py
@@ -26,7 +26,7 @@ from ...utils import (
class TestAES(object):
test_CBC = generate_encrypt_test(
- lambda path: load_nist_vectors_from_file(path, "ENCRYPT"),
+ lambda path: load_nist_vectors_from_file(path),
os.path.join("ciphers", "AES", "CBC"),
[
"CBCGFSbox128.rsp",
@@ -50,7 +50,7 @@ class TestAES(object):
)
test_ECB = generate_encrypt_test(
- lambda path: load_nist_vectors_from_file(path, "ENCRYPT"),
+ lambda path: load_nist_vectors_from_file(path),
os.path.join("ciphers", "AES", "ECB"),
[
"ECBGFSbox128.rsp",
@@ -74,7 +74,7 @@ class TestAES(object):
)
test_OFB = generate_encrypt_test(
- lambda path: load_nist_vectors_from_file(path, "ENCRYPT"),
+ lambda path: load_nist_vectors_from_file(path),
os.path.join("ciphers", "AES", "OFB"),
[
"OFBGFSbox128.rsp",
@@ -98,7 +98,7 @@ class TestAES(object):
)
test_CFB = generate_encrypt_test(
- lambda path: load_nist_vectors_from_file(path, "ENCRYPT"),
+ lambda path: load_nist_vectors_from_file(path),
os.path.join("ciphers", "AES", "CFB"),
[
"CFB128GFSbox128.rsp",
diff --git a/tests/hazmat/primitives/test_arc4.py b/tests/hazmat/primitives/test_arc4.py
index cf0c5eb4..71b5d63a 100644
--- a/tests/hazmat/primitives/test_arc4.py
+++ b/tests/hazmat/primitives/test_arc4.py
@@ -23,8 +23,8 @@ from ...utils import load_nist_vectors_from_file
class TestARC4(object):
- test_thing = generate_stream_encryption_test(
- lambda path: load_nist_vectors_from_file(path, "ENCRYPT"),
+ test_rfc = generate_stream_encryption_test(
+ lambda path: load_nist_vectors_from_file(path),
os.path.join("ciphers", "ARC4"),
[
"rfc-6229-40.txt",
diff --git a/tests/hazmat/primitives/test_blowfish.py b/tests/hazmat/primitives/test_blowfish.py
index a7f13823..6f670ad7 100644
--- a/tests/hazmat/primitives/test_blowfish.py
+++ b/tests/hazmat/primitives/test_blowfish.py
@@ -24,7 +24,7 @@ from ...utils import load_nist_vectors_from_file
class TestBlowfish(object):
test_ECB = generate_encrypt_test(
- lambda path: load_nist_vectors_from_file(path, "ENCRYPT"),
+ lambda path: load_nist_vectors_from_file(path),
os.path.join("ciphers", "Blowfish"),
["bf-ecb.txt"],
lambda key: algorithms.Blowfish(binascii.unhexlify(key)),
@@ -36,7 +36,7 @@ class TestBlowfish(object):
)
test_CBC = generate_encrypt_test(
- lambda path: load_nist_vectors_from_file(path, "ENCRYPT"),
+ lambda path: load_nist_vectors_from_file(path),
os.path.join("ciphers", "Blowfish"),
["bf-cbc.txt"],
lambda key, iv: algorithms.Blowfish(binascii.unhexlify(key)),
@@ -48,7 +48,7 @@ class TestBlowfish(object):
)
test_OFB = generate_encrypt_test(
- lambda path: load_nist_vectors_from_file(path, "ENCRYPT"),
+ lambda path: load_nist_vectors_from_file(path),
os.path.join("ciphers", "Blowfish"),
["bf-ofb.txt"],
lambda key, iv: algorithms.Blowfish(binascii.unhexlify(key)),
@@ -60,7 +60,7 @@ class TestBlowfish(object):
)
test_CFB = generate_encrypt_test(
- lambda path: load_nist_vectors_from_file(path, "ENCRYPT"),
+ lambda path: load_nist_vectors_from_file(path),
os.path.join("ciphers", "Blowfish"),
["bf-cfb.txt"],
lambda key, iv: algorithms.Blowfish(binascii.unhexlify(key)),
diff --git a/tests/hazmat/primitives/test_cast5.py b/tests/hazmat/primitives/test_cast5.py
index b2988437..4256e2c4 100644
--- a/tests/hazmat/primitives/test_cast5.py
+++ b/tests/hazmat/primitives/test_cast5.py
@@ -24,11 +24,9 @@ from ...utils import load_nist_vectors_from_file
class TestCAST5(object):
test_ECB = generate_encrypt_test(
- lambda path: load_nist_vectors_from_file(path, "ENCRYPT"),
+ lambda path: load_nist_vectors_from_file(path),
os.path.join("ciphers", "CAST5"),
- [
- "cast5-ecb.txt",
- ],
+ ["cast5-ecb.txt"],
lambda key: algorithms.CAST5(binascii.unhexlify((key))),
lambda key: modes.ECB(),
only_if=lambda backend: backend.ciphers.supported(
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 0692c8d1..457cd869 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -62,7 +62,19 @@ def test_load_nist_vectors_encrypt():
PLAINTEXT = 9798c4640bad75c7c3227db910174e72
""").splitlines()
- assert load_nist_vectors(vector_data, "ENCRYPT") == [
+ assert load_nist_vectors(vector_data) == [
+ {
+ "key": b"00000000000000000000000000000000",
+ "iv": b"00000000000000000000000000000000",
+ "plaintext": b"f34481ec3cc627bacd5dc3fb08f273e6",
+ "ciphertext": b"0336763e966d92595a567cc9ce537f5e",
+ },
+ {
+ "key": b"00000000000000000000000000000000",
+ "iv": b"00000000000000000000000000000000",
+ "plaintext": b"9798c4640bad75c7c3227db910174e72",
+ "ciphertext": b"a9a1631bf4996954ebc093957b234589",
+ },
{
"key": b"00000000000000000000000000000000",
"iv": b"00000000000000000000000000000000",
@@ -116,7 +128,19 @@ def test_load_nist_vectors_decrypt():
PLAINTEXT = 9798c4640bad75c7c3227db910174e72
""").splitlines()
- assert load_nist_vectors(vector_data, "DECRYPT") == [
+ assert load_nist_vectors(vector_data) == [
+ {
+ "key": b"00000000000000000000000000000000",
+ "iv": b"00000000000000000000000000000000",
+ "plaintext": b"f34481ec3cc627bacd5dc3fb08f273e6",
+ "ciphertext": b"0336763e966d92595a567cc9ce537f5e",
+ },
+ {
+ "key": b"00000000000000000000000000000000",
+ "iv": b"00000000000000000000000000000000",
+ "plaintext": b"9798c4640bad75c7c3227db910174e72",
+ "ciphertext": b"a9a1631bf4996954ebc093957b234589",
+ },
{
"key": b"00000000000000000000000000000000",
"iv": b"00000000000000000000000000000000",
@@ -134,8 +158,7 @@ def test_load_nist_vectors_decrypt():
def test_load_nist_vectors_from_file_encrypt():
assert load_nist_vectors_from_file(
- os.path.join("ciphers", "AES", "CBC", "CBCGFSbox128.rsp"),
- "ENCRYPT"
+ os.path.join("ciphers", "AES", "CBC", "CBCGFSbox128.rsp")
) == [
{
"key": b"00000000000000000000000000000000",
@@ -179,13 +202,54 @@ def test_load_nist_vectors_from_file_encrypt():
"plaintext": b"58c8e00b2631686d54eab84b91f0aca1",
"ciphertext": b"08a4e2efec8a8e3312ca7460b9040bbf",
},
+ {
+ "key": b"00000000000000000000000000000000",
+ "iv": b"00000000000000000000000000000000",
+ "plaintext": b"f34481ec3cc627bacd5dc3fb08f273e6",
+ "ciphertext": b"0336763e966d92595a567cc9ce537f5e",
+ },
+ {
+ "key": b"00000000000000000000000000000000",
+ "iv": b"00000000000000000000000000000000",
+ "plaintext": b"9798c4640bad75c7c3227db910174e72",
+ "ciphertext": b"a9a1631bf4996954ebc093957b234589",
+ },
+ {
+ "key": b"00000000000000000000000000000000",
+ "iv": b"00000000000000000000000000000000",
+ "plaintext": b"96ab5c2ff612d9dfaae8c31f30c42168",
+ "ciphertext": b"ff4f8391a6a40ca5b25d23bedd44a597",
+ },
+ {
+ "key": b"00000000000000000000000000000000",
+ "iv": b"00000000000000000000000000000000",
+ "plaintext": b"6a118a874519e64e9963798a503f1d35",
+ "ciphertext": b"dc43be40be0e53712f7e2bf5ca707209",
+ },
+ {
+ "key": b"00000000000000000000000000000000",
+ "iv": b"00000000000000000000000000000000",
+ "plaintext": b"cb9fceec81286ca3e989bd979b0cb284",
+ "ciphertext": b"92beedab1895a94faa69b632e5cc47ce",
+ },
+ {
+ "key": b"00000000000000000000000000000000",
+ "iv": b"00000000000000000000000000000000",
+ "plaintext": b"b26aeb1874e47ca8358ff22378f09144",
+ "ciphertext": b"459264f4798f6a78bacb89c15ed3d601",
+ },
+ {
+ "key": b"00000000000000000000000000000000",
+ "iv": b"00000000000000000000000000000000",
+ "plaintext": b"58c8e00b2631686d54eab84b91f0aca1",
+ "ciphertext": b"08a4e2efec8a8e3312ca7460b9040bbf",
+ },
]
def test_load_nist_vectors_from_file_decrypt():
assert load_nist_vectors_from_file(
os.path.join("ciphers", "AES", "CBC", "CBCGFSbox128.rsp"),
- "DECRYPT",
) == [
{
"key": b"00000000000000000000000000000000",
@@ -229,6 +293,48 @@ def test_load_nist_vectors_from_file_decrypt():
"plaintext": b"58c8e00b2631686d54eab84b91f0aca1",
"ciphertext": b"08a4e2efec8a8e3312ca7460b9040bbf",
},
+ {
+ "key": b"00000000000000000000000000000000",
+ "iv": b"00000000000000000000000000000000",
+ "plaintext": b"f34481ec3cc627bacd5dc3fb08f273e6",
+ "ciphertext": b"0336763e966d92595a567cc9ce537f5e",
+ },
+ {
+ "key": b"00000000000000000000000000000000",
+ "iv": b"00000000000000000000000000000000",
+ "plaintext": b"9798c4640bad75c7c3227db910174e72",
+ "ciphertext": b"a9a1631bf4996954ebc093957b234589",
+ },
+ {
+ "key": b"00000000000000000000000000000000",
+ "iv": b"00000000000000000000000000000000",
+ "plaintext": b"96ab5c2ff612d9dfaae8c31f30c42168",
+ "ciphertext": b"ff4f8391a6a40ca5b25d23bedd44a597",
+ },
+ {
+ "key": b"00000000000000000000000000000000",
+ "iv": b"00000000000000000000000000000000",
+ "plaintext": b"6a118a874519e64e9963798a503f1d35",
+ "ciphertext": b"dc43be40be0e53712f7e2bf5ca707209",
+ },
+ {
+ "key": b"00000000000000000000000000000000",
+ "iv": b"00000000000000000000000000000000",
+ "plaintext": b"cb9fceec81286ca3e989bd979b0cb284",
+ "ciphertext": b"92beedab1895a94faa69b632e5cc47ce",
+ },
+ {
+ "key": b"00000000000000000000000000000000",
+ "iv": b"00000000000000000000000000000000",
+ "plaintext": b"b26aeb1874e47ca8358ff22378f09144",
+ "ciphertext": b"459264f4798f6a78bacb89c15ed3d601",
+ },
+ {
+ "key": b"00000000000000000000000000000000",
+ "iv": b"00000000000000000000000000000000",
+ "plaintext": b"58c8e00b2631686d54eab84b91f0aca1",
+ "ciphertext": b"08a4e2efec8a8e3312ca7460b9040bbf",
+ },
]
diff --git a/tests/utils.py b/tests/utils.py
index cc56a9ac..0b215543 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -14,7 +14,7 @@
import os.path
-def load_nist_vectors(vector_data, op):
+def load_nist_vectors(vector_data):
section = None
count = None
data = {}
@@ -35,32 +35,29 @@ def load_nist_vectors(vector_data, op):
section = line[1:-1]
continue
- if section != op:
- continue
-
# Build our data using a simple Key = Value format
name, value = line.split(" = ")
# COUNT is a special token that indicates a new block of data
if name.upper() == "COUNT":
count = value
- data[count] = {}
+ data[section, count] = {}
# For all other tokens we simply want the name, value stored in
# the dictionary
else:
- data[count][name.lower()] = value.encode("ascii")
+ data[section, count][name.lower()] = value.encode("ascii")
# We want to test only for a particular operation, we sort them for the
# benefit of the tests of this function.
return [v for k, v in sorted(data.items(), key=lambda kv: kv[0])]
-def load_nist_vectors_from_file(filename, op):
+def load_nist_vectors_from_file(filename):
base = os.path.join(
os.path.dirname(__file__), "hazmat", "primitives", "vectors",
)
with open(os.path.join(base, filename), "r") as vector_file:
- return load_nist_vectors(vector_file, op)
+ return load_nist_vectors(vector_file)
def load_cryptrec_vectors_from_file(filename):