Search in sources :

Example 11 with ECFieldElement

use of com.github.zhenwei.core.math.ec.ECFieldElement in project LinLong-Java by zhenwei1108.

the class SecT239K1Point method getYCoord.

public ECFieldElement getYCoord() {
    ECFieldElement X = x, L = y;
    if (this.isInfinity() || X.isZero()) {
        return L;
    }
    // Y is actually Lambda (X + Y/X) here; convert to affine value on the fly
    ECFieldElement Y = L.add(X).multiply(X);
    ECFieldElement Z = zs[0];
    if (!Z.isOne()) {
        Y = Y.divide(Z);
    }
    return Y;
}
Also used : ECFieldElement(com.github.zhenwei.core.math.ec.ECFieldElement)

Example 12 with ECFieldElement

use of com.github.zhenwei.core.math.ec.ECFieldElement in project LinLong-Java by zhenwei1108.

the class SecT239K1Point 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;
    }
    // NOTE: twicePlus() only optimized for lambda-affine argument
    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 = L1Sq.add(L1Z1);
    ECFieldElement L2plus1 = L2.addOne();
    ECFieldElement A = 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 SecT239K1Point(curve, A, curve.getB());
    }
    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 SecT239K1Point(curve, X3, L3, new ECFieldElement[] { Z3 });
}
Also used : ECCurve(com.github.zhenwei.core.math.ec.ECCurve) ECFieldElement(com.github.zhenwei.core.math.ec.ECFieldElement)

Example 13 with ECFieldElement

use of com.github.zhenwei.core.math.ec.ECFieldElement in project LinLong-Java by zhenwei1108.

the class SecT283K1Point method getYCoord.

public ECFieldElement getYCoord() {
    ECFieldElement X = x, L = y;
    if (this.isInfinity() || X.isZero()) {
        return L;
    }
    // Y is actually Lambda (X + Y/X) here; convert to affine value on the fly
    ECFieldElement Y = L.add(X).multiply(X);
    ECFieldElement Z = zs[0];
    if (!Z.isOne()) {
        Y = Y.divide(Z);
    }
    return Y;
}
Also used : ECFieldElement(com.github.zhenwei.core.math.ec.ECFieldElement)

Example 14 with ECFieldElement

use of com.github.zhenwei.core.math.ec.ECFieldElement in project LinLong-Java by zhenwei1108.

the class SecT283K1Point 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;
    }
    // NOTE: twicePlus() only optimized for lambda-affine argument
    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 = L1Sq.add(L1Z1);
    ECFieldElement L2plus1 = L2.addOne();
    ECFieldElement A = 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 SecT283K1Point(curve, A, curve.getB());
    }
    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 SecT283K1Point(curve, X3, L3, new ECFieldElement[] { Z3 });
}
Also used : ECCurve(com.github.zhenwei.core.math.ec.ECCurve) ECFieldElement(com.github.zhenwei.core.math.ec.ECFieldElement)

Example 15 with ECFieldElement

use of com.github.zhenwei.core.math.ec.ECFieldElement in project LinLong-Java by zhenwei1108.

the class SecT283K1Point 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();
}
Also used : ECFieldElement(com.github.zhenwei.core.math.ec.ECFieldElement)

Aggregations

ECFieldElement (com.github.zhenwei.core.math.ec.ECFieldElement)133 ECCurve (com.github.zhenwei.core.math.ec.ECCurve)71 ECPoint (com.github.zhenwei.core.math.ec.ECPoint)36 BigInteger (java.math.BigInteger)7 ECDomainParameters (com.github.zhenwei.core.crypto.params.ECDomainParameters)3 ECPublicKeyParameters (com.github.zhenwei.core.crypto.params.ECPublicKeyParameters)2 ECPrivateKeyParameters (com.github.zhenwei.core.crypto.params.ECPrivateKeyParameters)1 ECMultiplier (com.github.zhenwei.core.math.ec.ECMultiplier)1 SecureRandom (java.security.SecureRandom)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1