Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/provider/DSA/TestKeyPairGenerator.java
41154 views
1
/*
2
* Copyright (c) 2003, 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 4800108 8072452 8181048
27
* @summary verify that precomputed DSA parameters are always used (512, 768,
28
* 1024, 2048, 3072 bit)
29
* @run main/othervm/timeout=15 TestKeyPairGenerator
30
*/
31
32
//
33
// This fix is really a performance fix, so this test is not foolproof.
34
// Without the precomputed parameters, it will take a minute or more
35
// (unless you have a very fast machine). With the fix, the test should
36
// complete in less than 2 seconds. Use 15 second timeout to leave some room.
37
//
38
39
import java.security.*;
40
import java.security.interfaces.*;
41
42
public class TestKeyPairGenerator {
43
44
private static void checkKeyLength(KeyPair kp, int len) throws Exception {
45
DSAPublicKey key = (DSAPublicKey)kp.getPublic();
46
int n = key.getParams().getP().bitLength();
47
System.out.println("Key length: " + n);
48
if (len != n) {
49
throw new Exception("Wrong key length");
50
}
51
}
52
53
public static void main(String[] args) throws Exception {
54
long start = System.currentTimeMillis();
55
KeyPairGenerator kpg;
56
KeyPair kp;
57
// problem was when not calling initialize()
58
// do that twice to artifically inflate the time
59
// on JDKs that do not have the fix
60
kpg = KeyPairGenerator.getInstance("DSA", "SUN");
61
kp = kpg.generateKeyPair();
62
63
kpg = KeyPairGenerator.getInstance("DSA", "SUN");
64
kp = kpg.generateKeyPair();
65
66
// some other basic tests
67
kp = kpg.generateKeyPair();
68
69
kpg.initialize(1024);
70
kp = kpg.generateKeyPair();
71
checkKeyLength(kp, 1024);
72
73
kpg.initialize(768);
74
kp = kpg.generateKeyPair();
75
checkKeyLength(kp, 768);
76
77
kpg.initialize(512);
78
kp = kpg.generateKeyPair();
79
checkKeyLength(kp, 512);
80
81
kpg.initialize(2048);
82
kp = kpg.generateKeyPair();
83
checkKeyLength(kp, 2048);
84
85
kpg.initialize(3072);
86
kp = kpg.generateKeyPair();
87
checkKeyLength(kp, 3072);
88
89
long stop = System.currentTimeMillis();
90
System.out.println("Time: " + (stop - start) + " ms.");
91
}
92
}
93
94