Merge bitcoin-core/secp256k1#1279: tests: lint wycheproof's python script
35ada3b954ccc6c54628fb3bcc0365d176297019 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 35ada3b954ccc6c54628fb3bcc0365d176297019 real-or-random: utACK 35ada3b954ccc6c54628fb3bcc0365d176297019 Tree-SHA512: ea405060d2e73ff3543626687de5bc5282be923b914bd5c8c53e65df8dca9bea0000c416603095efff29bc7ae43c2081454c4e506db0f6805443d023fbffaf4c
This commit is contained in:
commit
5be353d658
@ -7,8 +7,6 @@ Generate a C file with ECDSA testvectors from the Wycheproof project.
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import hashlib
|
|
||||||
import urllib.request
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
filename_input = sys.argv[1]
|
filename_input = sys.argv[1]
|
||||||
@ -19,7 +17,8 @@ with open(filename_input) as f:
|
|||||||
num_groups = len(doc['testGroups'])
|
num_groups = len(doc['testGroups'])
|
||||||
|
|
||||||
def to_c_array(x):
|
def to_c_array(x):
|
||||||
if x == "": return ""
|
if x == "":
|
||||||
|
return ""
|
||||||
s = ',0x'.join(a+b for a,b in zip(x[::2], x[1::2]))
|
s = ',0x'.join(a+b for a,b in zip(x[::2], x[1::2]))
|
||||||
return "0x" + s
|
return "0x" + s
|
||||||
|
|
||||||
@ -43,18 +42,23 @@ for i in range(num_groups):
|
|||||||
sig_size = len(test_vector['sig']) // 2
|
sig_size = len(test_vector['sig']) // 2
|
||||||
msg_size = len(test_vector['msg']) // 2
|
msg_size = len(test_vector['msg']) // 2
|
||||||
|
|
||||||
if test_vector['result'] == "invalid": expected_verify = 0
|
if test_vector['result'] == "invalid":
|
||||||
elif test_vector['result'] == "valid": expected_verify = 1
|
expected_verify = 0
|
||||||
else: raise ValueError("invalid result field")
|
elif test_vector['result'] == "valid":
|
||||||
|
expected_verify = 1
|
||||||
|
else:
|
||||||
|
raise ValueError("invalid result field")
|
||||||
|
|
||||||
if num_vectors != 0 and sig_size != 0: signatures += ",\n "
|
if num_vectors != 0 and sig_size != 0:
|
||||||
|
signatures += ",\n "
|
||||||
|
|
||||||
new_msg = False
|
new_msg = False
|
||||||
msg = to_c_array(test_vector['msg'])
|
msg = to_c_array(test_vector['msg'])
|
||||||
msg_offset = offset_msg_running
|
msg_offset = offset_msg_running
|
||||||
# check for repeated msg
|
# check for repeated msg
|
||||||
if msg not in cache_msgs.keys():
|
if msg not in cache_msgs:
|
||||||
if num_vectors != 0 and msg_size != 0: messages += ",\n "
|
if num_vectors != 0 and msg_size != 0:
|
||||||
|
messages += ",\n "
|
||||||
cache_msgs[msg] = offset_msg_running
|
cache_msgs[msg] = offset_msg_running
|
||||||
messages += msg
|
messages += msg
|
||||||
new_msg = True
|
new_msg = True
|
||||||
@ -65,8 +69,9 @@ for i in range(num_groups):
|
|||||||
pk = to_c_array(public_key['uncompressed'])
|
pk = to_c_array(public_key['uncompressed'])
|
||||||
pk_offset = offset_pk_running
|
pk_offset = offset_pk_running
|
||||||
# check for repeated pk
|
# check for repeated pk
|
||||||
if pk not in cache_public_keys.keys():
|
if pk not in cache_public_keys:
|
||||||
if num_vectors != 0: public_keys += ",\n "
|
if num_vectors != 0:
|
||||||
|
public_keys += ",\n "
|
||||||
cache_public_keys[pk] = offset_pk_running
|
cache_public_keys[pk] = offset_pk_running
|
||||||
public_keys += pk
|
public_keys += pk
|
||||||
new_pk = True
|
new_pk = True
|
||||||
@ -76,15 +81,11 @@ for i in range(num_groups):
|
|||||||
signatures += to_c_array(test_vector['sig'])
|
signatures += to_c_array(test_vector['sig'])
|
||||||
|
|
||||||
out += " /" + "* tcId: " + str(test_vector['tcId']) + ". " + test_vector['comment'] + " *" + "/\n"
|
out += " /" + "* tcId: " + str(test_vector['tcId']) + ". " + test_vector['comment'] + " *" + "/\n"
|
||||||
out += " {" + "{0}, {1}, {2}, {3}, {4}, {5}".format(
|
out += f" {{{pk_offset}, {msg_offset}, {msg_size}, {offset_sig}, {sig_size}, {expected_verify} }},\n"
|
||||||
pk_offset,
|
if new_msg:
|
||||||
msg_offset,
|
offset_msg_running += msg_size
|
||||||
msg_size,
|
if new_pk:
|
||||||
offset_sig,
|
offset_pk_running += 65
|
||||||
sig_size,
|
|
||||||
expected_verify) + " },\n"
|
|
||||||
if new_msg: offset_msg_running += msg_size
|
|
||||||
if new_pk: offset_pk_running += 65
|
|
||||||
offset_sig += sig_size
|
offset_sig += sig_size
|
||||||
num_vectors += 1
|
num_vectors += 1
|
||||||
|
|
||||||
@ -101,7 +102,7 @@ typedef struct {
|
|||||||
|
|
||||||
|
|
||||||
print("/* Note: this file was autogenerated using tests_wycheproof_generate.py. Do not edit. */")
|
print("/* Note: this file was autogenerated using tests_wycheproof_generate.py. Do not edit. */")
|
||||||
print("#define SECP256K1_ECDSA_WYCHEPROOF_NUMBER_TESTVECTORS ({})".format(num_vectors))
|
print(f"#define SECP256K1_ECDSA_WYCHEPROOF_NUMBER_TESTVECTORS ({num_vectors})")
|
||||||
|
|
||||||
print(struct_definition)
|
print(struct_definition)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user