use of com.github.zhenwei.core.crypto.params.DHPrivateKeyParameters in project LinLong-Java by zhenwei1108.
the class KeyAgreementSpi method generatePrivateKeyParameter.
private DHPrivateKeyParameters generatePrivateKeyParameter(PrivateKey privKey) throws InvalidKeyException {
if (privKey instanceof DHPrivateKey) {
if (privKey instanceof BCDHPrivateKey) {
return ((BCDHPrivateKey) privKey).engineGetKeyParameters();
} else {
DHPrivateKey pub = (DHPrivateKey) privKey;
DHParameterSpec params = pub.getParams();
return new DHPrivateKeyParameters(pub.getX(), new DHParameters(params.getP(), params.getG(), null, params.getL()));
}
} else {
throw new InvalidKeyException("private key not a DHPrivateKey");
}
}
use of com.github.zhenwei.core.crypto.params.DHPrivateKeyParameters in project LinLong-Java by zhenwei1108.
the class KeyPairGeneratorSpi method generateKeyPair.
public KeyPair generateKeyPair() {
if (!initialised) {
Integer paramStrength = Integers.valueOf(strength);
if (params.containsKey(paramStrength)) {
param = (DHKeyGenerationParameters) params.get(paramStrength);
} else {
DHParameterSpec dhParams = WeGooProvider.CONFIGURATION.getDHDefaultParameters(strength);
if (dhParams != null) {
param = convertParams(random, dhParams);
} else {
synchronized (lock) {
// our key size.
if (params.containsKey(paramStrength)) {
param = (DHKeyGenerationParameters) params.get(paramStrength);
} else {
DHParametersGenerator pGen = new DHParametersGenerator();
pGen.init(strength, PrimeCertaintyCalculator.getDefaultCertainty(strength), random);
param = new DHKeyGenerationParameters(random, pGen.generateParameters());
params.put(paramStrength, param);
}
}
}
}
engine.init(param);
initialised = true;
}
AsymmetricCipherKeyPair pair = engine.generateKeyPair();
DHPublicKeyParameters pub = (DHPublicKeyParameters) pair.getPublic();
DHPrivateKeyParameters priv = (DHPrivateKeyParameters) pair.getPrivate();
return new KeyPair(new BCDHPublicKey(pub), new BCDHPrivateKey(priv));
}
use of com.github.zhenwei.core.crypto.params.DHPrivateKeyParameters in project LinLong-Java by zhenwei1108.
the class MQVBasicAgreement method calculateAgreement.
public BigInteger calculateAgreement(CipherParameters pubKey) {
DHMQVPublicParameters pubParams = (DHMQVPublicParameters) pubKey;
DHPrivateKeyParameters staticPrivateKey = privParams.getStaticPrivateKey();
if (!privParams.getStaticPrivateKey().getParameters().equals(pubParams.getStaticPublicKey().getParameters())) {
throw new IllegalStateException("MQV public key components have wrong domain parameters");
}
if (privParams.getStaticPrivateKey().getParameters().getQ() == null) {
throw new IllegalStateException("MQV key domain parameters do not have Q set");
}
BigInteger agreement = calculateDHMQVAgreement(staticPrivateKey.getParameters(), staticPrivateKey, pubParams.getStaticPublicKey(), privParams.getEphemeralPrivateKey(), privParams.getEphemeralPublicKey(), pubParams.getEphemeralPublicKey());
if (agreement.equals(ONE)) {
throw new IllegalStateException("1 is not a valid agreement value for MQV");
}
return agreement;
}
use of com.github.zhenwei.core.crypto.params.DHPrivateKeyParameters in project LinLong-Java by zhenwei1108.
the class DHKeyPairGenerator method generateKeyPair.
public AsymmetricCipherKeyPair generateKeyPair() {
DHKeyGeneratorHelper helper = DHKeyGeneratorHelper.INSTANCE;
DHParameters dhp = param.getParameters();
BigInteger x = helper.calculatePrivate(dhp, param.getRandom());
BigInteger y = helper.calculatePublic(dhp, x);
return new AsymmetricCipherKeyPair(new DHPublicKeyParameters(y, dhp), new DHPrivateKeyParameters(x, dhp));
}
use of com.github.zhenwei.core.crypto.params.DHPrivateKeyParameters in project LinLong-Java by zhenwei1108.
the class DHBasicKeyPairGenerator method generateKeyPair.
public AsymmetricCipherKeyPair generateKeyPair() {
DHKeyGeneratorHelper helper = DHKeyGeneratorHelper.INSTANCE;
DHParameters dhp = param.getParameters();
BigInteger x = helper.calculatePrivate(dhp, param.getRandom());
BigInteger y = helper.calculatePublic(dhp, x);
return new AsymmetricCipherKeyPair(new DHPublicKeyParameters(y, dhp), new DHPrivateKeyParameters(x, dhp));
}
Aggregations