jdk/test/sun/security/pkcs11/KeyPairGenerator/TestDH2048.java
changeset 35379 1e8e336ef66b
parent 20751 56898cefcda9
child 37361 a790f7bc3878
equal deleted inserted replaced
35378:7e19fa0e4e5b 35379:1e8e336ef66b
     1 /*
     1 /*
     2  * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    25  * @test
    25  * @test
    26  * @bug 7196382
    26  * @bug 7196382
    27  * @summary Ensure that 2048-bit DH key pairs can be generated
    27  * @summary Ensure that 2048-bit DH key pairs can be generated
    28  * @author Valerie Peng
    28  * @author Valerie Peng
    29  * @library ..
    29  * @library ..
       
    30  * @run main/othervm TestDH2048
       
    31  * @run main/othervm TestDH2048 sm
    30  */
    32  */
    31 
    33 
    32 import java.io.*;
    34 import java.security.InvalidParameterException;
    33 import java.util.*;
    35 import java.security.KeyPair;
    34 
    36 import java.security.KeyPairGenerator;
    35 import java.security.*;
    37 import java.security.Provider;
    36 
       
    37 import javax.crypto.*;
       
    38 
    38 
    39 public class TestDH2048 extends PKCS11Test {
    39 public class TestDH2048 extends PKCS11Test {
    40 
    40 
    41     private static void checkUnsupportedKeySize(KeyPairGenerator kpg, int ks)
    41     private static void checkUnsupportedKeySize(KeyPairGenerator kpg, int ks)
    42         throws Exception {
    42         throws Exception {
    45             throw new Exception("Expected IPE not thrown for " + ks);
    45             throw new Exception("Expected IPE not thrown for " + ks);
    46         } catch (InvalidParameterException ipe) {
    46         } catch (InvalidParameterException ipe) {
    47         }
    47         }
    48     }
    48     }
    49 
    49 
       
    50     @Override
    50     public void main(Provider p) throws Exception {
    51     public void main(Provider p) throws Exception {
    51         if (p.getService("KeyPairGenerator", "DH") == null) {
    52         if (p.getService("KeyPairGenerator", "DH") == null) {
    52             System.out.println("KPG for DH not supported, skipping");
    53             System.out.println("KPG for DH not supported, skipping");
    53             return;
    54             return;
    54         }
    55         }
    59         checkUnsupportedKeySize(kpg, 2176);
    60         checkUnsupportedKeySize(kpg, 2176);
    60         checkUnsupportedKeySize(kpg, 3072);
    61         checkUnsupportedKeySize(kpg, 3072);
    61     }
    62     }
    62 
    63 
    63     public static void main(String[] args) throws Exception {
    64     public static void main(String[] args) throws Exception {
    64         main(new TestDH2048());
    65         main(new TestDH2048(), args);
    65     }
    66     }
    66 }
    67 }