Added qTESLA certificate test.
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
import org.bouncycastle.operator.jcajce.JcaContentVerifierProviderBuilder;
import org.bouncycastle.pqc.jcajce.provider.BouncyCastlePQCProvider;
+import org.bouncycastle.pqc.jcajce.spec.QTESLAParameterSpec;
import org.bouncycastle.pqc.jcajce.spec.SPHINCS256KeyGenParameterSpec;
import org.bouncycastle.pqc.jcajce.spec.XMSSMTParameterSpec;
import org.bouncycastle.pqc.jcajce.spec.XMSSParameterSpec;
@@ -3013,7 +3014,7 @@ public void checkCreation8()
}
/*
- * we generate a self signed certificate for the sake of testing - XMSS
+ * we generate a self signed certificate for the sake of testing - XMSS^MT
*/
public void checkCreation9()
throws Exception
@@ -3063,6 +3064,57 @@ public void checkCreation9()
//System.out.println(cert);
}
+ /*
+ * we generate a self signed certificate for the sake of testing - qTESLA
+ */
+ public void checkCreationQTESLA()
+ throws Exception
+ {
+ //
+ // set up the keys
+ //
+ KeyPairGenerator kpg = KeyPairGenerator.getInstance("qTESLA", "BCPQC");
+
+ kpg.initialize(new QTESLAParameterSpec(QTESLAParameterSpec.HEURISTIC_I), new SecureRandom());
+
+ KeyPair kp = kpg.generateKeyPair();
+
+ PrivateKey privKey = kp.getPrivate();
+ PublicKey pubKey = kp.getPublic();
+
+ //
+ // distinguished name table.
+ //
+ X500NameBuilder builder = createStdBuilder();
+
+ //
+ // create the certificate - version 3
+ //
+ ContentSigner sigGen = new JcaContentSignerBuilder(pubKey.getAlgorithm()).setProvider("BCPQC").build(privKey);
+ X509v3CertificateBuilder certGen = new JcaX509v3CertificateBuilder(builder.build(), BigInteger.valueOf(1), new Date(System.currentTimeMillis() - 50000), new Date(System.currentTimeMillis() + 50000), builder.build(), pubKey);
+
+ X509Certificate cert = new JcaX509CertificateConverter().setProvider(BC).getCertificate(certGen.build(sigGen));
+
+ cert.checkValidity(new Date());
+
+ //
+ // check verifies in general
+ //
+ cert.verify(pubKey);
+
+ //
+ // check verifies with contained key
+ //
+ cert.verify(cert.getPublicKey());
+
+ ByteArrayInputStream bIn = new ByteArrayInputStream(cert.getEncoded());
+ CertificateFactory fact = CertificateFactory.getInstance("X.509", BC);
+
+ cert = (X509Certificate)fact.generateCertificate(bIn);
+
+ //System.out.println(cert);
+ }
+
/*
* we generate a self signed certificate across the range of DSA algorithms
*/
@@ -3933,6 +3985,11 @@ private void doSerialize(Serializable encodable)
public void performTest()
throws Exception
{
+ if (Security.getProvider("BCPQC") == null)
+ {
+ Security.addProvider(new BouncyCastlePQCProvider());
+ }
+
testDirect();
testIndirect();
testIndirect2();
@@ -3977,6 +4034,7 @@ public void performTest()
checkCreation8();
checkCreation9();
+ checkCreationQTESLA();
checkCreationDSA();
checkCreationECDSA();
checkCreationRSA();
