public override ECFieldElement Sqrt() { uint[] x = this.x; if (Nat192.IsZero(x) || Nat192.IsOne(x)) { return(this); } uint[] z = Nat192.Create(); uint[] numArray3 = Nat192.Create(); SecP192R1Field.Square(x, z); SecP192R1Field.Multiply(z, x, z); SecP192R1Field.SquareN(z, 2, numArray3); SecP192R1Field.Multiply(numArray3, z, numArray3); SecP192R1Field.SquareN(numArray3, 4, z); SecP192R1Field.Multiply(z, numArray3, z); SecP192R1Field.SquareN(z, 8, numArray3); SecP192R1Field.Multiply(numArray3, z, numArray3); SecP192R1Field.SquareN(numArray3, 0x10, z); SecP192R1Field.Multiply(z, numArray3, z); SecP192R1Field.SquareN(z, 0x20, numArray3); SecP192R1Field.Multiply(numArray3, z, numArray3); SecP192R1Field.SquareN(numArray3, 0x40, z); SecP192R1Field.Multiply(z, numArray3, z); SecP192R1Field.SquareN(z, 0x3e, z); SecP192R1Field.Square(z, numArray3); return(!Nat192.Eq(x, numArray3) ? null : new SecP192R1FieldElement(z)); }
public override ECFieldElement Sqrt() { uint[] y = x; if (Nat192.IsZero(y) || Nat192.IsOne(y)) { return(this); } uint[] array = Nat192.Create(); uint[] array2 = Nat192.Create(); SecP192R1Field.Square(y, array); SecP192R1Field.Multiply(array, y, array); SecP192R1Field.SquareN(array, 2, array2); SecP192R1Field.Multiply(array2, array, array2); SecP192R1Field.SquareN(array2, 4, array); SecP192R1Field.Multiply(array, array2, array); SecP192R1Field.SquareN(array, 8, array2); SecP192R1Field.Multiply(array2, array, array2); SecP192R1Field.SquareN(array2, 16, array); SecP192R1Field.Multiply(array, array2, array); SecP192R1Field.SquareN(array, 32, array2); SecP192R1Field.Multiply(array2, array, array2); SecP192R1Field.SquareN(array2, 64, array); SecP192R1Field.Multiply(array, array2, array); SecP192R1Field.SquareN(array, 62, array); SecP192R1Field.Square(array, array2); return((!Nat192.Eq(y, array2)) ? null : new SecP192R1FieldElement(array)); }
public virtual bool Equals(SecP192R1FieldElement other) { if (this == other) return true; if (null == other) return false; return Nat192.Eq(x, other.x); }
public virtual bool Equals(SecP192R1FieldElement other) { if (this == other) { return(true); } if (null == other) { return(false); } return(Nat192.Eq(x, other.x)); }
public override ECFieldElement Sqrt() { uint[] y = this.x; if (Nat192.IsZero(y) || Nat192.IsOne(y)) { return(this); } uint[] array = Nat192.Create(); SecP192K1Field.Square(y, array); SecP192K1Field.Multiply(array, y, array); uint[] array2 = Nat192.Create(); SecP192K1Field.Square(array, array2); SecP192K1Field.Multiply(array2, y, array2); uint[] array3 = Nat192.Create(); SecP192K1Field.SquareN(array2, 3, array3); SecP192K1Field.Multiply(array3, array2, array3); uint[] array4 = array3; SecP192K1Field.SquareN(array3, 2, array4); SecP192K1Field.Multiply(array4, array, array4); uint[] array5 = array; SecP192K1Field.SquareN(array4, 8, array5); SecP192K1Field.Multiply(array5, array4, array5); uint[] array6 = array4; SecP192K1Field.SquareN(array5, 3, array6); SecP192K1Field.Multiply(array6, array2, array6); uint[] array7 = Nat192.Create(); SecP192K1Field.SquareN(array6, 16, array7); SecP192K1Field.Multiply(array7, array5, array7); uint[] array8 = array5; SecP192K1Field.SquareN(array7, 35, array8); SecP192K1Field.Multiply(array8, array7, array8); uint[] z = array7; SecP192K1Field.SquareN(array8, 70, z); SecP192K1Field.Multiply(z, array8, z); uint[] array9 = array8; SecP192K1Field.SquareN(z, 19, array9); SecP192K1Field.Multiply(array9, array6, array9); uint[] z2 = array9; SecP192K1Field.SquareN(z2, 20, z2); SecP192K1Field.Multiply(z2, array6, z2); SecP192K1Field.SquareN(z2, 4, z2); SecP192K1Field.Multiply(z2, array2, z2); SecP192K1Field.SquareN(z2, 6, z2); SecP192K1Field.Multiply(z2, array2, z2); SecP192K1Field.Square(z2, z2); uint[] array10 = array2; SecP192K1Field.Square(z2, array10); if (!Nat192.Eq(y, array10)) { return(null); } return(new SecP192K1FieldElement(z2)); }
public override ECFieldElement Sqrt() { uint[] x = this.x; if (Nat192.IsZero(x) || Nat192.IsOne(x)) { return(this); } uint[] z = Nat192.Create(); SecP192K1Field.Square(x, z); SecP192K1Field.Multiply(z, x, z); uint[] numArray3 = Nat192.Create(); SecP192K1Field.Square(z, numArray3); SecP192K1Field.Multiply(numArray3, x, numArray3); uint[] numArray4 = Nat192.Create(); SecP192K1Field.SquareN(numArray3, 3, numArray4); SecP192K1Field.Multiply(numArray4, numArray3, numArray4); uint[] numArray5 = numArray4; SecP192K1Field.SquareN(numArray4, 2, numArray5); SecP192K1Field.Multiply(numArray5, z, numArray5); uint[] numArray6 = z; SecP192K1Field.SquareN(numArray5, 8, numArray6); SecP192K1Field.Multiply(numArray6, numArray5, numArray6); uint[] numArray7 = numArray5; SecP192K1Field.SquareN(numArray6, 3, numArray7); SecP192K1Field.Multiply(numArray7, numArray3, numArray7); uint[] numArray8 = Nat192.Create(); SecP192K1Field.SquareN(numArray7, 0x10, numArray8); SecP192K1Field.Multiply(numArray8, numArray6, numArray8); uint[] numArray9 = numArray6; SecP192K1Field.SquareN(numArray8, 0x23, numArray9); SecP192K1Field.Multiply(numArray9, numArray8, numArray9); uint[] numArray10 = numArray8; SecP192K1Field.SquareN(numArray9, 70, numArray10); SecP192K1Field.Multiply(numArray10, numArray9, numArray10); uint[] numArray11 = numArray9; SecP192K1Field.SquareN(numArray10, 0x13, numArray11); SecP192K1Field.Multiply(numArray11, numArray7, numArray11); uint[] numArray12 = numArray11; SecP192K1Field.SquareN(numArray12, 20, numArray12); SecP192K1Field.Multiply(numArray12, numArray7, numArray12); SecP192K1Field.SquareN(numArray12, 4, numArray12); SecP192K1Field.Multiply(numArray12, numArray3, numArray12); SecP192K1Field.SquareN(numArray12, 6, numArray12); SecP192K1Field.Multiply(numArray12, numArray3, numArray12); SecP192K1Field.Square(numArray12, numArray12); uint[] numArray13 = numArray3; SecP192K1Field.Square(numArray12, numArray13); return(!Nat192.Eq(x, numArray13) ? null : new SecP192K1FieldElement(numArray12)); }
/** * 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^190 - 2^62 uint[] x1 = this.x; if (Nat192.IsZero(x1) || Nat192.IsOne(x1)) { return(this); } uint[] t1 = Nat192.Create(); uint[] t2 = Nat192.Create(); SecP192R1Field.Square(x1, t1); SecP192R1Field.Multiply(t1, x1, t1); SecP192R1Field.SquareN(t1, 2, t2); SecP192R1Field.Multiply(t2, t1, t2); SecP192R1Field.SquareN(t2, 4, t1); SecP192R1Field.Multiply(t1, t2, t1); SecP192R1Field.SquareN(t1, 8, t2); SecP192R1Field.Multiply(t2, t1, t2); SecP192R1Field.SquareN(t2, 16, t1); SecP192R1Field.Multiply(t1, t2, t1); SecP192R1Field.SquareN(t1, 32, t2); SecP192R1Field.Multiply(t2, t1, t2); SecP192R1Field.SquareN(t2, 64, t1); SecP192R1Field.Multiply(t1, t2, t1); SecP192R1Field.SquareN(t1, 62, t1); SecP192R1Field.Square(t1, t2); return(Nat192.Eq(x1, t2) ? new SecP192R1FieldElement(t1) : null); }
/** * 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^190 - 2^30 - 2^10 - 2^6 - 2^5 - 2^4 - 2^1 * * Breaking up the exponent's binary representation into "repunits", we get: * { 159 1s } { 1 0s } { 19 1s } { 1 0s } { 3 1s } { 3 0s} { 3 1s } { 1 0s } * * Therefore we need an addition chain containing 3, 19, 159 (the lengths of the repunits) * We use: 1, 2, [3], 6, 8, 16, [19], 35, 70, 140, [159] */ uint[] x1 = this.x; if (Nat192.IsZero(x1) || Nat192.IsOne(x1)) { return(this); } uint[] x2 = Nat192.Create(); SecP192K1Field.Square(x1, x2); SecP192K1Field.Multiply(x2, x1, x2); uint[] x3 = Nat192.Create(); SecP192K1Field.Square(x2, x3); SecP192K1Field.Multiply(x3, x1, x3); uint[] x6 = Nat192.Create(); SecP192K1Field.SquareN(x3, 3, x6); SecP192K1Field.Multiply(x6, x3, x6); uint[] x8 = x6; SecP192K1Field.SquareN(x6, 2, x8); SecP192K1Field.Multiply(x8, x2, x8); uint[] x16 = x2; SecP192K1Field.SquareN(x8, 8, x16); SecP192K1Field.Multiply(x16, x8, x16); uint[] x19 = x8; SecP192K1Field.SquareN(x16, 3, x19); SecP192K1Field.Multiply(x19, x3, x19); uint[] x35 = Nat192.Create(); SecP192K1Field.SquareN(x19, 16, x35); SecP192K1Field.Multiply(x35, x16, x35); uint[] x70 = x16; SecP192K1Field.SquareN(x35, 35, x70); SecP192K1Field.Multiply(x70, x35, x70); uint[] x140 = x35; SecP192K1Field.SquareN(x70, 70, x140); SecP192K1Field.Multiply(x140, x70, x140); uint[] x159 = x70; SecP192K1Field.SquareN(x140, 19, x159); SecP192K1Field.Multiply(x159, x19, x159); uint[] t1 = x159; SecP192K1Field.SquareN(t1, 20, t1); SecP192K1Field.Multiply(t1, x19, t1); SecP192K1Field.SquareN(t1, 4, t1); SecP192K1Field.Multiply(t1, x3, t1); SecP192K1Field.SquareN(t1, 6, t1); SecP192K1Field.Multiply(t1, x3, t1); SecP192K1Field.Square(t1, t1); uint[] t2 = x3; SecP192K1Field.Square(t1, t2); return(Nat192.Eq(x1, t2) ? new SecP192K1FieldElement(t1) : null); }
public virtual bool Equals(SecP192K1FieldElement other) { return(this == other || (other != null && Nat192.Eq(this.x, other.x))); }