Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/pkcs11/Mac/ReinitMac.java
41152 views
1
/*
2
* Copyright (c) 2003, 2020, 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 4856966 8242332
27
* @summary
28
* @author Andreas Sterbenz
29
* @library /test/lib ..
30
* @key randomness
31
* @modules jdk.crypto.cryptoki
32
* @run main/othervm ReinitMac
33
* @run main/othervm -Djava.security.manager=allow ReinitMac sm
34
*/
35
36
import java.security.Provider;
37
import java.util.Random;
38
import java.util.List;
39
import javax.crypto.Mac;
40
import javax.crypto.spec.SecretKeySpec;
41
42
public class ReinitMac extends PKCS11Test {
43
44
public static void main(String[] args) throws Exception {
45
main(new ReinitMac(), args);
46
}
47
48
@Override
49
public void main(Provider p) throws Exception {
50
List<String> algorithms = getSupportedAlgorithms("Mac", "Hmac", p);
51
Random random = new Random();
52
byte[] data = new byte[10 * 1024];
53
random.nextBytes(data);
54
byte[] keyVal = new byte[16];
55
random.nextBytes(keyVal);
56
57
boolean success = true;
58
for (String alg : algorithms) {
59
try {
60
doTest(alg, p, keyVal, data);
61
} catch (Exception e) {
62
System.out.println("Unexpected exception: " + e);
63
e.printStackTrace();
64
success = false;
65
}
66
}
67
68
if (!success) {
69
throw new RuntimeException("Test failed");
70
} else {
71
System.out.println("All tests passed");
72
}
73
}
74
75
private void doTest(String alg, Provider p, byte[] keyVal, byte[] data)
76
throws Exception {
77
System.out.println("Testing " + alg);
78
SecretKeySpec key = new SecretKeySpec(keyVal, alg);
79
Mac mac = Mac.getInstance(alg, p);
80
mac.init(key);
81
mac.init(key);
82
mac.update(data);
83
mac.init(key);
84
mac.doFinal();
85
mac.doFinal();
86
mac.update(data);
87
mac.doFinal();
88
mac.reset();
89
mac.reset();
90
mac.init(key);
91
mac.reset();
92
mac.update(data);
93
mac.reset();
94
}
95
}
96
97