test/jdk/java/security/Signature/Offsets.java
changeset 47421 f9e03aef3a49
parent 47216 71c04702a3d5
child 50204 3195a713e24d
child 56542 56aaa6cb3693
equal deleted inserted replaced
47420:a2bf68a0365f 47421:f9e03aef3a49
    32 import java.security.SignatureException;
    32 import java.security.SignatureException;
    33 import jdk.test.lib.RandomFactory;
    33 import jdk.test.lib.RandomFactory;
    34 
    34 
    35 /*
    35 /*
    36  * @test
    36  * @test
    37  * @bug 8050374
    37  * @bug 8050374 8181048
    38  * @key randomness
    38  * @key randomness
    39  * @summary This test validates signature verification
    39  * @summary This test validates signature verification
    40  *          Signature.verify(byte[], int, int). The test uses RandomFactory to
    40  *          Signature.verify(byte[], int, int). The test uses RandomFactory to
    41  *          get random set of clear text data to sign. After the signature
    41  *          get random set of clear text data to sign. After the signature
    42  *          generation, the test tries to verify signature with the above API
    42  *          generation, the test tries to verify signature with the above API
   104 
   104 
   105         // create signature instance
   105         // create signature instance
   106         Signature signature = Signature.getInstance(algorithm, provider);
   106         Signature signature = Signature.getInstance(algorithm, provider);
   107 
   107 
   108         String keyAlgo;
   108         String keyAlgo;
       
   109         int keySize = 2048;
   109         if (algorithm.contains("RSA")) {
   110         if (algorithm.contains("RSA")) {
   110             keyAlgo = "RSA";
   111             keyAlgo = "RSA";
   111         } else if (algorithm.contains("ECDSA")) {
   112         } else if (algorithm.contains("ECDSA")) {
   112             keyAlgo = "EC";
   113             keyAlgo = "EC";
       
   114             keySize = 256;
   113         } else if (algorithm.contains("DSA")) {
   115         } else if (algorithm.contains("DSA")) {
   114             keyAlgo = "DSA";
   116             keyAlgo = "DSA";
       
   117             if (algorithm.startsWith("SHAwith") ||
       
   118                     algorithm.startsWith("SHA1with")) {
       
   119                 keySize = 1024;
       
   120             }
   115         } else {
   121         } else {
   116             throw new RuntimeException("Test doesn't support this signature "
   122             throw new RuntimeException("Test doesn't support this signature "
   117                     + "algorithm: " + algorithm);
   123                     + "algorithm: " + algorithm);
   118         }
   124         }
   119 
   125 
   120         KeyPairGenerator kpg = KeyPairGenerator.getInstance(keyAlgo, provider);
   126         KeyPairGenerator kpg = KeyPairGenerator.getInstance(keyAlgo, provider);
       
   127         kpg.initialize(keySize);
   121         KeyPair kp = kpg.generateKeyPair();
   128         KeyPair kp = kpg.generateKeyPair();
   122         PublicKey pubkey = kp.getPublic();
   129         PublicKey pubkey = kp.getPublic();
   123         PrivateKey privkey = kp.getPrivate();
   130         PrivateKey privkey = kp.getPrivate();
   124 
   131 
   125         return new Offsets(signature, pubkey, privkey, size, cleartext);
   132         return new Offsets(signature, pubkey, privkey, size, cleartext);