1111 print ("Usage: %s <dir>" % sys .argv [0 ])
1212 sys .exit (1 )
1313
14- s = (
15- """/**
14+ s = """/**
1615 * Automatically generated by %s.
1716 *
1817 * Test vectors according to BIP-374 ("Discrete Log Equality Proofs") are included in this file.
1918 * Tests are included in src/modules/dleq/tests_impl.h. */
20- """ % sys .argv [0 ]
21- )
19+ """ % sys .argv [0 ]
20+
2221
2322def hexstr_to_intarray (str ):
2423 try :
2524 return ", " .join ([f"0x{ b :02X} " for b in bytes .fromhex (str )])
2625 except ValueError :
2726 return "0x00"
2827
28+
2929def create_init (name , rows , cols ):
3030 return """
3131static const unsigned char %s[%d][%d] = {
@@ -35,9 +35,11 @@ def create_init(name, rows, cols):
3535 cols ,
3636 )
3737
38+
3839def init_array (key ):
3940 return textwrap .indent ("{ %s };" % ", " .join (test_case [key ]), "" )
4041
42+
4143def init_arrays (key ):
4244 s = textwrap .indent (
4345 ",\n " .join (["{ %s }" % hexstr_to_intarray (x ) for x in test_case [key ]]), 4 * " "
@@ -62,7 +64,7 @@ def init_arrays(key):
6264}
6365
6466
65- with open (sys .argv [1 ] + "/test_vectors_generate_proof.csv" , newline = '' ) as csvfile :
67+ with open (sys .argv [1 ] + "/test_vectors_generate_proof.csv" , newline = "" ) as csvfile :
6668 reader = csv .DictReader (csvfile )
6769 # Skip the first 5 rows since those test vectors don't use secp's generator point
6870 for _ in range (5 ):
@@ -76,27 +78,35 @@ def init_arrays(key):
7678 special_cases = {
7779 "point_B" : "INFINITY" ,
7880 "result_proof" : "INVALID" ,
79- "message" : ""
81+ "message" : "" ,
8082 }
81- test_case [key ].append ("0" if row [key ] in special_cases .get (key , []) else row [key ])
83+ test_case [key ].append (
84+ "0" if row [key ] in special_cases .get (key , []) else row [key ]
85+ )
8286 else :
8387 # these keys are not present in current csv file but are present in test_vectors_verify_proof.csv
8488 if key in {"point_A" , "point_C" }:
8589 # "0" is filled as value for these missing keys
8690 test_case [key ].append ("0" )
8791 elif key == "result_success" :
8892 # success/failure value is obtained from row["comment"] for the missing key "result_success"
89- test_case [key ].append ("1" if "Success" in row .get ("comment" , "" ) else "0" )
93+ test_case [key ].append (
94+ "1" if "Success" in row .get ("comment" , "" ) else "0"
95+ )
9096 else :
91- sys .exit ("Unexpected missing_key encountered when parsing test_vectors_generate_proof.csv" )
97+ sys .exit (
98+ "Unexpected missing_key encountered when parsing test_vectors_generate_proof.csv"
99+ )
92100
93101
94- with open (sys .argv [1 ] + "/test_vectors_verify_proof.csv" , newline = '' ) as csvfile :
102+ with open (sys .argv [1 ] + "/test_vectors_verify_proof.csv" , newline = "" ) as csvfile :
95103 reader = csv .DictReader (csvfile )
96- for _ in range (5 ): # Skip the first 5 rows since those test vectors don't use secp's generator point
104+ for _ in range (
105+ 5
106+ ): # Skip the first 5 rows since those test vectors don't use secp's generator point
97107 next (reader , None )
98108
99- for i in range (3 ):
109+ for i in range (3 ):
100110 # Fill point_A and point_C for the 3 success cases (array indices 0-2) from verify CSV
101111 # These correspond to generate and verify CSV rows 5-7
102112 row = next (reader )
@@ -108,15 +118,19 @@ def init_arrays(key):
108118 if key in row :
109119 # these keys are present in test_vectors_verify_proof.csv
110120 # not handling row[key] == "TRUE" since it doesn't appear in the BIP test vectors
111- test_case [key ].append ("0" if key == "result_success" and row [key ] == "FALSE" else row [key ])
121+ test_case [key ].append (
122+ "0" if key == "result_success" and row [key ] == "FALSE" else row [key ]
123+ )
112124 else :
113125 # these keys are not present in current csv file but are present in test_vectors_generate_proof.csv
114126 if key == "result_proof" :
115127 # interpret "result_proof" key in the test_vectors_generate_proof.csv test vectors
116128 # same as "proof" key in the test_vectors_verify_proof.csv test vectors
117129 test_case ["result_proof" ].append (row ["proof" ])
118130 elif key not in {"scalar_a" , "auxrand_r" }: # skip expected missing keys
119- sys .exit ("Unexpected missing key encountered when test_vectors_verify_proof.csv" )
131+ sys .exit (
132+ "Unexpected missing key encountered when test_vectors_verify_proof.csv"
133+ )
120134
121135
122136s += create_init ("a_bytes" , len (test_case ["scalar_a" ]), 32 )
0 commit comments