diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2015-09-24 19:17:26 -0500 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2015-09-24 19:17:26 -0500 |
commit | ddc9a581efbc11d9b6ccf74c9bcc11c4318be9ae (patch) | |
tree | 90709d01b4c81fe34f206760a4d7ed7c993d3768 /tests/utils.py | |
parent | 6272e95912ae8dc4eae295cd6bf27e6dfa0bdce9 (diff) | |
parent | 0e1989c211d52b93771db3e48524fc7975f796fa (diff) | |
download | cryptography-ddc9a581efbc11d9b6ccf74c9bcc11c4318be9ae.tar.gz cryptography-ddc9a581efbc11d9b6ccf74c9bcc11c4318be9ae.tar.bz2 cryptography-ddc9a581efbc11d9b6ccf74c9bcc11c4318be9ae.zip |
Merge pull request #2343 from simo5/ANS_X963
Implement ANSI X9.63 KDF
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 |