77''' 
88
99import  json 
10- import  hashlib 
11- import  urllib .request 
1210import  sys 
1311
1412filename_input  =  sys .argv [1 ]
1917num_groups  =  len (doc ['testGroups' ])
2018
2119def  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
103104print ("/* 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
106107print (struct_definition )
107108
0 commit comments