<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">Hi Björn,</div><div class=""><br class=""></div>You don’t even really need a square root by the way, just a Jacobi symbol evaluation.  Jacobi symbol is slightly easier for most fields, but much easier for eg p224.  Also, if for some reason you’re using EGCD instead of FLT to divide (it’s faster but needs blinding for side channels), you can get the Jacobi symbol along the way using quadratic reciprocity, but you can’t take a square root that way.<div class=""><br class=""></div><div class="">For both Montgomery and SW curves there’s an extra simple algorithm to do this.  Depending on the ladder algorithm you’re using, it basically amounts to computing 1/Z while also checking the Jacobi symbol of Z; you usually do not have to solve for y or even y^2.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Lemma for Montgomery curves: if a point on a Montgomery curve is even (i.e. twice another point) then it necessarily has a square x-coordinate.  If it is even and on the twist, then x is either 0 or nonsquare; the 0 case is an error (at least for RFC 7748, dunno about CPace).  This can be seen eg from the doubling formula:</div><div class=""><br class=""></div><div class="">Let Cy^2 = x(x^2 + Ax + 1), where for the curve C=1 is square, but for the twist it isn’t square.</div><div class=""><br class=""></div><div class="">Then x_dbl = (x^2 - 1)^2 / (4x (x^2 + Ax + 1)) = (x^2 - 1)^2 / (4 C y^2)</div><div class=""><br class=""></div><div class="">The output of the Montgomery ladder is always even if you’re clearing the cofactor.  So what you want to compute is X/Z, but also check that X/Z is square and nonzero.  This can be computed as X^2 / XZ.  Compute tmp = (XZ)^((p-3)/2).  Then the Jacobi symbol J = tmp * XZ; if J == 1 then the point is on curve and tmp = 1/XZ.  If j == -1 then the point is not on the curve.</div><div class=""><br class=""></div><div class="">If you’re using the usual Montgomery ladder (as copied into eg RFC 7748), it’s even easier.  You can see that X is always computed as the square of something, so it’s only Z that might not be square.  So you don’t need to use XZ as above, you can just do it with Z.  Compute tmp = Z^((p-3)/2), J = tmp * Z, output = X*tmp = X/Z if J==1 and error otherwise.</div><div class=""><br class=""></div><div class="">This fact is part of the motivation for Decaf / Ristretto.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">For odd-order short Weierstrass, all points are even and the lemma doesn’t hold anyway.  However, depending on the scalarmul algorithm, you likely have a very similar trick.  For example, if you’re using a Jacobian co-Z Montgomery ladder for x-only arithmetic, then the coordinates will be something like (X1 : X2 : Z^2) and (Y1 : Y2 : Z^3), where Z is unknown.  Indeed for x-only, Z can’t be known: it depends on y but Z^2 doesn’t.  The ladder setup uses this fact: you can compute the Jacobian X and Y without knowing y itself, but only y^2 and Z^2.  At the end, you solve for W := Z^2 and divide to get the output X-coordinate.<span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class=""> </span><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class=""> There are different ways to solve for Z^2 depending on the exact form of the ladder.</span></div><div class=""><br class=""></div><div class="">The key point is that your Jacobian Y-coordinates are part of the ladder state, so they're in the field by definition.  W = Z^2 is in the field since you solve for it using add/sub/mul, and X and x are in the field whether you’re on the curve or the twist.  But  the underlying y is in the field iff Z^3 is in the field, which is true if and only if W = “Z^2” you solved for is really square.  You could take the full square root W and recover the two possible y-coordinates, but if you only want x then you can just invert and check the Jacobi symbol using the exact same math as above.</div><div class=""><br class=""></div><div class="">The fastest publicly known SW ladder is my work at <a href="https://eprint.iacr.org/2020/437.pdf" class="">https://eprint.iacr.org/2020/437.pdf</a>, but (and this is not legal advice) there is a patent warning so you may want to consider the slightly slower <a href="ttps://ches.2017.rump.cr.yp.to/a1933e522beb16591d9dc8e373ad7079.pdf" class="">https://ches.2017.rump.cr.yp.to/a1933e522beb16591d9dc8e373ad7079.pdf</a> instead.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">As for the origin of the inverse square root trick, I believe that a special case of it for p==5 mod 8 is in the Ed25519 paper, and the general case is in my paper at <a href="https://eprint.iacr.org/2012/309.pdf" class="">https://eprint.iacr.org/2012/309.pdf</a>.  But someone else might have found it earlier or independently.</div><div class=""><br class=""></div><div class="">Regards,</div><div class="">— Mike<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jun 12, 2020, at 11:28 AM, Björn Haase <<a href="mailto:bjoern.m.haase@web.de" class="">bjoern.m.haase@web.de</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Hello Rene,<br class=""><br class="">yes that's true. If the check is done after a scalar multiplication,<br class="">this comes at almost no complexity adder, however still some additional<br class="">code. (Actually, IIRC it's not detailed in the elligator paper but in<br class="">the Ed25519 paper). In fact, I did already use it for speeding up<br class="">Elligator2.<br class=""><br class="">Thank's for the pointer.<br class=""><br class="">Björn<br class=""><br class=""><br class="">Am 12.06.2020 um 16:51 schrieb Rene Struik:<br class=""><blockquote type="cite" class="">Hi Bjorn:<br class=""><br class="">If one computes R:=k*Q, where the input point has coordinates<br class="">Q:=(x,y), one usually has to perform a conversion from projective<br class="">coordinates to affine coordinates, via inversion in GF(q). Checking<br class="">whether a compressed point Q is on a curve requires a square root<br class="">computation in the same field. Combining both operations (inversion +<br class="">square root computation) can be done at essentially the cost of the<br class="">square root computation. So, relative incremental cost is indeed<br class="">approximately zero, as suggested.<br class=""><br class="">sqrt{a}, 1/b can be computed via 1/sqrt{a*b^2} = 1/b*sqrt{a) --><br class="">1/sqrt{a}, sqrt{a}, 1/b (I believe this was first mentioned by Icart<br class="">and also used in the Elligator paper)<br class=""><br class="">I hope this helps.<br class=""><br class="">Rene<br class=""><br class="">On 6/12/2020 10:05 AM, Björn Haase wrote:<br class=""><blockquote type="cite" class="">Hi Rene,<br class=""><br class="">>at negligible incremental cost (a few field multiplies) even if one<br class="">implements ECDH using<br class="">>Montgomery ladders and is only given the x-coordinate of a point<br class=""><br class="">If you transfer the full point coordinates the cost indeed might be<br class="">small. If you spare the communication bandwidth and transfer the<br class="">x-coordinate only, you need code and computation for a full field<br class="">exponentiation (square root). IMO, this is worth to be spared, at least<br class="">on small targets.<br class=""><br class="">Yours,<br class=""><br class="">Björn.<br class=""><br class="">Am 12.06.2020 um 14:55 schrieb Rene Struik:<br class=""><blockquote type="cite" class="">Hi Bjorn:<br class=""><br class="">Why not simply check whether the point is on the curve? Within the<br class="">context of DH schemes, this is trivial to do and comes at negligible<br class="">incremental cost (a few field multiplies) even if one implements ECDH<br class="">using Montgomery ladders and is only given the x-coordinate of a point.<br class=""><br class="">Best regards, Rene<br class=""><br class=""><br class="">On 6/12/2020 3:32 AM, Björn Haase wrote:<br class=""><blockquote type="cite" class="">Hi to all,<br class=""><br class="">I am currently re-working the security proof for CPace<br class=""><a href="https://datatracker.ietf.org/doc/draft-haase-cpace/" class="">https://datatracker.ietf.org/doc/draft-haase-cpace/</a> such that tight<br class="">computational bounds for the adversary could be given.<br class=""><br class="">In this context, I am still looking for the name and defininition<br class="">of the<br class="">problem that captures the feature of "twist security", i.e. for the<br class="">tight reduction for the case where an active adversary passes a<br class="">point on<br class="">the twist to a honest party.<br class=""><br class="">I did not find an established security notion so far that captures<br class="">this<br class="">property so that I could re-use it in the re-worked proof.<br class="">I'd coin it "exponential transfer" and formulate it in the way:<br class="">Given two groups (modulo negation) J and J' with co-factors c and<br class="">c' in<br class="">which the discrete logarithm problem is assumed to be hard in the<br class="">prime<br class="">order subgroup and with c' = n * c and d=max(c,c'), the *exponential<br class="">transfer problem * is defined as:<br class="">Given two points B,X = B^(d * x) in J: Provide two points B' and X' in<br class="">J' with X' = B'^(d * x).<br class="">I'd like to avoid having to newly define it myself. I would very much<br class="">appreciate if anybody could give me a pointer.<br class="">Yours,<br class="">Björn<br class="">_______________________________________________<br class="">Curves mailing list<br class=""><a href="mailto:Curves@moderncrypto.org" class="">Curves@moderncrypto.org</a><br class="">https://moderncrypto.org/mailman/listinfo/curves<br class=""></blockquote><br class=""><br class=""></blockquote></blockquote><br class=""></blockquote>_______________________________________________<br class="">Curves mailing list<br class=""><a href="mailto:Curves@moderncrypto.org" class="">Curves@moderncrypto.org</a><br class="">https://moderncrypto.org/mailman/listinfo/curves<br class=""></div></div></blockquote></div><br class=""></div></body></html>