public override ECFieldElement Sqrt() { uint[] y = x; if (Nat128.IsZero(y) || Nat128.IsOne(y)) { return(this); } uint[] array = Nat128.Create(); SecP128R1Field.Square(y, array); SecP128R1Field.Multiply(array, y, array); uint[] array2 = Nat128.Create(); SecP128R1Field.SquareN(array, 2, array2); SecP128R1Field.Multiply(array2, array, array2); uint[] array3 = Nat128.Create(); SecP128R1Field.SquareN(array2, 4, array3); SecP128R1Field.Multiply(array3, array2, array3); uint[] array4 = array2; SecP128R1Field.SquareN(array3, 2, array4); SecP128R1Field.Multiply(array4, array, array4); uint[] z = array; SecP128R1Field.SquareN(array4, 10, z); SecP128R1Field.Multiply(z, array4, z); uint[] array5 = array3; SecP128R1Field.SquareN(z, 10, array5); SecP128R1Field.Multiply(array5, array4, array5); uint[] array6 = array4; SecP128R1Field.Square(array5, array6); SecP128R1Field.Multiply(array6, y, array6); uint[] z2 = array6; SecP128R1Field.SquareN(z2, 95, z2); uint[] array7 = array5; SecP128R1Field.Square(z2, array7); return((!Nat128.Eq(y, array7)) ? null : new SecP128R1FieldElement(z2)); }
public override ECFieldElement Sqrt() { uint[] x = this.x; if (Nat128.IsZero(x) || Nat128.IsOne(x)) { return(this); } uint[] z = Nat128.Create(); SecP128R1Field.Square(x, z); SecP128R1Field.Multiply(z, x, z); uint[] numArray3 = Nat128.Create(); SecP128R1Field.SquareN(z, 2, numArray3); SecP128R1Field.Multiply(numArray3, z, numArray3); uint[] numArray4 = Nat128.Create(); SecP128R1Field.SquareN(numArray3, 4, numArray4); SecP128R1Field.Multiply(numArray4, numArray3, numArray4); uint[] numArray5 = numArray3; SecP128R1Field.SquareN(numArray4, 2, numArray5); SecP128R1Field.Multiply(numArray5, z, numArray5); uint[] numArray6 = z; SecP128R1Field.SquareN(numArray5, 10, numArray6); SecP128R1Field.Multiply(numArray6, numArray5, numArray6); uint[] numArray7 = numArray4; SecP128R1Field.SquareN(numArray6, 10, numArray7); SecP128R1Field.Multiply(numArray7, numArray5, numArray7); uint[] numArray8 = numArray5; SecP128R1Field.Square(numArray7, numArray8); SecP128R1Field.Multiply(numArray8, x, numArray8); uint[] numArray9 = numArray8; SecP128R1Field.SquareN(numArray9, 0x5f, numArray9); uint[] numArray10 = numArray7; SecP128R1Field.Square(numArray9, numArray10); return(!Nat128.Eq(x, numArray10) ? null : new SecP128R1FieldElement(numArray9)); }
public virtual bool Equals(SecP128R1FieldElement other) { if (this == other) { return(true); } if (null == other) { return(false); } return(Nat128.Eq(x, other.x)); }
// D.1.4 91 /** * return a sqrt root - the routine verifies that the calculation returns the right value - if * none exists it returns null. */ public override ECFieldElement Sqrt() { /* * Raise this element to the exponent 2^126 - 2^95 * * Breaking up the exponent's binary representation into "repunits", we get: * { 31 1s } { 95 0s } * * Therefore we need an addition chain containing 31 (the length of the repunit) We use: * 1, 2, 4, 8, 10, 20, 30, [31] */ uint[] x1 = this.x; if (Nat128.IsZero(x1) || Nat128.IsOne(x1)) { return(this); } uint[] x2 = Nat128.Create(); SecP128R1Field.Square(x1, x2); SecP128R1Field.Multiply(x2, x1, x2); uint[] x4 = Nat128.Create(); SecP128R1Field.SquareN(x2, 2, x4); SecP128R1Field.Multiply(x4, x2, x4); uint[] x8 = Nat128.Create(); SecP128R1Field.SquareN(x4, 4, x8); SecP128R1Field.Multiply(x8, x4, x8); uint[] x10 = x4; SecP128R1Field.SquareN(x8, 2, x10); SecP128R1Field.Multiply(x10, x2, x10); uint[] x20 = x2; SecP128R1Field.SquareN(x10, 10, x20); SecP128R1Field.Multiply(x20, x10, x20); uint[] x30 = x8; SecP128R1Field.SquareN(x20, 10, x30); SecP128R1Field.Multiply(x30, x10, x30); uint[] x31 = x10; SecP128R1Field.Square(x30, x31); SecP128R1Field.Multiply(x31, x1, x31); uint[] t1 = x31; SecP128R1Field.SquareN(t1, 95, t1); uint[] t2 = x30; SecP128R1Field.Square(t1, t2); return(Nat128.Eq(x1, t2) ? new SecP128R1FieldElement(t1) : null); }
public virtual bool Equals(SecP128R1FieldElement other) { return(this == other || (other != null && Nat128.Eq(this.x, other.x))); }