/** * 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^382 - 2^126 - 2^94 + 2^30 uint[] x1 = this.x; if (Nat.IsZero(12, x1) || Nat.IsOne(12, x1)) return this; uint[] t1 = Nat.Create(12); uint[] t2 = Nat.Create(12); uint[] t3 = Nat.Create(12); uint[] t4 = Nat.Create(12); SecP384R1Field.Square(x1, t1); SecP384R1Field.Multiply(t1, x1, t1); SecP384R1Field.SquareN(t1, 2, t2); SecP384R1Field.Multiply(t2, t1, t2); SecP384R1Field.Square(t2, t2); SecP384R1Field.Multiply(t2, x1, t2); SecP384R1Field.SquareN(t2, 5, t3); SecP384R1Field.Multiply(t3, t2, t3); SecP384R1Field.SquareN(t3, 5, t4); SecP384R1Field.Multiply(t4, t2, t4); SecP384R1Field.SquareN(t4, 15, t2); SecP384R1Field.Multiply(t2, t4, t2); SecP384R1Field.SquareN(t2, 2, t3); SecP384R1Field.Multiply(t1, t3, t1); SecP384R1Field.SquareN(t3, 28, t3); SecP384R1Field.Multiply(t2, t3, t2); SecP384R1Field.SquareN(t2, 60, t3); SecP384R1Field.Multiply(t3, t2, t3); uint[] r = t2; SecP384R1Field.SquareN(t3, 120, r); SecP384R1Field.Multiply(r, t3, r); SecP384R1Field.SquareN(r, 15, r); SecP384R1Field.Multiply(r, t4, r); SecP384R1Field.SquareN(r, 33, r); SecP384R1Field.Multiply(r, t1, r); SecP384R1Field.SquareN(r, 64, r); SecP384R1Field.Multiply(r, x1, r); SecP384R1Field.SquareN(r, 30, t1); SecP384R1Field.Square(t1, t2); return Nat.Eq(12, x1, t2) ? new SecP384R1FieldElement(t1) : null; }
public virtual bool Equals(SecP384R1FieldElement other) { if (this == other) return true; if (null == other) return false; return Nat.Eq(12, x, other.x); }
public static uint[] FromBigInteger(BigInteger x) { uint[] numArray = Nat.FromBigInteger(0x209, x); if (Nat.Eq(0x11, numArray, P)) { Nat.Zero(0x11, numArray); } return(numArray); }
public static uint[] FromBigInteger(BigInteger x) { uint[] z = Nat.FromBigInteger(521, x); if (Nat.Eq(17, z, P)) { Nat.Zero(17, z); } return(z); }
public static uint[] FromBigInteger(BigInteger x) { uint[] array = Nat.FromBigInteger(521, x); if (Nat.Eq(17, array, P)) { Nat.Zero(17, array); } return(array); }
public static void AddOne(uint[] x, uint[] z) { uint c = Nat.Inc(16, x, z) + x[16]; if (c > P16 || (c == P16 && Nat.Eq(16, z, P))) { c += Nat.Inc(16, z); c &= P16; } z[16] = c; }
public static void AddOne(uint[] x, uint[] z) { uint num = Nat.Inc(16, x, z) + x[16]; if (num > 511u || (num == 511u && Nat.Eq(16, z, SecP521R1Field.P))) { num += Nat.Inc(16, z); num &= 511u; } z[16] = num; }
public static void AddOne(uint[] x, uint[] z) { uint num = Nat.Inc(16, x, z) + x[16]; if (num > 511 || (num == 511 && Nat.Eq(16, z, P))) { num += Nat.Inc(16, z); num &= 0x1FF; } z[16] = num; }
public static void AddOne(uint[] x, uint[] z) { uint num = Nat.Inc(0x10, x, z) + x[0x10]; if ((num > 0x1ff) || ((num == 0x1ff) && Nat.Eq(0x10, z, P))) { num += Nat.Inc(0x10, z); num &= 0x1ff; } z[0x10] = num; }
public static void Reduce23(uint[] z) { uint z16 = z[16]; uint c = Nat.AddWordTo(16, z16 >> 9, z) + (z16 & P16); if (c > P16 || (c == P16 && Nat.Eq(16, z, P))) { c += Nat.Inc(16, z); c &= P16; } z[16] = c; }
public virtual bool Equals(SecP521R1FieldElement other) { if (this == other) { return(true); } if (other == null) { return(false); } return(Nat.Eq(17, x, other.x)); }
public static void Reduce23(uint[] z) { uint num = z[16]; uint num2 = Nat.AddWordTo(16, num >> 9, z) + (num & 511u); if (num2 > 511u || (num2 == 511u && Nat.Eq(16, z, SecP521R1Field.P))) { num2 += Nat.Inc(16, z); num2 &= 511u; } z[16] = num2; }
public virtual bool Equals(SecP384R1FieldElement other) { if (this == other) { return(true); } if (null == other) { return(false); } return(Nat.Eq(12, x, other.x)); }
public static void Reduce23(uint[] z) { uint num = z[16]; uint num2 = Nat.AddWordTo(16, num >> 9, z) + (num & 0x1FF); if (num2 > 511 || (num2 == 511 && Nat.Eq(16, z, P))) { num2 += Nat.Inc(16, z); num2 &= 0x1FF; } z[16] = num2; }
public static void Reduce23(uint[] z) { uint num = z[0x10]; uint num2 = Nat.AddWordTo(0x10, num >> 9, z) + (num & 0x1ff); if ((num2 > 0x1ff) || ((num2 == 0x1ff) && Nat.Eq(0x10, z, P))) { num2 += Nat.Inc(0x10, z); num2 &= 0x1ff; } z[0x10] = num2; }
public override ECFieldElement Sqrt() { uint[] array = x; if (Nat.IsZero(17, array) || Nat.IsOne(17, array)) { return(this); } uint[] z = Nat.Create(17); uint[] array2 = Nat.Create(17); SecP521R1Field.SquareN(array, 519, z); SecP521R1Field.Square(z, array2); return((!Nat.Eq(17, array, array2)) ? null : new SecP521R1FieldElement(z)); }
public override ECFieldElement Sqrt() { uint[] x = this.x; if (Nat.IsZero(0x11, x) || Nat.IsOne(0x11, x)) { return(this); } uint[] z = Nat.Create(0x11); uint[] numArray3 = Nat.Create(0x11); SecP521R1Field.SquareN(x, 0x207, z); SecP521R1Field.Square(z, numArray3); return(!Nat.Eq(0x11, x, numArray3) ? null : new SecP521R1FieldElement(z)); }
public static void Reduce(uint[] xx, uint[] z) { uint num = xx[32]; uint num2 = Nat.ShiftDownBits(16, xx, 16, 9, num, z, 0) >> 23; num2 += num >> 9; num2 += Nat.AddTo(16, xx, z); if (num2 > 511 || (num2 == 511 && Nat.Eq(16, z, P))) { num2 += Nat.Inc(16, z); num2 &= 0x1FF; } z[16] = num2; }
public static void Reduce(uint[] xx, uint[] z) { uint c = xx[0x20]; uint num2 = Nat.ShiftDownBits(0x10, xx, 0x10, 9, c, z, 0) >> 0x17; num2 += c >> 9; num2 += Nat.AddTo(0x10, xx, z); if ((num2 > 0x1ff) || ((num2 == 0x1ff) && Nat.Eq(0x10, z, P))) { num2 += Nat.Inc(0x10, z); num2 &= 0x1ff; } z[0x10] = num2; }
public static void Reduce(uint[] xx, uint[] z) { Debug.Assert(xx[32] >> 18 == 0); uint xx32 = xx[32]; uint c = Nat.ShiftDownBits(16, xx, 16, 9, xx32, z, 0) >> 23; c += xx32 >> 9; c += Nat.AddTo(16, xx, z); if (c > P16 || (c == P16 && Nat.Eq(16, z, P))) { c += Nat.Inc(16, z); c &= P16; } z[16] = c; }
public override ECFieldElement Sqrt() { uint[] y = this.x; if (Nat.IsZero(12, y) || Nat.IsOne(12, y)) { return(this); } uint[] array = Nat.Create(12); uint[] array2 = Nat.Create(12); uint[] array3 = Nat.Create(12); uint[] array4 = Nat.Create(12); SecP384R1Field.Square(y, array); SecP384R1Field.Multiply(array, y, array); SecP384R1Field.SquareN(array, 2, array2); SecP384R1Field.Multiply(array2, array, array2); SecP384R1Field.Square(array2, array2); SecP384R1Field.Multiply(array2, y, array2); SecP384R1Field.SquareN(array2, 5, array3); SecP384R1Field.Multiply(array3, array2, array3); SecP384R1Field.SquareN(array3, 5, array4); SecP384R1Field.Multiply(array4, array2, array4); SecP384R1Field.SquareN(array4, 15, array2); SecP384R1Field.Multiply(array2, array4, array2); SecP384R1Field.SquareN(array2, 2, array3); SecP384R1Field.Multiply(array, array3, array); SecP384R1Field.SquareN(array3, 28, array3); SecP384R1Field.Multiply(array2, array3, array2); SecP384R1Field.SquareN(array2, 60, array3); SecP384R1Field.Multiply(array3, array2, array3); uint[] z = array2; SecP384R1Field.SquareN(array3, 120, z); SecP384R1Field.Multiply(z, array3, z); SecP384R1Field.SquareN(z, 15, z); SecP384R1Field.Multiply(z, array4, z); SecP384R1Field.SquareN(z, 33, z); SecP384R1Field.Multiply(z, array, z); SecP384R1Field.SquareN(z, 64, z); SecP384R1Field.Multiply(z, y, z); SecP384R1Field.SquareN(z, 30, array); SecP384R1Field.Square(array, array2); if (!Nat.Eq(12, y, array2)) { return(null); } return(new SecP384R1FieldElement(array)); }
/** * 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^519 uint[] x1 = this.x; if (Nat.IsZero(17, x1) || Nat.IsOne(17, x1)) { return(this); } uint[] t1 = Nat.Create(17); uint[] t2 = Nat.Create(17); SecP521R1Field.SquareN(x1, 519, t1); SecP521R1Field.Square(t1, t2); return(Nat.Eq(17, x1, t2) ? new SecP521R1FieldElement(t1) : null); }
public override ECFieldElement Sqrt() { uint[] x = this.x; if (Nat.IsZero(12, x) || Nat.IsOne(12, x)) { return(this); } uint[] z = Nat.Create(12); uint[] numArray3 = Nat.Create(12); uint[] numArray4 = Nat.Create(12); uint[] numArray5 = Nat.Create(12); SecP384R1Field.Square(x, z); SecP384R1Field.Multiply(z, x, z); SecP384R1Field.SquareN(z, 2, numArray3); SecP384R1Field.Multiply(numArray3, z, numArray3); SecP384R1Field.Square(numArray3, numArray3); SecP384R1Field.Multiply(numArray3, x, numArray3); SecP384R1Field.SquareN(numArray3, 5, numArray4); SecP384R1Field.Multiply(numArray4, numArray3, numArray4); SecP384R1Field.SquareN(numArray4, 5, numArray5); SecP384R1Field.Multiply(numArray5, numArray3, numArray5); SecP384R1Field.SquareN(numArray5, 15, numArray3); SecP384R1Field.Multiply(numArray3, numArray5, numArray3); SecP384R1Field.SquareN(numArray3, 2, numArray4); SecP384R1Field.Multiply(z, numArray4, z); SecP384R1Field.SquareN(numArray4, 0x1c, numArray4); SecP384R1Field.Multiply(numArray3, numArray4, numArray3); SecP384R1Field.SquareN(numArray3, 60, numArray4); SecP384R1Field.Multiply(numArray4, numArray3, numArray4); uint[] numArray6 = numArray3; SecP384R1Field.SquareN(numArray4, 120, numArray6); SecP384R1Field.Multiply(numArray6, numArray4, numArray6); SecP384R1Field.SquareN(numArray6, 15, numArray6); SecP384R1Field.Multiply(numArray6, numArray5, numArray6); SecP384R1Field.SquareN(numArray6, 0x21, numArray6); SecP384R1Field.Multiply(numArray6, z, numArray6); SecP384R1Field.SquareN(numArray6, 0x40, numArray6); SecP384R1Field.Multiply(numArray6, x, numArray6); SecP384R1Field.SquareN(numArray6, 30, z); SecP384R1Field.Square(z, numArray3); return(!Nat.Eq(12, x, numArray3) ? null : new SecP384R1FieldElement(z)); }
public virtual bool Equals(SecP384R1FieldElement other) { return(this == other || (other != null && Nat.Eq(12, this.x, other.x))); }