7
7
'''
8
8
9
9
import json
10
- import hashlib
11
- import urllib .request
12
10
import sys
13
11
14
12
filename_input = sys .argv [1 ]
19
17
num_groups = len (doc ['testGroups' ])
20
18
21
19
def to_c_array (x ):
22
- if x == "" : return ""
20
+ if x == "" :
21
+ return ""
23
22
s = ',0x' .join (a + b for a ,b in zip (x [::2 ], x [1 ::2 ]))
24
23
return "0x" + s
25
24
@@ -43,18 +42,23 @@ def to_c_array(x):
43
42
sig_size = len (test_vector ['sig' ]) // 2
44
43
msg_size = len (test_vector ['msg' ]) // 2
45
44
46
- if test_vector ['result' ] == "invalid" : expected_verify = 0
47
- elif test_vector ['result' ] == "valid" : expected_verify = 1
48
- else : raise ValueError ("invalid result field" )
45
+ if test_vector ['result' ] == "invalid" :
46
+ expected_verify = 0
47
+ elif test_vector ['result' ] == "valid" :
48
+ expected_verify = 1
49
+ else :
50
+ raise ValueError ("invalid result field" )
49
51
50
- if num_vectors != 0 and sig_size != 0 : signatures += ",\n "
52
+ if num_vectors != 0 and sig_size != 0 :
53
+ signatures += ",\n "
51
54
52
55
new_msg = False
53
56
msg = to_c_array (test_vector ['msg' ])
54
57
msg_offset = offset_msg_running
55
58
# check for repeated msg
56
- if msg not in cache_msgs .keys ():
57
- if num_vectors != 0 and msg_size != 0 : messages += ",\n "
59
+ if msg not in cache_msgs :
60
+ if num_vectors != 0 and msg_size != 0 :
61
+ messages += ",\n "
58
62
cache_msgs [msg ] = offset_msg_running
59
63
messages += msg
60
64
new_msg = True
@@ -65,8 +69,9 @@ def to_c_array(x):
65
69
pk = to_c_array (public_key ['uncompressed' ])
66
70
pk_offset = offset_pk_running
67
71
# check for repeated pk
68
- if pk not in cache_public_keys .keys ():
69
- if num_vectors != 0 : public_keys += ",\n "
72
+ if pk not in cache_public_keys :
73
+ if num_vectors != 0 :
74
+ public_keys += ",\n "
70
75
cache_public_keys [pk ] = offset_pk_running
71
76
public_keys += pk
72
77
new_pk = True
@@ -76,15 +81,11 @@ def to_c_array(x):
76
81
signatures += to_c_array (test_vector ['sig' ])
77
82
78
83
out += " /" + "* tcId: " + str (test_vector ['tcId' ]) + ". " + test_vector ['comment' ] + " *" + "/\n "
79
- out += " {" + "{0}, {1}, {2}, {3}, {4}, {5}" .format (
80
- pk_offset ,
81
- msg_offset ,
82
- msg_size ,
83
- offset_sig ,
84
- sig_size ,
85
- expected_verify ) + " },\n "
86
- if new_msg : offset_msg_running += msg_size
87
- if new_pk : offset_pk_running += 65
84
+ out += f" {{{ pk_offset } , { msg_offset } , { msg_size } , { offset_sig } , { sig_size } , { expected_verify } }},\n "
85
+ if new_msg :
86
+ offset_msg_running += msg_size
87
+ if new_pk :
88
+ offset_pk_running += 65
88
89
offset_sig += sig_size
89
90
num_vectors += 1
90
91
@@ -101,7 +102,7 @@ def to_c_array(x):
101
102
102
103
103
104
print ("/* Note: this file was autogenerated using tests_wycheproof_generate.py. Do not edit. */" )
104
- print ("#define SECP256K1_ECDSA_WYCHEPROOF_NUMBER_TESTVECTORS ({})" . format ( num_vectors ) )
105
+ print (f "#define SECP256K1_ECDSA_WYCHEPROOF_NUMBER_TESTVECTORS ({ num_vectors } )" )
105
106
106
107
print (struct_definition )
107
108
0 commit comments