aboutsummaryrefslogtreecommitdiffstats
path: root/tests/utils.py
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2014-03-10 23:30:28 -0400
committerPaul Kehrer <paul.l.kehrer@gmail.com>2014-03-10 23:30:28 -0400
commit2f2a206e18eabb88b52b2e04b3003eb55bfdbc18 (patch)
tree1b15336205378a10fc496e5ea5d587b5b155561c /tests/utils.py
parente654ce52985c319b84bdee1ed5325ec420c7da00 (diff)
downloadcryptography-2f2a206e18eabb88b52b2e04b3003eb55bfdbc18.tar.gz
cryptography-2f2a206e18eabb88b52b2e04b3003eb55bfdbc18.tar.bz2
cryptography-2f2a206e18eabb88b52b2e04b3003eb55bfdbc18.zip
add FIPS RSA test loader + tests
Diffstat (limited to 'tests/utils.py')
-rw-r--r--tests/utils.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/utils.py b/tests/utils.py
index 519edb41..b97c7f7b 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -298,3 +298,44 @@ def load_pkcs1_vectors(vector_data):
if key is not None and attr is not None:
key[attr].append(line.strip())
return vectors
+
+
+def load_rsa_nist_vectors(vector_data):
+ test_data = None
+ data = []
+
+ for line in vector_data:
+ line = line.strip()
+
+ # Blank lines and section headers are ignored
+ if not line or line.startswith("["):
+ continue
+
+ if line.startswith("# Salt len:"):
+ salt_length = int(line.split(":")[1].strip())
+ continue
+ elif line.startswith("#"):
+ continue
+
+ # Build our data using a simple Key = Value format
+ name, value = [c.strip() for c in line.split("=")]
+
+ if name == "n":
+ n = int(value, 16)
+ elif name == "e":
+ e = int(value, 16)
+ elif name == "SHAAlg":
+ test_data = {
+ "modulus": n,
+ "public_exponent": e,
+ "salt_length": salt_length,
+ "algorithm": value.encode("ascii")
+ }
+ data.append(test_data)
+ continue
+ # For all other tokens we simply want the name, value stored in
+ # the dictionary
+ else:
+ test_data[name.lower()] = value.encode("ascii")
+
+ return data