public static void twice(int[] x, int[] z) { int c = Nat.shiftUpBit(6, x, 0, z); if (c != 0 || (z[5] == P5 && Nat192.gte(z, P))) { Nat.add33To(6, PInv33, z); } } }
public static void square(int len, int[] x, int xOff, int[] zz, int zzOff) { int extLen = len << 1; int c = 0; int j = len, k = extLen; do { long xVal = (x[xOff + --j] & M); long p = xVal * xVal; zz[zzOff + --k] = (c << 31) | (int)(p >>> 33); zz[zzOff + --k] = (int)(p >>> 1); c = (int)p; } while (j > 0); for (int i = 1; i < len; ++i) { c = squareWordAdd(x, xOff, i, zz, zzOff); addWordAt(extLen, c, zz, zzOff, i << 1); } shiftUpBit(extLen, zz, zzOff, x[xOff] << 31); }
if (Nat.isZero(len, x)) if (Nat.isOne(len, x)) int[] u = Nat.copy(len, x); int[] a = Nat.create(len); a[0] = 1; int ac = 0; if (Nat.isOne(len, u)) int[] v = Nat.copy(len, p); int[] b = Nat.create(len); int bc = 0; if (Nat.gte(uvLen, u, v)) Nat.subFrom(uvLen, v, u); ac += Nat.subFrom(len, b, a) - bc; ac = inversionStep(p, u, uvLen, a, ac); if (Nat.isOne(uvLen, u)) Nat.subFrom(uvLen, u, v); bc += Nat.subFrom(len, a, b) - ac; bc = inversionStep(p, v, uvLen, b, bc); if (Nat.isOne(uvLen, v))
public static void mul(int[] x, int[] y, int[] zz) { Nat256.mul(x, y, zz); Nat256.mul(x, 8, y, 8, zz, 16); int c24 = Nat256.addToEachOther(zz, 8, zz, 16); int c16 = c24 + Nat256.addTo(zz, 0, zz, 8, 0); c24 += Nat256.addTo(zz, 24, zz, 16, c16); int[] dx = Nat256.create(), dy = Nat256.create(); boolean neg = Nat256.diff(x, 8, x, 0, dx, 0) != Nat256.diff(y, 8, y, 0, dy, 0); int[] tt = Nat256.createExt(); Nat256.mul(dx, dy, tt); c24 += neg ? Nat.addTo(16, tt, 0, zz, 8) : Nat.subFrom(16, tt, 0, zz, 8); Nat.addWordAt(32, c24, zz, 24); }
int[] t1 = Nat.create(12); int[] t2 = Nat.create(12); int[] Y1Squared = Nat.create(12); SecP384R1Field.square(Y1.x, Y1Squared); int[] T = Nat.create(12); SecP384R1Field.square(Y1Squared, T); SecP384R1Field.add(X1.x, Z1Squared, M); SecP384R1Field.multiply(M, t1, M); c = Nat.addBothTo(12, M, M, M); SecP384R1Field.reduce32(c, M); c = Nat.shiftUpBits(12, S, 2, 0); SecP384R1Field.reduce32(c, S); c = Nat.shiftUpBits(12, T, 3, 0, t1); SecP384R1Field.reduce32(c, t1);
int[] tt1 = Nat.create(24); int[] tt2 = Nat.create(24); int[] t3 = Nat.create(12); int[] t4 = Nat.create(12); int[] H = Nat.create(12); SecP384R1Field.subtract(U1, U2, H); int[] R = Nat.create(12); SecP384R1Field.subtract(S1, S2, R); if (Nat.isZero(12, H)) if (Nat.isZero(12, R)) SecP384R1Field.square(H, HSquared); int[] G = Nat.create(12); SecP384R1Field.multiply(HSquared, H, G); Nat384.mul(S1, G, tt1); c = Nat.addBothTo(12, V, V, G); SecP384R1Field.reduce32(c, G);
public static void square(int[] x, int[] zz) { Nat256.square(x, zz); Nat256.square(x, 8, zz, 16); int c24 = Nat256.addToEachOther(zz, 8, zz, 16); int c16 = c24 + Nat256.addTo(zz, 0, zz, 8, 0); c24 += Nat256.addTo(zz, 24, zz, 16, c16); int[] dx = Nat256.create(); Nat256.diff(x, 8, x, 0, dx, 0); int[] tt = Nat256.createExt(); Nat256.square(dx, tt); c24 += Nat.subFrom(16, tt, 0, zz, 8); Nat.addWordAt(32, c24, zz, 24); } }
public ECFieldElement add(ECFieldElement b) { int[] z = Nat.create(12); SecP384R1Field.add(x, ((SecP384R1FieldElement)b).x, z); return new SecP384R1FieldElement(z); }
public static void reduce32(int x, int[] z) { if ((x != 0 && Nat224.mul33WordAdd(PInv33, x, z, 0) != 0) || (z[6] == P6 && Nat224.gte(z, P))) { Nat.add33To(7, PInv33, z); } }
public static void twice(int[] x, int[] z) { int c = Nat.shiftUpBit(5, x, 0, z); if (c != 0 || (z[4] == P4 && Nat160.gte(z, P))) { Nat.addWordTo(5, PInv, z); } } }
public static int subDWordAt(int len, long x, int[] z, int zOff, int zPos) { // assert zPos <= (len - 2); long c = (z[zOff + zPos] & M) - (x & M); z[zOff + zPos] = (int)c; c >>= 32; c += (z[zOff + zPos + 1] & M) - (x >>> 32); z[zOff + zPos + 1] = (int)c; c >>= 32; return c == 0 ? 0 : decAt(len, z, zOff, zPos + 2); }