@@ -22,6 +22,7 @@ int main(int argc, char **argv) {
22
22
const char outfile [] = "src/precomputed_ecmult_gen.c" ;
23
23
FILE * fp ;
24
24
size_t config ;
25
+ int did_current_config = 0 ;
25
26
26
27
(void )argc ;
27
28
(void )argv ;
@@ -47,16 +48,29 @@ int main(int argc, char **argv) {
47
48
fprintf (fp , "#define S(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) SECP256K1_GE_STORAGE_CONST(0x##a##u,0x##b##u,0x##c##u,0x##d##u,0x##e##u,0x##f##u,0x##g##u,0x##h##u,0x##i##u,0x##j##u,0x##k##u,0x##l##u,0x##m##u,0x##n##u,0x##o##u,0x##p##u)\n" );
48
49
fprintf (fp , "const secp256k1_ge_storage secp256k1_ecmult_gen_prec_table[COMB_BLOCKS][COMB_POINTS] = {\n" );
49
50
50
- for (config = 0 ; config < sizeof (CONFIGS ) / sizeof (* CONFIGS ); ++ config ) {
51
- int blocks = CONFIGS [config ][0 ];
52
- int teeth = CONFIGS [config ][1 ];
53
- size_t points = ((size_t )1 ) << (teeth - 1 );
51
+ for (config = 0 ; config < sizeof (CONFIGS ) / sizeof (* CONFIGS ) + 1 ; ++ config ) {
52
+ int blocks , teeth ;
53
+ size_t points ;
54
54
int outer ;
55
55
size_t inner ;
56
+ secp256k1_ge_storage * table ;
56
57
57
- secp256k1_ge_storage * table = checked_malloc (& default_error_callback , blocks * points * sizeof (secp256k1_ge_storage ));
58
- secp256k1_ecmult_gen_compute_table (table , & secp256k1_ge_const_g , blocks , teeth );
58
+ if (config < sizeof (CONFIGS ) / sizeof (* CONFIGS )) {
59
+ /* In all but the last iteration, output the configurations in CONFIGS. */
60
+ blocks = CONFIGS [config ][0 ];
61
+ teeth = CONFIGS [config ][1 ];
62
+ if (blocks == COMB_BLOCKS && teeth == COMB_TEETH ) did_current_config = 1 ;
63
+ } else {
64
+ /* In the last iteration, output table for (COMB_BLOCKS, COMB_TEETH) if not
65
+ * already done. */
66
+ if (did_current_config ) continue ;
67
+ blocks = COMB_BLOCKS ;
68
+ teeth = COMB_TEETH ;
69
+ }
59
70
71
+ points = ((size_t )1 ) << (teeth - 1 );
72
+ table = checked_malloc (& default_error_callback , blocks * points * sizeof (secp256k1_ge_storage ));
73
+ secp256k1_ecmult_gen_compute_table (table , & secp256k1_ge_const_g , blocks , teeth );
60
74
fprintf (fp , "#if (COMB_BLOCKS == %d) && (COMB_TEETH == %d)\n" , blocks , teeth );
61
75
for (outer = 0 ; outer != blocks ; outer ++ ) {
62
76
fprintf (fp ,"{" );
0 commit comments