24 import java.security.interfaces.*; |
24 import java.security.interfaces.*; |
25 import java.security.spec.*; |
25 import java.security.spec.*; |
26 |
26 |
27 /** |
27 /** |
28 * @test |
28 * @test |
29 * @bug 8080462 |
29 * @bug 8080462 8226651 |
30 * @summary Ensure that PSS key and params check are implemented properly |
30 * @summary Ensure that PSS key and params check are implemented properly |
31 * regardless of call sequence |
31 * regardless of call sequence |
32 * @library /test/lib .. |
32 * @library /test/lib .. |
33 * @modules jdk.crypto.cryptoki |
33 * @modules jdk.crypto.cryptoki |
34 * @run main KeyAndParamCheckForPSS |
34 * @run main KeyAndParamCheckForPSS |
55 " due to no support"); |
55 " due to no support"); |
56 return; |
56 return; |
57 } |
57 } |
58 // NOTE: key length >= (digest length + 2) in bytes |
58 // NOTE: key length >= (digest length + 2) in bytes |
59 // otherwise, even salt length = 0 would not work |
59 // otherwise, even salt length = 0 would not work |
60 runTest(p, 1024, "SHA-384"); |
60 runTest(p, 1024, "SHA-256", "SHA-256"); |
61 runTest(p, 1040, "SHA-512"); |
61 runTest(p, 1024, "SHA-256", "SHA-384"); |
|
62 runTest(p, 1024, "SHA-256", "SHA-512"); |
|
63 runTest(p, 1024, "SHA-384", "SHA-256"); |
|
64 runTest(p, 1024, "SHA-384", "SHA-384"); |
|
65 runTest(p, 1024, "SHA-384", "SHA-512"); |
|
66 runTest(p, 1040, "SHA-512", "SHA-256"); |
|
67 runTest(p, 1040, "SHA-512", "SHA-384"); |
|
68 runTest(p, 1040, "SHA-512", "SHA-512"); |
62 } |
69 } |
63 |
70 |
64 private void runTest(Provider p, int keySize, String hashAlg) |
71 private void runTest(Provider p, int keySize, String hashAlg, |
65 throws Exception { |
72 String mgfHashAlg) throws Exception { |
66 System.out.println("Testing [" + keySize + " " + hashAlg + "]"); |
73 System.out.println("Testing [" + keySize + " " + hashAlg + "]"); |
67 |
74 |
68 // create a key pair with the supplied size |
75 // create a key pair with the supplied size |
69 KeyPairGenerator kpg = KeyPairGenerator.getInstance(KEYALG, p); |
76 KeyPairGenerator kpg = KeyPairGenerator.getInstance(KEYALG, p); |
70 kpg.initialize(keySize); |
77 kpg.initialize(keySize); |
71 KeyPair kp = kpg.generateKeyPair(); |
78 KeyPair kp = kpg.generateKeyPair(); |
72 |
79 |
73 int bigSaltLen = keySize/8 - 14; |
80 int bigSaltLen = keySize/8 - 14; |
74 AlgorithmParameterSpec paramsBad = new PSSParameterSpec(hashAlg, |
81 AlgorithmParameterSpec paramsBad = new PSSParameterSpec(hashAlg, |
75 "MGF1", new MGF1ParameterSpec(hashAlg), bigSaltLen, 1); |
82 "MGF1", new MGF1ParameterSpec(mgfHashAlg), bigSaltLen, 1); |
76 AlgorithmParameterSpec paramsGood = new PSSParameterSpec(hashAlg, |
83 AlgorithmParameterSpec paramsGood = new PSSParameterSpec(hashAlg, |
77 "MGF1", new MGF1ParameterSpec(hashAlg), 0, 1); |
84 "MGF1", new MGF1ParameterSpec(mgfHashAlg), 0, 1); |
78 |
85 |
79 PrivateKey priv = kp.getPrivate(); |
86 PrivateKey priv = kp.getPrivate(); |
80 PublicKey pub = kp.getPublic(); |
87 PublicKey pub = kp.getPublic(); |
81 |
88 |
82 // test#1 - setParameter then initSign |
89 // test#1 - setParameter then initSign |