Skip to content

Commit 2652224

Browse files
jonasnickroconnor-blockstream
authored andcommitted
generators: shallue_van_de_woestijne improve comments
1 parent 5d87e80 commit 2652224

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/modules/generator/main_impl.h

+29-1
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,20 @@ static void shallue_van_de_woestijne(secp256k1_ge* ge, const secp256k1_fe* t) {
111111
wd = 1 + b + t^2
112112
x3d = c^2 * t^2 = -3 * t^2
113113
114-
so that
114+
so that if j != 0, then
115115
116116
1 / wd = 1/j * x3d
117117
1 / x3d = 1/j * wd
118+
119+
x1 = d - c * t^2 * x3d / j
120+
x3 = 1 + wd^3 / j
121+
122+
If j = 0, the function outputs the point (d, f(d)). This point is equal
123+
to (x1, f(x1)) as defined above if division by 0 is defined to be 0. In
124+
below code this is not special-cased because secp256k1_fe_inv returns 0
125+
on input 0.
126+
127+
j = 0 happens only when t = 0 (since wd != 0 as -8 is not a square).
118128
*/
119129

120130
static const secp256k1_fe negc = SECP256K1_FE_CONST(0xf5d2d456, 0xcaf80e20, 0xdcc88f3d, 0x586869d3, 0x39e092ea, 0x25eb132b, 0x8272d850, 0xe32a03dd);
@@ -123,23 +133,41 @@ static void shallue_van_de_woestijne(secp256k1_ge* ge, const secp256k1_fe* t) {
123133
secp256k1_fe wd, x3d, jinv, tmp, x1, x2, x3, alphain, betain, gammain, y1, y2, y3;
124134
int alphaquad, betaquad;
125135

136+
/* wd = t^2 */
126137
secp256k1_fe_sqr(&wd, t); /* mag 1 */
138+
/* x1 = -c * t^2 */
127139
secp256k1_fe_mul(&x1, &negc, &wd); /* mag 1 */
140+
/* x3d = t^2 */
128141
x3d = wd; /* mag 1 */
142+
/* x3d = 3 * t^2 */
129143
secp256k1_fe_mul_int(&x3d, 3); /* mag 3 */
144+
/* x3d = -3 * t^2 */
130145
secp256k1_fe_negate(&x3d, &x3d, 3); /* mag 4 */
146+
/* wd = 1 + b + t^2 */
131147
secp256k1_fe_add_int(&wd, SECP256K1_B + 1); /* mag 2 */
148+
/* jinv = wd * x3d */
132149
secp256k1_fe_mul(&jinv, &wd, &x3d); /* mag 1 */
150+
/* jinv = 1/(wd * x3d) */
133151
secp256k1_fe_inv(&jinv, &jinv); /* mag 1 */
152+
/* x1 = -c * t^2 * x3d */
134153
secp256k1_fe_mul(&x1, &x1, &x3d); /* mag 1 */
154+
/* x1 = -c * t^2 * x3d * 1/j */
135155
secp256k1_fe_mul(&x1, &x1, &jinv); /* mag 1 */
156+
/* x1 = d + -c * t^2 * x3d * 1/j */
136157
secp256k1_fe_add(&x1, &d); /* mag 2 */
158+
/* x2 = x1 */
137159
x2 = x1; /* mag 2 */
160+
/* x2 = x1 + 1 */
138161
secp256k1_fe_add_int(&x2, 1); /* mag 3 */
162+
/* x2 = - (x1 + 1) */
139163
secp256k1_fe_negate(&x2, &x2, 3); /* mag 4 */
164+
/* x3 = wd^2 */
140165
secp256k1_fe_sqr(&x3, &wd); /* mag 1 */
166+
/* x3 = wd^3 */
141167
secp256k1_fe_mul(&x3, &x3, &wd); /* mag 1 */
168+
/* x3 = wd^3 * 1/j */
142169
secp256k1_fe_mul(&x3, &x3, &jinv); /* mag 1 */
170+
/* x3 = 1 + (wd^3 * 1/j) */
143171
secp256k1_fe_add_int(&x3, 1); /* mag 2 */
144172

145173
secp256k1_fe_sqr(&alphain, &x1); /* mag 1 */

0 commit comments

Comments
 (0)