aboutsummaryrefslogtreecommitdiffstats
path: root/tests/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/utils.py')
-rw-r--r--tests/utils.py49
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