aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/test_utils.py64
-rw-r--r--tests/utils.py32
2 files changed, 53 insertions, 43 deletions
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 4dede2e7..5c58fd76 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -347,10 +347,48 @@ def test_load_nist_gcm_vectors():
AAD =
Tag = 1665b0f1a0b456e1664cfd3de08ccd
PT =
+
+ [Keylen = 128]
+ [IVlen = 8]
+ [PTlen = 104]
+ [AADlen = 0]
+ [Taglen = 128]
+
+ Count = 0
+ Key = 58fab7632bcf10d2bcee58520bf37414
+ IV = 3c
+ CT = 15c4db4cbb451211179d57017f
+ AAD =
+ Tag = eae841d4355feeb3f786bc86625f1e5b
+ FAIL
""").splitlines()
assert load_nist_vectors(vector_data) == [
{'aad': b'',
'pt': b'',
+ 'iv': b'3c819d9a9bed087615030b65',
+ 'tag': b'250327c674aaf477aef2675748cf6971',
+ 'key': b'11754cd72aec309bf52f7687212e8957',
+ 'ct': b''},
+ {'aad': b'',
+ 'pt': b'',
+ 'iv': b'794ec588176c703d3d2a7a07',
+ 'tag': b'b6e6f197168f5049aeda32dafbdaeb',
+ 'key': b'272f16edb81a7abbea887357a58c1917',
+ 'ct': b''},
+ {'aad': b'',
+ 'iv': b'907763b19b9b4ab6bd4f0281',
+ 'tag': b'a2be08210d8c470a8df6e8fbd79ec5cf',
+ 'key': b'a49a5e26a2f8cb63d05546c2a62f5343',
+ 'ct': b'',
+ 'fail': True},
+ {'aad': b'e98e9d9c618e46fef32660976f854ee3',
+ 'pt': b'd1448fa852b84408e2dad8381f363de7',
+ 'iv': b'9549e4ba69a61cad7856efc1',
+ 'tag': b'd72da7f5c6cf0bca7242c71835809449',
+ 'key': b'5c1155084cc0ede76b3bc22e9f7574ef',
+ 'ct': b'f78b60ca125218493bea1c50a2e12ef4'},
+ {'aad': b'',
+ 'pt': b'',
'iv': b'4e8df20faaf2c8eebe922902',
'tag': b'e39aeaebe86aa309a4d062d6274339',
'key': b'eac258e99c55e6ae8ef1da26640613d7',
@@ -374,27 +412,9 @@ def test_load_nist_gcm_vectors():
'key': b'fd52925f39546b4c55ffb6b20c59898c',
'ct': b''},
{'aad': b'',
- 'pt': b'',
- 'iv': b'3c819d9a9bed087615030b65',
- 'tag': b'250327c674aaf477aef2675748cf6971',
- 'key': b'11754cd72aec309bf52f7687212e8957',
- 'ct': b''},
- {'aad': b'',
- 'pt': b'',
- 'iv': b'794ec588176c703d3d2a7a07',
- 'tag': b'b6e6f197168f5049aeda32dafbdaeb',
- 'key': b'272f16edb81a7abbea887357a58c1917',
- 'ct': b''},
- {'aad': b'',
- 'iv': b'907763b19b9b4ab6bd4f0281',
- 'tag': b'a2be08210d8c470a8df6e8fbd79ec5cf',
- 'key': b'a49a5e26a2f8cb63d05546c2a62f5343',
- 'ct': b'',
+ 'iv': b'3c',
+ 'tag': b'eae841d4355feeb3f786bc86625f1e5b',
+ 'key': b'58fab7632bcf10d2bcee58520bf37414',
+ 'ct': b'15c4db4cbb451211179d57017f',
'fail': True},
- {'aad': b'e98e9d9c618e46fef32660976f854ee3',
- 'pt': b'd1448fa852b84408e2dad8381f363de7',
- 'iv': b'9549e4ba69a61cad7856efc1',
- 'tag': b'd72da7f5c6cf0bca7242c71835809449',
- 'key': b'5c1155084cc0ede76b3bc22e9f7574ef',
- 'ct': b'f78b60ca125218493bea1c50a2e12ef4'},
]
diff --git a/tests/utils.py b/tests/utils.py
index 8fa9af92..94f97d59 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -23,28 +23,19 @@ def load_vectors_from_file(filename, loader):
def load_nist_vectors(vector_data):
- section = None
- count = None
- data = {}
+ test_data = None
+ data = []
for line in vector_data:
line = line.strip()
- # Blank lines are ignored
- if not line:
- continue
-
- # Lines starting with # are comments
- if line.startswith("#"):
- continue
-
- # Look for section headers
- if line.startswith("[") and line.endswith("]"):
- section = line[1:-1]
+ # Blank lines, comments, and section headers are ignored
+ if not line or line.startswith("#") or (line.startswith("[")
+ and line.endswith("]")):
continue
if line.strip() == "FAIL":
- data[section, count]["fail"] = True
+ test_data["fail"] = True
continue
# Build our data using a simple Key = Value format
@@ -52,16 +43,15 @@ def load_nist_vectors(vector_data):
# COUNT is a special token that indicates a new block of data
if name.upper() == "COUNT":
- count = value
- data[section, count] = {}
+ test_data = {}
+ data.append(test_data)
+ continue
# For all other tokens we simply want the name, value stored in
# the dictionary
else:
- data[section, count][name.lower()] = value.encode("ascii")
+ test_data[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])]
+ return data
def load_cryptrec_vectors(vector_data):