org.bouncycastle.pqc.crypto.qtesla.QTESLAKeyPairGenerator 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.
package org.bouncycastle.pqc.crypto.qtesla;
import java.security.SecureRandom;
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
import org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator;
import org.bouncycastle.crypto.KeyGenerationParameters;
/**
* Key-pair generator for qTESLA keys.
*/
public final class QTESLAKeyPairGenerator
implements AsymmetricCipherKeyPairGenerator
{
/**
* qTESLA Security Category
*/
private int securityCategory;
private SecureRandom secureRandom;
/**
* Initialize the generator with a security category and a source of randomness.
*
* @param param a {@link QTESLAKeyGenerationParameters} object.
*/
public void init(
KeyGenerationParameters param)
{
QTESLAKeyGenerationParameters parameters = (QTESLAKeyGenerationParameters)param;
this.secureRandom = parameters.getRandom();
this.securityCategory = parameters.getSecurityCategory();
}
/**
* Generate a key-pair.
*
* @return a matching key-pair consisting of (QTESLAPublicKeyParameters, QTESLAPrivateKeyParameters).
*/
public AsymmetricCipherKeyPair generateKeyPair()
{
byte[] privateKey = allocatePrivate(securityCategory);
byte[] publicKey = allocatePublic(securityCategory);
switch (securityCategory)
{
case QTESLASecurityCategory.PROVABLY_SECURE_I:
QTesla1p.generateKeyPair(publicKey, privateKey, secureRandom);
break;
case QTESLASecurityCategory.PROVABLY_SECURE_III:
QTesla3p.generateKeyPair(publicKey, privateKey, secureRandom);
break;
default:
throw new IllegalArgumentException("unknown security category: " + securityCategory);
}
return new AsymmetricCipherKeyPair(new QTESLAPublicKeyParameters(securityCategory, publicKey), new QTESLAPrivateKeyParameters(securityCategory, privateKey));
}
private byte[] allocatePrivate(int securityCategory)
{
return new byte[QTESLASecurityCategory.getPrivateSize(securityCategory)];
}
private byte[] allocatePublic(int securityCategory)
{
return new byte[QTESLASecurityCategory.getPublicSize(securityCategory)];
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy