public static void squareAddToExt(long[] x, long[] zz) { long[] tt = Nat128.createExt64(); implSquare(x, tt); addExt(zz, tt, zz); }
public SecT113FieldElement(BigInteger x) { if (x == null || x.signum() < 0 || x.bitLength() > 113) { throw new IllegalArgumentException("x value invalid for SecT113FieldElement"); } this.x = SecT113Field.fromBigInteger(x); }
public static void multiplyAddToExt(long[] x, long[] y, long[] zz) { long[] tt = Nat128.createExt64(); implMultiply(x, y, tt); addExt(zz, tt, zz); }
public static void squareN(long[] x, int n, long[] z) { // assert n > 0; long[] tt = Nat128.createExt64(); implSquare(x, tt); reduce(tt, z); while (--n > 0) { implSquare(z, tt); reduce(tt, z); } }
public static void invert(long[] x, long[] z) { if (Nat128.isZero64(x)) { throw new IllegalStateException(); } // Itoh-Tsujii inversion long[] t0 = Nat128.create64(); long[] t1 = Nat128.create64(); square(x, t0); multiply(t0, x, t0); square(t0, t0); multiply(t0, x, t0); squareN(t0, 3, t1); multiply(t1, t0, t1); square(t1, t1); multiply(t1, x, t1); squareN(t1, 7, t0); multiply(t0, t1, t0); squareN(t0, 14, t1); multiply(t1, t0, t1); squareN(t1, 28, t0); multiply(t0, t1, t0); squareN(t0, 56, t1); multiply(t1, t0, t1); square(t1, z); }
public ECFieldElement squarePlusProduct(ECFieldElement x, ECFieldElement y) { long[] ax = this.x; long[] xx = ((SecT113FieldElement)x).x, yx = ((SecT113FieldElement)y).x; long[] tt = Nat128.createExt64(); SecT113Field.squareAddToExt(ax, tt); SecT113Field.multiplyAddToExt(xx, yx, tt); long[] z = Nat128.create64(); SecT113Field.reduce(tt, z); return new SecT113FieldElement(z); }
public static void multiply(long[] x, long[] y, long[] z) { long[] tt = Nat128.createExt64(); implMultiply(x, y, tt); reduce(tt, z); }
public ECFieldElement multiplyPlusProduct(ECFieldElement b, ECFieldElement x, ECFieldElement y) { long[] ax = this.x, bx = ((SecT113FieldElement)b).x; long[] xx = ((SecT113FieldElement)x).x, yx = ((SecT113FieldElement)y).x; long[] tt = Nat128.createExt64(); SecT113Field.multiplyAddToExt(ax, bx, tt); SecT113Field.multiplyAddToExt(xx, yx, tt); long[] z = Nat128.create64(); SecT113Field.reduce(tt, z); return new SecT113FieldElement(z); }
protected static void implMultiply(long[] x, long[] y, long[] zz) { /* * "Three-way recursion" as described in "Batch binary Edwards", Daniel J. Bernstein. */ long f0 = x[0], f1 = x[1]; f1 = ((f0 >>> 57) ^ (f1 << 7)) & M57; f0 &= M57; long g0 = y[0], g1 = y[1]; g1 = ((g0 >>> 57) ^ (g1 << 7)) & M57; g0 &= M57; long[] H = new long[6]; implMulw(f0, g0, H, 0); // H(0) 57/56 bits implMulw(f1, g1, H, 2); // H(INF) 57/54 bits implMulw(f0 ^ f1, g0 ^ g1, H, 4); // H(1) 57/56 bits long r = H[1] ^ H[2]; long z0 = H[0], z3 = H[3], z1 = H[4] ^ z0 ^ r, z2 = H[5] ^ z3 ^ r; zz[0] = z0 ^ (z1 << 57); zz[1] = (z1 >>> 7) ^ (z2 << 50); zz[2] = (z2 >>> 14) ^ (z3 << 43); zz[3] = (z3 >>> 21); }
public ECFieldElement invert() { long[] z = Nat128.create64(); SecT113Field.invert(x, z); return new SecT113FieldElement(z); }
public ECFieldElement add(ECFieldElement b) { long[] z = Nat128.create64(); SecT113Field.add(x, ((SecT113FieldElement)b).x, z); return new SecT113FieldElement(z); }
public ECFieldElement addOne() { long[] z = Nat128.create64(); SecT113Field.addOne(x, z); return new SecT113FieldElement(z); }
public ECFieldElement multiply(ECFieldElement b) { long[] z = Nat128.create64(); SecT113Field.multiply(x, ((SecT113FieldElement)b).x, z); return new SecT113FieldElement(z); }
public static void square(long[] x, long[] z) { long[] tt = Nat128.createExt64(); implSquare(x, tt); reduce(tt, z); }