Search in sources :

Example 1 with CramerShoupParameters

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

the class CramerShoupKeyPairGenerator method generateKeyPair.

public AsymmetricCipherKeyPair generateKeyPair() {
    CramerShoupParameters csParams = param.getParameters();
    CramerShoupPrivateKeyParameters sk = generatePrivateKey(param.getRandom(), csParams);
    CramerShoupPublicKeyParameters pk = calculatePublicKey(csParams, sk);
    sk.setPk(pk);
    return new AsymmetricCipherKeyPair(pk, sk);
}
Also used : CramerShoupParameters(com.github.zhenwei.core.crypto.params.CramerShoupParameters) CramerShoupPrivateKeyParameters(com.github.zhenwei.core.crypto.params.CramerShoupPrivateKeyParameters) CramerShoupPublicKeyParameters(com.github.zhenwei.core.crypto.params.CramerShoupPublicKeyParameters) AsymmetricCipherKeyPair(com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair)

Example 2 with CramerShoupParameters

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

the class CramerShoupParametersGenerator method generateParameters.

/**
 * which generates the p and g values from the given parameters, returning the
 * CramerShoupParameters object.
 * <p>
 * Note: can take a while...
 * </p>
 *
 * @return a generated CramerShoupParameters object.
 */
public CramerShoupParameters generateParameters() {
    // 
    // find a safe prime p where p = 2*q + 1, where p and q are prime.
    // 
    BigInteger[] safePrimes = ParametersHelper.generateSafePrimes(size, certainty, random);
    // BigInteger p = safePrimes[0];
    BigInteger q = safePrimes[1];
    BigInteger g1 = ParametersHelper.selectGenerator(q, random);
    BigInteger g2 = ParametersHelper.selectGenerator(q, random);
    while (g1.equals(g2)) {
        g2 = ParametersHelper.selectGenerator(q, random);
    }
    return new CramerShoupParameters(q, g1, g2, new SHA256Digest());
}
Also used : CramerShoupParameters(com.github.zhenwei.core.crypto.params.CramerShoupParameters) SHA256Digest(com.github.zhenwei.core.crypto.digests.SHA256Digest) BigInteger(java.math.BigInteger)

Example 3 with CramerShoupParameters

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

the class CramerShoupParametersGenerator method generateParameters.

public CramerShoupParameters generateParameters(DHParameters dhParams) {
    BigInteger p = dhParams.getP();
    BigInteger g1 = dhParams.getG();
    // now we just need a second generator
    BigInteger g2 = ParametersHelper.selectGenerator(p, random);
    while (g1.equals(g2)) {
        g2 = ParametersHelper.selectGenerator(p, random);
    }
    return new CramerShoupParameters(p, g1, g2, new SHA256Digest());
}
Also used : CramerShoupParameters(com.github.zhenwei.core.crypto.params.CramerShoupParameters) SHA256Digest(com.github.zhenwei.core.crypto.digests.SHA256Digest) BigInteger(java.math.BigInteger)

Aggregations

CramerShoupParameters (com.github.zhenwei.core.crypto.params.CramerShoupParameters)3 SHA256Digest (com.github.zhenwei.core.crypto.digests.SHA256Digest)2 BigInteger (java.math.BigInteger)2 AsymmetricCipherKeyPair (com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair)1 CramerShoupPrivateKeyParameters (com.github.zhenwei.core.crypto.params.CramerShoupPrivateKeyParameters)1 CramerShoupPublicKeyParameters (com.github.zhenwei.core.crypto.params.CramerShoupPublicKeyParameters)1