Changeset View
Changeset View
Standalone View
Standalone View
src/secp256k1/src/group_impl.h
Show First 20 Lines • Show All 585 Lines • ▼ Show 20 Lines | static void secp256k1_gej_add_ge(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_ge *b) { | ||||
/* These two lines use the observation that either M == Malt or M == 0, | /* These two lines use the observation that either M == Malt or M == 0, | ||||
* so M^3 * Malt is either Malt^4 (which is computed by squaring), or | * so M^3 * Malt is either Malt^4 (which is computed by squaring), or | ||||
* zero (which is "computed" by cmov). So the cost is one squaring | * zero (which is "computed" by cmov). So the cost is one squaring | ||||
* versus two multiplications. */ | * versus two multiplications. */ | ||||
secp256k1_fe_sqr(&n, &n); | secp256k1_fe_sqr(&n, &n); | ||||
secp256k1_fe_cmov(&n, &m, degenerate); /* n = M^3 * Malt (2) */ | secp256k1_fe_cmov(&n, &m, degenerate); /* n = M^3 * Malt (2) */ | ||||
secp256k1_fe_sqr(&t, &rr_alt); /* t = Ralt^2 (1) */ | 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 = Malt*Z (1) */ | ||||
infinity = secp256k1_fe_normalizes_to_zero(&r->z) * (1 - a->infinity); | infinity = secp256k1_fe_normalizes_to_zero(&r->z) & ~a->infinity; | ||||
secp256k1_fe_mul_int(&r->z, 2); /* r->z = Z3 = 2*Malt*Z (2) */ | secp256k1_fe_mul_int(&r->z, 2); /* r->z = Z3 = 2*Malt*Z (2) */ | ||||
secp256k1_fe_negate(&q, &q, 1); /* q = -Q (2) */ | secp256k1_fe_negate(&q, &q, 1); /* q = -Q (2) */ | ||||
secp256k1_fe_add(&t, &q); /* t = Ralt^2-Q (3) */ | secp256k1_fe_add(&t, &q); /* t = Ralt^2-Q (3) */ | ||||
secp256k1_fe_normalize_weak(&t); | secp256k1_fe_normalize_weak(&t); | ||||
r->x = t; /* r->x = Ralt^2-Q (1) */ | r->x = t; /* r->x = Ralt^2-Q (1) */ | ||||
secp256k1_fe_mul_int(&t, 2); /* t = 2*x3 (2) */ | secp256k1_fe_mul_int(&t, 2); /* t = 2*x3 (2) */ | ||||
secp256k1_fe_add(&t, &q); /* t = 2*x3 - Q: (4) */ | secp256k1_fe_add(&t, &q); /* t = 2*x3 - Q: (4) */ | ||||
secp256k1_fe_mul(&t, &t, &rr_alt); /* t = Ralt*(2*x3 - Q) (1) */ | secp256k1_fe_mul(&t, &t, &rr_alt); /* t = Ralt*(2*x3 - Q) (1) */ | ||||
▲ Show 20 Lines • Show All 91 Lines • Show Last 20 Lines |