org.bouncycastle.pqc.crypto.mlkem.MLKEMKeyPairGenerator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcprov-debug-jdk15to18 Show documentation
Show all versions of bcprov-debug-jdk15to18 Show documentation
The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.5 to JDK 1.8.
The newest version!
package org.bouncycastle.pqc.crypto.mlkem;
import java.security.SecureRandom;
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
import org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator;
import org.bouncycastle.crypto.KeyGenerationParameters;
public class MLKEMKeyPairGenerator
implements AsymmetricCipherKeyPairGenerator
{
private MLKEMParameters mlkemParams;
private SecureRandom random;
private void initialize(
KeyGenerationParameters param)
{
this.mlkemParams = ((MLKEMKeyGenerationParameters)param).getParameters();
this.random = param.getRandom();
}
private AsymmetricCipherKeyPair genKeyPair()
{
MLKEMEngine engine = mlkemParams.getEngine();
engine.init(random);
byte[][] keyPair = engine.generateKemKeyPair();
MLKEMPublicKeyParameters pubKey = new MLKEMPublicKeyParameters(mlkemParams, keyPair[0], keyPair[1]);
MLKEMPrivateKeyParameters privKey = new MLKEMPrivateKeyParameters(mlkemParams, keyPair[2], keyPair[3], keyPair[4], keyPair[0], keyPair[1], keyPair[5]);
return new AsymmetricCipherKeyPair(pubKey, privKey);
}
public void init(KeyGenerationParameters param)
{
this.initialize(param);
}
public AsymmetricCipherKeyPair generateKeyPair()
{
return genKeyPair();
}
public AsymmetricCipherKeyPair internalGenerateKeyPair(byte[] d, byte[] z)
{
byte[][] keyPair = mlkemParams.getEngine().generateKemKeyPairInternal(d, z);
MLKEMPublicKeyParameters pubKey = new MLKEMPublicKeyParameters(mlkemParams, keyPair[0], keyPair[1]);
MLKEMPrivateKeyParameters privKey = new MLKEMPrivateKeyParameters(mlkemParams, keyPair[2], keyPair[3], keyPair[4], keyPair[0], keyPair[1]);
return new AsymmetricCipherKeyPair(pubKey, privKey);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy