diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2014-08-15 06:50:27 -1000 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2014-08-15 06:50:27 -1000 |
commit | 32df651fb8205711fafae360342f7d5103c072fa (patch) | |
tree | cd1e187768ac5098c980f6c38d5bf915a49d0b87 /tests/utils.py | |
parent | 0541d40b975a85ddc64d65c4fdc36bc5641bdfc6 (diff) | |
parent | 839c09d53e1450833f98958c5513bf9c227076a3 (diff) | |
download | cryptography-32df651fb8205711fafae360342f7d5103c072fa.tar.gz cryptography-32df651fb8205711fafae360342f7d5103c072fa.tar.bz2 cryptography-32df651fb8205711fafae360342f7d5103c072fa.zip |
Merge pull request #1298 from public/dh-vector-loader
KASVS vector loader
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 |