Skip to content

Commit d17f346

Browse files
peterdettmansipa
authored andcommitted
Optimization: avoid unnecessary doublings in precomputation
1 parent 2b45d49 commit d17f346

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/ecmult_gen_compute_table_impl.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,18 @@ static void secp256k1_ecmult_gen_compute_table(secp256k1_ge_storage* table, cons
4444
secp256k1_gej_set_infinity(&sum);
4545
for (tooth = 0; tooth < teeth; ++tooth) {
4646
/* Here u = 2^((block*teeth + tooth)*spacing) * gen/2. */
47-
int bit_off;
4847
/* Make sum = sum(2^((block*teeth + t)*spacing), t=0..tooth). */
4948
secp256k1_gej_add_var(&sum, &sum, &u, NULL);
5049
/* Make u = 2^((block*teeth + tooth)*spacing + 1) * gen/2. */
5150
secp256k1_gej_double_var(&u, &u, NULL);
5251
/* Make ds[tooth] = u = 2^((block*teeth + tooth)*spacing + 1) * gen/2. */
5352
ds[tooth] = u;
54-
/* Make u = 2^((block*teeth + tooth + 1)*spacing). */
55-
for (bit_off = 1; bit_off < spacing; ++bit_off) {
56-
secp256k1_gej_double_var(&u, &u, NULL);
53+
/* Make u = 2^((block*teeth + tooth + 1)*spacing), unless at the end. */
54+
if (block + tooth != blocks + teeth - 2) {
55+
int bit_off;
56+
for (bit_off = 1; bit_off < spacing; ++bit_off) {
57+
secp256k1_gej_double_var(&u, &u, NULL);
58+
}
5759
}
5860
}
5961
/* Now u = 2^(block*(teeth + 1)*spacing) * gen/2. */

0 commit comments

Comments
 (0)