public override ECFieldElement SquarePow(int pow) { if (pow < 1) { return(this); } ulong[] z = Nat576.Create64(); SecT571Field.SquareN(this.x, pow, z); return(new SecT571FieldElement(z)); }
public override ECFieldElement SquarePlusProduct(ECFieldElement x, ECFieldElement y) { ulong[] numArray = this.x; ulong[] numArray2 = ((SecT571FieldElement)x).x; ulong[] numArray3 = ((SecT571FieldElement)y).x; ulong[] zz = Nat576.CreateExt64(); SecT571Field.SquareAddToExt(numArray, zz); SecT571Field.MultiplyAddToExt(numArray2, numArray3, zz); ulong[] z = Nat576.Create64(); SecT571Field.Reduce(zz, z); return(new SecT571FieldElement(z)); }
public static void Invert(ulong[] x, ulong[] z) { if (Nat576.IsZero64(x)) { throw new InvalidOperationException(); } // Itoh-Tsujii inversion with bases { 2, 3, 5 } ulong[] t0 = Nat576.Create64(); ulong[] t1 = Nat576.Create64(); ulong[] t2 = Nat576.Create64(); Square(x, t2); // 5 | 570 Square(t2, t0); Square(t0, t1); Multiply(t0, t1, t0); SquareN(t0, 2, t1); Multiply(t0, t1, t0); Multiply(t0, t2, t0); // 3 | 114 SquareN(t0, 5, t1); Multiply(t0, t1, t0); SquareN(t1, 5, t1); Multiply(t0, t1, t0); // 2 | 38 SquareN(t0, 15, t1); Multiply(t0, t1, t2); // ! {2,3,5} | 19 SquareN(t2, 30, t0); SquareN(t0, 30, t1); Multiply(t0, t1, t0); // 3 | 9 SquareN(t0, 60, t1); Multiply(t0, t1, t0); SquareN(t1, 60, t1); Multiply(t0, t1, t0); // 3 | 3 SquareN(t0, 180, t1); Multiply(t0, t1, t0); SquareN(t1, 180, t1); Multiply(t0, t1, t0); Multiply(t0, t2, z); }
public override ECPoint LookupVar(int index) { ulong[] x = Nat576.Create64(), y = Nat576.Create64(); int pos = index * SECT571K1_FE_LONGS * 2; for (int j = 0; j < SECT571K1_FE_LONGS; ++j) { x[j] = m_table[pos + j]; y[j] = m_table[pos + SECT571K1_FE_LONGS + j]; } return(CreatePoint(x, y)); }
public override ECFieldElement MultiplyPlusProduct(ECFieldElement b, ECFieldElement x, ECFieldElement y) { ulong[] ax = this.x, bx = ((SecT571FieldElement)b).x; ulong[] xx = ((SecT571FieldElement)x).x, yx = ((SecT571FieldElement)y).x; ulong[] tt = Nat576.CreateExt64(); SecT571Field.MultiplyAddToExt(ax, bx, tt); SecT571Field.MultiplyAddToExt(xx, yx, tt); ulong[] z = Nat576.Create64(); SecT571Field.Reduce(tt, z); return(new SecT571FieldElement(z)); }
public override ECFieldElement MultiplyPlusProduct(ECFieldElement b, ECFieldElement x, ECFieldElement y) { ulong[] array = this.x; ulong[] y2 = ((SecT571FieldElement)b).x; ulong[] array2 = ((SecT571FieldElement)x).x; ulong[] y3 = ((SecT571FieldElement)y).x; ulong[] array3 = Nat576.CreateExt64(); SecT571Field.MultiplyAddToExt(array, y2, array3); SecT571Field.MultiplyAddToExt(array2, y3, array3); ulong[] z = Nat576.Create64(); SecT571Field.Reduce(array3, z); return(new SecT571FieldElement(z)); }
public static void Sqrt(ulong[] x, ulong[] z) { ulong[] array = Nat576.Create64(); ulong[] array2 = Nat576.Create64(); int num = 0; for (int i = 0; i < 4; i++) { ulong num2 = Interleave.Unshuffle(x[num++]); ulong num3 = Interleave.Unshuffle(x[num++]); array[i] = (num2 & 0xFFFFFFFFu) | (num3 << 32); array2[i] = (num2 >> 32) | (num3 & 0xFFFFFFFF00000000uL); } ulong num4 = Interleave.Unshuffle(x[num]); array[4] = num4 & 0xFFFFFFFFu; array2[4] = num4 >> 32; Multiply(array2, ROOT_Z, z); Add(z, array, z); }
public override ECPoint Lookup(int index) { ulong[] x = Nat576.Create64(), y = Nat576.Create64(); int pos = 0; for (int i = 0; i < m_size; ++i) { ulong MASK = (ulong)(long)(((i ^ index) - 1) >> 31); for (int j = 0; j < SECT571K1_FE_LONGS; ++j) { x[j] ^= m_table[pos + j] & MASK; y[j] ^= m_table[pos + SECT571K1_FE_LONGS + j] & MASK; } pos += (SECT571K1_FE_LONGS * 2); } return(CreatePoint(x, y)); }
public virtual ECPoint Lookup(int index) { ulong[] x = Nat576.Create64(), y = Nat576.Create64(); int pos = 0; for (int i = 0; i < m_size; ++i) { ulong MASK = (ulong)(long)(((i ^ index) - 1) >> 31); for (int j = 0; j < SECT571K1_FE_LONGS; ++j) { x[j] ^= m_table[pos + j] & MASK; y[j] ^= m_table[pos + SECT571K1_FE_LONGS + j] & MASK; } pos += (SECT571K1_FE_LONGS * 2); } return(m_outer.CreateRawPoint(new SecT571FieldElement(x), new SecT571FieldElement(y), false)); }
public static void Sqrt(ulong[] x, ulong[] z) { ulong[] evn = Nat576.Create64(), odd = Nat576.Create64(); int pos = 0; for (int i = 0; i < 4; ++i) { ulong u0 = Interleave.Unshuffle(x[pos++]); ulong u1 = Interleave.Unshuffle(x[pos++]); evn[i] = (u0 & 0x00000000FFFFFFFFUL) | (u1 << 32); odd[i] = (u0 >> 32) | (u1 & 0xFFFFFFFF00000000UL); } { ulong u0 = Interleave.Unshuffle(x[pos]); evn[4] = (u0 & 0x00000000FFFFFFFFUL); odd[4] = (u0 >> 32); } Multiply(odd, ROOT_Z, z); Add(z, evn, z); }
public static void Invert(ulong[] x, ulong[] z) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) if (Nat576.IsZero64(x)) { throw new InvalidOperationException(); } ulong[] array = Nat576.Create64(); ulong[] array2 = Nat576.Create64(); ulong[] array3 = Nat576.Create64(); Square(x, array3); Square(array3, array); Square(array, array2); Multiply(array, array2, array); SquareN(array, 2, array2); Multiply(array, array2, array); Multiply(array, array3, array); SquareN(array, 5, array2); Multiply(array, array2, array); SquareN(array2, 5, array2); Multiply(array, array2, array); SquareN(array, 15, array2); Multiply(array, array2, array3); SquareN(array3, 30, array); SquareN(array, 30, array2); Multiply(array, array2, array); SquareN(array, 60, array2); Multiply(array, array2, array); SquareN(array2, 60, array2); Multiply(array, array2, array); SquareN(array, 180, array2); Multiply(array, array2, array); SquareN(array2, 180, array2); Multiply(array, array2, array); Multiply(array, array3, z); }
public override ECFieldElement Multiply(ECFieldElement b) { ulong[] z = Nat576.Create64(); SecT571Field.Multiply(x, ((SecT571FieldElement)b).x, z); return(new SecT571FieldElement(z)); }
public override ECFieldElement AddOne() { ulong[] z = Nat576.Create64(); SecT571Field.AddOne(x, z); return(new SecT571FieldElement(z)); }
public SecT571FieldElement() { this.x = Nat576.Create64(); }
public override ECFieldElement Invert() { ulong[] z = Nat576.Create64(); SecT571Field.Invert(this.x, z); return(new SecT571FieldElement(z)); }
public override ECFieldElement Add(ECFieldElement b) { ulong[] z = Nat576.Create64(); SecT571Field.Add(this.x, ((SecT571FieldElement)b).x, z); return(new SecT571FieldElement(z)); }
public override ECPoint Twice() { if (this.IsInfinity) { return(this); } ECCurve curve = this.Curve; SecT571FieldElement X1 = (SecT571FieldElement)this.RawXCoord; if (X1.IsZero) { // A point with X == 0 is its own additive inverse return(curve.Infinity); } SecT571FieldElement L1 = (SecT571FieldElement)this.RawYCoord, Z1 = (SecT571FieldElement)this.RawZCoords[0]; ulong[] t1 = Nat576.Create64(); ulong[] t2 = Nat576.Create64(); ulong[] Z1Precomp = Z1.IsOne ? null : SecT571Field.PrecompMultiplicand(Z1.x); ulong[] L1Z1, Z1Sq; if (Z1Precomp == null) { L1Z1 = L1.x; Z1Sq = Z1.x; } else { SecT571Field.MultiplyPrecomp(L1.x, Z1Precomp, L1Z1 = t1); SecT571Field.Square(Z1.x, Z1Sq = t2); } ulong[] T = Nat576.Create64(); SecT571Field.Square(L1.x, T); SecT571Field.AddBothTo(L1Z1, Z1Sq, T); if (Nat576.IsZero64(T)) { return(new SecT571R1Point(curve, new SecT571FieldElement(T), SecT571R1Curve.SecT571R1_B_SQRT, IsCompressed)); } ulong[] tt = Nat576.CreateExt64(); SecT571Field.MultiplyAddToExt(T, L1Z1, tt); SecT571FieldElement X3 = new SecT571FieldElement(t1); SecT571Field.Square(T, X3.x); SecT571FieldElement Z3 = new SecT571FieldElement(T); if (Z1Precomp != null) { SecT571Field.Multiply(Z3.x, Z1Sq, Z3.x); } ulong[] X1Z1; if (Z1Precomp == null) { X1Z1 = X1.x; } else { SecT571Field.MultiplyPrecomp(X1.x, Z1Precomp, X1Z1 = t2); } SecT571Field.SquareAddToExt(X1Z1, tt); SecT571Field.Reduce(tt, t2); SecT571Field.AddBothTo(X3.x, Z3.x, t2); SecT571FieldElement L3 = new SecT571FieldElement(t2); return(new SecT571R1Point(curve, X3, L3, new ECFieldElement[] { Z3 }, IsCompressed)); }
public override ECPoint Add(ECPoint b) { if (this.IsInfinity) { return(b); } if (b.IsInfinity) { return(this); } ECCurve curve = this.Curve; SecT571FieldElement X1 = (SecT571FieldElement)this.RawXCoord; SecT571FieldElement X2 = (SecT571FieldElement)b.RawXCoord; if (X1.IsZero) { if (X2.IsZero) { return(curve.Infinity); } return(b.Add(this)); } SecT571FieldElement L1 = (SecT571FieldElement)this.RawYCoord, Z1 = (SecT571FieldElement)this.RawZCoords[0]; SecT571FieldElement L2 = (SecT571FieldElement)b.RawYCoord, Z2 = (SecT571FieldElement)b.RawZCoords[0]; ulong[] t1 = Nat576.Create64(); ulong[] t2 = Nat576.Create64(); ulong[] t3 = Nat576.Create64(); ulong[] t4 = Nat576.Create64(); ulong[] Z1Precomp = Z1.IsOne ? null : SecT571Field.PrecompMultiplicand(Z1.x); ulong[] U2, S2; if (Z1Precomp == null) { U2 = X2.x; S2 = L2.x; } else { SecT571Field.MultiplyPrecomp(X2.x, Z1Precomp, U2 = t2); SecT571Field.MultiplyPrecomp(L2.x, Z1Precomp, S2 = t4); } ulong[] Z2Precomp = Z2.IsOne ? null : SecT571Field.PrecompMultiplicand(Z2.x); ulong[] U1, S1; if (Z2Precomp == null) { U1 = X1.x; S1 = L1.x; } else { SecT571Field.MultiplyPrecomp(X1.x, Z2Precomp, U1 = t1); SecT571Field.MultiplyPrecomp(L1.x, Z2Precomp, S1 = t3); } ulong[] A = t3; SecT571Field.Add(S1, S2, A); ulong[] B = t4; SecT571Field.Add(U1, U2, B); if (Nat576.IsZero64(B)) { if (Nat576.IsZero64(A)) { return(Twice()); } return(curve.Infinity); } SecT571FieldElement X3, L3, Z3; if (X2.IsZero) { // TODO This can probably be optimized quite a bit ECPoint p = this.Normalize(); X1 = (SecT571FieldElement)p.XCoord; ECFieldElement Y1 = p.YCoord; ECFieldElement Y2 = L2; ECFieldElement L = Y1.Add(Y2).Divide(X1); X3 = (SecT571FieldElement)L.Square().Add(L).Add(X1).AddOne(); if (X3.IsZero) { return(new SecT571R1Point(curve, X3, SecT571R1Curve.SecT571R1_B_SQRT, IsCompressed)); } ECFieldElement Y3 = L.Multiply(X1.Add(X3)).Add(X3).Add(Y1); L3 = (SecT571FieldElement)Y3.Divide(X3).Add(X3); Z3 = (SecT571FieldElement)curve.FromBigInteger(BigInteger.One); } else { SecT571Field.Square(B, B); ulong[] APrecomp = SecT571Field.PrecompMultiplicand(A); ulong[] AU1 = t1; ulong[] AU2 = t2; SecT571Field.MultiplyPrecomp(U1, APrecomp, AU1); SecT571Field.MultiplyPrecomp(U2, APrecomp, AU2); X3 = new SecT571FieldElement(t1); SecT571Field.Multiply(AU1, AU2, X3.x); if (X3.IsZero) { return(new SecT571R1Point(curve, X3, SecT571R1Curve.SecT571R1_B_SQRT, IsCompressed)); } Z3 = new SecT571FieldElement(t3); SecT571Field.MultiplyPrecomp(B, APrecomp, Z3.x); if (Z2Precomp != null) { SecT571Field.MultiplyPrecomp(Z3.x, Z2Precomp, Z3.x); } ulong[] tt = Nat576.CreateExt64(); SecT571Field.Add(AU2, B, t4); SecT571Field.SquareAddToExt(t4, tt); SecT571Field.Add(L1.x, Z1.x, t4); SecT571Field.MultiplyAddToExt(t4, Z3.x, tt); L3 = new SecT571FieldElement(t4); SecT571Field.Reduce(tt, L3.x); if (Z1Precomp != null) { SecT571Field.MultiplyPrecomp(Z3.x, Z1Precomp, Z3.x); } } return(new SecT571R1Point(curve, X3, L3, new ECFieldElement[] { Z3 }, IsCompressed)); }