File tree Expand file tree Collapse file tree 1 file changed +5
-13
lines changed
Expand file tree Collapse file tree 1 file changed +5
-13
lines changed Original file line number Diff line number Diff line change @@ -328,26 +328,18 @@ std::pair<FieldElement, bool> FieldElement::sqrt() const {
328328 // If beta^2 == -a, return beta * sqrt(-1)
329329 // Otherwise, no square root exists
330330
331- FieldElement beta = (*this * *this * *this ).pow_p58 () * *this ;
332- // Equivalent: beta = a^((p+3)/8) using a * a^((p-5)/8) = a * (a^3)^((p-5)/8) approach
333- // Actually: (p+3)/8 = (2^255-16)/8 = 2^252-2
334- // Let's use the correct formula:
335- // beta = a^((p+3)/8) = a * (a^((p-5)/8)) ... no.
336- // (p+3)/8 applied to a:
337- // a^((p+3)/8) = a * a^((p-5)/8) = a * pow_p58(a)
338- // Wait: (p+3)/8 = (p-5)/8 + 1, so a^((p+3)/8) = a * a^((p-5)/8)
331+ // a^((p+3)/8) = a * a^((p-5)/8) since (p+3)/8 = (p-5)/8 + 1
332+ FieldElement beta = this ->pow_p58 () * *this ;
339333
340- FieldElement beta2 = this ->pow_p58 () * *this ; // a^((p-5)/8 + 1) = a^((p+3)/8)
341-
342- FieldElement check = beta2.square ();
334+ FieldElement check = beta.square ();
343335
344336 if (check == *this ) {
345- return {beta2 , true };
337+ return {beta , true };
346338 }
347339
348340 FieldElement neg = FieldElement::zero () - *this ;
349341 if (check == neg) {
350- return {beta2 * sqrt_m1 (), true };
342+ return {beta * sqrt_m1 (), true };
351343 }
352344
353345 return {FieldElement::zero (), false };
You can’t perform that action at this time.
0 commit comments