use of com.github.zhenwei.core.math.ec.ECFieldElement in project LinLong-Java by zhenwei1108.
the class SecT113R2Point method twicePlus.
public ECPoint twicePlus(ECPoint b) {
if (this.isInfinity()) {
return b;
}
if (b.isInfinity()) {
return twice();
}
ECCurve curve = this.getCurve();
ECFieldElement X1 = this.x;
if (X1.isZero()) {
// A point with X == 0 is its own additive inverse
return b;
}
ECFieldElement X2 = b.getRawXCoord(), Z2 = b.getZCoord(0);
if (X2.isZero() || !Z2.isOne()) {
return twice().add(b);
}
ECFieldElement L1 = this.y, Z1 = this.zs[0];
ECFieldElement L2 = b.getRawYCoord();
ECFieldElement X1Sq = X1.square();
ECFieldElement L1Sq = L1.square();
ECFieldElement Z1Sq = Z1.square();
ECFieldElement L1Z1 = L1.multiply(Z1);
ECFieldElement T = curve.getA().multiply(Z1Sq).add(L1Sq).add(L1Z1);
ECFieldElement L2plus1 = L2.addOne();
ECFieldElement A = curve.getA().add(L2plus1).multiply(Z1Sq).add(L1Sq).multiplyPlusProduct(T, X1Sq, Z1Sq);
ECFieldElement X2Z1Sq = X2.multiply(Z1Sq);
ECFieldElement B = X2Z1Sq.add(T).square();
if (B.isZero()) {
if (A.isZero()) {
return b.twice();
}
return curve.getInfinity();
}
if (A.isZero()) {
return new SecT113R2Point(curve, A, curve.getB().sqrt());
}
ECFieldElement X3 = A.square().multiply(X2Z1Sq);
ECFieldElement Z3 = A.multiply(B).multiply(Z1Sq);
ECFieldElement L3 = A.add(B).square().multiplyPlusProduct(T, L2plus1, Z3);
return new SecT113R2Point(curve, X3, L3, new ECFieldElement[] { Z3 });
}
use of com.github.zhenwei.core.math.ec.ECFieldElement in project LinLong-Java by zhenwei1108.
the class SecT131R1Point method twice.
public ECPoint twice() {
if (this.isInfinity()) {
return this;
}
ECCurve curve = this.getCurve();
ECFieldElement X1 = this.x;
if (X1.isZero()) {
// A point with X == 0 is its own additive inverse
return curve.getInfinity();
}
ECFieldElement L1 = this.y, Z1 = this.zs[0];
boolean Z1IsOne = Z1.isOne();
ECFieldElement L1Z1 = Z1IsOne ? L1 : L1.multiply(Z1);
ECFieldElement Z1Sq = Z1IsOne ? Z1 : Z1.square();
ECFieldElement a = curve.getA();
ECFieldElement aZ1Sq = Z1IsOne ? a : a.multiply(Z1Sq);
ECFieldElement T = L1.square().add(L1Z1).add(aZ1Sq);
if (T.isZero()) {
return new SecT131R1Point(curve, T, curve.getB().sqrt());
}
ECFieldElement X3 = T.square();
ECFieldElement Z3 = Z1IsOne ? T : T.multiply(Z1Sq);
ECFieldElement X1Z1 = Z1IsOne ? X1 : X1.multiply(Z1);
ECFieldElement L3 = X1Z1.squarePlusProduct(T, L1Z1).add(X3).add(Z3);
return new SecT131R1Point(curve, X3, L3, new ECFieldElement[] { Z3 });
}
use of com.github.zhenwei.core.math.ec.ECFieldElement in project LinLong-Java by zhenwei1108.
the class SecT131R1Point method getCompressionYTilde.
protected boolean getCompressionYTilde() {
ECFieldElement X = this.getRawXCoord();
if (X.isZero()) {
return false;
}
ECFieldElement Y = this.getRawYCoord();
// Y is actually Lambda (X + Y/X) here
return Y.testBitZero() != X.testBitZero();
}
use of com.github.zhenwei.core.math.ec.ECFieldElement in project LinLong-Java by zhenwei1108.
the class SecT131R1Point method negate.
public ECPoint negate() {
if (this.isInfinity()) {
return this;
}
ECFieldElement X = this.x;
if (X.isZero()) {
return this;
}
// L is actually Lambda (X + Y/X) here
ECFieldElement L = this.y, Z = this.zs[0];
return new SecT131R1Point(curve, X, L.add(Z), new ECFieldElement[] { Z });
}
use of com.github.zhenwei.core.math.ec.ECFieldElement in project LinLong-Java by zhenwei1108.
the class SecT131R2Point method twicePlus.
public ECPoint twicePlus(ECPoint b) {
if (this.isInfinity()) {
return b;
}
if (b.isInfinity()) {
return twice();
}
ECCurve curve = this.getCurve();
ECFieldElement X1 = this.x;
if (X1.isZero()) {
// A point with X == 0 is its own additive inverse
return b;
}
ECFieldElement X2 = b.getRawXCoord(), Z2 = b.getZCoord(0);
if (X2.isZero() || !Z2.isOne()) {
return twice().add(b);
}
ECFieldElement L1 = this.y, Z1 = this.zs[0];
ECFieldElement L2 = b.getRawYCoord();
ECFieldElement X1Sq = X1.square();
ECFieldElement L1Sq = L1.square();
ECFieldElement Z1Sq = Z1.square();
ECFieldElement L1Z1 = L1.multiply(Z1);
ECFieldElement T = curve.getA().multiply(Z1Sq).add(L1Sq).add(L1Z1);
ECFieldElement L2plus1 = L2.addOne();
ECFieldElement A = curve.getA().add(L2plus1).multiply(Z1Sq).add(L1Sq).multiplyPlusProduct(T, X1Sq, Z1Sq);
ECFieldElement X2Z1Sq = X2.multiply(Z1Sq);
ECFieldElement B = X2Z1Sq.add(T).square();
if (B.isZero()) {
if (A.isZero()) {
return b.twice();
}
return curve.getInfinity();
}
if (A.isZero()) {
return new SecT131R2Point(curve, A, curve.getB().sqrt());
}
ECFieldElement X3 = A.square().multiply(X2Z1Sq);
ECFieldElement Z3 = A.multiply(B).multiply(Z1Sq);
ECFieldElement L3 = A.add(B).square().multiplyPlusProduct(T, L2plus1, Z3);
return new SecT131R2Point(curve, X3, L3, new ECFieldElement[] { Z3 });
}
Aggregations