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));
}
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));
}
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;
}
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);
}
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());
}
Aggregations