Skip to content

Commit

Permalink
group: Simplify secp256k1_ge_set_all_gej
Browse files Browse the repository at this point in the history
No semantic changes.
  • Loading branch information
real-or-random committed Oct 8, 2024
1 parent 3f6bfd3 commit 3774805
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions src/group_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,37 +198,29 @@ static void secp256k1_ge_set_gej_var(secp256k1_ge *r, secp256k1_gej *a) {
static void secp256k1_ge_set_all_gej(secp256k1_ge *r, const secp256k1_gej *a, size_t len) {
secp256k1_fe u;
size_t i;
size_t last_i = SIZE_MAX;
#ifdef VERIFY
for (i = 0; i < len; i++) {
SECP256K1_GEJ_VERIFY(&a[i]);
VERIFY_CHECK(!secp256k1_gej_is_infinity(&a[i]));
}
#endif

for (i = 0; i < len; i++) {
/* Use destination's x coordinates as scratch space */
if (last_i == SIZE_MAX) {
r[i].x = a[i].z;
} else {
secp256k1_fe_mul(&r[i].x, &r[last_i].x, &a[i].z);
}
last_i = i;
}
if (last_i == SIZE_MAX) {
if (len == 0) {
return;
}
secp256k1_fe_inv(&u, &r[last_i].x);

i = last_i;
while (i > 0) {
i--;
secp256k1_fe_mul(&r[last_i].x, &r[i].x, &u);
secp256k1_fe_mul(&u, &u, &a[last_i].z);
last_i = i;
/* Use destination's x coordinates as scratch space */
r[0].x = a[0].z;
for (i = 1; i < len; i++) {
secp256k1_fe_mul(&r[i].x, &r[i - 1].x, &a[i].z);
}
VERIFY_CHECK(!a[last_i].infinity);
r[last_i].x = u;
secp256k1_fe_inv(&u, &r[len - 1].x);

for (i = len - 1; i > 0; i--) {
secp256k1_fe_mul(&r[i].x, &r[i - 1].x, &u);
secp256k1_fe_mul(&u, &u, &a[i].z);
}
r[0].x = u;

for (i = 0; i < len; i++) {
secp256k1_ge_set_gej_zinv(&r[i], &a[i], &r[i].x);
Expand Down

0 comments on commit 3774805

Please sign in to comment.