Search in sources :

Example 1 with ElGamalParameters

use of org.openecard.bouncycastle.crypto.params.ElGamalParameters in project open-ecard by ecsec.

the class PACEKey method generateKeyPair.

/**
 * Generate a key pair.
 */
public void generateKeyPair() {
    reseed();
    if (pdp.isDH()) {
        ElGamalParameterSpec p = (ElGamalParameterSpec) pdp.getParameter();
        int numBits = p.getG().bitLength();
        BigInteger d = new BigInteger(numBits, rand);
        ElGamalParameters egp = new ElGamalParameters(p.getP(), p.getG());
        sk = new ElGamalPrivateKeyParameters(d, egp);
        pk = new ElGamalPublicKeyParameters(egp.getG().multiply(d), egp);
    } else if (pdp.isECDH()) {
        ECParameterSpec p = (ECParameterSpec) pdp.getParameter();
        int numBits = p.getN().bitLength();
        BigInteger d = new BigInteger(numBits, rand);
        ECDomainParameters ecp = new ECDomainParameters(p.getCurve(), p.getG(), p.getN(), p.getH());
        sk = new ECPrivateKeyParameters(d, ecp);
        pk = new ECPublicKeyParameters(ecp.getG().multiply(d), ecp);
    } else {
        throw new IllegalArgumentException();
    }
}
Also used : ECPrivateKeyParameters(org.openecard.bouncycastle.crypto.params.ECPrivateKeyParameters) ECDomainParameters(org.openecard.bouncycastle.crypto.params.ECDomainParameters) ElGamalParameters(org.openecard.bouncycastle.crypto.params.ElGamalParameters) ElGamalPrivateKeyParameters(org.openecard.bouncycastle.crypto.params.ElGamalPrivateKeyParameters) ECParameterSpec(org.openecard.bouncycastle.jce.spec.ECParameterSpec) BigInteger(java.math.BigInteger) ElGamalPublicKeyParameters(org.openecard.bouncycastle.crypto.params.ElGamalPublicKeyParameters) ECPublicKeyParameters(org.openecard.bouncycastle.crypto.params.ECPublicKeyParameters) ElGamalParameterSpec(org.openecard.bouncycastle.jce.spec.ElGamalParameterSpec) ECPoint(org.openecard.bouncycastle.math.ec.ECPoint)

Example 2 with ElGamalParameters

use of org.openecard.bouncycastle.crypto.params.ElGamalParameters in project open-ecard by ecsec.

the class CAKey method generateKeyPair.

/**
 * Generate a key pair.
 */
public void generateKeyPair() {
    reseed();
    if (cdp.isDH()) {
        ElGamalParameterSpec p = (ElGamalParameterSpec) cdp.getParameter();
        int numBits = p.getG().bitLength();
        BigInteger d = new BigInteger(numBits, rand);
        ElGamalParameters egp = new ElGamalParameters(p.getP(), p.getG());
        sk = new ElGamalPrivateKeyParameters(d, egp);
        pk = new ElGamalPublicKeyParameters(egp.getG().multiply(d), egp);
    } else if (cdp.isECDH()) {
        ECParameterSpec p = (ECParameterSpec) cdp.getParameter();
        int numBits = p.getN().bitLength();
        BigInteger d = new BigInteger(numBits, rand);
        ECDomainParameters ecp = new ECDomainParameters(p.getCurve(), p.getG(), p.getN(), p.getH());
        sk = new ECPrivateKeyParameters(d, ecp);
        pk = new ECPublicKeyParameters(ecp.getG().multiply(d), ecp);
    } else {
        throw new IllegalArgumentException();
    }
}
Also used : ECPrivateKeyParameters(org.openecard.bouncycastle.crypto.params.ECPrivateKeyParameters) ECDomainParameters(org.openecard.bouncycastle.crypto.params.ECDomainParameters) ElGamalParameters(org.openecard.bouncycastle.crypto.params.ElGamalParameters) ElGamalPrivateKeyParameters(org.openecard.bouncycastle.crypto.params.ElGamalPrivateKeyParameters) ECParameterSpec(org.openecard.bouncycastle.jce.spec.ECParameterSpec) BigInteger(java.math.BigInteger) ElGamalPublicKeyParameters(org.openecard.bouncycastle.crypto.params.ElGamalPublicKeyParameters) ECPublicKeyParameters(org.openecard.bouncycastle.crypto.params.ECPublicKeyParameters) ElGamalParameterSpec(org.openecard.bouncycastle.jce.spec.ElGamalParameterSpec) ECPoint(org.openecard.bouncycastle.math.ec.ECPoint)

Aggregations

BigInteger (java.math.BigInteger)2 ECDomainParameters (org.openecard.bouncycastle.crypto.params.ECDomainParameters)2 ECPrivateKeyParameters (org.openecard.bouncycastle.crypto.params.ECPrivateKeyParameters)2 ECPublicKeyParameters (org.openecard.bouncycastle.crypto.params.ECPublicKeyParameters)2 ElGamalParameters (org.openecard.bouncycastle.crypto.params.ElGamalParameters)2 ElGamalPrivateKeyParameters (org.openecard.bouncycastle.crypto.params.ElGamalPrivateKeyParameters)2 ElGamalPublicKeyParameters (org.openecard.bouncycastle.crypto.params.ElGamalPublicKeyParameters)2 ECParameterSpec (org.openecard.bouncycastle.jce.spec.ECParameterSpec)2 ElGamalParameterSpec (org.openecard.bouncycastle.jce.spec.ElGamalParameterSpec)2 ECPoint (org.openecard.bouncycastle.math.ec.ECPoint)2