Skip to content

Commit 65dcde7

Browse files
committed
added CMS lookups for composite signatures and digests.
added test for composite timestamping.
1 parent 400e147 commit 65dcde7

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed

pkix/src/main/java/org/bouncycastle/cms/DefaultCMSSignatureAlgorithmNameGenerator.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.bouncycastle.asn1.eac.EACObjectIdentifiers;
1111
import org.bouncycastle.asn1.edec.EdECObjectIdentifiers;
1212
import org.bouncycastle.asn1.gm.GMObjectIdentifiers;
13+
import org.bouncycastle.asn1.iana.IANAObjectIdentifiers;
1314
import org.bouncycastle.asn1.misc.MiscObjectIdentifiers;
1415
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers;
1516
import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers;
@@ -247,6 +248,25 @@ public DefaultCMSSignatureAlgorithmNameGenerator()
247248
addSimpleAlg(NISTObjectIdentifiers.id_hash_slh_dsa_shake_256s_with_shake256, "SLH-DSA-SHAKE-256S-WITH-SHAKE256");
248249
addSimpleAlg(NISTObjectIdentifiers.id_hash_slh_dsa_shake_256f_with_shake256, "SLH-DSA-SHAKE-256F-WITH-SHAKE256");
249250

251+
addSimpleAlg(IANAObjectIdentifiers.id_MLDSA44_RSA2048_PSS_SHA256, "MLDSA44-RSA2048-PSS-SHA256");
252+
addSimpleAlg(IANAObjectIdentifiers.id_MLDSA44_RSA2048_PKCS15_SHA256, "MLDSA44-RSA2048-PKCS15-SHA256");
253+
addSimpleAlg(IANAObjectIdentifiers.id_MLDSA44_Ed25519_SHA512, "MLDSA44-Ed25519-SHA512");
254+
addSimpleAlg(IANAObjectIdentifiers.id_MLDSA44_ECDSA_P256_SHA256, "MLDSA44-ECDSA-P256-SHA256");
255+
addSimpleAlg(IANAObjectIdentifiers.id_MLDSA65_RSA3072_PSS_SHA512, "MLDSA65-RSA3072-PSS-SHA512");
256+
addSimpleAlg(IANAObjectIdentifiers.id_MLDSA65_RSA3072_PKCS15_SHA512, "MLDSA65-RSA3072-PKCS15-SHA512");
257+
addSimpleAlg(IANAObjectIdentifiers.id_MLDSA65_RSA4096_PSS_SHA512, "MLDSA65-RSA4096-PSS-SHA512");
258+
addSimpleAlg(IANAObjectIdentifiers.id_MLDSA65_RSA4096_PKCS15_SHA512, "MLDSA65-RSA4096-PKCS15-SHA512");
259+
addSimpleAlg(IANAObjectIdentifiers.id_MLDSA65_ECDSA_P256_SHA512, "MLDSA65-ECDSA-P256-SHA512");
260+
addSimpleAlg(IANAObjectIdentifiers.id_MLDSA65_ECDSA_P384_SHA512, "MLDSA65-ECDSA-P384-SHA512");
261+
addSimpleAlg(IANAObjectIdentifiers.id_MLDSA65_ECDSA_brainpoolP256r1_SHA512, "MLDSA65-ECDSA-brainpoolP256r1-SHA512");
262+
addSimpleAlg(IANAObjectIdentifiers.id_MLDSA65_Ed25519_SHA512, "MLDSA65-Ed25519-SHA512");
263+
addSimpleAlg(IANAObjectIdentifiers.id_MLDSA87_ECDSA_P384_SHA512, "MLDSA87-ECDSA-P384-SHA512");
264+
addSimpleAlg(IANAObjectIdentifiers.id_MLDSA87_ECDSA_brainpoolP384r1_SHA512, "MLDSA87-ECDSA-brainpoolP384r1-SHA512");
265+
addSimpleAlg(IANAObjectIdentifiers.id_MLDSA87_Ed448_SHAKE256, "MLDSA87-Ed448-SHAKE256");
266+
addSimpleAlg(IANAObjectIdentifiers.id_MLDSA87_RSA3072_PSS_SHA512, "MLDSA87-RSA3072-PSS-SHA512");
267+
addSimpleAlg(IANAObjectIdentifiers.id_MLDSA87_RSA4096_PSS_SHA512, "MLDSA87-RSA4096-PSS-SHA512");
268+
addSimpleAlg(IANAObjectIdentifiers.id_MLDSA87_ECDSA_P521_SHA512, "MLDSA87-ECDSA-P521-SHA512");
269+
250270
addSimpleAlg(BCObjectIdentifiers.picnic_signature, "Picnic");
251271
}
252272

pkix/src/main/java/org/bouncycastle/operator/DefaultDigestAlgorithmIdentifierFinder.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.bouncycastle.asn1.eac.EACObjectIdentifiers;
1515
import org.bouncycastle.asn1.edec.EdECObjectIdentifiers;
1616
import org.bouncycastle.asn1.gm.GMObjectIdentifiers;
17+
import org.bouncycastle.asn1.iana.IANAObjectIdentifiers;
1718
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers;
1819
import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers;
1920
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
@@ -168,6 +169,25 @@ public class DefaultDigestAlgorithmIdentifierFinder
168169
digestOids.put(NISTObjectIdentifiers.id_hash_ml_dsa_65_with_sha512, NISTObjectIdentifiers.id_sha512);
169170
digestOids.put(NISTObjectIdentifiers.id_hash_ml_dsa_87_with_sha512, NISTObjectIdentifiers.id_sha512);
170171

172+
digestOids.put(IANAObjectIdentifiers.id_MLDSA44_RSA2048_PSS_SHA256, NISTObjectIdentifiers.id_sha512);
173+
digestOids.put(IANAObjectIdentifiers.id_MLDSA44_RSA2048_PKCS15_SHA256, NISTObjectIdentifiers.id_sha512);
174+
digestOids.put(IANAObjectIdentifiers.id_MLDSA44_Ed25519_SHA512, NISTObjectIdentifiers.id_sha512);
175+
digestOids.put(IANAObjectIdentifiers.id_MLDSA44_ECDSA_P256_SHA256, NISTObjectIdentifiers.id_sha512);
176+
digestOids.put(IANAObjectIdentifiers.id_MLDSA65_RSA3072_PSS_SHA512, NISTObjectIdentifiers.id_sha512);
177+
digestOids.put(IANAObjectIdentifiers.id_MLDSA65_RSA3072_PKCS15_SHA512, NISTObjectIdentifiers.id_sha512);
178+
digestOids.put(IANAObjectIdentifiers.id_MLDSA65_RSA4096_PSS_SHA512, NISTObjectIdentifiers.id_sha512);
179+
digestOids.put(IANAObjectIdentifiers.id_MLDSA65_RSA4096_PKCS15_SHA512, NISTObjectIdentifiers.id_sha512);
180+
digestOids.put(IANAObjectIdentifiers.id_MLDSA65_ECDSA_P256_SHA512, NISTObjectIdentifiers.id_sha512);
181+
digestOids.put(IANAObjectIdentifiers.id_MLDSA65_ECDSA_P384_SHA512, NISTObjectIdentifiers.id_sha512);
182+
digestOids.put(IANAObjectIdentifiers.id_MLDSA65_ECDSA_brainpoolP256r1_SHA512, NISTObjectIdentifiers.id_sha512);
183+
digestOids.put(IANAObjectIdentifiers.id_MLDSA65_Ed25519_SHA512, NISTObjectIdentifiers.id_sha512);
184+
digestOids.put(IANAObjectIdentifiers.id_MLDSA87_ECDSA_P384_SHA512, NISTObjectIdentifiers.id_sha512);
185+
digestOids.put(IANAObjectIdentifiers.id_MLDSA87_ECDSA_brainpoolP384r1_SHA512, NISTObjectIdentifiers.id_sha512);
186+
digestOids.put(IANAObjectIdentifiers.id_MLDSA87_Ed448_SHAKE256, NISTObjectIdentifiers.id_sha512);
187+
digestOids.put(IANAObjectIdentifiers.id_MLDSA87_RSA4096_PSS_SHA512, NISTObjectIdentifiers.id_sha512);
188+
digestOids.put(IANAObjectIdentifiers.id_MLDSA87_ECDSA_P521_SHA512, NISTObjectIdentifiers.id_sha512);
189+
digestOids.put(IANAObjectIdentifiers.id_MLDSA87_RSA3072_PSS_SHA512, NISTObjectIdentifiers.id_sha512);
190+
171191
digestOids.put(BCObjectIdentifiers.falcon, NISTObjectIdentifiers.id_shake256);
172192
digestOids.put(BCObjectIdentifiers.falcon_512, NISTObjectIdentifiers.id_shake256);
173193
digestOids.put(BCObjectIdentifiers.falcon_1024, NISTObjectIdentifiers.id_shake256);

pkix/src/test/java/org/bouncycastle/tsp/test/PQCTSPTest.java

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.security.Security;
99
import java.security.cert.X509Certificate;
1010
import java.util.Date;
11+
import java.util.Iterator;
1112

1213
import junit.framework.TestCase;
1314
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
@@ -23,6 +24,7 @@
2324
import org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder;
2425
import org.bouncycastle.cms.jcajce.JcaSignerInfoGeneratorBuilder;
2526
import org.bouncycastle.cms.jcajce.JcaSignerInfoVerifierBuilder;
27+
import org.bouncycastle.jcajce.provider.asymmetric.compositesignatures.CompositeIndex;
2628
import org.bouncycastle.jce.provider.BouncyCastleProvider;
2729
import org.bouncycastle.operator.ContentSigner;
2830
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
@@ -344,4 +346,88 @@ public void testMLDSA()
344346

345347
assertNotNull("no signingCertificate attribute found", table.get(PKCSObjectIdentifiers.id_aa_signingCertificate));
346348
}
349+
350+
public void testComposite()
351+
throws Exception
352+
{
353+
for (Iterator it = CompositeIndex.getSupportedIdentifiers().iterator(); it.hasNext(); )
354+
{
355+
String name = CompositeIndex.getAlgorithmName((ASN1ObjectIdentifier)it.next());
356+
doTestComposite(name);
357+
}
358+
}
359+
360+
private void doTestComposite(String algorithmName)
361+
throws Exception
362+
{
363+
//
364+
// set up the keys
365+
//
366+
PrivateKey privKey;
367+
PublicKey pubKey;
368+
369+
try
370+
{
371+
KeyPairGenerator g = KeyPairGenerator.getInstance(algorithmName, BC);
372+
373+
KeyPair p = g.generateKeyPair();
374+
375+
privKey = p.getPrivate();
376+
pubKey = p.getPublic();
377+
}
378+
catch (Exception e)
379+
{
380+
fail("error setting up keys - " + e);
381+
return;
382+
}
383+
384+
//
385+
// extensions
386+
//
387+
388+
//
389+
// create the certificate - version 1
390+
//
391+
392+
ContentSigner sigGen = new JcaContentSignerBuilder(algorithmName)
393+
.setProvider(BC).build(privKey);
394+
JcaX509v3CertificateBuilder certGen = new JcaX509v3CertificateBuilder(
395+
new X500Name("CN=Test"),
396+
BigInteger.valueOf(1),
397+
new Date(System.currentTimeMillis() - 50000),
398+
new Date(System.currentTimeMillis() + 50000),
399+
new X500Name("CN=Test"),
400+
pubKey);
401+
402+
certGen.addExtension(Extension.extendedKeyUsage, true, new ExtendedKeyUsage(KeyPurposeId.id_kp_timeStamping));
403+
404+
X509Certificate cert = new JcaX509CertificateConverter()
405+
.setProvider("BC").getCertificate(certGen.build(sigGen));
406+
407+
ContentSigner signer = new JcaContentSignerBuilder(algorithmName).setProvider(BC).build(privKey);
408+
409+
TimeStampTokenGenerator tsTokenGen = new TimeStampTokenGenerator(
410+
new JcaSignerInfoGeneratorBuilder(new JcaDigestCalculatorProviderBuilder().build())
411+
.build(signer, cert), new SHA1DigestCalculator(), new ASN1ObjectIdentifier("1.2"));
412+
413+
// tsTokenGen.addCertificates(certs);
414+
415+
TimeStampRequestGenerator reqGen = new TimeStampRequestGenerator();
416+
TimeStampRequest request = reqGen.generate(TSPAlgorithms.SHA3_256, new byte[32], BigInteger.valueOf(100));
417+
418+
TimeStampResponseGenerator tsRespGen = new TimeStampResponseGenerator(tsTokenGen, TSPAlgorithms.ALLOWED);
419+
420+
TimeStampResponse tsResp = tsRespGen.generate(request, new BigInteger("23"), new Date());
421+
422+
tsResp = new TimeStampResponse(tsResp.getEncoded());
423+
424+
TimeStampToken tsToken = tsResp.getTimeStampToken();
425+
426+
tsToken.validate(new JcaSignerInfoVerifierBuilder(new JcaDigestCalculatorProviderBuilder().build())
427+
.setProvider(BC).build(cert));
428+
429+
AttributeTable table = tsToken.getSignedAttributes();
430+
431+
assertNotNull("no signingCertificate attribute found", table.get(PKCSObjectIdentifiers.id_aa_signingCertificate));
432+
}
347433
}

0 commit comments

Comments
 (0)