Skip to content

Commit f2275a4

Browse files
committed
Optimization: avoid unnecessary doublings
1 parent 953155f commit f2275a4

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
@@ -33,16 +33,18 @@ static void secp256k1_ecmult_gen_compute_table(secp256k1_ge_storage* table, cons
3333
secp256k1_gej_set_infinity(&sum);
3434
for (tooth = 0; tooth < teeth; ++tooth) {
3535
/* Here u = 2^((block*teeth + tooth)*spacing) * gen. */
36-
int bit_off;
3736
/* Make sum = sum(2^((block*teeth + t)*spacing), t=0..tooth). */
3837
secp256k1_gej_add_var(&sum, &sum, &u, NULL);
3938
/* Make u = 2^((block*teeth + tooth)*spacing + 1) * gen. */
4039
secp256k1_gej_double_var(&u, &u, NULL);
4140
/* Make ds[tooth] = u = 2^((block*teeth + tooth)*spacing + 1) * gen. */
4241
ds[tooth] = u;
43-
/* Make u = 2^((block*teeth + tooth + 1)*spacing). */
44-
for (bit_off = 1; bit_off < spacing; ++bit_off) {
45-
secp256k1_gej_double_var(&u, &u, NULL);
42+
/* Make u = 2^((block*teeth + tooth + 1)*spacing), unless at the end. */
43+
if (block + tooth != blocks + teeth - 2) {
44+
int bit_off;
45+
for (bit_off = 1; bit_off < spacing; ++bit_off) {
46+
secp256k1_gej_double_var(&u, &u, NULL);
47+
}
4648
}
4749
}
4850
/* Now u = 2^(block*(teeth + 1)*spacing) * gen. */

0 commit comments

Comments
 (0)