11/*
2- * Copyright (c) 2019, 2023 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2019, 2025 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2020 * or visit www.oracle.com if you need additional information or have any
2121 * questions.
2222 */
23- import java .security .*;
24- import java .security .interfaces .*;
25- import java .security .spec .*;
26- import java .util .stream .IntStream ;
23+ import java .security .InvalidAlgorithmParameterException ;
24+ import java .security .InvalidKeyException ;
25+ import java .security .KeyPair ;
26+ import java .security .NoSuchAlgorithmException ;
27+ import java .security .PrivateKey ;
28+ import java .security .Provider ;
29+ import java .security .PublicKey ;
30+ import java .security .Signature ;
31+ import java .security .SignatureException ;
32+ import java .security .spec .AlgorithmParameterSpec ;
33+ import java .security .spec .MGF1ParameterSpec ;
34+ import java .security .spec .PSSParameterSpec ;
35+ import java .util .ArrayList ;
36+ import java .util .List ;
37+
2738import jtreg .SkippedException ;
2839
2940/**
30- * @test
41+ * @test id=sha
3142 * @bug 8080462 8226651 8242332
3243 * @summary Generate a RSASSA-PSS signature and verify it using PKCS11 provider
3344 * @library /test/lib ..
3445 * @modules jdk.crypto.cryptoki
3546 * @run main SignatureTestPSS
3647 */
48+
49+ /**
50+ * @test id=sha3
51+ * @bug 8080462 8226651 8242332
52+ * @summary Generate a RSASSA-PSS signature and verify it using PKCS11 provider
53+ * @library /test/lib ..
54+ * @modules jdk.crypto.cryptoki
55+ * @run main SignatureTestPSS sha3
56+ */
3757public class SignatureTestPSS extends PKCS11Test {
3858
3959 private static final String SIGALG = "RSASSA-PSS" ;
4060
4161 private static final int [] KEYSIZES = { 2048 , 3072 };
42- private static final String [] DIGESTS = {
62+
63+ private static String [] DIGESTS = null ;
64+
65+ private static final String [] SHA_DIGESTS = {
4366 "SHA-224" , "SHA-256" , "SHA-384" , "SHA-512" ,
44- "SHA3-224" , "SHA3-256" , "SHA3-384" , "SHA3-512" ,
4567 };
68+ private static final String [] SHA3_DIGESTS = {
69+ "SHA3-224" , "SHA3-256" , "SHA3-384" , "SHA3-512"
70+ };
71+
4672 private static final byte [] DATA = generateData (100 );
4773
4874 /**
@@ -55,9 +81,12 @@ public class SignatureTestPSS extends PKCS11Test {
5581 */
5682 private static final int UPDATE_TIMES_HUNDRED = 100 ;
5783
58- private static boolean skipTest = true ;
84+ private static final List < String > skippedAlgs = new ArrayList <>() ;
5985
6086 public static void main (String [] args ) throws Exception {
87+ DIGESTS = (args .length > 0 && "sha3" .equals (args [0 ])) ?
88+ SHA3_DIGESTS : SHA_DIGESTS ;
89+
6190 main (new SignatureTestPSS (), args );
6291 }
6392
@@ -80,24 +109,24 @@ public void main(Provider p) throws Exception {
80109 PSSUtil .isHashSupported (p , hash , mgfHash );
81110 if (s == PSSUtil .AlgoSupport .NO ) {
82111 System .out .println (" => Skip; no support" );
112+ skippedAlgs .add ("[Hash = " + hash +
113+ ", MGF1 Hash = " + mgfHash + "]" );
83114 continue ;
84115 }
85116 checkSignature (p , DATA , pubKey , privKey , hash , mgfHash , s );
86117 }
87118 };
88119 }
89120
90- // start testing below
91- if (skipTest ) {
92- throw new SkippedException ("Test Skipped" );
121+ if (!skippedAlgs .isEmpty ()) {
122+ throw new SkippedException ("Test Skipped :" + skippedAlgs );
93123 }
94124 }
95125
96126 private static void checkSignature (Provider p , byte [] data , PublicKey pub ,
97127 PrivateKey priv , String hash , String mgfHash , PSSUtil .AlgoSupport s )
98128 throws NoSuchAlgorithmException , InvalidKeyException ,
99- SignatureException , NoSuchProviderException ,
100- InvalidAlgorithmParameterException {
129+ SignatureException {
101130
102131 // only test RSASSA-PSS signature against the supplied hash/mgfHash
103132 // if they are supported; otherwise PKCS11 library will throw
@@ -112,14 +141,27 @@ private static void checkSignature(Provider p, byte[] data, PublicKey pub,
112141 } catch (InvalidAlgorithmParameterException iape ) {
113142 if (s == PSSUtil .AlgoSupport .MAYBE ) {
114143 // confirmed to be unsupported; skip the rest of the test
115- System .out .println (" => Skip; no PSS support" );
144+ System .out .printf (" => Skip; no PSS support public key: %s, private key: %s, " +
145+ "hash: %s, mgf hash: %s, Algo Support: %s%n" ,
146+ pub ,
147+ priv ,
148+ hash ,
149+ mgfHash ,
150+ s );
151+ skippedAlgs .add (String .format (
152+ "[public key: %s, private key: %s, " +
153+ "hash: %s, mgf hash: %s, Algo Support: %s]" ,
154+ pub ,
155+ priv ,
156+ hash ,
157+ mgfHash ,
158+ s )
159+ );
116160 return ;
117161 } else {
118162 throw new RuntimeException ("Unexpected Exception" , iape );
119163 }
120164 }
121- // start testing below
122- skipTest = false ;
123165
124166 for (int i = 0 ; i < UPDATE_TIMES_HUNDRED ; i ++) {
125167 sig .update (data );
0 commit comments