internal static ProjectivePoint Identity() { return(new ProjectivePoint { X = FieldElement51.Zero(), Y = FieldElement51.One(), Z = FieldElement51.One() }); }
/// Compress this point using the Ristretto encoding. public CompressedRistretto Compress() { var invsqrt = new Func <FieldElement51, (bool, FieldElement51)>((el) => { return(FieldElement51.SqrtRatioI(FieldElement51.One(), el)); }); var X = Ep.X; var Y = Ep.Y; var Z = Ep.Z; var T = Ep.T; var u1 = Z.Add(Y).Mul(Z.Sub(Y)); var u2 = X.Mul(Y); // Ignore return value since this is always square var inv = invsqrt(u1.Mul(u2.Square())); var i1 = inv.Item2.Mul(u1); var i2 = inv.Item2.Mul(u2); var z_inv = i1.Mul(i2.Mul(T)); var den_inv = i2; var iX = X.Mul(Consts.SQRT_M1); var iY = Y.Mul(Consts.SQRT_M1); var ristretto_magic = (Consts.INVSQRT_A_MINUS_D); var enchanted_denominator = i1.Mul(ristretto_magic); var rotate = T.Mul(z_inv).IsNegative(); X.ConditionalAssign(iY, rotate); Y.ConditionalAssign(iX, rotate); den_inv.ConditionalAssign(enchanted_denominator, rotate); Y.ConditionalNegate(X.Mul(z_inv).IsNegative()); var s = den_inv.Mul(Z.Sub(Y)); var s_is_negative = s.IsNegative(); s.ConditionalNegate(s_is_negative); return(new CompressedRistretto(s.ToBytes())); }
internal static EdwardsPoint Decompress(byte[] bytes) { var invsqrt = new Func <FieldElement51, (bool, FieldElement51)>((el) => { return(FieldElement51.SqrtRatioI(FieldElement51.One(), el)); }); var s = FieldElement51.FromBytes(bytes); // Step 2. Compute (X:Y:Z:T). var one = FieldElement51.One(); var ss = s.Square(); var u1 = one - ss; // 1 + as² var u2 = one + ss; // 1 - as² where a=-1 var u2_sqr = u2.Square(); // (1 - as²)² // v == ad(1+as²)² - (1-as²)² where d=-121665/121666 var nEdwardsD = Consts.EDWARDS_D.Negate(); var v = nEdwardsD * u1.Square() - u2_sqr; var I = invsqrt(v * u2_sqr); // 1/sqrt(v*u_2²) var Dx = I.Item2 * u2; // 1/sqrt(v) var Dy = I.Item2 * Dx * v; // 1/u2 // x == | 2s/sqrt(v) | == + sqrt(4s²/(ad(1+as²)² - (1-as²)²)) var x = (s + s) * Dx; var x_neg = x.IsNegative(); x.ConditionalNegate(x_neg); // y == (1-as²)/(1+as²) var y = u1 * Dy; // t == ((1+as²) sqrt(4s²/(ad(1+as²)² - (1-as²)²)))/(1-as²) var t = x * y; return(new EdwardsPoint(x, y, one, t)); }
public AffineNielsPoint() { Y_plus_X = FieldElement51.One(); Y_minus_X = FieldElement51.One(); XY2d = FieldElement51.Zero(); }