2
2
3
3
import java .io .ByteArrayInputStream ;
4
4
import java .io .ByteArrayOutputStream ;
5
- import java .io .InputStreamReader ;
6
5
import java .io .IOException ;
6
+ import java .io .InputStreamReader ;
7
7
import java .io .ObjectInputStream ;
8
8
import java .io .ObjectOutputStream ;
9
9
import java .io .Serializable ;
137
137
import org .bouncycastle .pqc .jcajce .spec .SPHINCSPlusParameterSpec ;
138
138
import org .bouncycastle .pqc .jcajce .spec .XMSSMTParameterSpec ;
139
139
import org .bouncycastle .pqc .jcajce .spec .XMSSParameterSpec ;
140
+ import org .bouncycastle .test .TestResourceFinder ;
140
141
import org .bouncycastle .util .Encodable ;
141
142
import org .bouncycastle .util .Strings ;
142
143
import org .bouncycastle .util .encoders .Base64 ;
@@ -2965,7 +2966,7 @@ public void checkCRLCompositeCreation()
2965
2966
{
2966
2967
isTrue (e .getMessage ().equals ("no matching key found" ));
2967
2968
}
2968
-
2969
+
2969
2970
// single key test
2970
2971
crl .verify (ecPub , BC );
2971
2972
@@ -4034,7 +4035,7 @@ public void checkCreationECDSA()
4034
4035
}
4035
4036
4036
4037
public void checkCreationPicnic ()
4037
- throws Exception
4038
+ throws Exception
4038
4039
{
4039
4040
if (Security .getProvider ("BCPQC" ) == null )
4040
4041
{
@@ -4060,12 +4061,12 @@ public void checkCreationPicnic()
4060
4061
//
4061
4062
ContentSigner sigGen = new JcaContentSignerBuilder ("PICNIC" ).setProvider ("BCPQC" ).build (privKey );
4062
4063
X509v3CertificateBuilder certGen = new JcaX509v3CertificateBuilder (builder .build (), BigInteger .valueOf (1 ), new Date (System .currentTimeMillis () - 50000 ), new Date (System .currentTimeMillis () + 50000 ), builder .build (), pubKey )
4063
- .addExtension (new ASN1ObjectIdentifier ("2.5.29.15" ), true ,
4064
- new X509KeyUsage (X509KeyUsage .encipherOnly ))
4065
- .addExtension (new ASN1ObjectIdentifier ("2.5.29.37" ), true ,
4066
- new DERSequence (KeyPurposeId .anyExtendedKeyUsage ))
4067
- .addExtension (new ASN1ObjectIdentifier ("2.5.29.17" ), true ,
4068
- new GeneralNames (
new GeneralName (
GeneralName .
rfc822Name ,
"[email protected] " )));
4064
+ .addExtension (new ASN1ObjectIdentifier ("2.5.29.15" ), true ,
4065
+ new X509KeyUsage (X509KeyUsage .encipherOnly ))
4066
+ .addExtension (new ASN1ObjectIdentifier ("2.5.29.37" ), true ,
4067
+ new DERSequence (KeyPurposeId .anyExtendedKeyUsage ))
4068
+ .addExtension (new ASN1ObjectIdentifier ("2.5.29.17" ), true ,
4069
+ new GeneralNames (
new GeneralName (
GeneralName .
rfc822Name ,
"[email protected] " )));
4069
4070
4070
4071
X509Certificate baseCert = new JcaX509CertificateConverter ().setProvider (BC ).getCertificate (certGen .build (sigGen ));
4071
4072
@@ -4077,8 +4078,8 @@ public void checkCreationPicnic()
4077
4078
//
4078
4079
4079
4080
certGen = new JcaX509v3CertificateBuilder (builder .build (), BigInteger .valueOf (1 ), new Date (System .currentTimeMillis () - 50000 ), new Date (System .currentTimeMillis () + 50000 ), builder .build (), pubKey )
4080
- .copyAndAddExtension (new ASN1ObjectIdentifier ("2.5.29.15" ), true , baseCert )
4081
- .copyAndAddExtension (new ASN1ObjectIdentifier ("2.5.29.37" ), false , baseCert );
4081
+ .copyAndAddExtension (new ASN1ObjectIdentifier ("2.5.29.15" ), true , baseCert )
4082
+ .copyAndAddExtension (new ASN1ObjectIdentifier ("2.5.29.37" ), false , baseCert );
4082
4083
4083
4084
X509Certificate cert = new JcaX509CertificateConverter ().setProvider (BC ).getCertificate (certGen .build (sigGen ));
4084
4085
@@ -4122,8 +4123,8 @@ public void checkCreationPicnic()
4122
4123
KeyPair nhKp = kpGen .generateKeyPair ();
4123
4124
4124
4125
certGen = new JcaX509v3CertificateBuilder (builder .build (), BigInteger .valueOf (1 ), new Date (System .currentTimeMillis () - 50000 ), new Date (System .currentTimeMillis () + 50000 ), builder .build (), nhKp .getPublic ())
4125
- .copyAndAddExtension (new ASN1ObjectIdentifier ("2.5.29.15" ), true , baseCert )
4126
- .copyAndAddExtension (new ASN1ObjectIdentifier ("2.5.29.37" ), false , baseCert );
4126
+ .copyAndAddExtension (new ASN1ObjectIdentifier ("2.5.29.15" ), true , baseCert )
4127
+ .copyAndAddExtension (new ASN1ObjectIdentifier ("2.5.29.37" ), false , baseCert );
4127
4128
4128
4129
cert = new JcaX509CertificateConverter ().setProvider (BC ).getCertificate (certGen .build (sigGen ));
4129
4130
@@ -4620,7 +4621,7 @@ public void checkCreationComposite()
4620
4621
if (System .getProperty ("java.version" ).indexOf ("1.5." ) < 0 )
4621
4622
{
4622
4623
cert .verify (ecPub , new BouncyCastleProvider ()); // ec key only
4623
-
4624
+
4624
4625
cert .verify (lmsPub , new BouncyCastlePQCProvider ()); // lms key only
4625
4626
}
4626
4627
@@ -5425,23 +5426,23 @@ private void checkSerialisation()
5425
5426
5426
5427
// TESTS REGARDING COMPOSITES https://www.ietf.org/archive/id/draft-ounsworth-pq-composite-sigs-13.html
5427
5428
private static String [] compositeSignaturesOIDs = {
5428
- "2.16.840.1.114027.80.8.1.1" , //id-MLDSA44-RSA2048-PSS-SHA256
5429
- "2.16.840.1.114027.80.8.1.2" , //id-MLDSA44-RSA2048-PKCS15-SHA256
5430
- "2.16.840.1.114027.80.8.1.3" , //id-MLDSA44-Ed25519-SHA512
5431
- "2.16.840.1.114027.80.8.1.4" , //id-MLDSA44-ECDSA-P256-SHA256
5432
- "2.16.840.1.114027.80.8.1.5" , //id-MLDSA44-ECDSA-brainpoolP256r1-SHA256
5433
- "2.16.840.1.114027.80.8.1.6" , //id-MLDSA65-RSA3072-PSS-SHA512
5434
- "2.16.840.1.114027.80.8.1.7" , //id-MLDSA65-RSA3072-PKCS15-SHA512
5435
- "2.16.840.1.114027.80.8.1.8" , //id-MLDSA65-ECDSA-P256-SHA512
5436
- "2.16.840.1.114027.80.8.1.9" , //id-MLDSA65-ECDSA-brainpoolP256r1-SHA512
5437
- "2.16.840.1.114027.80.8.1.10" , //id-MLDSA65-Ed25519-SHA512
5438
- "2.16.840.1.114027.80.8.1.11" , //id-MLDSA87-ECDSA-P384-SHA512
5439
- "2.16.840.1.114027.80.8.1.12" , //id-MLDSA87-ECDSA-brainpoolP384r1-SHA512
5440
- "2.16.840.1.114027.80.8.1.13" , //id-MLDSA87-Ed448-SHA512
5441
- // Falcon composites below were excluded from the draft. See MiscObjectIdentifiers for details.
5442
- "2.16.840.1.114027.80.8.1.14" , //id-Falcon512-ECDSA-P256-SHA256
5443
- "2.16.840.1.114027.80.8.1.15" , //id-Falcon512-ECDSA-brainpoolP256r1-SHA256
5444
- "2.16.840.1.114027.80.8.1.16" , //id-Falcon512-Ed25519-SHA512
5429
+ "2.16.840.1.114027.80.8.1.1" , //id-MLDSA44-RSA2048-PSS-SHA256
5430
+ "2.16.840.1.114027.80.8.1.2" , //id-MLDSA44-RSA2048-PKCS15-SHA256
5431
+ "2.16.840.1.114027.80.8.1.3" , //id-MLDSA44-Ed25519-SHA512
5432
+ "2.16.840.1.114027.80.8.1.4" , //id-MLDSA44-ECDSA-P256-SHA256
5433
+ "2.16.840.1.114027.80.8.1.5" , //id-MLDSA44-ECDSA-brainpoolP256r1-SHA256
5434
+ "2.16.840.1.114027.80.8.1.6" , //id-MLDSA65-RSA3072-PSS-SHA512
5435
+ "2.16.840.1.114027.80.8.1.7" , //id-MLDSA65-RSA3072-PKCS15-SHA512
5436
+ "2.16.840.1.114027.80.8.1.8" , //id-MLDSA65-ECDSA-P256-SHA512
5437
+ "2.16.840.1.114027.80.8.1.9" , //id-MLDSA65-ECDSA-brainpoolP256r1-SHA512
5438
+ "2.16.840.1.114027.80.8.1.10" , //id-MLDSA65-Ed25519-SHA512
5439
+ "2.16.840.1.114027.80.8.1.11" , //id-MLDSA87-ECDSA-P384-SHA512
5440
+ "2.16.840.1.114027.80.8.1.12" , //id-MLDSA87-ECDSA-brainpoolP384r1-SHA512
5441
+ "2.16.840.1.114027.80.8.1.13" , //id-MLDSA87-Ed448-SHA512
5442
+ // Falcon composites below were excluded from the draft. See MiscObjectIdentifiers for details.
5443
+ "2.16.840.1.114027.80.8.1.14" , //id-Falcon512-ECDSA-P256-SHA256
5444
+ "2.16.840.1.114027.80.8.1.15" , //id-Falcon512-ECDSA-brainpoolP256r1-SHA256
5445
+ "2.16.840.1.114027.80.8.1.16" , //id-Falcon512-Ed25519-SHA512
5445
5446
};
5446
5447
5447
5448
private void checkCompositeSignatureCertificateCreation ()
@@ -5465,7 +5466,7 @@ private void checkCompositeSignatureCertificateCreation()
5465
5466
X509Certificate cert = new JcaX509CertificateConverter ().setProvider ("BC" ).getCertificate (certHolder );
5466
5467
5467
5468
isEquals (oid , cert .getSigAlgOID ());
5468
- CompositePublicKey compositePublicKey = (CompositePublicKey ) cert .getPublicKey ();
5469
+ CompositePublicKey compositePublicKey = (CompositePublicKey )cert .getPublicKey ();
5469
5470
isEquals (CompositeSignaturesConstants .ASN1IdentifierAlgorithmNameMap .get (new ASN1ObjectIdentifier (oid )), compositePublicKey .getAlgorithm ());
5470
5471
5471
5472
isEquals (subjectName , cert .getSubjectX500Principal ().getName ());
@@ -5475,7 +5476,7 @@ private void checkCompositeSignatureCertificateCreation()
5475
5476
}
5476
5477
}
5477
5478
catch (NoSuchAlgorithmException | NoSuchProviderException | CertificateException | OperatorCreationException |
5478
- SignatureException | InvalidKeyException | TestFailedException e )
5479
+ SignatureException | InvalidKeyException | TestFailedException e )
5479
5480
{
5480
5481
fail ("checkCompositeSignatureCertificateCreation failed: " + e .getMessage ());
5481
5482
}
@@ -5486,8 +5487,8 @@ private void checkParseCompositePublicKey()
5486
5487
try
5487
5488
{
5488
5489
//compositePublicKeyExampleRFC.pem contains the sample public key from https://www.ietf.org/archive/id/draft-ounsworth-pq-composite-sigs-13.html
5489
- PEMParser pemParser = new PEMParser (new InputStreamReader (this . getClass (). getResourceAsStream ( "compositePublicKeyExampleRFC.pem" )));
5490
- SubjectPublicKeyInfo subjectPublicKeyInfo = (SubjectPublicKeyInfo ) pemParser .readObject ();
5490
+ PEMParser pemParser = new PEMParser (new InputStreamReader (TestResourceFinder . findTestResource ( "pqc/composite" , "compositePublicKeyExampleRFC.pem" )));
5491
+ SubjectPublicKeyInfo subjectPublicKeyInfo = (SubjectPublicKeyInfo )pemParser .readObject ();
5491
5492
isEquals (subjectPublicKeyInfo .getAlgorithm ().getAlgorithm (), MiscObjectIdentifiers .id_MLDSA44_ECDSA_P256_SHA256 );
5492
5493
5493
5494
CompositePublicKey compositePublicKey = new CompositePublicKey (subjectPublicKeyInfo );
@@ -5508,8 +5509,8 @@ private void checkParseCompositePrivateKey()
5508
5509
//compositePrivateKeyExample.pem does NOT contain the sample private key from https://www.ietf.org/archive/id/draft-ounsworth-pq-composite-sigs-13.html
5509
5510
//because the at this moment, the Dilithium private key formats don't match.
5510
5511
//this sample was generated from this BC implementation
5511
- PEMParser pemParser = new PEMParser (new InputStreamReader (this . getClass (). getResourceAsStream ( "compositePrivateKeyExample.pem" )));
5512
- PrivateKeyInfo privateKeyInfo = (PrivateKeyInfo ) pemParser .readObject ();
5512
+ PEMParser pemParser = new PEMParser (new InputStreamReader (TestResourceFinder . findTestResource ( "pqc/composite" , "compositePrivateKeyExample.pem" )));
5513
+ PrivateKeyInfo privateKeyInfo = (PrivateKeyInfo )pemParser .readObject ();
5513
5514
5514
5515
isEquals (privateKeyInfo .getPrivateKeyAlgorithm ().getAlgorithm (), MiscObjectIdentifiers .id_MLDSA44_ECDSA_P256_SHA256 );
5515
5516
@@ -5529,14 +5530,14 @@ private void checkParseAndVerifyCompositeCertificate()
5529
5530
try
5530
5531
{
5531
5532
//compositeCertificateExampleRFC.pem contains the sample certificate from https://www.ietf.org/archive/id/draft-ounsworth-pq-composite-sigs-13.html
5532
- PEMParser pemParser = new PEMParser (new InputStreamReader (this . getClass (). getResourceAsStream ( "compositeCertificateExampleRFC.pem" )));
5533
- X509CertificateHolder certificateHolder = (X509CertificateHolder ) pemParser .readObject ();
5533
+ PEMParser pemParser = new PEMParser (new InputStreamReader (TestResourceFinder . findTestResource ( "pqc/composite" , "compositeCertificateExampleRFC.pem" )));
5534
+ X509CertificateHolder certificateHolder = (X509CertificateHolder )pemParser .readObject ();
5534
5535
JcaX509CertificateConverter x509Converter = new JcaX509CertificateConverter ().setProvider ("BC" );
5535
5536
X509Certificate certificate = x509Converter .getCertificate (certificateHolder );
5536
5537
5537
5538
isEquals (certificate .getSigAlgOID (), MiscObjectIdentifiers .id_MLDSA44_ECDSA_P256_SHA256 .toString ());
5538
5539
5539
- CompositePublicKey compositePublicKey = (CompositePublicKey ) certificate .getPublicKey ();
5540
+ CompositePublicKey compositePublicKey = (CompositePublicKey )certificate .getPublicKey ();
5540
5541
5541
5542
isEquals (compositePublicKey .getPublicKeys ().get (0 ).getAlgorithm (), "DILITHIUM2" );
5542
5543
isEquals (compositePublicKey .getPublicKeys ().get (1 ).getAlgorithm (), "ECDSA" );
0 commit comments