Search in sources :

Example 26 with ECDomainParameters

use of com.github.zhenwei.core.crypto.params.ECDomainParameters in project LinLong-Java by zhenwei1108.

the class ECElGamalEncryptor method encrypt.

/**
 * Process a single EC point using the basic ElGamal algorithm.
 *
 * @param point the EC point to process.
 * @return the result of the Elgamal process.
 */
public ECPair encrypt(ECPoint point) {
    if (key == null) {
        throw new IllegalStateException("ECElGamalEncryptor not initialised");
    }
    ECDomainParameters ec = key.getParameters();
    BigInteger k = ECUtil.generateK(ec.getN(), random);
    ECMultiplier basePointMultiplier = createBasePointMultiplier();
    ECPoint[] gamma_phi = new ECPoint[] { basePointMultiplier.multiply(ec.getG(), k), key.getQ().multiply(k).add(ECAlgorithms.cleanPoint(ec.getCurve(), point)) };
    ec.getCurve().normalizeAll(gamma_phi);
    return new ECPair(gamma_phi[0], gamma_phi[1]);
}
Also used : ECDomainParameters(com.github.zhenwei.core.crypto.params.ECDomainParameters) BigInteger(java.math.BigInteger) ECMultiplier(com.github.zhenwei.core.math.ec.ECMultiplier) ECPoint(com.github.zhenwei.core.math.ec.ECPoint)

Example 27 with ECDomainParameters

use of com.github.zhenwei.core.crypto.params.ECDomainParameters in project LinLong-Java by zhenwei1108.

the class ECNewPublicKeyTransform method transform.

/**
 * Transform an existing cipher text pair using the ElGamal algorithm. Note: the input cipherText
 * will need to be preserved in order to complete the transformation to the new public key.
 *
 * @param cipherText the EC point to process.
 * @return returns a new ECPair representing the result of the process.
 */
public ECPair transform(ECPair cipherText) {
    if (key == null) {
        throw new IllegalStateException("ECNewPublicKeyTransform not initialised");
    }
    ECDomainParameters ec = key.getParameters();
    BigInteger n = ec.getN();
    ECMultiplier basePointMultiplier = createBasePointMultiplier();
    BigInteger k = ECUtil.generateK(n, random);
    ECPoint[] gamma_phi = new ECPoint[] { basePointMultiplier.multiply(ec.getG(), k), key.getQ().multiply(k).add(ECAlgorithms.cleanPoint(ec.getCurve(), cipherText.getY())) };
    ec.getCurve().normalizeAll(gamma_phi);
    return new ECPair(gamma_phi[0], gamma_phi[1]);
}
Also used : ECDomainParameters(com.github.zhenwei.core.crypto.params.ECDomainParameters) BigInteger(java.math.BigInteger) ECMultiplier(com.github.zhenwei.core.math.ec.ECMultiplier) ECPoint(com.github.zhenwei.core.math.ec.ECPoint)

Example 28 with ECDomainParameters

use of com.github.zhenwei.core.crypto.params.ECDomainParameters in project LinLong-Java by zhenwei1108.

the class ECVKOAgreement method calculateAgreement.

public byte[] calculateAgreement(CipherParameters pubKey) {
    ECPublicKeyParameters pub = (ECPublicKeyParameters) pubKey;
    ECDomainParameters params = key.getParameters();
    if (!params.equals(pub.getParameters())) {
        throw new IllegalStateException("ECVKO public key has wrong domain parameters");
    }
    BigInteger hd = params.getH().multiply(ukm).multiply(key.getD()).mod(params.getN());
    // Always perform calculations on the exact curve specified by our private key's parameters
    ECPoint pubPoint = ECAlgorithms.cleanPoint(params.getCurve(), pub.getQ());
    if (pubPoint.isInfinity()) {
        throw new IllegalStateException("Infinity is not a valid public key for ECDHC");
    }
    ECPoint P = pubPoint.multiply(hd).normalize();
    if (P.isInfinity()) {
        throw new IllegalStateException("Infinity is not a valid agreement value for ECVKO");
    }
    return fromPoint(P);
}
Also used : ECDomainParameters(com.github.zhenwei.core.crypto.params.ECDomainParameters) BigInteger(java.math.BigInteger) ECPoint(com.github.zhenwei.core.math.ec.ECPoint) ECPublicKeyParameters(com.github.zhenwei.core.crypto.params.ECPublicKeyParameters)

Example 29 with ECDomainParameters

use of com.github.zhenwei.core.crypto.params.ECDomainParameters in project LinLong-Java by zhenwei1108.

the class ECMQVBasicAgreement method calculateAgreement.

public BigInteger calculateAgreement(CipherParameters pubKey) {
    if (Properties.isOverrideSet("org.bouncycastle.ec.disable_mqv")) {
        throw new IllegalStateException("ECMQV explicitly disabled");
    }
    MQVPublicParameters pubParams = (MQVPublicParameters) pubKey;
    ECPrivateKeyParameters staticPrivateKey = privParams.getStaticPrivateKey();
    ECDomainParameters parameters = staticPrivateKey.getParameters();
    if (!parameters.equals(pubParams.getStaticPublicKey().getParameters())) {
        throw new IllegalStateException("ECMQV public key components have wrong domain parameters");
    }
    ECPoint agreement = calculateMqvAgreement(parameters, staticPrivateKey, privParams.getEphemeralPrivateKey(), privParams.getEphemeralPublicKey(), pubParams.getStaticPublicKey(), pubParams.getEphemeralPublicKey()).normalize();
    if (agreement.isInfinity()) {
        throw new IllegalStateException("Infinity is not a valid agreement value for MQV");
    }
    return agreement.getAffineXCoord().toBigInteger();
}
Also used : ECPrivateKeyParameters(com.github.zhenwei.core.crypto.params.ECPrivateKeyParameters) ECDomainParameters(com.github.zhenwei.core.crypto.params.ECDomainParameters) ECPoint(com.github.zhenwei.core.math.ec.ECPoint) MQVPublicParameters(com.github.zhenwei.core.crypto.params.MQVPublicParameters)

Example 30 with ECDomainParameters

use of com.github.zhenwei.core.crypto.params.ECDomainParameters in project LinLong-Java by zhenwei1108.

the class DSTU4145Signer method generateSignature.

public BigInteger[] generateSignature(byte[] message) {
    ECDomainParameters ec = key.getParameters();
    ECCurve curve = ec.getCurve();
    ECFieldElement h = hash2FieldElement(curve, message);
    if (h.isZero()) {
        h = curve.fromBigInteger(ONE);
    }
    BigInteger n = ec.getN();
    BigInteger e, r, s;
    ECFieldElement Fe, y;
    BigInteger d = ((ECPrivateKeyParameters) key).getD();
    ECMultiplier basePointMultiplier = createBasePointMultiplier();
    do {
        do {
            do {
                e = generateRandomInteger(n, random);
                Fe = basePointMultiplier.multiply(ec.getG(), e).normalize().getAffineXCoord();
            } while (Fe.isZero());
            y = h.multiply(Fe);
            r = fieldElement2Integer(n, y);
        } while (r.signum() == 0);
        s = r.multiply(d).add(e).mod(n);
    } while (s.signum() == 0);
    return new BigInteger[] { r, s };
}
Also used : ECPrivateKeyParameters(com.github.zhenwei.core.crypto.params.ECPrivateKeyParameters) ECDomainParameters(com.github.zhenwei.core.crypto.params.ECDomainParameters) ECCurve(com.github.zhenwei.core.math.ec.ECCurve) BigInteger(java.math.BigInteger) ECMultiplier(com.github.zhenwei.core.math.ec.ECMultiplier) ECFieldElement(com.github.zhenwei.core.math.ec.ECFieldElement)

Aggregations

ECDomainParameters (com.github.zhenwei.core.crypto.params.ECDomainParameters)35 BigInteger (java.math.BigInteger)22 ECPoint (com.github.zhenwei.core.math.ec.ECPoint)21 ECPublicKeyParameters (com.github.zhenwei.core.crypto.params.ECPublicKeyParameters)12 ECPrivateKeyParameters (com.github.zhenwei.core.crypto.params.ECPrivateKeyParameters)10 ECCurve (com.github.zhenwei.core.math.ec.ECCurve)10 ASN1ObjectIdentifier (com.github.zhenwei.core.asn1.ASN1ObjectIdentifier)9 ECMultiplier (com.github.zhenwei.core.math.ec.ECMultiplier)9 ECParameterSpec (com.github.zhenwei.provider.jce.spec.ECParameterSpec)9 X9ECParameters (com.github.zhenwei.core.asn1.x9.X9ECParameters)7 ASN1Integer (com.github.zhenwei.core.asn1.ASN1Integer)6 ECNamedDomainParameters (com.github.zhenwei.core.crypto.params.ECNamedDomainParameters)6 ASN1Encodable (com.github.zhenwei.core.asn1.ASN1Encodable)5 X962Parameters (com.github.zhenwei.core.asn1.x9.X962Parameters)5 ECKeyGenerationParameters (com.github.zhenwei.core.crypto.params.ECKeyGenerationParameters)4 IOException (java.io.IOException)4 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)4 ASN1Sequence (com.github.zhenwei.core.asn1.ASN1Sequence)3 DEROctetString (com.github.zhenwei.core.asn1.DEROctetString)3 GOST3410PublicKeyAlgParameters (com.github.zhenwei.core.asn1.cryptopro.GOST3410PublicKeyAlgParameters)3