Skip to content

Commit

Permalink
Update comments in _gej_add_ge
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdettman committed Dec 22, 2021
1 parent fe0a8de commit 0869459
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/group_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ static void secp256k1_gej_add_zinv_var(secp256k1_gej *r, const secp256k1_gej *a,


static void secp256k1_gej_add_ge(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_ge *b) {
/* Operations: 7 mul, 5 sqr, 4 normalize, 21 mul_int/add/negate/cmov */
/* Operations: 7 mul, 5 sqr, 24 add/cmov/half/mul_int/negate/normalize_weak/normalizes_to_zero */
static const secp256k1_fe fe_1 = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 1);
secp256k1_fe zz, u1, u2, s1, s2, t, tt, m, n, q, rr;
secp256k1_fe m_alt, rr_alt;
Expand All @@ -517,9 +517,9 @@ static void secp256k1_gej_add_ge(secp256k1_gej *r, const secp256k1_gej *a, const
* M = S1+S2
* Q = T*M^2
* R = T^2-U1*U2
* X3 = 4*(R^2-Q)
* Y3 = 4*(R*(3*Q-2*R^2)-M^4)
* Z3 = 2*M*Z
* X3 = R^2-Q
* Y3 = (R*(3*Q-2*R^2)-M^4)/2
* Z3 = M*Z
* (Note that the paper uses xi = Xi / Zi and yi = Yi / Zi instead.)
*
* This formula has the benefit of being the same for both addition
Expand Down Expand Up @@ -591,17 +591,17 @@ static void secp256k1_gej_add_ge(secp256k1_gej *r, const secp256k1_gej *a, const
secp256k1_fe_sqr(&n, &n);
secp256k1_fe_cmov(&n, &m, degenerate); /* n = M^3 * Malt (2) */
secp256k1_fe_sqr(&t, &rr_alt); /* t = Ralt^2 (1) */
secp256k1_fe_mul(&r->z, &a->z, &m_alt); /* r->z = Malt*Z (1) */
secp256k1_fe_mul(&r->z, &a->z, &m_alt); /* r->z = Z3 = Malt*Z (1) */
infinity = secp256k1_fe_normalizes_to_zero(&r->z) & ~a->infinity;
secp256k1_fe_negate(&q, &q, 1); /* q = -Q (2) */
secp256k1_fe_add(&t, &q); /* t = Ralt^2-Q (3) */
r->x = t; /* r->x = Ralt^2-Q (3) */
secp256k1_fe_mul_int(&t, 2); /* t = 2*x3 (6) */
secp256k1_fe_add(&t, &q); /* t = 2*x3 - Q: (8) */
secp256k1_fe_mul(&t, &t, &rr_alt); /* t = Ralt*(2*x3 - Q) (1) */
secp256k1_fe_add(&t, &n); /* t = Ralt*(2*x3 - Q) + M^3*Malt (3) */
secp256k1_fe_negate(&r->y, &t, 3); /* r->y = Ralt*(Q - 2*x3) - M^3*Malt (4) */
secp256k1_fe_half(&r->y); /* r->y = (Ralt*(Q - 2*x3) - M^3*Malt)/2 (3) */
secp256k1_fe_add(&t, &q); /* t = Ralt^2 - Q (3) */
r->x = t; /* r->x = X3 = Ralt^2 - Q (3) */
secp256k1_fe_mul_int(&t, 2); /* t = 2*X3 (6) */
secp256k1_fe_add(&t, &q); /* t = 2*X3 - Q (8) */
secp256k1_fe_mul(&t, &t, &rr_alt); /* t = Ralt*(2*X3 - Q) (1) */
secp256k1_fe_add(&t, &n); /* t = Ralt*(2*X3 - Q) + M^3*Malt (3) */
secp256k1_fe_negate(&r->y, &t, 3); /* r->y = Ralt*(Q - 2*X3) - M^3*Malt (4) */
secp256k1_fe_half(&r->y); /* r->y = Y3 = (Ralt*(Q - 2*X3) - M^3*Malt)/2 (3) */

/** In case a->infinity == 1, replace r with (b->x, b->y, 1). */
secp256k1_fe_cmov(&r->x, &b->x, a->infinity);
Expand Down

0 comments on commit 0869459

Please sign in to comment.