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); }
public boolean equals(Object other) { if (other == this) { return true; } if (!(other instanceof Curve25519FieldElement)) { return false; } Curve25519FieldElement o = (Curve25519FieldElement)other; return Nat256.eq(x, o.x); }
public static int[] fromBigInteger(BigInteger x) { int[] z = Nat256.fromBigInteger(x); if ((z[7] >>> 1) >= P7s1 && Nat256.gte(z, P)) { Nat256.subFrom(P, z); } return z; }
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); } }
int[] tt1 = Nat256.createExt(); int[] t2 = Nat256.create(); int[] t3 = Nat256.create(); int[] t4 = Nat256.create(); int[] H = Nat256.create(); Curve25519Field.subtract(U1, U2, H); if (Nat256.isZero(H)) if (Nat256.isZero(R)) int[] HSquared = Nat256.create(); Curve25519Field.square(H, HSquared); int[] G = Nat256.create(); Curve25519Field.multiply(HSquared, H, G); Nat256.mul(S1, G, tt1); c = Nat256.addBothTo(V, V, G); Curve25519Field.reduce27(c, G);
int[] M = Nat256.create(); Curve25519Field.square(X1.x, M); c = Nat256.addBothTo(M, M, M); c += Nat256.addTo(W1.x, M); Curve25519Field.reduce27(c, M); int[] _2Y1 = Nat256.create(); Curve25519Field.twice(Y1.x, _2Y1); int[] _2Y1Squared = Nat256.create(); Curve25519Field.multiply(_2Y1, Y1.x, _2Y1Squared); int[] S = Nat256.create(); Curve25519Field.multiply(_2Y1Squared, X1.x, S); Curve25519Field.twice(S, S); int[] _8T = Nat256.create(); Curve25519Field.square(_2Y1Squared, _8T); Curve25519Field.twice(_8T, _8T); if (!Nat256.isOne(Z1.x))
public ECFieldElement addOne() { int[] z = Nat256.create(); SM2P256V1Field.addOne(x, z); return new SM2P256V1FieldElement(z); }
int[] Y1Squared = Nat256.create(); SecP256K1Field.square(Y1.x, Y1Squared); int[] T = Nat256.create(); SecP256K1Field.square(Y1Squared, T); int[] M = Nat256.create(); SecP256K1Field.square(X1.x, M); c = Nat256.addBothTo(M, M, M); SecP256K1Field.reduce32(c, M); SecP256K1Field.reduce32(c, S); int[] t1 = Nat256.create(); c = Nat.shiftUpBits(8, T, 3, 0, t1); SecP256K1Field.reduce32(c, t1);
public static void half(int[] x, int[] z) { if ((x[0] & 1) == 0) { Nat.shiftDownBit(8, x, 0, z); } else { int c = Nat256.add(x, P, z); Nat.shiftDownBit(8, z, c); } }
public boolean testBitZero() { return Nat256.getBit(x, 0) == 1; }
int[] tt1 = Nat256.createExt(); int[] t2 = Nat256.create(); int[] t3 = Nat256.create(); int[] t4 = Nat256.create(); int[] H = Nat256.create(); Curve25519Field.subtract(U1, U2, H); if (Nat256.isZero(H)) if (Nat256.isZero(R)) int[] HSquared = Nat256.create(); Curve25519Field.square(H, HSquared); int[] G = Nat256.create(); Curve25519Field.multiply(HSquared, H, G); Nat256.mul(S1, G, tt1); c = Nat256.addBothTo(V, V, G); Curve25519Field.reduce27(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 static int[] fromBigInteger(BigInteger x) { int[] z = Nat256.fromBigInteger(x); while (Nat256.gte(z, P)) { Nat256.subFrom(P, z); } return z; }
int[] M = Nat256.create(); Curve25519Field.square(X1.x, M); c = Nat256.addBothTo(M, M, M); c += Nat256.addTo(W1.x, M); Curve25519Field.reduce27(c, M); int[] _2Y1 = Nat256.create(); Curve25519Field.twice(Y1.x, _2Y1); int[] _2Y1Squared = Nat256.create(); Curve25519Field.multiply(_2Y1, Y1.x, _2Y1Squared); int[] S = Nat256.create(); Curve25519Field.multiply(_2Y1Squared, X1.x, S); Curve25519Field.twice(S, S); int[] _8T = Nat256.create(); Curve25519Field.square(_2Y1Squared, _8T); Curve25519Field.twice(_8T, _8T); if (!Nat256.isOne(Z1.x))