diff options
author | Simo Sorce <simo@redhat.com> | 2015-09-22 21:56:20 -0400 |
---|---|---|
committer | Simo Sorce <simo@redhat.com> | 2015-09-24 19:38:41 -0400 |
commit | 7600dee64841edf777bb7b64fdc1cd461a08ecf8 (patch) | |
tree | 253f827c4e939b28a40bf2c37b17cae59f7b2029 /tests/utils.py | |
parent | 53c8f6aa520cb0de6346b3fbe42229adf910dd13 (diff) | |
download | cryptography-7600dee64841edf777bb7b64fdc1cd461a08ecf8.tar.gz cryptography-7600dee64841edf777bb7b64fdc1cd461a08ecf8.tar.bz2 cryptography-7600dee64841edf777bb7b64fdc1cd461a08ecf8.zip |
Add vector loader for X9.63 vectors
Signed-off-by: Simo Sorce <simo@redhat.com>
Diffstat (limited to 'tests/utils.py')
-rw-r--r-- | tests/utils.py | 49 |
1 files changed, 49 insertions, 0 deletions
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 |