public static void multiplyAddToExt(long[] x, long[] y, long[] zz) { long[] tt = Nat576.createExt64(); implMultiply(x, y, tt); addExt(zz, tt, zz); }
public SecT571FieldElement(BigInteger x) { if (x == null || x.signum() < 0 || x.bitLength() > 571) { throw new IllegalArgumentException("x value invalid for SecT571FieldElement"); } this.x = SecT571Field.fromBigInteger(x); }
protected static void implMultiply(long[] x, long[] y, long[] zz) { // for (int i = 0; i < 9; ++i) // { // implMulwAcc(x, y[i], zz, i); // } long[] precomp = precompMultiplicand(y); implMultiplyPrecomp(x, precomp, zz); }
public static void squareN(long[] x, int n, long[] z) { // assert n > 0; long[] tt = Nat576.createExt64(); implSquare(x, tt); reduce(tt, z); while (--n > 0) { implSquare(z, tt); reduce(tt, z); } }
long[] Z1Precomp = Z1.isOne() ? null : SecT571Field.precompMultiplicand(Z1.x); long[] U2, S2; if (Z1Precomp == null) SecT571Field.multiplyPrecomp(X2.x, Z1Precomp, U2 = t2); SecT571Field.multiplyPrecomp(L2.x, Z1Precomp, S2 = t4); long[] Z2Precomp = Z2.isOne() ? null : SecT571Field.precompMultiplicand(Z2.x); long[] U1, S1; if (Z2Precomp == null) SecT571Field.multiplyPrecomp(X1.x, Z2Precomp, U1 = t1); SecT571Field.multiplyPrecomp(L1.x, Z2Precomp, S1 = t3); SecT571Field.add(S1, S2, A); SecT571Field.add(U1, U2, B); SecT571Field.square(B, B); long[] APrecomp = SecT571Field.precompMultiplicand(A); SecT571Field.multiplyPrecomp(U1, APrecomp, AU1); SecT571Field.multiplyPrecomp(U2, APrecomp, AU2); SecT571Field.multiply(AU1, AU2, X3.x); SecT571Field.multiplyPrecomp(B, APrecomp, Z3.x);
SecT571Field.square(X1.x, X1Sq); SecT571Field.square(L1.x, L1Sq); SecT571Field.square(Z1.x, Z1Sq); SecT571Field.multiply(L1.x, Z1.x, L1Z1); SecT571Field.addBothTo(Z1Sq, L1Sq, T); long[] Z1SqPrecomp = SecT571Field.precompMultiplicand(Z1Sq); SecT571Field.multiplyPrecomp(L2.x, Z1SqPrecomp, A); SecT571Field.add(A, L1Sq, A); SecT571Field.multiplyAddToExt(A, T, tt); SecT571Field.multiplyPrecompAddToExt(X1Sq, Z1SqPrecomp, tt); SecT571Field.reduce(tt, A); SecT571Field.multiplyPrecomp(X2.x, Z1SqPrecomp, X2Z1Sq); SecT571Field.add(X2Z1Sq, T, B); SecT571Field.square(B, B); SecT571Field.square(A, X3.x); SecT571Field.multiply(X3.x, X2Z1Sq, X3.x); SecT571Field.multiply(A, B, Z3.x); SecT571Field.multiplyPrecomp(Z3.x, Z1SqPrecomp, Z3.x);
long[] t2 = Nat576.create64(); long[] Z1Precomp = Z1.isOne() ? null : SecT571Field.precompMultiplicand(Z1.x); long[] L1Z1, Z1Sq; if (Z1Precomp == null) SecT571Field.multiplyPrecomp(L1.x, Z1Precomp, L1Z1 = t1); SecT571Field.square(Z1.x, Z1Sq = t2); SecT571Field.square(L1.x, T); SecT571Field.addBothTo(L1Z1, Z1Sq, T); SecT571Field.multiplyAddToExt(T, L1Z1, tt); SecT571Field.square(T, X3.x); SecT571Field.multiply(Z3.x, Z1Sq, Z3.x); 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);
square(x, t2); square(t2, t0); square(t0, t1); multiply(t0, t1, t0); squareN(t0, 2, t1); multiply(t0, t1, t0); multiply(t0, t2, t0); squareN(t0, 5, t1); multiply(t0, t1, t0); squareN(t1, 5, t1); multiply(t0, t1, t0); squareN(t0, 15, t1); multiply(t0, t1, t2); squareN(t2, 30, t0); squareN(t0, 30, t1); multiply(t0, t1, t0); squareN(t0, 60, t1); multiply(t0, t1, t0); squareN(t1, 60, t1); multiply(t0, t1, t0); squareN(t0, 180, t1); multiply(t0, t1, t0); squareN(t1, 180, t1);
public static void multiply(long[] x, long[] y, long[] z) { long[] tt = Nat576.createExt64(); implMultiply(x, y, tt); reduce(tt, z); }
public static void multiplyPrecomp(long[] x, long[] precomp, long[] z) { long[] tt = Nat576.createExt64(); implMultiplyPrecomp(x, precomp, tt); reduce(tt, z); }
public static void multiplyPrecompAddToExt(long[] x, long[] precomp, long[] zz) { long[] tt = Nat576.createExt64(); implMultiplyPrecomp(x, precomp, tt); addExt(zz, tt, zz); }
public static void squareAddToExt(long[] x, long[] zz) { long[] tt = Nat576.createExt64(); implSquare(x, tt); addExt(zz, tt, zz); }
public static long[] precompMultiplicand(long[] x) { /* * Precompute table of all 4-bit products of x (first section) */ int len = 9 << 4; long[] t = new long[len << 1]; System.arraycopy(x, 0, t, 9, 9); // reduce5(T0, 9); int tOff = 0; for (int i = 7; i > 0; --i) { tOff += 18; Nat.shiftUpBit64(9, t, tOff >>> 1, 0L, t, tOff); reduce5(t, tOff); add(t, 9, t, tOff, t, tOff + 9); } /* * Second section with all 4-bit products of B shifted 4 bits */ Nat.shiftUpBits64(len, t, 0, 4, 0L, t, len); return t; }
public static void sqrt(long[] x, long[] z) { long[] evn = Nat576.create64(), odd = Nat576.create64(); int pos = 0; for (int i = 0; i < 4; ++i) { long u0 = Interleave.unshuffle(x[pos++]); long u1 = Interleave.unshuffle(x[pos++]); evn[i] = (u0 & 0x00000000FFFFFFFFL) | (u1 << 32); odd[i] = (u0 >>> 32) | (u1 & 0xFFFFFFFF00000000L); } { long u0 = Interleave.unshuffle(x[pos]); evn[4] = (u0 & 0x00000000FFFFFFFFL); odd[4] = (u0 >>> 32); } multiply(odd, ROOT_Z, z); add(z, evn, z); }
public ECFieldElement addOne() { long[] z = Nat576.create64(); SecT571Field.addOne(x, z); return new SecT571FieldElement(z); }
public ECFieldElement add(ECFieldElement b) { long[] z = Nat576.create64(); SecT571Field.add(x, ((SecT571FieldElement)b).x, z); return new SecT571FieldElement(z); }
public ECFieldElement multiply(ECFieldElement b) { long[] z = Nat576.create64(); SecT571Field.multiply(x, ((SecT571FieldElement)b).x, z); return new SecT571FieldElement(z); }
public ECFieldElement invert() { long[] z = Nat576.create64(); SecT571Field.invert(x, z); return new SecT571FieldElement(z); }
long[] Z1Precomp = Z1.isOne() ? null : SecT571Field.precompMultiplicand(Z1.x); long[] U2, S2; if (Z1Precomp == null) SecT571Field.multiplyPrecomp(X2.x, Z1Precomp, U2 = t2); SecT571Field.multiplyPrecomp(L2.x, Z1Precomp, S2 = t4); long[] Z2Precomp = Z2.isOne() ? null : SecT571Field.precompMultiplicand(Z2.x); long[] U1, S1; if (Z2Precomp == null) SecT571Field.multiplyPrecomp(X1.x, Z2Precomp, U1 = t1); SecT571Field.multiplyPrecomp(L1.x, Z2Precomp, S1 = t3); SecT571Field.add(S1, S2, A); SecT571Field.add(U1, U2, B); SecT571Field.square(B, B); long[] APrecomp = SecT571Field.precompMultiplicand(A); SecT571Field.multiplyPrecomp(U1, APrecomp, AU1); SecT571Field.multiplyPrecomp(U2, APrecomp, AU2); SecT571Field.multiply(AU1, AU2, X3.x); SecT571Field.multiplyPrecomp(B, APrecomp, Z3.x);