Skip to content

Commit 5be353d

Browse files
Merge #1279: tests: lint wycheproof's python script
35ada3b tests: lint wycheproof's python script (RandomLattice) Pull request description: This PR lints tests_wycheproof_generate.py according to bitcoin's python linting scripts. This is a follow-up to PR #1245. ACKs for top commit: sipa: utACK 35ada3b real-or-random: utACK 35ada3b Tree-SHA512: ea405060d2e73ff3543626687de5bc5282be923b914bd5c8c53e65df8dca9bea0000c416603095efff29bc7ae43c2081454c4e506db0f6805443d023fbffaf4c
2 parents 04bf3f6 + 35ada3b commit 5be353d

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

tools/tests_wycheproof_generate.py

+22-21
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
'''
88

99
import json
10-
import hashlib
11-
import urllib.request
1210
import sys
1311

1412
filename_input = sys.argv[1]
@@ -19,7 +17,8 @@
1917
num_groups = len(doc['testGroups'])
2018

2119
def to_c_array(x):
22-
if x == "": return ""
20+
if x == "":
21+
return ""
2322
s = ',0x'.join(a+b for a,b in zip(x[::2], x[1::2]))
2423
return "0x" + s
2524

@@ -43,18 +42,23 @@ def to_c_array(x):
4342
sig_size = len(test_vector['sig']) // 2
4443
msg_size = len(test_vector['msg']) // 2
4544

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")
4951

50-
if num_vectors != 0 and sig_size != 0: signatures += ",\n "
52+
if num_vectors != 0 and sig_size != 0:
53+
signatures += ",\n "
5154

5255
new_msg = False
5356
msg = to_c_array(test_vector['msg'])
5457
msg_offset = offset_msg_running
5558
# 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 "
5862
cache_msgs[msg] = offset_msg_running
5963
messages += msg
6064
new_msg = True
@@ -65,8 +69,9 @@ def to_c_array(x):
6569
pk = to_c_array(public_key['uncompressed'])
6670
pk_offset = offset_pk_running
6771
# 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 "
7075
cache_public_keys[pk] = offset_pk_running
7176
public_keys += pk
7277
new_pk = True
@@ -76,15 +81,11 @@ def to_c_array(x):
7681
signatures += to_c_array(test_vector['sig'])
7782

7883
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
8889
offset_sig += sig_size
8990
num_vectors += 1
9091

@@ -101,7 +102,7 @@ def to_c_array(x):
101102

102103

103104
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})")
105106

106107
print(struct_definition)
107108

0 commit comments

Comments
 (0)