diff options
Diffstat (limited to 'tests/utils.py')
-rw-r--r-- | tests/utils.py | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/tests/utils.py b/tests/utils.py index 9d01746a..ad676c04 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -127,6 +127,9 @@ def load_openssl_vectors(vector_data): def load_hash_vectors(vector_data): vectors = [] + key = None + msg = None + md = None for line in vector_data: line = line.strip() @@ -136,6 +139,11 @@ def load_hash_vectors(vector_data): if line.startswith("Len"): length = int(line.split(" = ")[1]) + elif line.startswith("Key"): + """ + HMAC vectors contain a key attribute. Hash vectors do not. + """ + key = line.split(" = ")[1].encode("ascii") elif line.startswith("Msg"): """ In the NIST vectors they have chosen to represent an empty @@ -145,8 +153,16 @@ def load_hash_vectors(vector_data): msg = line.split(" = ")[1].encode("ascii") if length > 0 else b"" elif line.startswith("MD"): md = line.split(" = ")[1] - # after MD is found the Msg+MD tuple is complete - vectors.append((msg, md)) + # after MD is found the Msg+MD (+ potential key) tuple is complete + if key is not None: + vectors.append((msg, md, key)) + key = None + msg = None + md = None + else: + vectors.append((msg, md)) + msg = None + md = None else: raise ValueError("Unknown line in hash vector") return vectors |