Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/crypto/spec/DESKeySpec/CheckWeakKeys.java
41152 views
1
/*
2
* Copyright (c) 2005, 2007, 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 6340919
27
* @summary Incorrect list of keys reported as weak by DESKeySpec.isWeak()
28
* @author Brad R. Wetmore
29
*/
30
import javax.crypto.spec.DESKeySpec;
31
32
public class CheckWeakKeys {
33
34
/**
35
* Weak/semi-weak keys copied from FIPS 74.
36
*
37
* "...The first 6 keys have duals different than themselves, hence
38
* each is both a key and a dual giving 12 keys with duals. The last
39
* four keys equal their duals, and are called self-dual keys..."
40
*
41
* 1. E001E001F101F101 01E001E001F101F1
42
* 2. FE1FFE1FFEOEFEOE 1FFE1FFEOEFEOEFE
43
* 3. E01FE01FF10EF10E 1FE01FEOOEF10EF1
44
* 4. 01FE01FE01FE01FE FE01FE01FE01FE01
45
* 5. 011F011F010E010E 1F011F010E010E01
46
* 6. E0FEE0FEF1FEF1FE FEE0FEE0FEF1FEF1
47
* 7. 0101010101010101 0101010101010101
48
* 8. FEFEFEFEFEFEFEFE FEFEFEFEFEFEFEFE
49
* 9. E0E0E0E0F1F1F1F1 E0E0E0E0F1F1F1F1
50
* 10. 1F1F1F1F0E0E0E0E 1F1F1F1F0E0E0E0E
51
*/
52
static private byte [][] weakKeys = {
53
{ (byte)0xE0, (byte)0x01, (byte)0xE0, (byte)0x01,
54
(byte)0xF1, (byte)0x01, (byte)0xF1, (byte)0x01 },
55
56
{ (byte)0x01, (byte)0xE0, (byte)0x01, (byte)0xE0,
57
(byte)0x01, (byte)0xF1, (byte)0x01, (byte)0xF1 },
58
59
{ (byte)0xFE, (byte)0x1F, (byte)0xFE, (byte)0x1F,
60
(byte)0xFE, (byte)0x0E, (byte)0xFE, (byte)0x0E },
61
62
{ (byte)0x1F, (byte)0xFE, (byte)0x1F, (byte)0xFE,
63
(byte)0x0E, (byte)0xFE, (byte)0x0E, (byte)0xFE },
64
65
{ (byte)0xE0, (byte)0x1F, (byte)0xE0, (byte)0x1F,
66
(byte)0xF1, (byte)0x0E, (byte)0xF1, (byte)0x0E },
67
68
{ (byte)0x1F, (byte)0xE0, (byte)0x1F, (byte)0xE0,
69
(byte)0x0E, (byte)0xF1, (byte)0x0E, (byte)0xF1 },
70
71
{ (byte)0x01, (byte)0xFE, (byte)0x01, (byte)0xFE,
72
(byte)0x01, (byte)0xFE, (byte)0x01, (byte)0xFE },
73
74
{ (byte)0xFE, (byte)0x01, (byte)0xFE, (byte)0x01,
75
(byte)0xFE, (byte)0x01, (byte)0xFE, (byte)0x01 },
76
77
{ (byte)0x01, (byte)0x1F, (byte)0x01, (byte)0x1F,
78
(byte)0x01, (byte)0x0E, (byte)0x01, (byte)0x0E },
79
80
{ (byte)0x1F, (byte)0x01, (byte)0x1F, (byte)0x01,
81
(byte)0x0E, (byte)0x01, (byte)0x0E, (byte)0x01 },
82
83
{ (byte)0xE0, (byte)0xFE, (byte)0xE0, (byte)0xFE,
84
(byte)0xF1, (byte)0xFE, (byte)0xF1, (byte)0xFE },
85
86
{ (byte)0xFE, (byte)0xE0, (byte)0xFE, (byte)0xE0,
87
(byte)0xFE, (byte)0xF1, (byte)0xFE, (byte)0xF1 },
88
89
{ (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01,
90
(byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01 },
91
92
{ (byte)0xFE, (byte)0xFE, (byte)0xFE, (byte)0xFE,
93
(byte)0xFE, (byte)0xFE, (byte)0xFE, (byte)0xFE },
94
95
{ (byte)0xE0, (byte)0xE0, (byte)0xE0, (byte)0xE0,
96
(byte)0xF1, (byte)0xF1, (byte)0xF1, (byte)0xF1 },
97
98
{ (byte)0x1F, (byte)0x1F, (byte)0x1F, (byte)0x1F,
99
(byte)0x0E, (byte)0x0E, (byte)0x0E, (byte)0x0E }
100
};
101
102
public static void main(String[] args) throws Exception {
103
104
boolean failed = false;
105
106
for (int i = 0; i < weakKeys.length; i++) {
107
DESKeySpec desSpec = new DESKeySpec(weakKeys[i]);
108
if (!DESKeySpec.isWeak(weakKeys[i], 0)) {
109
failed = true;
110
System.out.println("Entry " + i + " should be weak");
111
}
112
}
113
114
if (failed) {
115
throw new Exception("Failed test!!!");
116
}
117
118
System.out.println("Passed test.");
119
}
120
}
121
122