From 987cc708e25df42a95e6a1eae189b190e58643e0 Mon Sep 17 00:00:00 2001 From: Mohammed Attia Date: Wed, 12 Mar 2014 16:07:21 +0200 Subject: Add loader and loader test for FIPS DSA KeyPair vectors --- tests/utils.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'tests/utils.py') diff --git a/tests/utils.py b/tests/utils.py index b97c7f7b..00f8353e 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -339,3 +339,58 @@ def load_rsa_nist_vectors(vector_data): test_data[name.lower()] = value.encode("ascii") return data + + +def load_fips_dsa_key_pair_vectors(vector_data): + """ + Loads data out of the FIPS DSA KeyPair vector files. + """ + vectors = [] + # When the flag is "on" it tells the loader to continue constructing + # dictionaries. We turn the flag to "off" during the blocks of the + # vectors of N=224 because we don't support it. + flag = "on" + for line in vector_data: + line = line.strip() + + if not line or line.startswith("#"): + continue + if line.startswith("[mod = L=1024"): + continue + if line.startswith("[mod = L=2048, N=224"): + flag = "off" + continue + if line.startswith("[mod = L=2048, N=256"): + flag = "on" + continue + if line.startswith("[mod = L=3072"): + continue + + if flag == "off": + continue + + if flag == "on": + if line.startswith("P"): + vectors.append({'p': int(line.split("=")[1], 16)}) + continue + if line.startswith("Q"): + vectors[-1]['q'] = int(line.split("=")[1], 16) + continue + if line.startswith("G"): + vectors[-1]['g'] = int(line.split("=")[1], 16) + continue + if line.startswith("X") and 'x' not in vectors[-1]: + vectors[-1]['x'] = int(line.split("=")[1], 16) + continue + if line.startswith("X") and 'x' in vectors[-1]: + vectors.append({'p': vectors[-1]['p'], + 'q': vectors[-1]['q'], + 'g': vectors[-1]['g'], + 'x': int(line.split("=")[1], 16) + }) + continue + if line.startswith("Y"): + vectors[-1]['y'] = int(line.split("=")[1], 16) + continue + + return vectors -- cgit v1.2.3 From 22ccb8771f9479809810506cf04b5175e1c7957c Mon Sep 17 00:00:00 2001 From: Mohammed Attia Date: Wed, 12 Mar 2014 18:27:59 +0200 Subject: Remove some of the vectors in the loader test --- tests/utils.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'tests/utils.py') diff --git a/tests/utils.py b/tests/utils.py index 00f8353e..c8181585 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -372,25 +372,19 @@ def load_fips_dsa_key_pair_vectors(vector_data): if flag == "on": if line.startswith("P"): vectors.append({'p': int(line.split("=")[1], 16)}) - continue - if line.startswith("Q"): + elif line.startswith("Q"): vectors[-1]['q'] = int(line.split("=")[1], 16) - continue - if line.startswith("G"): + elif line.startswith("G"): vectors[-1]['g'] = int(line.split("=")[1], 16) - continue - if line.startswith("X") and 'x' not in vectors[-1]: + elif line.startswith("X") and 'x' not in vectors[-1]: vectors[-1]['x'] = int(line.split("=")[1], 16) - continue - if line.startswith("X") and 'x' in vectors[-1]: + elif line.startswith("X") and 'x' in vectors[-1]: vectors.append({'p': vectors[-1]['p'], 'q': vectors[-1]['q'], 'g': vectors[-1]['g'], 'x': int(line.split("=")[1], 16) }) - continue - if line.startswith("Y"): + elif line.startswith("Y"): vectors[-1]['y'] = int(line.split("=")[1], 16) - continue return vectors -- cgit v1.2.3 From 49b92596b693d90233b66007e1a76bbd75e00f0c Mon Sep 17 00:00:00 2001 From: Mohammed Attia Date: Wed, 12 Mar 2014 20:07:05 +0200 Subject: Change flag to a bool --- tests/utils.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'tests/utils.py') diff --git a/tests/utils.py b/tests/utils.py index c8181585..720a9054 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -346,30 +346,30 @@ def load_fips_dsa_key_pair_vectors(vector_data): Loads data out of the FIPS DSA KeyPair vector files. """ vectors = [] - # When the flag is "on" it tells the loader to continue constructing - # dictionaries. We turn the flag to "off" during the blocks of the - # vectors of N=224 because we don't support it. - flag = "on" + # When reading_key_data is set to True it tells the loader to continue + # constructing dictionaries. We set reading_key_data to False during the + # blocks of the vectors of N=224 because we don't support it. + reading_key_data = True for line in vector_data: line = line.strip() if not line or line.startswith("#"): continue - if line.startswith("[mod = L=1024"): + elif line.startswith("[mod = L=1024"): continue - if line.startswith("[mod = L=2048, N=224"): - flag = "off" + elif line.startswith("[mod = L=2048, N=224"): + reading_key_data = False continue - if line.startswith("[mod = L=2048, N=256"): - flag = "on" + elif line.startswith("[mod = L=2048, N=256"): + reading_key_data = True continue - if line.startswith("[mod = L=3072"): + elif line.startswith("[mod = L=3072"): continue - if flag == "off": + if not reading_key_data: continue - if flag == "on": + elif reading_key_data: if line.startswith("P"): vectors.append({'p': int(line.split("=")[1], 16)}) elif line.startswith("Q"): -- cgit v1.2.3