]> git.lizzy.rs Git - plan9front.git/blob - sys/src/libauthsrv/elligator2.mp
upas/marshal: fix printinreplyto function
[plan9front.git] / sys / src / libauthsrv / elligator2.mp
1 #elligator2:
2 #       curve a*x^2+y^2==1+d*x^2*y^2
3 #       input r0
4 #       n is any non-square
5 #
6 elligator2(p,a,d, n, r0, X,Y,Z,T) mod(p) {
7         r = n*r0*r0;
8         D = (d*r+a-d)*(d*r-a*r-d);
9         N = (r+1)*(a-2*d);
10         ND = N*D;
11         if(ND == 0) {
12                 c = 1;
13                 e = 0;
14         } else {
15                 e = msqrt(ND, p);
16                 if(e != 0) {
17                         c = 1;
18                         e = 1/e;
19                 } else {
20                         c = -1;
21                         e = n*r0*misqrt(n*ND, p);
22                 }
23         }
24         s = c*N*e;
25         t = -c*N*(r-1)*((a-2*d)*e)^2-1;
26         X = 2*s*t;
27         Y = (1-a*s*s)*(1+a*s*s);
28         Z = (1+a*s*s)*t;
29         T = (2*s)*(1-a*s*s);
30 }