Path: blob/master/test/jdk/sun/security/provider/DSA/SupportedDSAParamGen.java
41154 views
/*1* Copyright (c) 2016, 2021, 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 8072452 816349826* @summary Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits27* This test has been split based on lower/higher key sizes in order to28* reduce individual execution times and run in parallel29* (see SupportedDSAParamGenLongKey.java)30* @run main/timeout=300 SupportedDSAParamGen 1024 16031* @run main/timeout=300 SupportedDSAParamGen 2048 22432* @run main/timeout=300 SupportedDSAParamGen 2048 25633*/34import java.security.*;35import java.security.spec.*;36import java.security.interfaces.*;3738public class SupportedDSAParamGen {3940public static void main(String[] args) throws Exception {41AlgorithmParameterGenerator apg =42AlgorithmParameterGenerator.getInstance("DSA", "SUN");4344DSAGenParameterSpec spec = new DSAGenParameterSpec(45Integer.valueOf(args[0]).intValue(),46Integer.valueOf(args[1]).intValue());4748System.out.println("Generating (" + spec.getPrimePLength() +49", " + spec.getSubprimeQLength() + ") DSA Parameters");50long start = System.currentTimeMillis();51apg.init(spec, null);52AlgorithmParameters param = apg.generateParameters();53long stop = System.currentTimeMillis();54System.out.println("Time: " + (stop - start) + " ms.");55checkParamStrength(param, spec);56}5758private static void checkParamStrength(AlgorithmParameters param,59DSAGenParameterSpec genParam) throws Exception {6061String algo = param.getAlgorithm();62if (!algo.equalsIgnoreCase("DSA")) {63throw new Exception("Unexpected type of parameters: " + algo);64}6566DSAParameterSpec spec = param.getParameterSpec(DSAParameterSpec.class);67int valueL = spec.getP().bitLength();68int strength = genParam.getPrimePLength();69if (strength != valueL) {70System.out.println(71"P: Expected " + strength + " but actual " + valueL);72throw new Exception("Wrong P strength");73}7475int valueN = spec.getQ().bitLength();76strength = genParam.getSubprimeQLength();77if (strength != valueN) {78System.out.println(79"Q: Expected " + strength + " but actual " + valueN);80throw new Exception("Wrong Q strength");81}82}83}848586