aboutsummaryrefslogtreecommitdiffstats
path: root/tests/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/utils.py')
-rw-r--r--tests/utils.py66
1 files changed, 44 insertions, 22 deletions
diff --git a/tests/utils.py b/tests/utils.py
index 2bbecd7d..0d9567f9 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -135,26 +135,6 @@ def load_cryptrec_vectors(vector_data):
return cryptrec_list
-def load_openssl_vectors(vector_data):
- vectors = []
-
- for line in vector_data:
- line = line.strip()
-
- # Blank lines and comments are ignored
- if not line or line.startswith("#"):
- continue
-
- vector = line.split(":")
- vectors.append({
- "key": vector[1].encode("ascii"),
- "iv": vector[2].encode("ascii"),
- "plaintext": vector[3].encode("ascii"),
- "ciphertext": vector[4].encode("ascii"),
- })
- return vectors
-
-
def load_hash_vectors(vector_data):
vectors = []
key = None
@@ -197,16 +177,55 @@ def load_hash_vectors(vector_data):
def load_pkcs1_vectors(vector_data):
"""
Loads data out of RSA PKCS #1 vector files.
-
- Currently only returns the key pairs.
"""
private_key_vector = None
public_key_vector = None
attr = None
key = None
+ example_vector = None
+ examples = []
vectors = []
for line in vector_data:
if (
+ line.startswith("# PSS Example") or
+ line.startswith("# PKCS#1 v1.5 Signature")
+ ):
+ if example_vector:
+ for key, value in six.iteritems(example_vector):
+ hex_str = "".join(value).replace(" ", "").encode("ascii")
+ example_vector[key] = hex_str
+ examples.append(example_vector)
+
+ attr = None
+ example_vector = collections.defaultdict(list)
+
+ if line.startswith("# Message to be signed"):
+ attr = "message"
+ continue
+ elif line.startswith("# Salt"):
+ attr = "salt"
+ continue
+ elif line.startswith("# Signature"):
+ attr = "signature"
+ continue
+ elif (
+ example_vector and
+ line.startswith("# =============================================")
+ ):
+ for key, value in six.iteritems(example_vector):
+ hex_str = "".join(value).replace(" ", "").encode("ascii")
+ example_vector[key] = hex_str
+ examples.append(example_vector)
+ example_vector = None
+ attr = None
+ elif example_vector and line.startswith("#"):
+ continue
+ else:
+ if attr is not None and example_vector is not None:
+ example_vector[attr].append(line.strip())
+ continue
+
+ if (
line.startswith("# Example") or
line.startswith("# =============================================")
):
@@ -222,6 +241,9 @@ def load_pkcs1_vectors(vector_data):
hex_str = "".join(value).replace(" ", "")
private_key_vector[key] = int(hex_str, 16)
+ private_key_vector["examples"] = examples
+ examples = []
+
assert (
private_key_vector['public_exponent'] ==
public_key_vector['public_exponent']