aboutsummaryrefslogtreecommitdiffstats
path: root/tests/utils.py
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2014-03-15 10:49:21 -0430
committerPaul Kehrer <paul.l.kehrer@gmail.com>2014-03-15 10:49:21 -0430
commitf05b18615bfe5134b95186fb515dd4b8a208acca (patch)
treea01217108cf0c93bfe5137d39787dd5eb93de14e /tests/utils.py
parent53faebcfdd7154d1f481ef7e0cc62a1a0c1a8334 (diff)
parent2da0013829cff0a2dd0c171baa0fec85ff1c21d8 (diff)
downloadcryptography-f05b18615bfe5134b95186fb515dd4b8a208acca.tar.gz
cryptography-f05b18615bfe5134b95186fb515dd4b8a208acca.tar.bz2
cryptography-f05b18615bfe5134b95186fb515dd4b8a208acca.zip
Merge pull request #789 from skeuomorf/loader
Loader for DSA FIPS KeyPair vectors
Diffstat (limited to 'tests/utils.py')
-rw-r--r--tests/utils.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/utils.py b/tests/utils.py
index b97c7f7b..720a9054 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -339,3 +339,52 @@ 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 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
+ elif line.startswith("[mod = L=1024"):
+ continue
+ elif line.startswith("[mod = L=2048, N=224"):
+ reading_key_data = False
+ continue
+ elif line.startswith("[mod = L=2048, N=256"):
+ reading_key_data = True
+ continue
+ elif line.startswith("[mod = L=3072"):
+ continue
+
+ if not reading_key_data:
+ continue
+
+ elif reading_key_data:
+ if line.startswith("P"):
+ vectors.append({'p': int(line.split("=")[1], 16)})
+ elif line.startswith("Q"):
+ vectors[-1]['q'] = int(line.split("=")[1], 16)
+ elif line.startswith("G"):
+ vectors[-1]['g'] = int(line.split("=")[1], 16)
+ elif line.startswith("X") and 'x' not in vectors[-1]:
+ vectors[-1]['x'] = int(line.split("=")[1], 16)
+ 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)
+ })
+ elif line.startswith("Y"):
+ vectors[-1]['y'] = int(line.split("=")[1], 16)
+
+ return vectors