private static bool TrySqrt(uint[] nc, uint[] r, uint[] t) { uint[] d1 = Nat224.Create(); Nat224.Copy(r, d1); uint[] e1 = Nat224.Create(); e1[0] = 1; uint[] f1 = Nat224.Create(); RP(nc, d1, e1, f1, t); uint[] d0 = Nat224.Create(); uint[] e0 = Nat224.Create(); for (int k = 1; k < 96; ++k) { Nat224.Copy(d1, d0); Nat224.Copy(e1, e0); RS(d1, e1, f1, t); if (Nat224.IsZero(d1)) { Mod.Invert(SecP224R1Field.P, e0, t); SecP224R1Field.Multiply(t, d0, t); return(true); } } return(false); }
public static void AddOne(uint[] x, uint[] z) { Nat224.Copy(x, z); uint c = Nat224.Inc(z, 0); if (c != 0 || (z[6] == P6 && Nat224.Gte(z, P))) { Nat224.AddDWord(PInv, z, 0); } }
private static void RM(uint[] nc, uint[] d0, uint[] e0, uint[] d1, uint[] e1, uint[] f1, uint[] t) { SecP224R1Field.Multiply(e1, e0, t); SecP224R1Field.Multiply(t, nc, t); SecP224R1Field.Multiply(d1, d0, f1); SecP224R1Field.Add(f1, t, f1); SecP224R1Field.Multiply(d1, e0, t); Nat224.Copy(f1, d1); SecP224R1Field.Multiply(e1, d0, e1); SecP224R1Field.Add(e1, t, e1); SecP224R1Field.Square(e1, f1); SecP224R1Field.Multiply(f1, nc, f1); }
private static bool IsSquare(uint[] x) { uint[] z = Nat224.Create(); uint[] numArray2 = Nat224.Create(); Nat224.Copy(x, z); for (int i = 0; i < 7; i++) { Nat224.Copy(z, numArray2); SecP224R1Field.SquareN(z, ((int)1) << i, z); SecP224R1Field.Multiply(z, numArray2, z); } SecP224R1Field.SquareN(z, 0x5f, z); return(Nat224.IsOne(z)); }
private static bool IsSquare(uint[] x) { uint[] z = Nat224.Create(); uint[] array = Nat224.Create(); Nat224.Copy(x, z); for (int i = 0; i < 7; i++) { Nat224.Copy(z, array); SecP224R1Field.SquareN(z, 1 << i, z); SecP224R1Field.Multiply(z, array, z); } SecP224R1Field.SquareN(z, 95, z); return(Nat224.IsOne(z)); }
public override ECLookupTable CreateCacheSafeLookupTable(ECPoint[] points, int off, int len) { uint[] table = new uint[len * SECP224R1_FE_INTS * 2]; { int pos = 0; for (int i = 0; i < len; ++i) { ECPoint p = points[off + i]; Nat224.Copy(((SecP224R1FieldElement)p.RawXCoord).x, 0, table, pos); pos += SECP224R1_FE_INTS; Nat224.Copy(((SecP224R1FieldElement)p.RawYCoord).x, 0, table, pos); pos += SECP224R1_FE_INTS; } } return(new SecP224R1LookupTable(this, table, len)); }
private static bool IsSquare(uint[] x) { uint[] t1 = Nat224.Create(); uint[] t2 = Nat224.Create(); Nat224.Copy(x, t1); for (int i = 0; i < 7; ++i) { Nat224.Copy(t1, t2); SecP224R1Field.SquareN(t1, 1 << i, t1); SecP224R1Field.Multiply(t1, t2, t1); } SecP224R1Field.SquareN(t1, 95, t1); return(Nat224.IsOne(t1)); }
/** * return a sqrt root - the routine verifies that the calculation returns the right value - if * none exists it returns null. */ public override ECFieldElement Sqrt() { uint[] c = this.x; if (Nat224.IsZero(c) || Nat224.IsOne(c)) { return(this); } uint[] nc = Nat224.Create(); SecP224R1Field.Negate(c, nc); uint[] r = Mod.Random(SecP224R1Field.P); for (;;) { uint[] d1 = Nat224.Create(); Nat224.Copy(r, d1); uint[] e1 = Nat224.Create(); e1[0] = 1; uint[] f1 = Nat224.Create(); RP(nc, d1, e1, f1); uint[] d0 = Nat224.Create(); uint[] e0 = Nat224.Create(); for (int k = 1; k < 96; ++k) { Nat224.Copy(d1, d0); Nat224.Copy(e1, e0); RS(d1, e1, f1); if (Nat224.IsZero(d1)) { Mod.Invert(SecP224R1Field.P, e0, f1); SecP224R1Field.Multiply(f1, d0, f1); SecP224R1Field.Square(f1, d1); return(Nat224.Eq(c, d1) ? new SecP224R1FieldElement(f1) : null); } } // Avoid any possible infinite loop due to a bad random number generator SecP224R1Field.AddOne(r, r); } }
private static void RP(uint[] nc, uint[] d1, uint[] e1, uint[] f1, uint[] t) { Nat224.Copy(nc, f1); uint[] z = Nat224.Create(); uint[] numArray2 = Nat224.Create(); for (int i = 0; i < 7; i++) { Nat224.Copy(d1, z); Nat224.Copy(e1, numArray2); int num2 = ((int)1) << i; while (--num2 >= 0) { RS(d1, e1, f1, t); } RM(nc, z, numArray2, d1, e1, f1, t); } }
private static void RP(uint[] nc, uint[] d1, uint[] e1, uint[] f1, uint[] t) { Nat224.Copy(nc, f1); uint[] array = Nat224.Create(); uint[] array2 = Nat224.Create(); for (int i = 0; i < 7; i++) { Nat224.Copy(d1, array); Nat224.Copy(e1, array2); int num = 1 << i; while (--num >= 0) { SecP224R1FieldElement.RS(d1, e1, f1, t); } SecP224R1FieldElement.RM(nc, array, array2, d1, e1, f1, t); } }
private static void RP(uint[] nc, uint[] d1, uint[] e1, uint[] f1, uint[] t) { Nat224.Copy(nc, f1); uint[] d0 = Nat224.Create(); uint[] e0 = Nat224.Create(); for (int i = 0; i < 7; ++i) { Nat224.Copy(d1, d0); Nat224.Copy(e1, e0); int j = 1 << i; while (--j >= 0) { RS(d1, e1, f1, t); } RM(nc, d0, e0, d1, e1, f1, t); } }
private static bool TrySqrt(uint[] nc, uint[] r, uint[] t) { uint[] z = Nat224.Create(); Nat224.Copy(r, z); uint[] numArray2 = Nat224.Create(); numArray2[0] = 1; uint[] numArray3 = Nat224.Create(); RP(nc, z, numArray2, numArray3, t); uint[] numArray4 = Nat224.Create(); uint[] numArray5 = Nat224.Create(); for (int i = 1; i < 0x60; i++) { Nat224.Copy(z, numArray4); Nat224.Copy(numArray2, numArray5); RS(z, numArray2, numArray3, t); if (Nat224.IsZero(z)) { Mod.Invert(SecP224R1Field.P, numArray5, t); SecP224R1Field.Multiply(t, numArray4, t); return(true); } } return(false); }
private static bool TrySqrt(uint[] nc, uint[] r, uint[] t) { uint[] array = Nat224.Create(); Nat224.Copy(r, array); uint[] array2 = Nat224.Create(); array2[0] = 1u; uint[] array3 = Nat224.Create(); SecP224R1FieldElement.RP(nc, array, array2, array3, t); uint[] array4 = Nat224.Create(); uint[] z = Nat224.Create(); for (int i = 1; i < 96; i++) { Nat224.Copy(array, array4); Nat224.Copy(array2, z); SecP224R1FieldElement.RS(array, array2, array3, t); if (Nat224.IsZero(array)) { Mod.Invert(SecP224R1Field.P, z, t); SecP224R1Field.Multiply(t, array4, t); return(true); } } return(false); }