From 7600dee64841edf777bb7b64fdc1cd461a08ecf8 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 22 Sep 2015 21:56:20 -0400 Subject: Add vector loader for X9.63 vectors Signed-off-by: Simo Sorce --- tests/utils.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'tests/utils.py') diff --git a/tests/utils.py b/tests/utils.py index 7e7abdf1..c0052c9a 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -6,6 +6,7 @@ from __future__ import absolute_import, division, print_function import binascii import collections +import math import re from contextlib import contextmanager @@ -760,3 +761,51 @@ def load_kasvs_ecdh_vectors(vector_data): } return vectors + + +def load_x963_vectors(vector_data): + """ + Loads data out of the X9.63 vector data + """ + + vectors = [] + + # Sets Metadata + hashname = None + vector = dict() + for line in vector_data: + line = line.strip() + + if line.startswith("[SHA"): + hashname = line[1:-1] + shared_secret_len = 0 + shared_info_len = 0 + key_data_len = 0 + elif line.startswith("[shared secret length"): + shared_secret_len = int(line[1:-1].split("=")[1].strip()) + elif line.startswith("[SharedInfo length"): + shared_info_len = int(line[1:-1].split("=")[1].strip()) + elif line.startswith("[key data length"): + key_data_len = int(line[1:-1].split("=")[1].strip()) + elif line.startswith("COUNT"): + count = int(line.split("=")[1].strip()) + vector["hash"] = hashname + vector["count"] = count + vector["shared secret length"] = shared_secret_len + vector["SharedInfo length"] = shared_info_len + vector["key data length"] = key_data_len + elif line.startswith("Z"): + vector["Z"] = line.split("=")[1].strip() + assert math.ceil(shared_secret_len / 8) * 2 == len(vector["Z"]) + elif line.startswith("SharedInfo"): + if shared_info_len != 0: + vector["SharedInfo"] = line.split("=")[1].strip() + silen = len(vector["SharedInfo"]) + assert math.ceil(shared_info_len / 8) * 2 == silen + elif line.startswith("key_data"): + vector["key_data"] = line.split("=")[1].strip() + assert math.ceil(key_data_len / 8) * 2 == len(vector["key_data"]) + vectors.append(vector) + vector = dict() + + return vectors -- cgit v1.2.3