Search in sources :

Example 16 with AsymmetricCipherKeyPair

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

the class ElGamalKeyPairGenerator method generateKeyPair.

public AsymmetricCipherKeyPair generateKeyPair() {
    DHKeyGeneratorHelper helper = DHKeyGeneratorHelper.INSTANCE;
    ElGamalParameters egp = param.getParameters();
    DHParameters dhp = new DHParameters(egp.getP(), egp.getG(), null, egp.getL());
    BigInteger x = helper.calculatePrivate(dhp, param.getRandom());
    BigInteger y = helper.calculatePublic(dhp, x);
    return new AsymmetricCipherKeyPair(new ElGamalPublicKeyParameters(y, egp), new ElGamalPrivateKeyParameters(x, egp));
}
Also used : ElGamalParameters(com.github.zhenwei.core.crypto.params.ElGamalParameters) DHParameters(com.github.zhenwei.core.crypto.params.DHParameters) ElGamalPrivateKeyParameters(com.github.zhenwei.core.crypto.params.ElGamalPrivateKeyParameters) BigInteger(java.math.BigInteger) ElGamalPublicKeyParameters(com.github.zhenwei.core.crypto.params.ElGamalPublicKeyParameters) AsymmetricCipherKeyPair(com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair)

Example 17 with AsymmetricCipherKeyPair

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

the class GOST3410KeyPairGenerator method generateKeyPair.

public AsymmetricCipherKeyPair generateKeyPair() {
    BigInteger p, q, a, x, y;
    GOST3410Parameters GOST3410Params = param.getParameters();
    SecureRandom random = param.getRandom();
    q = GOST3410Params.getQ();
    p = GOST3410Params.getP();
    a = GOST3410Params.getA();
    int minWeight = 64;
    for (; ; ) {
        x = BigIntegers.createRandomBigInteger(256, random);
        if (x.signum() < 1 || x.compareTo(q) >= 0) {
            continue;
        }
        if (WNafUtil.getNafWeight(x) < minWeight) {
            continue;
        }
        break;
    }
    // 
    // calculate the public key.
    // 
    y = a.modPow(x, p);
    return new AsymmetricCipherKeyPair(new GOST3410PublicKeyParameters(y, GOST3410Params), new GOST3410PrivateKeyParameters(x, GOST3410Params));
}
Also used : GOST3410Parameters(com.github.zhenwei.core.crypto.params.GOST3410Parameters) GOST3410PrivateKeyParameters(com.github.zhenwei.core.crypto.params.GOST3410PrivateKeyParameters) BigInteger(java.math.BigInteger) SecureRandom(java.security.SecureRandom) GOST3410PublicKeyParameters(com.github.zhenwei.core.crypto.params.GOST3410PublicKeyParameters) AsymmetricCipherKeyPair(com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair)

Example 18 with AsymmetricCipherKeyPair

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

the class NTRUSigningKeyPairGenerator method generateKeyPair.

/**
 * Generates a new signature key pair. Starts <code>B+1</code> threads.
 *
 * @return a key pair
 */
public AsymmetricCipherKeyPair generateKeyPair() {
    NTRUSigningPublicKeyParameters pub = null;
    ExecutorService executor = Executors.newCachedThreadPool();
    List<Future<NTRUSigningPrivateKeyParameters.Basis>> bases = new ArrayList<Future<NTRUSigningPrivateKeyParameters.Basis>>();
    for (int k = params.B; k >= 0; k--) {
        bases.add(executor.submit(new BasisGenerationTask()));
    }
    executor.shutdown();
    List<NTRUSigningPrivateKeyParameters.Basis> basises = new ArrayList<NTRUSigningPrivateKeyParameters.Basis>();
    for (int k = params.B; k >= 0; k--) {
        Future<NTRUSigningPrivateKeyParameters.Basis> basis = bases.get(k);
        try {
            basises.add(basis.get());
            if (k == params.B) {
                pub = new NTRUSigningPublicKeyParameters(basis.get().h, params.getSigningParameters());
            }
        } catch (Exception e) {
            throw new IllegalStateException(e);
        }
    }
    NTRUSigningPrivateKeyParameters priv = new NTRUSigningPrivateKeyParameters(basises, pub);
    AsymmetricCipherKeyPair kp = new AsymmetricCipherKeyPair(pub, priv);
    return kp;
}
Also used : ArrayList(java.util.ArrayList) AsymmetricCipherKeyPair(com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future)

Example 19 with AsymmetricCipherKeyPair

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

the class XMSSMT method generateKeys.

/**
 * Generate a new XMSSMT private key / public key pair.
 */
public void generateKeys() {
    XMSSMTKeyPairGenerator kpGen = new XMSSMTKeyPairGenerator();
    kpGen.init(new XMSSMTKeyGenerationParameters(getParams(), prng));
    AsymmetricCipherKeyPair kp = kpGen.generateKeyPair();
    privateKey = (XMSSMTPrivateKeyParameters) kp.getPrivate();
    publicKey = (XMSSMTPublicKeyParameters) kp.getPublic();
    importState(privateKey, publicKey);
}
Also used : AsymmetricCipherKeyPair(com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair)

Example 20 with AsymmetricCipherKeyPair

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

the class XMSS method generateKeys.

// public void generateKeys()
// {
// /* generate private key */
// privateKey = generatePrivateKey(params, prng);
// XMSSNode root = privateKey.getBDSState().initialize(privateKey, (OTSHashAddress)new OTSHashAddress.Builder().build());
// 
// privateKey = new XMSSPrivateKeyParameters.Builder(params).withIndex(privateKey.getIndex())
// .withSecretKeySeed(privateKey.getSecretKeySeed()).withSecretKeyPRF(privateKey.getSecretKeyPRF())
// .withPublicSeed(privateKey.getPublicSeed()).withRoot(root.getValue())
// .withBDSState(privateKey.getBDSState()).build();
// publicKey = new XMSSPublicKeyParameters.Builder(params).withRoot(root.getValue())
// .withPublicSeed(getPublicSeed()).build();
// 
// }
// 
// /**
// * Generate an XMSS private key.
// *
// * @return XMSS private key.
// */
// private XMSSPrivateKeyParameters generatePrivateKey(XMSSParameters params, SecureRandom prng)
// {
// int n = params.getDigestSize();
// byte[] secretKeySeed = new byte[n];
// prng.nextBytes(secretKeySeed);
// byte[] secretKeyPRF = new byte[n];
// prng.nextBytes(secretKeyPRF);
// byte[] publicSeed = new byte[n];
// prng.nextBytes(publicSeed);
// 
// XMSS xmss = new XMSS(params, prng);
// 
// //        this.privateKey = xmss.privateKey;
// //        this.publicKey = xmss.publicKey;
// //        this.wotsPlus = xmss.wotsPlus;
// //        this.khf = xmss.khf;
// 
// XMSSPrivateKeyParameters privateKey = new XMSSPrivateKeyParameters.Builder(params).withSecretKeySeed(secretKeySeed)
// .withSecretKeyPRF(secretKeyPRF).withPublicSeed(publicSeed)
// .withBDSState(new BDS(xmss)).build();
// 
// return privateKey;
// }
/**
 * Generate a new XMSS private key / public key pair.
 */
public void generateKeys() {
    XMSSKeyPairGenerator kpGen = new XMSSKeyPairGenerator();
    kpGen.init(new XMSSKeyGenerationParameters(getParams(), prng));
    AsymmetricCipherKeyPair kp = kpGen.generateKeyPair();
    privateKey = (XMSSPrivateKeyParameters) kp.getPrivate();
    publicKey = (XMSSPublicKeyParameters) kp.getPublic();
    wotsPlus.importKeys(new byte[params.getTreeDigestSize()], this.privateKey.getPublicSeed());
}
Also used : AsymmetricCipherKeyPair(com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair)

Aggregations

AsymmetricCipherKeyPair (com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair)41 KeyPair (java.security.KeyPair)17 BigInteger (java.math.BigInteger)9 ECPrivateKeyParameters (com.github.zhenwei.core.crypto.params.ECPrivateKeyParameters)6 ECPublicKeyParameters (com.github.zhenwei.core.crypto.params.ECPublicKeyParameters)6 DHPublicKeyParameters (com.github.zhenwei.core.crypto.params.DHPublicKeyParameters)4 DHParameters (com.github.zhenwei.core.crypto.params.DHParameters)3 DHPrivateKeyParameters (com.github.zhenwei.core.crypto.params.DHPrivateKeyParameters)3 ECParameterSpec (com.github.zhenwei.provider.jce.spec.ECParameterSpec)3 SHA512Digest (com.github.zhenwei.core.crypto.digests.SHA512Digest)2 DHKeyGenerationParameters (com.github.zhenwei.core.crypto.params.DHKeyGenerationParameters)2 DSAPrivateKeyParameters (com.github.zhenwei.core.crypto.params.DSAPrivateKeyParameters)2 DSAPublicKeyParameters (com.github.zhenwei.core.crypto.params.DSAPublicKeyParameters)2 ElGamalParameters (com.github.zhenwei.core.crypto.params.ElGamalParameters)2 ElGamalPrivateKeyParameters (com.github.zhenwei.core.crypto.params.ElGamalPrivateKeyParameters)2 ElGamalPublicKeyParameters (com.github.zhenwei.core.crypto.params.ElGamalPublicKeyParameters)2 GOST3410PrivateKeyParameters (com.github.zhenwei.core.crypto.params.GOST3410PrivateKeyParameters)2 GOST3410PublicKeyParameters (com.github.zhenwei.core.crypto.params.GOST3410PublicKeyParameters)2 RSAKeyParameters (com.github.zhenwei.core.crypto.params.RSAKeyParameters)2 RSAPrivateCrtKeyParameters (com.github.zhenwei.core.crypto.params.RSAPrivateCrtKeyParameters)2