Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/provider/DSA/SupportedDSAParamGen.java
38853 views
1
/*
2
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
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
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 8072452
27
* @key intermittent
28
* @summary Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
29
* @run main/timeout=300 SupportedDSAParamGen 1024 160
30
* @run main/timeout=300 SupportedDSAParamGen 2048 224
31
* @run main/timeout=300 SupportedDSAParamGen 2048 256
32
* @run main/timeout=700 SupportedDSAParamGen 3072 256
33
*/
34
import java.security.*;
35
import java.security.spec.*;
36
import java.security.interfaces.*;
37
38
public class SupportedDSAParamGen {
39
40
public static void main(String[] args) throws Exception {
41
AlgorithmParameterGenerator apg =
42
AlgorithmParameterGenerator.getInstance("DSA", "SUN");
43
44
DSAGenParameterSpec spec = new DSAGenParameterSpec(
45
Integer.valueOf(args[0]).intValue(),
46
Integer.valueOf(args[1]).intValue());
47
48
System.out.println("Generating (" + spec.getPrimePLength() +
49
", " + spec.getSubprimeQLength() + ") DSA Parameters");
50
long start = System.currentTimeMillis();
51
apg.init(spec, null);
52
AlgorithmParameters param = apg.generateParameters();
53
long stop = System.currentTimeMillis();
54
System.out.println("Time: " + (stop - start) + " ms.");
55
checkParamStrength(param, spec);
56
}
57
58
private static void checkParamStrength(AlgorithmParameters param,
59
DSAGenParameterSpec genParam) throws Exception {
60
61
String algo = param.getAlgorithm();
62
if (!algo.equalsIgnoreCase("DSA")) {
63
throw new Exception("Unexpected type of parameters: " + algo);
64
}
65
66
DSAParameterSpec spec = param.getParameterSpec(DSAParameterSpec.class);
67
int valueL = spec.getP().bitLength();
68
int strength = genParam.getPrimePLength();
69
if (strength != valueL) {
70
System.out.println(
71
"P: Expected " + strength + " but actual " + valueL);
72
throw new Exception("Wrong P strength");
73
}
74
75
int valueN = spec.getQ().bitLength();
76
strength = genParam.getSubprimeQLength();
77
if (strength != valueN) {
78
System.out.println(
79
"Q: Expected " + strength + " but actual " + valueN);
80
throw new Exception("Wrong Q strength");
81
}
82
}
83
}
84
85