libsodium: Needed for Dnscrypto-proxy Release 1.3.0
[tomato.git] / release / src / router / libsodium / src / libsodium / crypto_sign / ed25519 / ref10 / ge_frombytes.c
blob1a059ee93faaa41c3954877c7f8d4e3d1ce21266
1 #include "ge.h"
3 static const fe d = {
4 #include "d.h"
5 } ;
7 static const fe sqrtm1 = {
8 #include "sqrtm1.h"
9 } ;
11 int ge_frombytes_negate_vartime(ge_p3 *h,const unsigned char *s)
13 fe u;
14 fe v;
15 fe v3;
16 fe vxx;
17 fe check;
19 fe_frombytes(h->Y,s);
20 fe_1(h->Z);
21 fe_sq(u,h->Y);
22 fe_mul(v,u,d);
23 fe_sub(u,u,h->Z); /* u = y^2-1 */
24 fe_add(v,v,h->Z); /* v = dy^2+1 */
26 fe_sq(v3,v);
27 fe_mul(v3,v3,v); /* v3 = v^3 */
28 fe_sq(h->X,v3);
29 fe_mul(h->X,h->X,v);
30 fe_mul(h->X,h->X,u); /* x = uv^7 */
32 fe_pow22523(h->X,h->X); /* x = (uv^7)^((q-5)/8) */
33 fe_mul(h->X,h->X,v3);
34 fe_mul(h->X,h->X,u); /* x = uv^3(uv^7)^((q-5)/8) */
36 fe_sq(vxx,h->X);
37 fe_mul(vxx,vxx,v);
38 fe_sub(check,vxx,u); /* vx^2-u */
39 if (fe_isnonzero(check)) {
40 fe_add(check,vxx,u); /* vx^2+u */
41 if (fe_isnonzero(check)) return -1;
42 fe_mul(h->X,h->X,sqrtm1);
45 if (fe_isnegative(h->X) == (s[31] >> 7))
46 fe_neg(h->X,h->X);
48 fe_mul(h->T,h->X,h->Y);
49 return 0;