aboutsummaryrefslogtreecommitdiffstats
path: root/tests/utils.py
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2015-04-29 19:41:26 -0400
committerSimo Sorce <simo@redhat.com>2015-05-01 15:58:35 -0400
commit917addbb06c1cf7059fbf5465ffade186f8675f2 (patch)
tree1496c89b02133ca7a1f86316cb09ff91f2a66476 /tests/utils.py
parent12953e390654ae5ea0195558a4f78cf2ae01cb8f (diff)
downloadcryptography-917addbb06c1cf7059fbf5465ffade186f8675f2.tar.gz
cryptography-917addbb06c1cf7059fbf5465ffade186f8675f2.tar.bz2
cryptography-917addbb06c1cf7059fbf5465ffade186f8675f2.zip
Add loader for ECDH test vectors
Also fix test vector files, they had a truncated line for the EE set in both init and resp files. Signed-off-by: Simo Sorce <simo@redhat.com>
Diffstat (limited to 'tests/utils.py')
-rw-r--r--tests/utils.py104
1 files changed, 104 insertions, 0 deletions
diff --git a/tests/utils.py b/tests/utils.py
index 65c99fbf..4c74ca7c 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -656,3 +656,107 @@ def load_kasvs_dh_vectors(vector_data):
}
return vectors
+
+
+def load_kasvs_ecdh_vectors(vector_data):
+ """
+ Loads data out of the KASVS key exchange vector data
+ """
+
+ curve_name_map = {
+ "P-192": "secp192r1",
+ "P-224": "secp224r1",
+ "P-256": "secp256r1",
+ "P-384": "secp384r1",
+ "P-521": "secp521r1",
+ }
+
+ result_rx = re.compile(r"([FP]) \(([0-9]+) -")
+
+ tags = []
+ sets = dict()
+ vectors = []
+
+ # find info in header
+ for line in vector_data:
+ line = line.strip()
+
+ if line.startswith("#"):
+ parm = line.split("Parameter set(s) supported:")
+ if len(parm) == 2:
+ names = parm[1].strip().split()
+ for n in names:
+ tags.append("[%s]" % n)
+ break
+
+ # Sets Metadata
+ tag = None
+ curve = None
+ for line in vector_data:
+ line = line.strip()
+
+ if not line or line.startswith("#"):
+ continue
+
+ if line in tags:
+ tag = line
+ curve = None
+ elif line.startswith("[Curve selected:"):
+ curve = curve_name_map[line.split(':')[1].strip()[:-1]]
+
+ if tag is not None and curve is not None:
+ sets[tag.strip("[]")] = curve
+ tag = None
+ if len(tags) == len(sets):
+ break
+
+ # Data
+ data = {
+ "CAVS": dict(),
+ "IUT": dict(),
+ }
+ tag = None
+ for line in vector_data:
+ line = line.strip()
+
+ if not line or line.startswith("#"):
+ continue
+
+ if line.startswith("["):
+ tag = line.split()[0][1:]
+ elif line.startswith("COUNT = "):
+ data["COUNT"] = int(line.split("=")[1], 16)
+ elif line.startswith("dsCAVS = "):
+ data["CAVS"]["d"] = int(line.split("=")[1], 16)
+ elif line.startswith("QsCAVSx = "):
+ data["CAVS"]["x"] = int(line.split("=")[1], 16)
+ elif line.startswith("QsCAVSy = "):
+ data["CAVS"]["y"] = int(line.split("=")[1], 16)
+ elif line.startswith("dsIUT = "):
+ data["IUT"]["d"] = int(line.split("=")[1], 16)
+ elif line.startswith("QsIUTx = "):
+ data["IUT"]["x"] = int(line.split("=")[1], 16)
+ elif line.startswith("QsIUTy = "):
+ data["IUT"]["y"] = int(line.split("=")[1], 16)
+ elif line.startswith("Z = "):
+ data["Z"] = int(line.split("=")[1], 16)
+ elif line.startswith("Result = "):
+ result_str = line.split("=")[1].strip()
+ match = result_rx.match(result_str)
+
+ if match.group(1) == "F":
+ data["fail"] = True
+ else:
+ data["fail"] = False
+ data["errno"] = int(match.group(2))
+
+ data["curve"] = sets[tag]
+
+ vectors.append(data)
+
+ data = {
+ "CAVS": dict(),
+ "IUT": dict(),
+ }
+
+ return vectors