Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/com/sun/crypto/provider/Mac/HmacMD5.java
41159 views
1
/*
2
* Copyright (c) 1998, 2015, 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 0000000
27
* @summary Checks compliance of the HMAC-MD5 implementation with
28
* RFC 2104, using the test vectors specified there.
29
* @author Jan Luehe
30
*/
31
32
import java.security.*;
33
import javax.crypto.*;
34
import javax.crypto.spec.*;
35
36
public class HmacMD5 {
37
38
public static void main(String argv[]) throws Exception {
39
int i, j, n;
40
Mac mac;
41
42
byte[][][] test_data = {
43
{
44
{ (byte)0x0b, (byte)0x0b, (byte)0x0b, (byte)0x0b,
45
(byte)0x0b, (byte)0x0b, (byte)0x0b, (byte)0x0b,
46
(byte)0x0b, (byte)0x0b, (byte)0x0b, (byte)0x0b,
47
(byte)0x0b, (byte)0x0b, (byte)0x0b, (byte)0x0b }, // key1
48
"Hi There".getBytes(), // data1
49
{ (byte)0x92, (byte)0x94, (byte)0x72, (byte)0x7a,
50
(byte)0x36, (byte)0x38, (byte)0xbb, (byte)0x1c,
51
(byte)0x13, (byte)0xf4, (byte)0x8e, (byte)0xf8,
52
(byte)0x15, (byte)0x8b, (byte)0xfc, (byte)0x9d // result1
53
}
54
},
55
{
56
"Jefe".getBytes(), // key2
57
"what do ya want for nothing?".getBytes(), // data2
58
{ (byte)0x75, (byte)0x0c, (byte)0x78, (byte)0x3e,
59
(byte)0x6a, (byte)0xb0, (byte)0xb5, (byte)0x03,
60
(byte)0xea, (byte)0xa8, (byte)0x6e, (byte)0x31,
61
(byte)0x0a, (byte)0x5d, (byte)0xb7, (byte)0x38 // result2
62
}
63
},
64
{
65
{ (byte)0xAA, (byte)0xAA, (byte)0xAA, (byte)0xAA,
66
(byte)0xAA, (byte)0xAA, (byte)0xAA, (byte)0xAA,
67
(byte)0xAA, (byte)0xAA, (byte)0xAA, (byte)0xAA,
68
(byte)0xAA, (byte)0xAA, (byte)0xAA, (byte)0xAA // key3
69
},
70
{ (byte)0xDD, (byte)0xDD, (byte)0xDD, (byte)0xDD,
71
(byte)0xDD, (byte)0xDD, (byte)0xDD, (byte)0xDD,
72
(byte)0xDD, (byte)0xDD, (byte)0xDD, (byte)0xDD,
73
(byte)0xDD, (byte)0xDD, (byte)0xDD, (byte)0xDD,
74
(byte)0xDD, (byte)0xDD, (byte)0xDD, (byte)0xDD,
75
(byte)0xDD, (byte)0xDD, (byte)0xDD, (byte)0xDD,
76
(byte)0xDD, (byte)0xDD, (byte)0xDD, (byte)0xDD,
77
(byte)0xDD, (byte)0xDD, (byte)0xDD, (byte)0xDD,
78
(byte)0xDD, (byte)0xDD, (byte)0xDD, (byte)0xDD,
79
(byte)0xDD, (byte)0xDD, (byte)0xDD, (byte)0xDD,
80
(byte)0xDD, (byte)0xDD, (byte)0xDD, (byte)0xDD,
81
(byte)0xDD, (byte)0xDD, (byte)0xDD, (byte)0xDD,
82
(byte)0xDD, (byte)0xDD // data3
83
},
84
{ (byte)0x56, (byte)0xbe, (byte)0x34, (byte)0x52,
85
(byte)0x1d, (byte)0x14, (byte)0x4c, (byte)0x88,
86
(byte)0xdb, (byte)0xb8, (byte)0xc7, (byte)0x33,
87
(byte)0xf0, (byte)0xe8, (byte)0xb3, (byte)0xf6 // result3
88
}
89
}
90
};
91
92
mac = Mac.getInstance("HmacMD5", "SunJCE");
93
for (i=0; i<3; i++) {
94
j=0;
95
96
mac.init(new SecretKeySpec(test_data[i][j++], "HMAC"));
97
byte[] result = mac.doFinal(test_data[i][j++]);
98
if (result.length != test_data[i][j].length) {
99
throw new Exception("Different result length");
100
}
101
for (n=0; n<result.length; n++) {
102
if (result[n] != test_data[i][j][n]) {
103
throw new Exception("Different");
104
}
105
}
106
}
107
108
// now test multiple-part operation, using the 2nd test vector
109
mac = Mac.getInstance("HmacMD5", "SunJCE");
110
mac.init(new SecretKeySpec("Jefe".getBytes(), "HMAC"));
111
mac.update("what do ya ".getBytes());
112
mac.update("want for ".getBytes());
113
mac.update("nothing?".getBytes());
114
byte[] result = mac.doFinal();
115
if (result.length != test_data[1][2].length) {
116
throw new Exception("Different result length");
117
}
118
for (i=0; i<result.length; i++) {
119
if (result[i] != test_data[1][2][i]) {
120
throw new Exception("Different");
121
}
122
}
123
124
System.out.println("Test SUCCEEDED");
125
}
126
}
127
128