Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/provider/DSA/SupportedDSAParamGen.java
38853 views
/*1* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 807245226* @key intermittent27* @summary Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits28* @run main/timeout=300 SupportedDSAParamGen 1024 16029* @run main/timeout=300 SupportedDSAParamGen 2048 22430* @run main/timeout=300 SupportedDSAParamGen 2048 25631* @run main/timeout=700 SupportedDSAParamGen 3072 25632*/33import java.security.*;34import java.security.spec.*;35import java.security.interfaces.*;3637public class SupportedDSAParamGen {3839public static void main(String[] args) throws Exception {40AlgorithmParameterGenerator apg =41AlgorithmParameterGenerator.getInstance("DSA", "SUN");4243DSAGenParameterSpec spec = new DSAGenParameterSpec(44Integer.valueOf(args[0]).intValue(),45Integer.valueOf(args[1]).intValue());4647System.out.println("Generating (" + spec.getPrimePLength() +48", " + spec.getSubprimeQLength() + ") DSA Parameters");49long start = System.currentTimeMillis();50apg.init(spec, null);51AlgorithmParameters param = apg.generateParameters();52long stop = System.currentTimeMillis();53System.out.println("Time: " + (stop - start) + " ms.");54checkParamStrength(param, spec);55}5657private static void checkParamStrength(AlgorithmParameters param,58DSAGenParameterSpec genParam) throws Exception {5960String algo = param.getAlgorithm();61if (!algo.equalsIgnoreCase("DSA")) {62throw new Exception("Unexpected type of parameters: " + algo);63}6465DSAParameterSpec spec = param.getParameterSpec(DSAParameterSpec.class);66int valueL = spec.getP().bitLength();67int strength = genParam.getPrimePLength();68if (strength != valueL) {69System.out.println(70"P: Expected " + strength + " but actual " + valueL);71throw new Exception("Wrong P strength");72}7374int valueN = spec.getQ().bitLength();75strength = genParam.getSubprimeQLength();76if (strength != valueN) {77System.out.println(78"Q: Expected " + strength + " but actual " + valueN);79throw new Exception("Wrong Q strength");80}81}82}838485