import org.bouncycastle.math.raw.Nat; //导入方法依赖的package包/类
public ECPoint twice()
{
if (this.isInfinity())
{
return this;
}
ECCurve curve = this.getCurve();
SecP384R1FieldElement Y1 = (SecP384R1FieldElement)this.y;
if (Y1.isZero())
{
return curve.getInfinity();
}
SecP384R1FieldElement X1 = (SecP384R1FieldElement)this.x, Z1 = (SecP384R1FieldElement)this.zs[0];
int c;
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);
boolean Z1IsOne = Z1.isOne();
int[] Z1Squared = Z1.x;
if (!Z1IsOne)
{
Z1Squared = t2;
SecP384R1Field.square(Z1.x, Z1Squared);
}
SecP384R1Field.subtract(X1.x, Z1Squared, t1);
int[] M = t2;
SecP384R1Field.add(X1.x, Z1Squared, M);
SecP384R1Field.multiply(M, t1, M);
c = Nat.addBothTo(12, M, M, M);
SecP384R1Field.reduce32(c, M);
int[] S = Y1Squared;
SecP384R1Field.multiply(Y1Squared, X1.x, S);
c = Nat.shiftUpBits(12, S, 2, 0);
SecP384R1Field.reduce32(c, S);
c = Nat.shiftUpBits(12, T, 3, 0, t1);
SecP384R1Field.reduce32(c, t1);
SecP384R1FieldElement X3 = new SecP384R1FieldElement(T);
SecP384R1Field.square(M, X3.x);
SecP384R1Field.subtract(X3.x, S, X3.x);
SecP384R1Field.subtract(X3.x, S, X3.x);
SecP384R1FieldElement Y3 = new SecP384R1FieldElement(S);
SecP384R1Field.subtract(S, X3.x, Y3.x);
SecP384R1Field.multiply(Y3.x, M, Y3.x);
SecP384R1Field.subtract(Y3.x, t1, Y3.x);
SecP384R1FieldElement Z3 = new SecP384R1FieldElement(M);
SecP384R1Field.twice(Y1.x, Z3.x);
if (!Z1IsOne)
{
SecP384R1Field.multiply(Z3.x, Z1.x, Z3.x);
}
return new SecP384R1Point(curve, X3, Y3, new ECFieldElement[]{ Z3 }, this.withCompression);
}