public static void Invert(ulong[] x, ulong[] z) { if (Nat192.IsZero64(x)) { throw new InvalidOperationException(); } // Itoh-Tsujii inversion ulong[] t0 = Nat192.Create64(); ulong[] t1 = Nat192.Create64(); Square(x, t0); Multiply(t0, x, t0); SquareN(t0, 2, t1); Multiply(t1, t0, t1); SquareN(t1, 4, t0); Multiply(t0, t1, t0); SquareN(t0, 8, t1); Multiply(t1, t0, t1); SquareN(t1, 16, t0); Multiply(t0, t1, t0); SquareN(t0, 32, t1); Multiply(t1, t0, t1); Square(t1, t1); Multiply(t1, x, t1); SquareN(t1, 65, t0); Multiply(t0, t1, t0); Square(t0, z); }
public override ECFieldElement SquarePow(int pow) { if (pow < 1) return this; ulong[] z = Nat192.Create64(); SecT163Field.SquareN(x, pow, z); return new SecT163FieldElement(z); }
public override ECFieldElement SquarePow(int pow) { if (pow < 1) { return(this); } ulong[] z = Nat192.Create64(); SecT131Field.SquareN(x, pow, z); return(new SecT131FieldElement(z)); }
public override ECFieldElement SquarePlusProduct(ECFieldElement x, ECFieldElement y) { ulong[] array = this.x; ulong[] array2 = ((SecT163FieldElement)x).x; ulong[] y2 = ((SecT163FieldElement)y).x; ulong[] array3 = Nat192.CreateExt64(); SecT163Field.SquareAddToExt(array, array3); SecT163Field.MultiplyAddToExt(array2, y2, array3); ulong[] z = Nat192.Create64(); SecT163Field.Reduce(array3, z); return(new SecT163FieldElement(z)); }
public override ECFieldElement SquarePlusProduct(ECFieldElement x, ECFieldElement y) { ulong[] ax = this.x; ulong[] xx = ((SecT163FieldElement)x).x, yx = ((SecT163FieldElement)y).x; ulong[] tt = Nat192.CreateExt64(); SecT163Field.SquareAddToExt(ax, tt); SecT163Field.MultiplyAddToExt(xx, yx, tt); ulong[] z = Nat192.Create64(); SecT163Field.Reduce(tt, z); return new SecT163FieldElement(z); }
public override ECFieldElement MultiplyPlusProduct(ECFieldElement b, ECFieldElement x, ECFieldElement y) { ulong[] ax = this.x, bx = ((SecT131FieldElement)b).x; ulong[] xx = ((SecT131FieldElement)x).x, yx = ((SecT131FieldElement)y).x; ulong[] tt = Nat.Create64(5); SecT131Field.MultiplyAddToExt(ax, bx, tt); SecT131Field.MultiplyAddToExt(xx, yx, tt); ulong[] z = Nat192.Create64(); SecT131Field.Reduce(tt, z); return(new SecT131FieldElement(z)); }
public override ECPoint LookupVar(int index) { ulong[] x = Nat192.Create64(), y = Nat192.Create64(); int pos = index * SECT163R1_FE_LONGS * 2; for (int j = 0; j < SECT163R1_FE_LONGS; ++j) { x[j] = m_table[pos + j]; y[j] = m_table[pos + SECT163R1_FE_LONGS + j]; } return(CreatePoint(x, y)); }
public override ECFieldElement MultiplyPlusProduct(ECFieldElement b, ECFieldElement x, ECFieldElement y) { ulong[] array = this.x; ulong[] y2 = ((SecT131FieldElement)b).x; ulong[] array2 = ((SecT131FieldElement)x).x; ulong[] y3 = ((SecT131FieldElement)y).x; ulong[] array3 = Nat.Create64(5); SecT131Field.MultiplyAddToExt(array, y2, array3); SecT131Field.MultiplyAddToExt(array2, y3, array3); ulong[] z = Nat192.Create64(); SecT131Field.Reduce(array3, z); return(new SecT131FieldElement(z)); }
public static void Invert(ulong[] x, ulong[] z) { if (Nat192.IsZero64(x)) { throw new InvalidOperationException(); } // Itoh-Tsujii inversion with bases { 2, 3 } ulong[] t0 = Nat192.Create64(); ulong[] t1 = Nat192.Create64(); Square(x, t0); // 3 | 162 SquareN(t0, 1, t1); Multiply(t0, t1, t0); SquareN(t1, 1, t1); Multiply(t0, t1, t0); // 3 | 54 SquareN(t0, 3, t1); Multiply(t0, t1, t0); SquareN(t1, 3, t1); Multiply(t0, t1, t0); // 3 | 18 SquareN(t0, 9, t1); Multiply(t0, t1, t0); SquareN(t1, 9, t1); Multiply(t0, t1, t0); // 3 | 6 SquareN(t0, 27, t1); Multiply(t0, t1, t0); SquareN(t1, 27, t1); Multiply(t0, t1, t0); // 2 | 2 SquareN(t0, 81, t1); Multiply(t0, t1, z); }
public virtual ECPoint Lookup(int index) { ulong[] x = Nat192.Create64(), y = Nat192.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 < SECT163R1_FE_LONGS; ++j) { x[j] ^= m_table[pos + j] & MASK; y[j] ^= m_table[pos + SECT163R1_FE_LONGS + j] & MASK; } pos += (SECT163R1_FE_LONGS * 2); } return(m_outer.CreateRawPoint(new SecT163FieldElement(x), new SecT163FieldElement(y), false)); }
public override ECPoint Lookup(int index) { ulong[] x = Nat192.Create64(), y = Nat192.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 < SECT163R1_FE_LONGS; ++j) { x[j] ^= m_table[pos + j] & MASK; y[j] ^= m_table[pos + SECT163R1_FE_LONGS + j] & MASK; } pos += (SECT163R1_FE_LONGS * 2); } return(CreatePoint(x, y)); }
public static void Sqrt(ulong[] x, ulong[] z) { ulong[] odd = Nat192.Create64(); ulong u0, u1; u0 = Interleave.Unshuffle(x[0]); u1 = Interleave.Unshuffle(x[1]); ulong e0 = (u0 & 0x00000000FFFFFFFFUL) | (u1 << 32); odd[0] = (u0 >> 32) | (u1 & 0xFFFFFFFF00000000UL); u0 = Interleave.Unshuffle(x[2]); ulong e1 = (u0 & 0x00000000FFFFFFFFUL); odd[1] = (u0 >> 32); Multiply(odd, ROOT_Z, z); z[0] ^= e0; z[1] ^= e1; }
public override ECFieldElement Multiply(ECFieldElement b) { ulong[] z = Nat192.Create64(); SecT131Field.Multiply(x, ((SecT131FieldElement)b).x, z); return(new SecT131FieldElement(z)); }
public override ECFieldElement AddOne() { ulong[] z = Nat192.Create64(); SecT131Field.AddOne(x, z); return(new SecT131FieldElement(z)); }
public SecT131FieldElement() { this.x = Nat192.Create64(); }
public SecT163FieldElement() { x = Nat192.Create64(); }
public override ECFieldElement Add(ECFieldElement b) { ulong[] z = Nat192.Create64(); SecT163Field.Add(x, ((SecT163FieldElement)b).x, z); return new SecT163FieldElement(z); }
public override ECFieldElement Sqrt() { ulong[] z = Nat192.Create64(); SecT163Field.Sqrt(x, z); return new SecT163FieldElement(z); }
public override ECFieldElement HalfTrace() { ulong[] z = Nat192.Create64(); SecT163Field.HalfTrace(x, z); return new SecT163FieldElement(z); }