< prev index next >

test/jdk/sun/security/rsa/pss/SignatureTest2.java

Print this page

 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 import java.security.*;
 24 import java.security.interfaces.RSAPrivateKey;
 25 import java.security.interfaces.RSAPublicKey;
 26 import java.security.spec.*;
 27 import java.util.Arrays;
 28 import java.util.stream.IntStream;
 29 import static javax.crypto.Cipher.PRIVATE_KEY;
 30 import static javax.crypto.Cipher.PUBLIC_KEY;
 31 
 32 /**
 33  * @test
 34  * @bug 8146293 8238448
 35  * @summary Create a signature for RSASSA-PSS and get its signed data.
 36  *          re-initiate the signature with the public key. The signature
 37  *          can be verified by acquired signed data.
 38  * @run main SignatureTest2 768
 39  * @run main SignatureTest2 1024
 40  * @run main SignatureTest2 1025
 41  * @run main SignatureTest2 2048
 42  * @run main SignatureTest2 2049
 43  * @run main/timeout=240 SignatureTest2 4096
 44  */
 45 public class SignatureTest2 {
 46     /**
 47      * ALGORITHM name, fixed as RSA.
 48      */
 49     private static final String KEYALG = "RSASSA-PSS";
 50 
 51     /**
 52      * JDK default RSA Provider.
 53      */
 54     private static final String PROVIDER = "SunRsaSign";
 55 
 56     /**
 57      * How much times signature updated.
 58      */
 59     private static final int UPDATE_TIMES_TWO = 2;
 60 
 61     /**
 62      * How much times signature initial updated.
 63      */
 64     private static final int UPDATE_TIMES_TEN = 10;
 65 
 66     /**
 67      * Digest algorithms to test w/ RSASSA-PSS signature algorithms
 68      */
 69     private static final String[] DIGEST_ALG = {
 70         "SHA-1", "SHA-224", "SHA-256", "SHA-384",
 71         "SHA-512", "SHA-512/224", "SHA-512/256"

 72     };
 73 
 74     private static final String SIG_ALG = "RSASSA-PSS";
 75 
 76     private static PSSParameterSpec genPSSParameter(String digestAlgo,
 77         int digestLen, int keySize) {
 78         // pick a salt length based on the key length and digestAlgo
 79         int saltLength = keySize/8 - digestLen - 2;
 80         if (saltLength < 0) {
 81             System.out.println("keysize: " + keySize/8 + ", digestLen: " + digestLen);
 82             return null;
 83         }
 84         return new PSSParameterSpec(digestAlgo, "MGF1",
 85             new MGF1ParameterSpec(digestAlgo), saltLength, 1);
 86     }
 87 
 88     public static void main(String[] args) throws Exception {
 89         final int testSize = Integer.parseInt(args[0]);
 90 
 91         byte[] data = new byte[100];

 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 import java.security.*;
 24 import java.security.interfaces.RSAPrivateKey;
 25 import java.security.interfaces.RSAPublicKey;
 26 import java.security.spec.*;
 27 import java.util.Arrays;
 28 import java.util.stream.IntStream;
 29 import static javax.crypto.Cipher.PRIVATE_KEY;
 30 import static javax.crypto.Cipher.PUBLIC_KEY;
 31 
 32 /**
 33  * @test
 34  * @bug 8146293 8238448 8172366
 35  * @summary Create a signature for RSASSA-PSS and get its signed data.
 36  *          re-initiate the signature with the public key. The signature
 37  *          can be verified by acquired signed data.
 38  * @run main SignatureTest2 768
 39  * @run main SignatureTest2 1024
 40  * @run main SignatureTest2 1025
 41  * @run main SignatureTest2 2048
 42  * @run main SignatureTest2 2049
 43  * @run main/timeout=240 SignatureTest2 4096
 44  */
 45 public class SignatureTest2 {
 46     /**
 47      * ALGORITHM name, fixed as RSA.
 48      */
 49     private static final String KEYALG = "RSASSA-PSS";
 50 
 51     /**
 52      * JDK default RSA Provider.
 53      */
 54     private static final String PROVIDER = "SunRsaSign";
 55 
 56     /**
 57      * How much times signature updated.
 58      */
 59     private static final int UPDATE_TIMES_TWO = 2;
 60 
 61     /**
 62      * How much times signature initial updated.
 63      */
 64     private static final int UPDATE_TIMES_TEN = 10;
 65 
 66     /**
 67      * Digest algorithms to test w/ RSASSA-PSS signature algorithms
 68      */
 69     private static final String[] DIGEST_ALG = {
 70         "SHA-1", "SHA-224", "SHA-256", "SHA-384",
 71         "SHA-512", "SHA-512/224", "SHA-512/256",
 72         "SHA3-224", "SHA3-256", "SHA3-384", "SHA3-512"
 73     };
 74 
 75     private static final String SIG_ALG = "RSASSA-PSS";
 76 
 77     private static PSSParameterSpec genPSSParameter(String digestAlgo,
 78         int digestLen, int keySize) {
 79         // pick a salt length based on the key length and digestAlgo
 80         int saltLength = keySize/8 - digestLen - 2;
 81         if (saltLength < 0) {
 82             System.out.println("keysize: " + keySize/8 + ", digestLen: " + digestLen);
 83             return null;
 84         }
 85         return new PSSParameterSpec(digestAlgo, "MGF1",
 86             new MGF1ParameterSpec(digestAlgo), saltLength, 1);
 87     }
 88 
 89     public static void main(String[] args) throws Exception {
 90         final int testSize = Integer.parseInt(args[0]);
 91 
 92         byte[] data = new byte[100];
< prev index next >