|
12 | 12 | import java.security.PrivateKey;
|
13 | 13 | import java.security.PublicKey;
|
14 | 14 | import java.security.Security;
|
| 15 | +import java.security.Signature; |
15 | 16 | import java.security.cert.CertificateFactory;
|
16 | 17 | import java.security.cert.X509Certificate;
|
17 | 18 | import java.security.spec.PKCS8EncodedKeySpec;
|
|
41 | 42 | import org.bouncycastle.cert.DeltaCertificateTool;
|
42 | 43 | import org.bouncycastle.cert.X509CertificateHolder;
|
43 | 44 | import org.bouncycastle.cert.jcajce.JcaX509CertificateHolder;
|
| 45 | +import org.bouncycastle.jcajce.interfaces.MLDSAPrivateKey; |
| 46 | +import org.bouncycastle.jcajce.interfaces.SLHDSAPrivateKey; |
44 | 47 | import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
45 | 48 | import org.bouncycastle.operator.ContentVerifierProvider;
|
46 | 49 | import org.bouncycastle.operator.OperatorCreationException;
|
|
49 | 52 | import org.bouncycastle.pqc.crypto.mlkem.MLKEMPrivateKeyParameters;
|
50 | 53 | import org.bouncycastle.pqc.crypto.util.PrivateKeyFactory;
|
51 | 54 | import org.bouncycastle.pqc.jcajce.provider.BouncyCastlePQCProvider;
|
| 55 | +import org.bouncycastle.util.Strings; |
52 | 56 | import org.bouncycastle.util.io.Streams;
|
53 | 57 | import org.bouncycastle.util.io.pem.PemReader;
|
54 | 58 |
|
@@ -238,7 +242,11 @@ else if (zipName.endsWith("_priv.der"))
|
238 | 242 |
|
239 | 243 | privateKey = (PrivateKey)keyFact.generatePrivate(new PKCS8EncodedKeySpec(derData));
|
240 | 244 | privateKeys.put(zipName, privateKey);
|
241 |
| - System.err.println(zipName); |
| 245 | + |
| 246 | + if (privateKey instanceof SLHDSAPrivateKey || privateKey instanceof MLDSAPrivateKey) |
| 247 | + { |
| 248 | + doSigCheck(privateKey); |
| 249 | + } |
242 | 250 | }
|
243 | 251 | catch (Exception e)
|
244 | 252 | {
|
@@ -298,6 +306,34 @@ else if (zipName.endsWith("_ciphertext.bin"))
|
298 | 306 | checkCertificates(producer, certificates, ignored, privateKeys, cipherTexts);
|
299 | 307 | }
|
300 | 308 |
|
| 309 | + public static void doSigCheck(PrivateKey privKey) |
| 310 | + throws Exception |
| 311 | + { |
| 312 | + Signature sig = Signature.getInstance(privKey.getAlgorithm(), "BC"); |
| 313 | + |
| 314 | + sig.initSign(privKey); |
| 315 | + |
| 316 | + sig.update(Strings.toByteArray("abc")); |
| 317 | + |
| 318 | + byte[] genSig = sig.sign(); |
| 319 | + |
| 320 | + if (privKey instanceof MLDSAPrivateKey) |
| 321 | + { |
| 322 | + sig.initVerify(((MLDSAPrivateKey)privKey).getPublicKey()); |
| 323 | + } |
| 324 | + else |
| 325 | + { |
| 326 | + sig.initVerify(((SLHDSAPrivateKey)privKey).getPublicKey()); |
| 327 | + } |
| 328 | + |
| 329 | + sig.update(Strings.toByteArray("abc")); |
| 330 | + |
| 331 | + if (!sig.verify(genSig)) |
| 332 | + { |
| 333 | + throw new IllegalStateException("sig failed to verify"); |
| 334 | + } |
| 335 | + } |
| 336 | + |
301 | 337 | public static void processArtifacts(String producer, String dirName)
|
302 | 338 | throws Exception
|
303 | 339 | {
|
@@ -366,6 +402,11 @@ else if (fileName.endsWith("_priv.der"))
|
366 | 402 |
|
367 | 403 | privateKey = (PrivateKey)keyFact.generatePrivate(new PKCS8EncodedKeySpec(derData));
|
368 | 404 | privateKeys.put(fileName, privateKey);
|
| 405 | + |
| 406 | + if (privateKey instanceof SLHDSAPrivateKey || privateKey instanceof MLDSAPrivateKey) |
| 407 | + { |
| 408 | + doSigCheck(privateKey); |
| 409 | + } |
369 | 410 | }
|
370 | 411 | catch (Exception e)
|
371 | 412 | {
|
|
0 commit comments