Page MenuHomec4science

ECCEGKeyGenerator.java
No OneTemporary

File Metadata

Created
Tue, Dec 31, 00:08

ECCEGKeyGenerator.java

package crypto.elgamal;
import java.math.BigInteger;
import java.security.SecureRandom;
import org.bouncycastle.asn1.nist.NISTNamedCurves;
import org.bouncycastle.asn1.x9.X9ECParameters;
import org.bouncycastle.math.ec.ECPoint;
public class ECCEGKeyGenerator {
private SecureRandom randGen;
private BigInteger order;
private X9ECParameters ecParams;
public ECCEGKeyGenerator(String curveName) {
this.randGen = new SecureRandom();
this.ecParams = NISTNamedCurves.getByName(curveName);
this.order = ecParams.getN();
}
/**
*
* @param order
* order of the group
* @return
*/
public KeyPair generateKey() {
// generate the secret and random coefficient
BigInteger secret = new BigInteger(order.bitLength() - 1, randGen);
BigInteger a1 = new BigInteger(order.bitLength() - 1, randGen);
BigInteger[] coefficients = new BigInteger[2];
coefficients[0] = secret;
coefficients[1] = a1;
// generate both secret shares
PartialSecret secretMU = new PartialSecret(PartialSecret.PART_MU, coefficients, order);
PartialSecret secretSPU = new PartialSecret(PartialSecret.PART_SPU, coefficients, order);
// generate public key
ECPoint pubKey = ecParams.getG().multiply(secret);
return new KeyPair(secretMU, secretSPU, pubKey);
}
}

Event Timeline