jdk/test/sun/security/provider/DSA/SupportedDSAParamGen.java
author ssahoo
Tue, 07 Jun 2016 09:00:11 -0700
changeset 38859 76eee114a175
parent 37366 2a9763cab068
permissions -rw-r--r--
8157896: TestDSAGenParameterSpec.java test fails with timeout 8157898: SupportedDSAParamGen.java failed with timeout Reviewed-by: xuelei
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37361
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
     1
/*
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
     4
 *
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
     8
 *
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    13
 * accompanied this code).
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    14
 *
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    18
 *
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    21
 * questions.
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    22
 */
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    23
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    24
/*
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    25
 * @test
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    26
 * @bug 8072452
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    27
 * @summary Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    28
 * @run main/timeout=300 SupportedDSAParamGen 1024 160
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    29
 * @run main/timeout=300 SupportedDSAParamGen 2048 224
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    30
 * @run main/timeout=300 SupportedDSAParamGen 2048 256
38859
76eee114a175 8157896: TestDSAGenParameterSpec.java test fails with timeout
ssahoo
parents: 37366
diff changeset
    31
 * @run main/timeout=700 SupportedDSAParamGen 3072 256
37361
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    32
 */
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    33
import java.security.*;
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    34
import java.security.spec.*;
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    35
import java.security.interfaces.*;
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    36
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    37
public class SupportedDSAParamGen {
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    38
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    39
    public static void main(String[] args) throws Exception {
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    40
        AlgorithmParameterGenerator apg =
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    41
            AlgorithmParameterGenerator.getInstance("DSA", "SUN");
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    42
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    43
        DSAGenParameterSpec spec = new DSAGenParameterSpec(
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    44
                Integer.valueOf(args[0]).intValue(),
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    45
                Integer.valueOf(args[1]).intValue());
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    46
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    47
        System.out.println("Generating (" + spec.getPrimePLength() +
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    48
                ", " + spec.getSubprimeQLength() + ") DSA Parameters");
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    49
        long start = System.currentTimeMillis();
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    50
        apg.init(spec, null);
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    51
        AlgorithmParameters param = apg.generateParameters();
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    52
        long stop = System.currentTimeMillis();
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    53
        System.out.println("Time: " + (stop - start) + " ms.");
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    54
        checkParamStrength(param, spec);
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    55
    }
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    56
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    57
    private static void checkParamStrength(AlgorithmParameters param,
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    58
            DSAGenParameterSpec genParam) throws Exception {
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    59
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    60
        String algo = param.getAlgorithm();
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    61
        if (!algo.equalsIgnoreCase("DSA")) {
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    62
            throw new Exception("Unexpected type of parameters: " + algo);
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    63
        }
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    64
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    65
        DSAParameterSpec spec = param.getParameterSpec(DSAParameterSpec.class);
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    66
        int valueL = spec.getP().bitLength();
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    67
        int strength = genParam.getPrimePLength();
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    68
        if (strength != valueL) {
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    69
            System.out.println(
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    70
                    "P: Expected " + strength + " but actual " + valueL);
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    71
            throw new Exception("Wrong P strength");
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    72
        }
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    73
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    74
        int valueN = spec.getQ().bitLength();
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    75
        strength = genParam.getSubprimeQLength();
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    76
        if (strength != valueN) {
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    77
            System.out.println(
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    78
                    "Q: Expected " + strength + " but actual " + valueN);
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    79
            throw new Exception("Wrong Q strength");
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    80
        }
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    81
    }
a790f7bc3878 8072452: Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
xuelei
parents:
diff changeset
    82
}