From 08694593420d25c6ed0318572a5588fe3d2282a3 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Wed, 22 Dec 2021 14:20:01 +0700 Subject: [PATCH] Update comments in _gej_add_ge --- src/group_impl.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/group_impl.h b/src/group_impl.h index e5db70fd3f..c9cc5fcbf0 100644 --- a/src/group_impl.h +++ b/src/group_impl.h @@ -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; @@ -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 @@ -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);