Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/provider/DSA/SupportedDSAParamGen.java
41154 views
1
/*
2
* Copyright (c) 2016, 2021, 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 8163498
27
* @summary Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
28
* This test has been split based on lower/higher key sizes in order to
29
* reduce individual execution times and run in parallel
30
* (see SupportedDSAParamGenLongKey.java)
31
* @run main/timeout=300 SupportedDSAParamGen 1024 160
32
* @run main/timeout=300 SupportedDSAParamGen 2048 224
33
* @run main/timeout=300 SupportedDSAParamGen 2048 256
34
*/
35
import java.security.*;
36
import java.security.spec.*;
37
import java.security.interfaces.*;
38
39
public class SupportedDSAParamGen {
40
41
public static void main(String[] args) throws Exception {
42
AlgorithmParameterGenerator apg =
43
AlgorithmParameterGenerator.getInstance("DSA", "SUN");
44
45
DSAGenParameterSpec spec = new DSAGenParameterSpec(
46
Integer.valueOf(args[0]).intValue(),
47
Integer.valueOf(args[1]).intValue());
48
49
System.out.println("Generating (" + spec.getPrimePLength() +
50
", " + spec.getSubprimeQLength() + ") DSA Parameters");
51
long start = System.currentTimeMillis();
52
apg.init(spec, null);
53
AlgorithmParameters param = apg.generateParameters();
54
long stop = System.currentTimeMillis();
55
System.out.println("Time: " + (stop - start) + " ms.");
56
checkParamStrength(param, spec);
57
}
58
59
private static void checkParamStrength(AlgorithmParameters param,
60
DSAGenParameterSpec genParam) throws Exception {
61
62
String algo = param.getAlgorithm();
63
if (!algo.equalsIgnoreCase("DSA")) {
64
throw new Exception("Unexpected type of parameters: " + algo);
65
}
66
67
DSAParameterSpec spec = param.getParameterSpec(DSAParameterSpec.class);
68
int valueL = spec.getP().bitLength();
69
int strength = genParam.getPrimePLength();
70
if (strength != valueL) {
71
System.out.println(
72
"P: Expected " + strength + " but actual " + valueL);
73
throw new Exception("Wrong P strength");
74
}
75
76
int valueN = spec.getQ().bitLength();
77
strength = genParam.getSubprimeQLength();
78
if (strength != valueN) {
79
System.out.println(
80
"Q: Expected " + strength + " but actual " + valueN);
81
throw new Exception("Wrong Q strength");
82
}
83
}
84
}
85
86