From 749ac5b6f95fdc1f09bdbefdf7744c43606b6573 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Mon, 18 Nov 2013 18:12:41 -0600 Subject: simplify nist loader to completely ignore sections --- tests/test_utils.py | 52 ++++++++++++++++++++++++++-------------------------- tests/utils.py | 40 +++++++++++----------------------------- 2 files changed, 37 insertions(+), 55 deletions(-) (limited to 'tests') diff --git a/tests/test_utils.py b/tests/test_utils.py index 0d71174b..5c58fd76 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -364,11 +364,29 @@ def test_load_nist_gcm_vectors(): """).splitlines() assert load_nist_vectors(vector_data) == [ {'aad': b'', - 'iv': b'3c', - 'tag': b'eae841d4355feeb3f786bc86625f1e5b', - 'key': b'58fab7632bcf10d2bcee58520bf37414', - 'ct': b'15c4db4cbb451211179d57017f', + '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', @@ -394,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 988a80b0..94f97d59 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -23,36 +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("]"): - if "=" in line: - # GCM section headers - if "Keylen" in line: - section = line[1:-1] - else: - section += line[1:-1] - else: - # non-GCM section headers - 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 @@ -60,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): -- cgit v1.2.3