public SecP256K1FieldElement(BigInteger x) { if (x == null || x.signum() < 0 || x.compareTo(Q) >= 0) { throw new IllegalArgumentException("x value invalid for SecP256K1FieldElement"); } this.x = SecP256K1Field.fromBigInteger(x); }
SecP256K1Field.square(x1, x2); SecP256K1Field.multiply(x2, x1, x2); int[] x3 = Nat256.create(); SecP256K1Field.square(x2, x3); SecP256K1Field.multiply(x3, x1, x3); int[] x6 = Nat256.create(); SecP256K1Field.squareN(x3, 3, x6); SecP256K1Field.multiply(x6, x3, x6); int[] x9 = x6; SecP256K1Field.squareN(x6, 3, x9); SecP256K1Field.multiply(x9, x3, x9); int[] x11 = x9; SecP256K1Field.squareN(x9, 2, x11); SecP256K1Field.multiply(x11, x2, x11); int[] x22 = Nat256.create(); SecP256K1Field.squareN(x11, 11, x22); SecP256K1Field.multiply(x22, x11, x22); int[] x44 = x11; SecP256K1Field.squareN(x22, 22, x44); SecP256K1Field.multiply(x44, x22, x44); int[] x88 = Nat256.create(); SecP256K1Field.squareN(x44, 44, x88); SecP256K1Field.multiply(x88, x44, x88); int[] x176 = Nat256.create(); SecP256K1Field.squareN(x88, 88, x176); SecP256K1Field.multiply(x176, x88, x176); int[] x220 = x88; SecP256K1Field.squareN(x176, 44, x220); SecP256K1Field.multiply(x220, x44, x220);
SecP256K1Field.square(Z1.x, S2); SecP256K1Field.multiply(S2, X2.x, U2); SecP256K1Field.multiply(S2, Z1.x, S2); SecP256K1Field.multiply(S2, Y2.x, S2); SecP256K1Field.square(Z2.x, S1); SecP256K1Field.multiply(S1, X1.x, U1); SecP256K1Field.multiply(S1, Z2.x, S1); SecP256K1Field.multiply(S1, Y1.x, S1); SecP256K1Field.subtract(U1, U2, H); SecP256K1Field.subtract(S1, S2, R); SecP256K1Field.square(H, HSquared); SecP256K1Field.multiply(HSquared, H, G); SecP256K1Field.multiply(HSquared, U1, V); SecP256K1Field.negate(G, G); Nat256.mul(S1, G, tt1); SecP256K1Field.reduce32(c, G);
SecP256K1Field.square(Y1.x, Y1Squared); SecP256K1Field.square(Y1Squared, T); SecP256K1Field.square(X1.x, M); c = Nat256.addBothTo(M, M, M); SecP256K1Field.reduce32(c, M); SecP256K1Field.multiply(Y1Squared, X1.x, S); c = Nat.shiftUpBits(8, S, 2, 0); SecP256K1Field.reduce32(c, S); SecP256K1Field.reduce32(c, t1); SecP256K1Field.square(M, X3.x); SecP256K1Field.subtract(X3.x, S, X3.x); SecP256K1Field.subtract(X3.x, S, X3.x); SecP256K1Field.subtract(S, X3.x, Y3.x); SecP256K1Field.multiply(Y3.x, M, Y3.x); SecP256K1Field.subtract(Y3.x, t1, Y3.x); SecP256K1Field.twice(Y1.x, Z3.x); if (!Z1.isOne()) SecP256K1Field.multiply(Z3.x, Z1.x, Z3.x);
public ECFieldElement multiply(ECFieldElement b) { int[] z = Nat256.create(); SecP256K1Field.multiply(x, ((SecP256K1FieldElement)b).x, z); return new SecP256K1FieldElement(z); }
public ECFieldElement square() { int[] z = Nat256.create(); SecP256K1Field.square(x, z); return new SecP256K1FieldElement(z); }
public ECFieldElement addOne() { int[] z = Nat256.create(); SecP256K1Field.addOne(x, z); return new SecP256K1FieldElement(z); }
public ECFieldElement add(ECFieldElement b) { int[] z = Nat256.create(); SecP256K1Field.add(x, ((SecP256K1FieldElement)b).x, z); return new SecP256K1FieldElement(z); }
public ECFieldElement negate() { int[] z = Nat256.create(); SecP256K1Field.negate(x, z); return new SecP256K1FieldElement(z); }
SecP256K1Field.square(Z1.x, S2); SecP256K1Field.multiply(S2, X2.x, U2); SecP256K1Field.multiply(S2, Z1.x, S2); SecP256K1Field.multiply(S2, Y2.x, S2); SecP256K1Field.square(Z2.x, S1); SecP256K1Field.multiply(S1, X1.x, U1); SecP256K1Field.multiply(S1, Z2.x, S1); SecP256K1Field.multiply(S1, Y1.x, S1); SecP256K1Field.subtract(U1, U2, H); SecP256K1Field.subtract(S1, S2, R); SecP256K1Field.square(H, HSquared); SecP256K1Field.multiply(HSquared, H, G); SecP256K1Field.multiply(HSquared, U1, V); SecP256K1Field.negate(G, G); Nat256.mul(S1, G, tt1); SecP256K1Field.reduce32(c, G);
SecP256K1Field.square(Y1.x, Y1Squared); SecP256K1Field.square(Y1Squared, T); SecP256K1Field.square(X1.x, M); c = Nat256.addBothTo(M, M, M); SecP256K1Field.reduce32(c, M); SecP256K1Field.multiply(Y1Squared, X1.x, S); c = Nat.shiftUpBits(8, S, 2, 0); SecP256K1Field.reduce32(c, S); SecP256K1Field.reduce32(c, t1); SecP256K1Field.square(M, X3.x); SecP256K1Field.subtract(X3.x, S, X3.x); SecP256K1Field.subtract(X3.x, S, X3.x); SecP256K1Field.subtract(S, X3.x, Y3.x); SecP256K1Field.multiply(Y3.x, M, Y3.x); SecP256K1Field.subtract(Y3.x, t1, Y3.x); SecP256K1Field.twice(Y1.x, Z3.x); if (!Z1.isOne()) SecP256K1Field.multiply(Z3.x, Z1.x, Z3.x);
public ECFieldElement multiply(ECFieldElement b) { int[] z = Nat256.create(); SecP256K1Field.multiply(x, ((SecP256K1FieldElement)b).x, z); return new SecP256K1FieldElement(z); }
public ECFieldElement square() { int[] z = Nat256.create(); SecP256K1Field.square(x, z); return new SecP256K1FieldElement(z); }
public ECFieldElement addOne() { int[] z = Nat256.create(); SecP256K1Field.addOne(x, z); return new SecP256K1FieldElement(z); }
public ECFieldElement add(ECFieldElement b) { int[] z = Nat256.create(); SecP256K1Field.add(x, ((SecP256K1FieldElement)b).x, z); return new SecP256K1FieldElement(z); }
public ECFieldElement negate() { int[] z = Nat256.create(); SecP256K1Field.negate(x, z); return new SecP256K1FieldElement(z); }
SecP256K1Field.square(x1, x2); SecP256K1Field.multiply(x2, x1, x2); int[] x3 = Nat256.create(); SecP256K1Field.square(x2, x3); SecP256K1Field.multiply(x3, x1, x3); int[] x6 = Nat256.create(); SecP256K1Field.squareN(x3, 3, x6); SecP256K1Field.multiply(x6, x3, x6); int[] x9 = x6; SecP256K1Field.squareN(x6, 3, x9); SecP256K1Field.multiply(x9, x3, x9); int[] x11 = x9; SecP256K1Field.squareN(x9, 2, x11); SecP256K1Field.multiply(x11, x2, x11); int[] x22 = Nat256.create(); SecP256K1Field.squareN(x11, 11, x22); SecP256K1Field.multiply(x22, x11, x22); int[] x44 = x11; SecP256K1Field.squareN(x22, 22, x44); SecP256K1Field.multiply(x44, x22, x44); int[] x88 = Nat256.create(); SecP256K1Field.squareN(x44, 44, x88); SecP256K1Field.multiply(x88, x44, x88); int[] x176 = Nat256.create(); SecP256K1Field.squareN(x88, 88, x176); SecP256K1Field.multiply(x176, x88, x176); int[] x220 = x88; SecP256K1Field.squareN(x176, 44, x220); SecP256K1Field.multiply(x220, x44, x220);
public ECFieldElement divide(ECFieldElement b) { // return multiply(b.invert()); int[] z = Nat256.create(); Mod.invert(SecP256K1Field.P, ((SecP256K1FieldElement)b).x, z); SecP256K1Field.multiply(z, x, z); return new SecP256K1FieldElement(z); }