diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2014-04-12 10:02:18 -0400 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2014-04-12 10:02:18 -0400 |
commit | b1a610ba4239519befa88e5613116b7deae0ff6f (patch) | |
tree | 88065662ac72eb78c9e73bde6a523309590743d9 /tests/utils.py | |
parent | 762f660a93921abfbc82faa3a02a385810dde9dd (diff) | |
parent | cf0486082b8709fbb9002cfafb9cea93805cf76d (diff) | |
download | cryptography-b1a610ba4239519befa88e5613116b7deae0ff6f.tar.gz cryptography-b1a610ba4239519befa88e5613116b7deae0ff6f.tar.bz2 cryptography-b1a610ba4239519befa88e5613116b7deae0ff6f.zip |
Merge pull request #911 from public/ecdsa-vector-loader
ECDSA vector loader
Diffstat (limited to 'tests/utils.py')
-rw-r--r-- | tests/utils.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/utils.py b/tests/utils.py index 6ee735a1..5fa7e7e0 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -427,3 +427,58 @@ def load_fips_dsa_key_pair_vectors(vector_data): vectors[-1]['y'] = int(line.split("=")[1], 16) return vectors + + +def load_fips_ecdsa_key_pair_vectors(vector_data): + """ + Loads data out of the FIPS ECDSA KeyPair vector files. + """ + vectors = [] + key_data = None + + nist_name_map = { + "[P-192]": "secp192r1", + "[P-224]": "secp224r1", + "[P-256]": "secp192r1", + "[P-384]": "secp384r1", + "[P-521]": "secp521r1", + "[K-163]": "sect163k1", + "[K-233]": "sect233k1", + "[K-283]": "sect233k1", + "[K-409]": "sect409k1", + "[K-571]": "sect571k1", + "[B-163]": "sect163r2", + "[B-233]": "sect233r1", + "[B-283]": "sect283r1", + "[B-409]": "sect409r1", + "[B-571]": "sect571r1", + } + + for line in vector_data: + line = line.strip() + + if not line or line.startswith("#"): + continue + + if line in nist_name_map: + curve_name = nist_name_map[line] + + elif line.startswith("d = "): + if key_data is not None: + vectors.append(key_data) + + key_data = { + "curve": curve_name, + "d": int(line.split("=")[1], 16) + } + + elif key_data is not None: + if line.startswith("Qx = "): + key_data["x"] = int(line.split("=")[1], 16) + elif line.startswith("Qy = "): + key_data["y"] = int(line.split("=")[1], 16) + + if key_data is not None: + vectors.append(key_data) + + return vectors |