diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2014-09-08 09:51:24 -0700 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2014-09-08 09:51:24 -0700 |
commit | 38b11cc978c9b1eacc5c1902628a9542ad5f104f (patch) | |
tree | 816297750f737579234a322534a3a997386a9251 /tests/utils.py | |
parent | e0e9541322cd9186d62f0d807efd77b3467b3ad3 (diff) | |
parent | e9d027a99b7b945e4254e2ddd407c34d500cd22d (diff) | |
download | cryptography-38b11cc978c9b1eacc5c1902628a9542ad5f104f.tar.gz cryptography-38b11cc978c9b1eacc5c1902628a9542ad5f104f.tar.bz2 cryptography-38b11cc978c9b1eacc5c1902628a9542ad5f104f.zip |
Merge branch 'master' into pem-loading-backend
Diffstat (limited to 'tests/utils.py')
-rw-r--r-- | tests/utils.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/utils.py b/tests/utils.py index 5c0e2343..5557ea85 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -624,3 +624,62 @@ def load_fips_ecdsa_signing_vectors(vector_data): if data is not None: vectors.append(data) return vectors + + +def load_kasvs_dh_vectors(vector_data): + """ + Loads data out of the KASVS key exchange vector data + """ + + result_rx = re.compile(r"([FP]) \(([0-9]+) -") + + vectors = [] + data = { + "fail_z": False, + "fail_agree": False + } + + for line in vector_data: + line = line.strip() + + if not line or line.startswith("#"): + continue + + if line.startswith("P = "): + data["p"] = int(line.split("=")[1], 16) + elif line.startswith("Q = "): + data["q"] = int(line.split("=")[1], 16) + elif line.startswith("G = "): + data["g"] = int(line.split("=")[1], 16) + elif line.startswith("Z = "): + z_hex = line.split("=")[1].strip().encode("ascii") + data["z"] = binascii.unhexlify(z_hex) + elif line.startswith("XstatCAVS = "): + data["x1"] = int(line.split("=")[1], 16) + elif line.startswith("YstatCAVS = "): + data["y1"] = int(line.split("=")[1], 16) + elif line.startswith("XstatIUT = "): + data["x2"] = int(line.split("=")[1], 16) + elif line.startswith("YstatIUT = "): + data["y2"] = 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": + if int(match.group(2)) in (5, 10): + data["fail_z"] = True + else: + data["fail_agree"] = True + + vectors.append(data) + + data = { + "p": data["p"], + "q": data["q"], + "g": data["g"], + "fail_z": False, + "fail_agree": False + } + + return vectors |