public SM2P256V1FieldElement(BigInteger x) { if (x == null || x.signum() < 0 || x.compareTo(Q) >= 0) { throw new IllegalArgumentException("x value invalid for SM2P256V1FieldElement"); } this.x = SM2P256V1Field.fromBigInteger(x); }
SM2P256V1Field.square(x1, x2); SM2P256V1Field.multiply(x2, x1, x2); int[] x4 = Nat256.create(); SM2P256V1Field.squareN(x2, 2, x4); SM2P256V1Field.multiply(x4, x2, x4); int[] x6 = Nat256.create(); SM2P256V1Field.squareN(x4, 2, x6); SM2P256V1Field.multiply(x6, x2, x6); int[] x12 = x2; SM2P256V1Field.squareN(x6, 6, x12); SM2P256V1Field.multiply(x12, x6, x12); int[] x24 = Nat256.create(); SM2P256V1Field.squareN(x12, 12, x24); SM2P256V1Field.multiply(x24, x12, x24); int[] x30 = x12; SM2P256V1Field.squareN(x24, 6, x30); SM2P256V1Field.multiply(x30, x6, x30); int[] x31 = x6; SM2P256V1Field.square(x30, x31); SM2P256V1Field.multiply(x31, x1, x31); SM2P256V1Field.squareN(x31, 31, t1); SM2P256V1Field.multiply(t1, x31, x62); SM2P256V1Field.squareN(t1, 32, t1); SM2P256V1Field.multiply(t1, x62, t1); SM2P256V1Field.squareN(t1, 62, t1); SM2P256V1Field.multiply(t1, x62, t1);
SM2P256V1Field.square(Z1.x, S2); SM2P256V1Field.multiply(S2, X2.x, U2); SM2P256V1Field.multiply(S2, Z1.x, S2); SM2P256V1Field.multiply(S2, Y2.x, S2); SM2P256V1Field.square(Z2.x, S1); SM2P256V1Field.multiply(S1, X1.x, U1); SM2P256V1Field.multiply(S1, Z2.x, S1); SM2P256V1Field.multiply(S1, Y1.x, S1); SM2P256V1Field.subtract(U1, U2, H); SM2P256V1Field.subtract(S1, S2, R); SM2P256V1Field.square(H, HSquared); SM2P256V1Field.multiply(HSquared, H, G); SM2P256V1Field.multiply(HSquared, U1, V); SM2P256V1Field.negate(G, G); Nat256.mul(S1, G, tt1); SM2P256V1Field.reduce32(c, G);
SM2P256V1Field.square(Y1.x, Y1Squared); SM2P256V1Field.square(Y1Squared, T); SM2P256V1Field.square(Z1.x, Z1Squared); SM2P256V1Field.subtract(X1.x, Z1Squared, t1); SM2P256V1Field.add(X1.x, Z1Squared, M); SM2P256V1Field.multiply(M, t1, M); c = Nat256.addBothTo(M, M, M); SM2P256V1Field.reduce32(c, M); SM2P256V1Field.multiply(Y1Squared, X1.x, S); c = Nat.shiftUpBits(8, S, 2, 0); SM2P256V1Field.reduce32(c, S); SM2P256V1Field.reduce32(c, t1); SM2P256V1Field.square(M, X3.x); SM2P256V1Field.subtract(X3.x, S, X3.x); SM2P256V1Field.subtract(X3.x, S, X3.x); SM2P256V1Field.subtract(S, X3.x, Y3.x); SM2P256V1Field.multiply(Y3.x, M, Y3.x); SM2P256V1Field.subtract(Y3.x, t1, Y3.x); SM2P256V1Field.twice(Y1.x, Z3.x); if (!Z1IsOne)
public static void addOne(int[] x, int[] z) { int c = Nat.inc(8, x, z); if (c != 0 || ((z[7] >>> 1) >= P7s1 && Nat256.gte(z, P))) { addPInvTo(z); } }
public ECFieldElement multiply(ECFieldElement b) { int[] z = Nat256.create(); SM2P256V1Field.multiply(x, ((SM2P256V1FieldElement)b).x, z); return new SM2P256V1FieldElement(z); }
public ECFieldElement square() { int[] z = Nat256.create(); SM2P256V1Field.square(x, z); return new SM2P256V1FieldElement(z); }
public ECFieldElement addOne() { int[] z = Nat256.create(); SM2P256V1Field.addOne(x, z); return new SM2P256V1FieldElement(z); }
public ECFieldElement negate() { int[] z = Nat256.create(); SM2P256V1Field.negate(x, z); return new SM2P256V1FieldElement(z); }
public ECFieldElement add(ECFieldElement b) { int[] z = Nat256.create(); SM2P256V1Field.add(x, ((SM2P256V1FieldElement)b).x, z); return new SM2P256V1FieldElement(z); }
public static void twice(int[] x, int[] z) { int c = Nat.shiftUpBit(8, x, 0, z); if (c != 0 || ((z[7] >>> 1) >= P7s1 && Nat256.gte(z, P))) { addPInvTo(z); } }
public ECFieldElement divide(ECFieldElement b) { // return multiply(b.invert()); int[] z = Nat256.create(); Mod.invert(SM2P256V1Field.P, ((SM2P256V1FieldElement)b).x, z); SM2P256V1Field.multiply(z, x, z); return new SM2P256V1FieldElement(z); }
public static void add(int[] x, int[] y, int[] z) { int c = Nat256.add(x, y, z); if (c != 0 || ((z[7] >>> 1) >= P7s1 && Nat256.gte(z, P))) { addPInvTo(z); } }
public static void multiply(int[] x, int[] y, int[] z) { int[] tt = Nat256.createExt(); Nat256.mul(x, y, tt); reduce(tt, z); }
public static void square(int[] x, int[] z) { int[] tt = Nat256.createExt(); Nat256.square(x, tt); reduce(tt, z); }