Skip to content

Commit 949e85b

Browse files
committed
Merge bitcoin#550: Optimize secp256k1_fe_normalize_weak calls.
9bd89c8 Optimize secp256k1_fe_normalize_weak calls. Move secp256k1_fe_normalize_weak calls out of ECMULT_TABLE_GET_GE and ECMULT_TABLE_GET_GE_STORAGE and into secp256k1_ge_globalz_set_table_gej instead. (Russell O'Connor) Pull request description: Move secp256k1_fe_normalize_weak calls out of ECMULT_TABLE_GET_GE and ECMULT_TABLE_GET_GE_STORAGE and into secp256k1_ge_globalz_set_table_gej instead. Tree-SHA512: 7bbb1aca8e37a268a26d7061bd1f390db129e697792f1d5ddd10ea34927616edc26ef118b500c3e5e14d1d463196033ef64e4d34b765380325c24835458b7a9b
2 parents b408c6a + 9bd89c8 commit 949e85b

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/ecmult_impl.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,8 @@ static void secp256k1_ecmult_odd_multiples_table_storage_var(const int n, secp25
277277
if ((n) > 0) { \
278278
*(r) = (pre)[((n)-1)/2]; \
279279
} else { \
280-
secp256k1_ge_neg((r), &(pre)[(-(n)-1)/2]); \
280+
*(r) = (pre)[(-(n)-1)/2]; \
281+
secp256k1_fe_negate(&((r)->y), &((r)->y), 1); \
281282
} \
282283
} while(0)
283284

@@ -289,7 +290,7 @@ static void secp256k1_ecmult_odd_multiples_table_storage_var(const int n, secp25
289290
secp256k1_ge_from_storage((r), &(pre)[((n)-1)/2]); \
290291
} else { \
291292
secp256k1_ge_from_storage((r), &(pre)[(-(n)-1)/2]); \
292-
secp256k1_ge_neg((r), (r)); \
293+
secp256k1_fe_negate(&((r)->y), &((r)->y), 1); \
293294
} \
294295
} while(0)
295296

src/group_impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ static void secp256k1_ge_globalz_set_table_gej(size_t len, secp256k1_ge *r, secp
175175
/* The z of the final point gives us the "global Z" for the table. */
176176
r[i].x = a[i].x;
177177
r[i].y = a[i].y;
178+
/* Ensure all y values are in weak normal form for fast negation of points */
179+
secp256k1_fe_normalize_weak(&r[i].y);
178180
*globalz = a[i].z;
179181
r[i].infinity = 0;
180182
zs = zr[i];

0 commit comments

Comments
 (0)