Skip to content

Commit 1777163

Browse files
committed
Always generate tables for current (blocks,teeth) config
1 parent 1ae98bb commit 1777163

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/precompute_ecmult_gen.c

+20-6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ int main(int argc, char **argv) {
2222
const char outfile[] = "src/precomputed_ecmult_gen.c";
2323
FILE* fp;
2424
size_t config;
25+
int did_current_config = 0;
2526

2627
(void)argc;
2728
(void)argv;
@@ -47,16 +48,29 @@ int main(int argc, char **argv) {
4748
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");
4849
fprintf(fp, "const secp256k1_ge_storage secp256k1_ecmult_gen_prec_table[COMB_BLOCKS][COMB_POINTS] = {\n");
4950

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;
5454
int outer;
5555
size_t inner;
56+
secp256k1_ge_storage* table;
5657

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+
}
5970

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);
6074
fprintf(fp, "#if (COMB_BLOCKS == %d) && (COMB_TEETH == %d)\n", blocks, teeth);
6175
for (outer = 0; outer != blocks; outer++) {
6276
fprintf(fp,"{");

0 commit comments

Comments
 (0)