-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtmp.py
More file actions
49 lines (43 loc) · 1.49 KB
/
tmp.py
File metadata and controls
49 lines (43 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Temporary utility to parse test vector imput file formats and convert them to JSON
# must be adapted for each file because the format is not universal (see vecteurs/README.md)
import json
vec = []
V = {}
V["operation"] = "SIGN"
V["expected"] = "OK"
V["curve"] = "s"
def reset():
global V
r = {}
r["operation"] = V["operation"]
r["expected"] = V["expected"]
r["curve"] = V["curve"]
V = r
V["da"] = ""
V["digest"] = ""
V["r"] = ""
V["s"] = ""
V["k"] = ""
with open("../../../Desktop/SigGenComponent.txt", 'r') as f:
for line in f:
if line.startswith("[P-"):
V["curve"] = line[1:].split(",")[0].replace("P-192", "secp192r1").replace("P-224", "secp224r1").replace("P-256", "secp256r1").replace("P-384", "secp384r1").replace("P-521", "secp521r1")
if line.startswith("Msg = "):
V["digest"] = line.split(" = ")[1].strip()
if line.startswith("d = "):
V["da"] = line.split(" = ")[1].strip()
if line.startswith("k = "):
V["k"] = line.split(" = ")[1].strip()
if line.startswith("R = "):
V["r"] = line.split(" = ")[1].strip()
if line.startswith("S = "):
V["s"] = line.split(" = ")[1].strip()
if V["curve"] == "secp192r1" or V["curve"] == "secp224r1" or V["curve"] == "secp256r1":
vec.append(V)
reset()
f = {}
f["type"] = None
f["alg"] = "ECDSA"
f["mode"] = None
f["vectors"] = vec
json.dump(f, open("/tmp/json.json", "w"))