FromBytes method
Implementation
bool FromBytes(Uint8List s) {
var u = FieldElement();
var v = FieldElement();
var v3 = FieldElement();
var vxx = FieldElement();
var check = FieldElement();
FeFromBytes(Y, s);
FeOne(Z);
FeSquare(u, Y);
FeMul(v, u, d);
FeSub(u, u, Z); // y = y^2-1
FeAdd(v, v, Z); // v = dy^2+1
FeSquare(v3, v);
FeMul(v3, v3, v); // v3 = v^3
FeSquare(X, v3);
FeMul(X, X, v);
FeMul(X, X, u); // x = uv^7
fePow22523(X, X); // x = (uv^7)^((q-5)/8)
FeMul(X, X, v3);
FeMul(X, X, u); // x = uv^3(uv^7)^((q-5)/8)
var tmpX = Uint8List(32);
var tmp2 = Uint8List(32);
FeSquare(vxx, X);
FeMul(vxx, vxx, v);
FeSub(check, vxx, u); // vx^2-u
if (FeIsNonZero(check) == 1) {
FeAdd(check, vxx, u); // vx^2+u
if (FeIsNonZero(check) == 1) {
return false;
}
FeMul(X, X, SqrtM1);
FeToBytes(tmpX, X);
for (var i = 0; i < tmp2.length; i++) {
tmp2[31 - i] = tmp2[i];
}
}
if (FeIsNegative(X) != (s[31] >> 7)) {
FeNeg(X, X);
}
FeMul(T, X, Y);
return true;
}