diff options
-rw-r--r-- | crypto/des.c | 2003 |
1 files changed, 854 insertions, 1149 deletions
diff --git a/crypto/des.c b/crypto/des.c index fc5d1b61a0e9..a3c863dddded 100644 --- a/crypto/des.c +++ b/crypto/des.c | |||
@@ -1,18 +1,9 @@ | |||
1 | /* | 1 | /* |
2 | * Cryptographic API. | 2 | * Cryptographic API. |
3 | * | 3 | * |
4 | * DES & Triple DES EDE Cipher Algorithms. | 4 | * DES & Triple DES EDE Cipher Algorithms. |
5 | * | 5 | * |
6 | * Originally released as descore by Dana L. How <how@isl.stanford.edu>. | 6 | * Copyright (c) 2005 Dag Arne Osvik <da@osvik.no> |
7 | * Modified by Raimar Falke <rf13@inf.tu-dresden.de> for the Linux-Kernel. | ||
8 | * Derived from Cryptoapi and Nettle implementations, adapted for in-place | ||
9 | * scatterlist interface. Changed LGPL to GPL per section 3 of the LGPL. | ||
10 | * | ||
11 | * Copyright (c) 1992 Dana L. How. | ||
12 | * Copyright (c) Raimar Falke <rf13@inf.tu-dresden.de> | ||
13 | * Copyright (c) Gisle Sælensminde <gisle@ii.uib.no> | ||
14 | * Copyright (C) 2001 Niels Möller. | ||
15 | * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> | ||
16 | * | 7 | * |
17 | * This program is free software; you can redistribute it and/or modify | 8 | * This program is free software; you can redistribute it and/or modify |
18 | * it under the terms of the GNU General Public License as published by | 9 | * it under the terms of the GNU General Public License as published by |
@@ -20,11 +11,11 @@ | |||
20 | * (at your option) any later version. | 11 | * (at your option) any later version. |
21 | * | 12 | * |
22 | */ | 13 | */ |
14 | |||
15 | #include <linux/bitops.h> | ||
23 | #include <linux/init.h> | 16 | #include <linux/init.h> |
24 | #include <linux/module.h> | 17 | #include <linux/module.h> |
25 | #include <linux/mm.h> | ||
26 | #include <linux/errno.h> | 18 | #include <linux/errno.h> |
27 | #include <asm/scatterlist.h> | ||
28 | #include <linux/crypto.h> | 19 | #include <linux/crypto.h> |
29 | 20 | ||
30 | #define DES_KEY_SIZE 8 | 21 | #define DES_KEY_SIZE 8 |
@@ -35,7 +26,8 @@ | |||
35 | #define DES3_EDE_EXPKEY_WORDS (3 * DES_EXPKEY_WORDS) | 26 | #define DES3_EDE_EXPKEY_WORDS (3 * DES_EXPKEY_WORDS) |
36 | #define DES3_EDE_BLOCK_SIZE DES_BLOCK_SIZE | 27 | #define DES3_EDE_BLOCK_SIZE DES_BLOCK_SIZE |
37 | 28 | ||
38 | #define ROR(d,c,o) ((d) = (d) >> (c) | (d) << (o)) | 29 | #define ROL(x, r) ((x) = rol32((x), (r))) |
30 | #define ROR(x, r) ((x) = ror32((x), (r))) | ||
39 | 31 | ||
40 | struct des_ctx { | 32 | struct des_ctx { |
41 | u32 expkey[DES_EXPKEY_WORDS]; | 33 | u32 expkey[DES_EXPKEY_WORDS]; |
@@ -45,1145 +37,815 @@ struct des3_ede_ctx { | |||
45 | u32 expkey[DES3_EDE_EXPKEY_WORDS]; | 37 | u32 expkey[DES3_EDE_EXPKEY_WORDS]; |
46 | }; | 38 | }; |
47 | 39 | ||
48 | static const u32 des_keymap[] = { | 40 | /* Lookup tables for key expansion */ |
49 | 0x02080008, 0x02082000, 0x00002008, 0x00000000, | 41 | |
50 | 0x02002000, 0x00080008, 0x02080000, 0x02082008, | 42 | static const u8 pc1[256] = { |
51 | 0x00000008, 0x02000000, 0x00082000, 0x00002008, | 43 | 0x00, 0x00, 0x40, 0x04, 0x10, 0x10, 0x50, 0x14, |
52 | 0x00082008, 0x02002008, 0x02000008, 0x02080000, | 44 | 0x04, 0x40, 0x44, 0x44, 0x14, 0x50, 0x54, 0x54, |
53 | 0x00002000, 0x00082008, 0x00080008, 0x02002000, | 45 | 0x02, 0x02, 0x42, 0x06, 0x12, 0x12, 0x52, 0x16, |
54 | 0x02082008, 0x02000008, 0x00000000, 0x00082000, | 46 | 0x06, 0x42, 0x46, 0x46, 0x16, 0x52, 0x56, 0x56, |
55 | 0x02000000, 0x00080000, 0x02002008, 0x02080008, | 47 | 0x80, 0x08, 0xc0, 0x0c, 0x90, 0x18, 0xd0, 0x1c, |
56 | 0x00080000, 0x00002000, 0x02082000, 0x00000008, | 48 | 0x84, 0x48, 0xc4, 0x4c, 0x94, 0x58, 0xd4, 0x5c, |
57 | 0x00080000, 0x00002000, 0x02000008, 0x02082008, | 49 | 0x82, 0x0a, 0xc2, 0x0e, 0x92, 0x1a, 0xd2, 0x1e, |
58 | 0x00002008, 0x02000000, 0x00000000, 0x00082000, | 50 | 0x86, 0x4a, 0xc6, 0x4e, 0x96, 0x5a, 0xd6, 0x5e, |
59 | 0x02080008, 0x02002008, 0x02002000, 0x00080008, | 51 | 0x20, 0x20, 0x60, 0x24, 0x30, 0x30, 0x70, 0x34, |
60 | 0x02082000, 0x00000008, 0x00080008, 0x02002000, | 52 | 0x24, 0x60, 0x64, 0x64, 0x34, 0x70, 0x74, 0x74, |
61 | 0x02082008, 0x00080000, 0x02080000, 0x02000008, | 53 | 0x22, 0x22, 0x62, 0x26, 0x32, 0x32, 0x72, 0x36, |
62 | 0x00082000, 0x00002008, 0x02002008, 0x02080000, | 54 | 0x26, 0x62, 0x66, 0x66, 0x36, 0x72, 0x76, 0x76, |
63 | 0x00000008, 0x02082000, 0x00082008, 0x00000000, | 55 | 0xa0, 0x28, 0xe0, 0x2c, 0xb0, 0x38, 0xf0, 0x3c, |
64 | 0x02000000, 0x02080008, 0x00002000, 0x00082008, | 56 | 0xa4, 0x68, 0xe4, 0x6c, 0xb4, 0x78, 0xf4, 0x7c, |
65 | 57 | 0xa2, 0x2a, 0xe2, 0x2e, 0xb2, 0x3a, 0xf2, 0x3e, | |
66 | 0x08000004, 0x00020004, 0x00000000, 0x08020200, | 58 | 0xa6, 0x6a, 0xe6, 0x6e, 0xb6, 0x7a, 0xf6, 0x7e, |
67 | 0x00020004, 0x00000200, 0x08000204, 0x00020000, | 59 | 0x08, 0x80, 0x48, 0x84, 0x18, 0x90, 0x58, 0x94, |
68 | 0x00000204, 0x08020204, 0x00020200, 0x08000000, | 60 | 0x0c, 0xc0, 0x4c, 0xc4, 0x1c, 0xd0, 0x5c, 0xd4, |
69 | 0x08000200, 0x08000004, 0x08020000, 0x00020204, | 61 | 0x0a, 0x82, 0x4a, 0x86, 0x1a, 0x92, 0x5a, 0x96, |
70 | 0x00020000, 0x08000204, 0x08020004, 0x00000000, | 62 | 0x0e, 0xc2, 0x4e, 0xc6, 0x1e, 0xd2, 0x5e, 0xd6, |
71 | 0x00000200, 0x00000004, 0x08020200, 0x08020004, | 63 | 0x88, 0x88, 0xc8, 0x8c, 0x98, 0x98, 0xd8, 0x9c, |
72 | 0x08020204, 0x08020000, 0x08000000, 0x00000204, | 64 | 0x8c, 0xc8, 0xcc, 0xcc, 0x9c, 0xd8, 0xdc, 0xdc, |
73 | 0x00000004, 0x00020200, 0x00020204, 0x08000200, | 65 | 0x8a, 0x8a, 0xca, 0x8e, 0x9a, 0x9a, 0xda, 0x9e, |
74 | 0x00000204, 0x08000000, 0x08000200, 0x00020204, | 66 | 0x8e, 0xca, 0xce, 0xce, 0x9e, 0xda, 0xde, 0xde, |
75 | 0x08020200, 0x00020004, 0x00000000, 0x08000200, | 67 | 0x28, 0xa0, 0x68, 0xa4, 0x38, 0xb0, 0x78, 0xb4, |
76 | 0x08000000, 0x00000200, 0x08020004, 0x00020000, | 68 | 0x2c, 0xe0, 0x6c, 0xe4, 0x3c, 0xf0, 0x7c, 0xf4, |
77 | 0x00020004, 0x08020204, 0x00020200, 0x00000004, | 69 | 0x2a, 0xa2, 0x6a, 0xa6, 0x3a, 0xb2, 0x7a, 0xb6, |
78 | 0x08020204, 0x00020200, 0x00020000, 0x08000204, | 70 | 0x2e, 0xe2, 0x6e, 0xe6, 0x3e, 0xf2, 0x7e, 0xf6, |
79 | 0x08000004, 0x08020000, 0x00020204, 0x00000000, | 71 | 0xa8, 0xa8, 0xe8, 0xac, 0xb8, 0xb8, 0xf8, 0xbc, |
80 | 0x00000200, 0x08000004, 0x08000204, 0x08020200, | 72 | 0xac, 0xe8, 0xec, 0xec, 0xbc, 0xf8, 0xfc, 0xfc, |
81 | 0x08020000, 0x00000204, 0x00000004, 0x08020004, | 73 | 0xaa, 0xaa, 0xea, 0xae, 0xba, 0xba, 0xfa, 0xbe, |
82 | 74 | 0xae, 0xea, 0xee, 0xee, 0xbe, 0xfa, 0xfe, 0xfe | |
83 | 0x80040100, 0x01000100, 0x80000000, 0x81040100, | ||
84 | 0x00000000, 0x01040000, 0x81000100, 0x80040000, | ||
85 | 0x01040100, 0x81000000, 0x01000000, 0x80000100, | ||
86 | 0x81000000, 0x80040100, 0x00040000, 0x01000000, | ||
87 | 0x81040000, 0x00040100, 0x00000100, 0x80000000, | ||
88 | 0x00040100, 0x81000100, 0x01040000, 0x00000100, | ||
89 | 0x80000100, 0x00000000, 0x80040000, 0x01040100, | ||
90 | 0x01000100, 0x81040000, 0x81040100, 0x00040000, | ||
91 | 0x81040000, 0x80000100, 0x00040000, 0x81000000, | ||
92 | 0x00040100, 0x01000100, 0x80000000, 0x01040000, | ||
93 | 0x81000100, 0x00000000, 0x00000100, 0x80040000, | ||
94 | 0x00000000, 0x81040000, 0x01040100, 0x00000100, | ||
95 | 0x01000000, 0x81040100, 0x80040100, 0x00040000, | ||
96 | 0x81040100, 0x80000000, 0x01000100, 0x80040100, | ||
97 | 0x80040000, 0x00040100, 0x01040000, 0x81000100, | ||
98 | 0x80000100, 0x01000000, 0x81000000, 0x01040100, | ||
99 | |||
100 | 0x04010801, 0x00000000, 0x00010800, 0x04010000, | ||
101 | 0x04000001, 0x00000801, 0x04000800, 0x00010800, | ||
102 | 0x00000800, 0x04010001, 0x00000001, 0x04000800, | ||
103 | 0x00010001, 0x04010800, 0x04010000, 0x00000001, | ||
104 | 0x00010000, 0x04000801, 0x04010001, 0x00000800, | ||
105 | 0x00010801, 0x04000000, 0x00000000, 0x00010001, | ||
106 | 0x04000801, 0x00010801, 0x04010800, 0x04000001, | ||
107 | 0x04000000, 0x00010000, 0x00000801, 0x04010801, | ||
108 | 0x00010001, 0x04010800, 0x04000800, 0x00010801, | ||
109 | 0x04010801, 0x00010001, 0x04000001, 0x00000000, | ||
110 | 0x04000000, 0x00000801, 0x00010000, 0x04010001, | ||
111 | 0x00000800, 0x04000000, 0x00010801, 0x04000801, | ||
112 | 0x04010800, 0x00000800, 0x00000000, 0x04000001, | ||
113 | 0x00000001, 0x04010801, 0x00010800, 0x04010000, | ||
114 | 0x04010001, 0x00010000, 0x00000801, 0x04000800, | ||
115 | 0x04000801, 0x00000001, 0x04010000, 0x00010800, | ||
116 | |||
117 | 0x00000400, 0x00000020, 0x00100020, 0x40100000, | ||
118 | 0x40100420, 0x40000400, 0x00000420, 0x00000000, | ||
119 | 0x00100000, 0x40100020, 0x40000020, 0x00100400, | ||
120 | 0x40000000, 0x00100420, 0x00100400, 0x40000020, | ||
121 | 0x40100020, 0x00000400, 0x40000400, 0x40100420, | ||
122 | 0x00000000, 0x00100020, 0x40100000, 0x00000420, | ||
123 | 0x40100400, 0x40000420, 0x00100420, 0x40000000, | ||
124 | 0x40000420, 0x40100400, 0x00000020, 0x00100000, | ||
125 | 0x40000420, 0x00100400, 0x40100400, 0x40000020, | ||
126 | 0x00000400, 0x00000020, 0x00100000, 0x40100400, | ||
127 | 0x40100020, 0x40000420, 0x00000420, 0x00000000, | ||
128 | 0x00000020, 0x40100000, 0x40000000, 0x00100020, | ||
129 | 0x00000000, 0x40100020, 0x00100020, 0x00000420, | ||
130 | 0x40000020, 0x00000400, 0x40100420, 0x00100000, | ||
131 | 0x00100420, 0x40000000, 0x40000400, 0x40100420, | ||
132 | 0x40100000, 0x00100420, 0x00100400, 0x40000400, | ||
133 | |||
134 | 0x00800000, 0x00001000, 0x00000040, 0x00801042, | ||
135 | 0x00801002, 0x00800040, 0x00001042, 0x00801000, | ||
136 | 0x00001000, 0x00000002, 0x00800002, 0x00001040, | ||
137 | 0x00800042, 0x00801002, 0x00801040, 0x00000000, | ||
138 | 0x00001040, 0x00800000, 0x00001002, 0x00000042, | ||
139 | 0x00800040, 0x00001042, 0x00000000, 0x00800002, | ||
140 | 0x00000002, 0x00800042, 0x00801042, 0x00001002, | ||
141 | 0x00801000, 0x00000040, 0x00000042, 0x00801040, | ||
142 | 0x00801040, 0x00800042, 0x00001002, 0x00801000, | ||
143 | 0x00001000, 0x00000002, 0x00800002, 0x00800040, | ||
144 | 0x00800000, 0x00001040, 0x00801042, 0x00000000, | ||
145 | 0x00001042, 0x00800000, 0x00000040, 0x00001002, | ||
146 | 0x00800042, 0x00000040, 0x00000000, 0x00801042, | ||
147 | 0x00801002, 0x00801040, 0x00000042, 0x00001000, | ||
148 | 0x00001040, 0x00801002, 0x00800040, 0x00000042, | ||
149 | 0x00000002, 0x00001042, 0x00801000, 0x00800002, | ||
150 | |||
151 | 0x10400000, 0x00404010, 0x00000010, 0x10400010, | ||
152 | 0x10004000, 0x00400000, 0x10400010, 0x00004010, | ||
153 | 0x00400010, 0x00004000, 0x00404000, 0x10000000, | ||
154 | 0x10404010, 0x10000010, 0x10000000, 0x10404000, | ||
155 | 0x00000000, 0x10004000, 0x00404010, 0x00000010, | ||
156 | 0x10000010, 0x10404010, 0x00004000, 0x10400000, | ||
157 | 0x10404000, 0x00400010, 0x10004010, 0x00404000, | ||
158 | 0x00004010, 0x00000000, 0x00400000, 0x10004010, | ||
159 | 0x00404010, 0x00000010, 0x10000000, 0x00004000, | ||
160 | 0x10000010, 0x10004000, 0x00404000, 0x10400010, | ||
161 | 0x00000000, 0x00404010, 0x00004010, 0x10404000, | ||
162 | 0x10004000, 0x00400000, 0x10404010, 0x10000000, | ||
163 | 0x10004010, 0x10400000, 0x00400000, 0x10404010, | ||
164 | 0x00004000, 0x00400010, 0x10400010, 0x00004010, | ||
165 | 0x00400010, 0x00000000, 0x10404000, 0x10000010, | ||
166 | 0x10400000, 0x10004010, 0x00000010, 0x00404000, | ||
167 | |||
168 | 0x00208080, 0x00008000, 0x20200000, 0x20208080, | ||
169 | 0x00200000, 0x20008080, 0x20008000, 0x20200000, | ||
170 | 0x20008080, 0x00208080, 0x00208000, 0x20000080, | ||
171 | 0x20200080, 0x00200000, 0x00000000, 0x20008000, | ||
172 | 0x00008000, 0x20000000, 0x00200080, 0x00008080, | ||
173 | 0x20208080, 0x00208000, 0x20000080, 0x00200080, | ||
174 | 0x20000000, 0x00000080, 0x00008080, 0x20208000, | ||
175 | 0x00000080, 0x20200080, 0x20208000, 0x00000000, | ||
176 | 0x00000000, 0x20208080, 0x00200080, 0x20008000, | ||
177 | 0x00208080, 0x00008000, 0x20000080, 0x00200080, | ||
178 | 0x20208000, 0x00000080, 0x00008080, 0x20200000, | ||
179 | 0x20008080, 0x20000000, 0x20200000, 0x00208000, | ||
180 | 0x20208080, 0x00008080, 0x00208000, 0x20200080, | ||
181 | 0x00200000, 0x20000080, 0x20008000, 0x00000000, | ||
182 | 0x00008000, 0x00200000, 0x20200080, 0x00208080, | ||
183 | 0x20000000, 0x20208000, 0x00000080, 0x20008080, | ||
184 | }; | 75 | }; |
185 | 76 | ||
186 | static const u8 rotors[] = { | 77 | static const u8 rs[256] = { |
187 | 34, 13, 5, 46, 47, 18, 32, 41, 11, 53, 33, 20, | 78 | 0x00, 0x00, 0x80, 0x80, 0x02, 0x02, 0x82, 0x82, |
188 | 14, 36, 30, 24, 49, 2, 15, 37, 42, 50, 0, 21, | 79 | 0x04, 0x04, 0x84, 0x84, 0x06, 0x06, 0x86, 0x86, |
189 | 38, 48, 6, 26, 39, 4, 52, 25, 12, 27, 31, 40, | 80 | 0x08, 0x08, 0x88, 0x88, 0x0a, 0x0a, 0x8a, 0x8a, |
190 | 1, 17, 28, 29, 23, 51, 35, 7, 3, 22, 9, 43, | 81 | 0x0c, 0x0c, 0x8c, 0x8c, 0x0e, 0x0e, 0x8e, 0x8e, |
191 | 82 | 0x10, 0x10, 0x90, 0x90, 0x12, 0x12, 0x92, 0x92, | |
192 | 41, 20, 12, 53, 54, 25, 39, 48, 18, 31, 40, 27, | 83 | 0x14, 0x14, 0x94, 0x94, 0x16, 0x16, 0x96, 0x96, |
193 | 21, 43, 37, 0, 1, 9, 22, 44, 49, 2, 7, 28, | 84 | 0x18, 0x18, 0x98, 0x98, 0x1a, 0x1a, 0x9a, 0x9a, |
194 | 45, 55, 13, 33, 46, 11, 6, 32, 19, 34, 38, 47, | 85 | 0x1c, 0x1c, 0x9c, 0x9c, 0x1e, 0x1e, 0x9e, 0x9e, |
195 | 8, 24, 35, 36, 30, 3, 42, 14, 10, 29, 16, 50, | 86 | 0x20, 0x20, 0xa0, 0xa0, 0x22, 0x22, 0xa2, 0xa2, |
196 | 87 | 0x24, 0x24, 0xa4, 0xa4, 0x26, 0x26, 0xa6, 0xa6, | |
197 | 55, 34, 26, 38, 11, 39, 53, 5, 32, 45, 54, 41, | 88 | 0x28, 0x28, 0xa8, 0xa8, 0x2a, 0x2a, 0xaa, 0xaa, |
198 | 35, 2, 51, 14, 15, 23, 36, 3, 8, 16, 21, 42, | 89 | 0x2c, 0x2c, 0xac, 0xac, 0x2e, 0x2e, 0xae, 0xae, |
199 | 6, 12, 27, 47, 31, 25, 20, 46, 33, 48, 52, 4, | 90 | 0x30, 0x30, 0xb0, 0xb0, 0x32, 0x32, 0xb2, 0xb2, |
200 | 22, 7, 49, 50, 44, 17, 1, 28, 24, 43, 30, 9, | 91 | 0x34, 0x34, 0xb4, 0xb4, 0x36, 0x36, 0xb6, 0xb6, |
201 | 92 | 0x38, 0x38, 0xb8, 0xb8, 0x3a, 0x3a, 0xba, 0xba, | |
202 | 12, 48, 40, 52, 25, 53, 38, 19, 46, 6, 11, 55, | 93 | 0x3c, 0x3c, 0xbc, 0xbc, 0x3e, 0x3e, 0xbe, 0xbe, |
203 | 49, 16, 10, 28, 29, 37, 50, 17, 22, 30, 35, 1, | 94 | 0x40, 0x40, 0xc0, 0xc0, 0x42, 0x42, 0xc2, 0xc2, |
204 | 20, 26, 41, 4, 45, 39, 34, 31, 47, 5, 13, 18, | 95 | 0x44, 0x44, 0xc4, 0xc4, 0x46, 0x46, 0xc6, 0xc6, |
205 | 36, 21, 8, 9, 3, 0, 15, 42, 7, 2, 44, 23, | 96 | 0x48, 0x48, 0xc8, 0xc8, 0x4a, 0x4a, 0xca, 0xca, |
206 | 97 | 0x4c, 0x4c, 0xcc, 0xcc, 0x4e, 0x4e, 0xce, 0xce, | |
207 | 26, 5, 54, 13, 39, 38, 52, 33, 31, 20, 25, 12, | 98 | 0x50, 0x50, 0xd0, 0xd0, 0x52, 0x52, 0xd2, 0xd2, |
208 | 8, 30, 24, 42, 43, 51, 9, 0, 36, 44, 49, 15, | 99 | 0x54, 0x54, 0xd4, 0xd4, 0x56, 0x56, 0xd6, 0xd6, |
209 | 34, 40, 55, 18, 6, 53, 48, 45, 4, 19, 27, 32, | 100 | 0x58, 0x58, 0xd8, 0xd8, 0x5a, 0x5a, 0xda, 0xda, |
210 | 50, 35, 22, 23, 17, 14, 29, 1, 21, 16, 3, 37, | 101 | 0x5c, 0x5c, 0xdc, 0xdc, 0x5e, 0x5e, 0xde, 0xde, |
211 | 102 | 0x60, 0x60, 0xe0, 0xe0, 0x62, 0x62, 0xe2, 0xe2, | |
212 | 40, 19, 11, 27, 53, 52, 13, 47, 45, 34, 39, 26, | 103 | 0x64, 0x64, 0xe4, 0xe4, 0x66, 0x66, 0xe6, 0xe6, |
213 | 22, 44, 7, 1, 2, 10, 23, 14, 50, 3, 8, 29, | 104 | 0x68, 0x68, 0xe8, 0xe8, 0x6a, 0x6a, 0xea, 0xea, |
214 | 48, 54, 12, 32, 20, 38, 5, 6, 18, 33, 41, 46, | 105 | 0x6c, 0x6c, 0xec, 0xec, 0x6e, 0x6e, 0xee, 0xee, |
215 | 9, 49, 36, 37, 0, 28, 43, 15, 35, 30, 17, 51, | 106 | 0x70, 0x70, 0xf0, 0xf0, 0x72, 0x72, 0xf2, 0xf2, |
216 | 107 | 0x74, 0x74, 0xf4, 0xf4, 0x76, 0x76, 0xf6, 0xf6, | |
217 | 54, 33, 25, 41, 38, 13, 27, 4, 6, 48, 53, 40, | 108 | 0x78, 0x78, 0xf8, 0xf8, 0x7a, 0x7a, 0xfa, 0xfa, |
218 | 36, 3, 21, 15, 16, 24, 37, 28, 9, 17, 22, 43, | 109 | 0x7c, 0x7c, 0xfc, 0xfc, 0x7e, 0x7e, 0xfe, 0xfe |
219 | 5, 11, 26, 46, 34, 52, 19, 20, 32, 47, 55, 31, | ||
220 | 23, 8, 50, 51, 14, 42, 2, 29, 49, 44, 0, 10, | ||
221 | |||
222 | 11, 47, 39, 55, 52, 27, 41, 18, 20, 5, 38, 54, | ||
223 | 50, 17, 35, 29, 30, 7, 51, 42, 23, 0, 36, 2, | ||
224 | 19, 25, 40, 31, 48, 13, 33, 34, 46, 4, 12, 45, | ||
225 | 37, 22, 9, 10, 28, 1, 16, 43, 8, 3, 14, 24, | ||
226 | |||
227 | 18, 54, 46, 5, 6, 34, 48, 25, 27, 12, 45, 4, | ||
228 | 2, 24, 42, 36, 37, 14, 3, 49, 30, 7, 43, 9, | ||
229 | 26, 32, 47, 38, 55, 20, 40, 41, 53, 11, 19, 52, | ||
230 | 44, 29, 16, 17, 35, 8, 23, 50, 15, 10, 21, 0, | ||
231 | |||
232 | 32, 11, 31, 19, 20, 48, 5, 39, 41, 26, 6, 18, | ||
233 | 16, 7, 1, 50, 51, 28, 17, 8, 44, 21, 2, 23, | ||
234 | 40, 46, 4, 52, 12, 34, 54, 55, 38, 25, 33, 13, | ||
235 | 3, 43, 30, 0, 49, 22, 37, 9, 29, 24, 35, 14, | ||
236 | |||
237 | 46, 25, 45, 33, 34, 5, 19, 53, 55, 40, 20, 32, | ||
238 | 30, 21, 15, 9, 10, 42, 0, 22, 3, 35, 16, 37, | ||
239 | 54, 31, 18, 13, 26, 48, 11, 12, 52, 39, 47, 27, | ||
240 | 17, 2, 44, 14, 8, 36, 51, 23, 43, 7, 49, 28, | ||
241 | |||
242 | 31, 39, 6, 47, 48, 19, 33, 38, 12, 54, 34, 46, | ||
243 | 44, 35, 29, 23, 24, 1, 14, 36, 17, 49, 30, 51, | ||
244 | 11, 45, 32, 27, 40, 5, 25, 26, 13, 53, 4, 41, | ||
245 | 0, 16, 3, 28, 22, 50, 10, 37, 2, 21, 8, 42, | ||
246 | |||
247 | 45, 53, 20, 4, 5, 33, 47, 52, 26, 11, 48, 31, | ||
248 | 3, 49, 43, 37, 7, 15, 28, 50, 0, 8, 44, 10, | ||
249 | 25, 6, 46, 41, 54, 19, 39, 40, 27, 38, 18, 55, | ||
250 | 14, 30, 17, 42, 36, 9, 24, 51, 16, 35, 22, 1, | ||
251 | |||
252 | 6, 38, 34, 18, 19, 47, 4, 13, 40, 25, 5, 45, | ||
253 | 17, 8, 2, 51, 21, 29, 42, 9, 14, 22, 3, 24, | ||
254 | 39, 20, 31, 55, 11, 33, 53, 54, 41, 52, 32, 12, | ||
255 | 28, 44, 0, 1, 50, 23, 7, 10, 30, 49, 36, 15, | ||
256 | |||
257 | 20, 52, 48, 32, 33, 4, 18, 27, 54, 39, 19, 6, | ||
258 | 0, 22, 16, 10, 35, 43, 1, 23, 28, 36, 17, 7, | ||
259 | 53, 34, 45, 12, 25, 47, 38, 11, 55, 13, 46, 26, | ||
260 | 42, 3, 14, 15, 9, 37, 21, 24, 44, 8, 50, 29, | ||
261 | |||
262 | 27, 6, 55, 39, 40, 11, 25, 34, 4, 46, 26, 13, | ||
263 | 7, 29, 23, 17, 42, 50, 8, 30, 35, 43, 24, 14, | ||
264 | 31, 41, 52, 19, 32, 54, 45, 18, 5, 20, 53, 33, | ||
265 | 49, 10, 21, 22, 16, 44, 28, 0, 51, 15, 2, 36, | ||
266 | }; | 110 | }; |
267 | 111 | ||
268 | static const u8 parity[] = { | 112 | static const u32 pc2[1024] = { |
269 | 8,1,0,8,0,8,8,0,0,8,8,0,8,0,2,8,0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,3, | 113 | 0x00000000, 0x00000000, 0x00000000, 0x00000000, |
270 | 0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0,8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8, | 114 | 0x00040000, 0x00000000, 0x04000000, 0x00100000, |
271 | 0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0,8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8, | 115 | 0x00400000, 0x00000008, 0x00000800, 0x40000000, |
272 | 8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8,0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0, | 116 | 0x00440000, 0x00000008, 0x04000800, 0x40100000, |
273 | 0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0,8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8, | 117 | 0x00000400, 0x00000020, 0x08000000, 0x00000100, |
274 | 8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8,0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0, | 118 | 0x00040400, 0x00000020, 0x0c000000, 0x00100100, |
275 | 8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8,0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0, | 119 | 0x00400400, 0x00000028, 0x08000800, 0x40000100, |
276 | 4,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0,8,5,0,8,0,8,8,0,0,8,8,0,8,0,6,8, | 120 | 0x00440400, 0x00000028, 0x0c000800, 0x40100100, |
121 | 0x80000000, 0x00000010, 0x00000000, 0x00800000, | ||
122 | 0x80040000, 0x00000010, 0x04000000, 0x00900000, | ||
123 | 0x80400000, 0x00000018, 0x00000800, 0x40800000, | ||
124 | 0x80440000, 0x00000018, 0x04000800, 0x40900000, | ||
125 | 0x80000400, 0x00000030, 0x08000000, 0x00800100, | ||
126 | 0x80040400, 0x00000030, 0x0c000000, 0x00900100, | ||
127 | 0x80400400, 0x00000038, 0x08000800, 0x40800100, | ||
128 | 0x80440400, 0x00000038, 0x0c000800, 0x40900100, | ||
129 | 0x10000000, 0x00000000, 0x00200000, 0x00001000, | ||
130 | 0x10040000, 0x00000000, 0x04200000, 0x00101000, | ||
131 | 0x10400000, 0x00000008, 0x00200800, 0x40001000, | ||
132 | 0x10440000, 0x00000008, 0x04200800, 0x40101000, | ||
133 | 0x10000400, 0x00000020, 0x08200000, 0x00001100, | ||
134 | 0x10040400, 0x00000020, 0x0c200000, 0x00101100, | ||
135 | 0x10400400, 0x00000028, 0x08200800, 0x40001100, | ||
136 | 0x10440400, 0x00000028, 0x0c200800, 0x40101100, | ||
137 | 0x90000000, 0x00000010, 0x00200000, 0x00801000, | ||
138 | 0x90040000, 0x00000010, 0x04200000, 0x00901000, | ||
139 | 0x90400000, 0x00000018, 0x00200800, 0x40801000, | ||
140 | 0x90440000, 0x00000018, 0x04200800, 0x40901000, | ||
141 | 0x90000400, 0x00000030, 0x08200000, 0x00801100, | ||
142 | 0x90040400, 0x00000030, 0x0c200000, 0x00901100, | ||
143 | 0x90400400, 0x00000038, 0x08200800, 0x40801100, | ||
144 | 0x90440400, 0x00000038, 0x0c200800, 0x40901100, | ||
145 | 0x00000200, 0x00080000, 0x00000000, 0x00000004, | ||
146 | 0x00040200, 0x00080000, 0x04000000, 0x00100004, | ||
147 | 0x00400200, 0x00080008, 0x00000800, 0x40000004, | ||
148 | 0x00440200, 0x00080008, 0x04000800, 0x40100004, | ||
149 | 0x00000600, 0x00080020, 0x08000000, 0x00000104, | ||
150 | 0x00040600, 0x00080020, 0x0c000000, 0x00100104, | ||
151 | 0x00400600, 0x00080028, 0x08000800, 0x40000104, | ||
152 | 0x00440600, 0x00080028, 0x0c000800, 0x40100104, | ||
153 | 0x80000200, 0x00080010, 0x00000000, 0x00800004, | ||
154 | 0x80040200, 0x00080010, 0x04000000, 0x00900004, | ||
155 | 0x80400200, 0x00080018, 0x00000800, 0x40800004, | ||
156 | 0x80440200, 0x00080018, 0x04000800, 0x40900004, | ||
157 | 0x80000600, 0x00080030, 0x08000000, 0x00800104, | ||
158 | 0x80040600, 0x00080030, 0x0c000000, 0x00900104, | ||
159 | 0x80400600, 0x00080038, 0x08000800, 0x40800104, | ||
160 | 0x80440600, 0x00080038, 0x0c000800, 0x40900104, | ||
161 | 0x10000200, 0x00080000, 0x00200000, 0x00001004, | ||
162 | 0x10040200, 0x00080000, 0x04200000, 0x00101004, | ||
163 | 0x10400200, 0x00080008, 0x00200800, 0x40001004, | ||
164 | 0x10440200, 0x00080008, 0x04200800, 0x40101004, | ||
165 | 0x10000600, 0x00080020, 0x08200000, 0x00001104, | ||
166 | 0x10040600, 0x00080020, 0x0c200000, 0x00101104, | ||
167 | 0x10400600, 0x00080028, 0x08200800, 0x40001104, | ||
168 | 0x10440600, 0x00080028, 0x0c200800, 0x40101104, | ||
169 | 0x90000200, 0x00080010, 0x00200000, 0x00801004, | ||
170 | 0x90040200, 0x00080010, 0x04200000, 0x00901004, | ||
171 | 0x90400200, 0x00080018, 0x00200800, 0x40801004, | ||
172 | 0x90440200, 0x00080018, 0x04200800, 0x40901004, | ||
173 | 0x90000600, 0x00080030, 0x08200000, 0x00801104, | ||
174 | 0x90040600, 0x00080030, 0x0c200000, 0x00901104, | ||
175 | 0x90400600, 0x00080038, 0x08200800, 0x40801104, | ||
176 | 0x90440600, 0x00080038, 0x0c200800, 0x40901104, | ||
177 | 0x00000002, 0x00002000, 0x20000000, 0x00000001, | ||
178 | 0x00040002, 0x00002000, 0x24000000, 0x00100001, | ||
179 | 0x00400002, 0x00002008, 0x20000800, 0x40000001, | ||
180 | 0x00440002, 0x00002008, 0x24000800, 0x40100001, | ||
181 | 0x00000402, 0x00002020, 0x28000000, 0x00000101, | ||
182 | 0x00040402, 0x00002020, 0x2c000000, 0x00100101, | ||
183 | 0x00400402, 0x00002028, 0x28000800, 0x40000101, | ||
184 | 0x00440402, 0x00002028, 0x2c000800, 0x40100101, | ||
185 | 0x80000002, 0x00002010, 0x20000000, 0x00800001, | ||
186 | 0x80040002, 0x00002010, 0x24000000, 0x00900001, | ||
187 | 0x80400002, 0x00002018, 0x20000800, 0x40800001, | ||
188 | 0x80440002, 0x00002018, 0x24000800, 0x40900001, | ||
189 | 0x80000402, 0x00002030, 0x28000000, 0x00800101, | ||
190 | 0x80040402, 0x00002030, 0x2c000000, 0x00900101, | ||
191 | 0x80400402, 0x00002038, 0x28000800, 0x40800101, | ||
192 | 0x80440402, 0x00002038, 0x2c000800, 0x40900101, | ||
193 | 0x10000002, 0x00002000, 0x20200000, 0x00001001, | ||
194 | 0x10040002, 0x00002000, 0x24200000, 0x00101001, | ||
195 | 0x10400002, 0x00002008, 0x20200800, 0x40001001, | ||
196 | 0x10440002, 0x00002008, 0x24200800, 0x40101001, | ||
197 | 0x10000402, 0x00002020, 0x28200000, 0x00001101, | ||
198 | 0x10040402, 0x00002020, 0x2c200000, 0x00101101, | ||
199 | 0x10400402, 0x00002028, 0x28200800, 0x40001101, | ||
200 | 0x10440402, 0x00002028, 0x2c200800, 0x40101101, | ||
201 | 0x90000002, 0x00002010, 0x20200000, 0x00801001, | ||
202 | 0x90040002, 0x00002010, 0x24200000, 0x00901001, | ||
203 | 0x90400002, 0x00002018, 0x20200800, 0x40801001, | ||
204 | 0x90440002, 0x00002018, 0x24200800, 0x40901001, | ||
205 | 0x90000402, 0x00002030, 0x28200000, 0x00801101, | ||
206 | 0x90040402, 0x00002030, 0x2c200000, 0x00901101, | ||
207 | 0x90400402, 0x00002038, 0x28200800, 0x40801101, | ||
208 | 0x90440402, 0x00002038, 0x2c200800, 0x40901101, | ||
209 | 0x00000202, 0x00082000, 0x20000000, 0x00000005, | ||
210 | 0x00040202, 0x00082000, 0x24000000, 0x00100005, | ||
211 | 0x00400202, 0x00082008, 0x20000800, 0x40000005, | ||
212 | 0x00440202, 0x00082008, 0x24000800, 0x40100005, | ||
213 | 0x00000602, 0x00082020, 0x28000000, 0x00000105, | ||
214 | 0x00040602, 0x00082020, 0x2c000000, 0x00100105, | ||
215 | 0x00400602, 0x00082028, 0x28000800, 0x40000105, | ||
216 | 0x00440602, 0x00082028, 0x2c000800, 0x40100105, | ||
217 | 0x80000202, 0x00082010, 0x20000000, 0x00800005, | ||
218 | 0x80040202, 0x00082010, 0x24000000, 0x00900005, | ||
219 | 0x80400202, 0x00082018, 0x20000800, 0x40800005, | ||
220 | 0x80440202, 0x00082018, 0x24000800, 0x40900005, | ||
221 | 0x80000602, 0x00082030, 0x28000000, 0x00800105, | ||
222 | 0x80040602, 0x00082030, 0x2c000000, 0x00900105, | ||
223 | 0x80400602, 0x00082038, 0x28000800, 0x40800105, | ||
224 | 0x80440602, 0x00082038, 0x2c000800, 0x40900105, | ||
225 | 0x10000202, 0x00082000, 0x20200000, 0x00001005, | ||
226 | 0x10040202, 0x00082000, 0x24200000, 0x00101005, | ||
227 | 0x10400202, 0x00082008, 0x20200800, 0x40001005, | ||
228 | 0x10440202, 0x00082008, 0x24200800, 0x40101005, | ||
229 | 0x10000602, 0x00082020, 0x28200000, 0x00001105, | ||
230 | 0x10040602, 0x00082020, 0x2c200000, 0x00101105, | ||
231 | 0x10400602, 0x00082028, 0x28200800, 0x40001105, | ||
232 | 0x10440602, 0x00082028, 0x2c200800, 0x40101105, | ||
233 | 0x90000202, 0x00082010, 0x20200000, 0x00801005, | ||
234 | 0x90040202, 0x00082010, 0x24200000, 0x00901005, | ||
235 | 0x90400202, 0x00082018, 0x20200800, 0x40801005, | ||
236 | 0x90440202, 0x00082018, 0x24200800, 0x40901005, | ||
237 | 0x90000602, 0x00082030, 0x28200000, 0x00801105, | ||
238 | 0x90040602, 0x00082030, 0x2c200000, 0x00901105, | ||
239 | 0x90400602, 0x00082038, 0x28200800, 0x40801105, | ||
240 | 0x90440602, 0x00082038, 0x2c200800, 0x40901105, | ||
241 | |||
242 | 0x00000000, 0x00000000, 0x00000000, 0x00000000, | ||
243 | 0x00000000, 0x00000008, 0x00080000, 0x10000000, | ||
244 | 0x02000000, 0x00000000, 0x00000080, 0x00001000, | ||
245 | 0x02000000, 0x00000008, 0x00080080, 0x10001000, | ||
246 | 0x00004000, 0x00000000, 0x00000040, 0x00040000, | ||
247 | 0x00004000, 0x00000008, 0x00080040, 0x10040000, | ||
248 | 0x02004000, 0x00000000, 0x000000c0, 0x00041000, | ||
249 | 0x02004000, 0x00000008, 0x000800c0, 0x10041000, | ||
250 | 0x00020000, 0x00008000, 0x08000000, 0x00200000, | ||
251 | 0x00020000, 0x00008008, 0x08080000, 0x10200000, | ||
252 | 0x02020000, 0x00008000, 0x08000080, 0x00201000, | ||
253 | 0x02020000, 0x00008008, 0x08080080, 0x10201000, | ||
254 | 0x00024000, 0x00008000, 0x08000040, 0x00240000, | ||
255 | 0x00024000, 0x00008008, 0x08080040, 0x10240000, | ||
256 | 0x02024000, 0x00008000, 0x080000c0, 0x00241000, | ||
257 | 0x02024000, 0x00008008, 0x080800c0, 0x10241000, | ||
258 | 0x00000000, 0x01000000, 0x00002000, 0x00000020, | ||
259 | 0x00000000, 0x01000008, 0x00082000, 0x10000020, | ||
260 | 0x02000000, 0x01000000, 0x00002080, 0x00001020, | ||
261 | 0x02000000, 0x01000008, 0x00082080, 0x10001020, | ||
262 | 0x00004000, 0x01000000, 0x00002040, 0x00040020, | ||
263 | 0x00004000, 0x01000008, 0x00082040, 0x10040020, | ||
264 | 0x02004000, 0x01000000, 0x000020c0, 0x00041020, | ||
265 | 0x02004000, 0x01000008, 0x000820c0, 0x10041020, | ||
266 | 0x00020000, 0x01008000, 0x08002000, 0x00200020, | ||
267 | 0x00020000, 0x01008008, 0x08082000, 0x10200020, | ||
268 | 0x02020000, 0x01008000, 0x08002080, 0x00201020, | ||
269 | 0x02020000, 0x01008008, 0x08082080, 0x10201020, | ||
270 | 0x00024000, 0x01008000, 0x08002040, 0x00240020, | ||
271 | 0x00024000, 0x01008008, 0x08082040, 0x10240020, | ||
272 | 0x02024000, 0x01008000, 0x080020c0, 0x00241020, | ||
273 | 0x02024000, 0x01008008, 0x080820c0, 0x10241020, | ||
274 | 0x00000400, 0x04000000, 0x00100000, 0x00000004, | ||
275 | 0x00000400, 0x04000008, 0x00180000, 0x10000004, | ||
276 | 0x02000400, 0x04000000, 0x00100080, 0x00001004, | ||
277 | 0x02000400, 0x04000008, 0x00180080, 0x10001004, | ||
278 | 0x00004400, 0x04000000, 0x00100040, 0x00040004, | ||
279 | 0x00004400, 0x04000008, 0x00180040, 0x10040004, | ||
280 | 0x02004400, 0x04000000, 0x001000c0, 0x00041004, | ||
281 | 0x02004400, 0x04000008, 0x001800c0, 0x10041004, | ||
282 | 0x00020400, 0x04008000, 0x08100000, 0x00200004, | ||
283 | 0x00020400, 0x04008008, 0x08180000, 0x10200004, | ||
284 | 0x02020400, 0x04008000, 0x08100080, 0x00201004, | ||
285 | 0x02020400, 0x04008008, 0x08180080, 0x10201004, | ||
286 | 0x00024400, 0x04008000, 0x08100040, 0x00240004, | ||
287 | 0x00024400, 0x04008008, 0x08180040, 0x10240004, | ||
288 | 0x02024400, 0x04008000, 0x081000c0, 0x00241004, | ||
289 | 0x02024400, 0x04008008, 0x081800c0, 0x10241004, | ||
290 | 0x00000400, 0x05000000, 0x00102000, 0x00000024, | ||
291 | 0x00000400, 0x05000008, 0x00182000, 0x10000024, | ||
292 | 0x02000400, 0x05000000, 0x00102080, 0x00001024, | ||
293 | 0x02000400, 0x05000008, 0x00182080, 0x10001024, | ||
294 | 0x00004400, 0x05000000, 0x00102040, 0x00040024, | ||
295 | 0x00004400, 0x05000008, 0x00182040, 0x10040024, | ||
296 | 0x02004400, 0x05000000, 0x001020c0, 0x00041024, | ||
297 | 0x02004400, 0x05000008, 0x001820c0, 0x10041024, | ||
298 | 0x00020400, 0x05008000, 0x08102000, 0x00200024, | ||
299 | 0x00020400, 0x05008008, 0x08182000, 0x10200024, | ||
300 | 0x02020400, 0x05008000, 0x08102080, 0x00201024, | ||
301 | 0x02020400, 0x05008008, 0x08182080, 0x10201024, | ||
302 | 0x00024400, 0x05008000, 0x08102040, 0x00240024, | ||
303 | 0x00024400, 0x05008008, 0x08182040, 0x10240024, | ||
304 | 0x02024400, 0x05008000, 0x081020c0, 0x00241024, | ||
305 | 0x02024400, 0x05008008, 0x081820c0, 0x10241024, | ||
306 | 0x00000800, 0x00010000, 0x20000000, 0x00000010, | ||
307 | 0x00000800, 0x00010008, 0x20080000, 0x10000010, | ||
308 | 0x02000800, 0x00010000, 0x20000080, 0x00001010, | ||
309 | 0x02000800, 0x00010008, 0x20080080, 0x10001010, | ||
310 | 0x00004800, 0x00010000, 0x20000040, 0x00040010, | ||
311 | 0x00004800, 0x00010008, 0x20080040, 0x10040010, | ||
312 | 0x02004800, 0x00010000, 0x200000c0, 0x00041010, | ||
313 | 0x02004800, 0x00010008, 0x200800c0, 0x10041010, | ||
314 | 0x00020800, 0x00018000, 0x28000000, 0x00200010, | ||
315 | 0x00020800, 0x00018008, 0x28080000, 0x10200010, | ||
316 | 0x02020800, 0x00018000, 0x28000080, 0x00201010, | ||
317 | 0x02020800, 0x00018008, 0x28080080, 0x10201010, | ||
318 | 0x00024800, 0x00018000, 0x28000040, 0x00240010, | ||
319 | 0x00024800, 0x00018008, 0x28080040, 0x10240010, | ||
320 | 0x02024800, 0x00018000, 0x280000c0, 0x00241010, | ||
321 | 0x02024800, 0x00018008, 0x280800c0, 0x10241010, | ||
322 | 0x00000800, 0x01010000, 0x20002000, 0x00000030, | ||
323 | 0x00000800, 0x01010008, 0x20082000, 0x10000030, | ||
324 | 0x02000800, 0x01010000, 0x20002080, 0x00001030, | ||
325 | 0x02000800, 0x01010008, 0x20082080, 0x10001030, | ||
326 | 0x00004800, 0x01010000, 0x20002040, 0x00040030, | ||
327 | 0x00004800, 0x01010008, 0x20082040, 0x10040030, | ||
328 | 0x02004800, 0x01010000, 0x200020c0, 0x00041030, | ||
329 | 0x02004800, 0x01010008, 0x200820c0, 0x10041030, | ||
330 | 0x00020800, 0x01018000, 0x28002000, 0x00200030, | ||
331 | 0x00020800, 0x01018008, 0x28082000, 0x10200030, | ||
332 | 0x02020800, 0x01018000, 0x28002080, 0x00201030, | ||
333 | 0x02020800, 0x01018008, 0x28082080, 0x10201030, | ||
334 | 0x00024800, 0x01018000, 0x28002040, 0x00240030, | ||
335 | 0x00024800, 0x01018008, 0x28082040, 0x10240030, | ||
336 | 0x02024800, 0x01018000, 0x280020c0, 0x00241030, | ||
337 | 0x02024800, 0x01018008, 0x280820c0, 0x10241030, | ||
338 | 0x00000c00, 0x04010000, 0x20100000, 0x00000014, | ||
339 | 0x00000c00, 0x04010008, 0x20180000, 0x10000014, | ||
340 | 0x02000c00, 0x04010000, 0x20100080, 0x00001014, | ||
341 | 0x02000c00, 0x04010008, 0x20180080, 0x10001014, | ||
342 | 0x00004c00, 0x04010000, 0x20100040, 0x00040014, | ||
343 | 0x00004c00, 0x04010008, 0x20180040, 0x10040014, | ||
344 | 0x02004c00, 0x04010000, 0x201000c0, 0x00041014, | ||
345 | 0x02004c00, 0x04010008, 0x201800c0, 0x10041014, | ||
346 | 0x00020c00, 0x04018000, 0x28100000, 0x00200014, | ||
347 | 0x00020c00, 0x04018008, 0x28180000, 0x10200014, | ||
348 | 0x02020c00, 0x04018000, 0x28100080, 0x00201014, | ||
349 | 0x02020c00, 0x04018008, 0x28180080, 0x10201014, | ||
350 | 0x00024c00, 0x04018000, 0x28100040, 0x00240014, | ||
351 | 0x00024c00, 0x04018008, 0x28180040, 0x10240014, | ||
352 | 0x02024c00, 0x04018000, 0x281000c0, 0x00241014, | ||
353 | 0x02024c00, 0x04018008, 0x281800c0, 0x10241014, | ||
354 | 0x00000c00, 0x05010000, 0x20102000, 0x00000034, | ||
355 | 0x00000c00, 0x05010008, 0x20182000, 0x10000034, | ||
356 | 0x02000c00, 0x05010000, 0x20102080, 0x00001034, | ||
357 | 0x02000c00, 0x05010008, 0x20182080, 0x10001034, | ||
358 | 0x00004c00, 0x05010000, 0x20102040, 0x00040034, | ||
359 | 0x00004c00, 0x05010008, 0x20182040, 0x10040034, | ||
360 | 0x02004c00, 0x05010000, 0x201020c0, 0x00041034, | ||
361 | 0x02004c00, 0x05010008, 0x201820c0, 0x10041034, | ||
362 | 0x00020c00, 0x05018000, 0x28102000, 0x00200034, | ||
363 | 0x00020c00, 0x05018008, 0x28182000, 0x10200034, | ||
364 | 0x02020c00, 0x05018000, 0x28102080, 0x00201034, | ||
365 | 0x02020c00, 0x05018008, 0x28182080, 0x10201034, | ||
366 | 0x00024c00, 0x05018000, 0x28102040, 0x00240034, | ||
367 | 0x00024c00, 0x05018008, 0x28182040, 0x10240034, | ||
368 | 0x02024c00, 0x05018000, 0x281020c0, 0x00241034, | ||
369 | 0x02024c00, 0x05018008, 0x281820c0, 0x10241034 | ||
277 | }; | 370 | }; |
278 | 371 | ||
372 | /* S-box lookup tables */ | ||
373 | |||
374 | static const u32 S1[64] = { | ||
375 | 0x01010400, 0x00000000, 0x00010000, 0x01010404, | ||
376 | 0x01010004, 0x00010404, 0x00000004, 0x00010000, | ||
377 | 0x00000400, 0x01010400, 0x01010404, 0x00000400, | ||
378 | 0x01000404, 0x01010004, 0x01000000, 0x00000004, | ||
379 | 0x00000404, 0x01000400, 0x01000400, 0x00010400, | ||
380 | 0x00010400, 0x01010000, 0x01010000, 0x01000404, | ||
381 | 0x00010004, 0x01000004, 0x01000004, 0x00010004, | ||
382 | 0x00000000, 0x00000404, 0x00010404, 0x01000000, | ||
383 | 0x00010000, 0x01010404, 0x00000004, 0x01010000, | ||
384 | 0x01010400, 0x01000000, 0x01000000, 0x00000400, | ||
385 | 0x01010004, 0x00010000, 0x00010400, 0x01000004, | ||
386 | 0x00000400, 0x00000004, 0x01000404, 0x00010404, | ||
387 | 0x01010404, 0x00010004, 0x01010000, 0x01000404, | ||
388 | 0x01000004, 0x00000404, 0x00010404, 0x01010400, | ||
389 | 0x00000404, 0x01000400, 0x01000400, 0x00000000, | ||
390 | 0x00010004, 0x00010400, 0x00000000, 0x01010004 | ||
391 | }; | ||
279 | 392 | ||
280 | static void des_small_fips_encrypt(u32 *expkey, u8 *dst, const u8 *src) | 393 | static const u32 S2[64] = { |
281 | { | 394 | 0x80108020, 0x80008000, 0x00008000, 0x00108020, |
282 | u32 x, y, z; | 395 | 0x00100000, 0x00000020, 0x80100020, 0x80008020, |
283 | 396 | 0x80000020, 0x80108020, 0x80108000, 0x80000000, | |
284 | x = src[7]; | 397 | 0x80008000, 0x00100000, 0x00000020, 0x80100020, |
285 | x <<= 8; | 398 | 0x00108000, 0x00100020, 0x80008020, 0x00000000, |
286 | x |= src[6]; | 399 | 0x80000000, 0x00008000, 0x00108020, 0x80100000, |
287 | x <<= 8; | 400 | 0x00100020, 0x80000020, 0x00000000, 0x00108000, |
288 | x |= src[5]; | 401 | 0x00008020, 0x80108000, 0x80100000, 0x00008020, |
289 | x <<= 8; | 402 | 0x00000000, 0x00108020, 0x80100020, 0x00100000, |
290 | x |= src[4]; | 403 | 0x80008020, 0x80100000, 0x80108000, 0x00008000, |
291 | y = src[3]; | 404 | 0x80100000, 0x80008000, 0x00000020, 0x80108020, |
292 | y <<= 8; | 405 | 0x00108020, 0x00000020, 0x00008000, 0x80000000, |
293 | y |= src[2]; | 406 | 0x00008020, 0x80108000, 0x00100000, 0x80000020, |
294 | y <<= 8; | 407 | 0x00100020, 0x80008020, 0x80000020, 0x00100020, |
295 | y |= src[1]; | 408 | 0x00108000, 0x00000000, 0x80008000, 0x00008020, |
296 | y <<= 8; | 409 | 0x80000000, 0x80100020, 0x80108020, 0x00108000 |
297 | y |= src[0]; | 410 | }; |
298 | z = ((x >> 004) ^ y) & 0x0F0F0F0FL; | ||
299 | x ^= z << 004; | ||
300 | y ^= z; | ||
301 | z = ((y >> 020) ^ x) & 0x0000FFFFL; | ||
302 | y ^= z << 020; | ||
303 | x ^= z; | ||
304 | z = ((x >> 002) ^ y) & 0x33333333L; | ||
305 | x ^= z << 002; | ||
306 | y ^= z; | ||
307 | z = ((y >> 010) ^ x) & 0x00FF00FFL; | ||
308 | y ^= z << 010; | ||
309 | x ^= z; | ||
310 | x = x >> 1 | x << 31; | ||
311 | z = (x ^ y) & 0x55555555L; | ||
312 | y ^= z; | ||
313 | x ^= z; | ||
314 | y = y >> 1 | y << 31; | ||
315 | z = expkey[0]; | ||
316 | z ^= y; | ||
317 | x ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); | ||
318 | z >>= 8; | ||
319 | x ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); | ||
320 | z >>= 8; | ||
321 | x ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); | ||
322 | z >>= 8; | ||
323 | x ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); | ||
324 | z = expkey[1]; | ||
325 | z ^= y; | ||
326 | z = z << 4 | z >> 28; | ||
327 | x ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); | ||
328 | z >>= 8; | ||
329 | x ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); | ||
330 | z >>= 8; | ||
331 | x ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); | ||
332 | z >>= 8; | ||
333 | x ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); | ||
334 | z = expkey[2]; | ||
335 | z ^= x; | ||
336 | y ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); | ||
337 | z >>= 8; | ||
338 | y ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); | ||
339 | z >>= 8; | ||
340 | y ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); | ||
341 | z >>= 8; | ||
342 | y ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); | ||
343 | z = expkey[3]; | ||
344 | z ^= x; | ||
345 | z = z << 4 | z >> 28; | ||
346 | y ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); | ||
347 | z >>= 8; | ||
348 | y ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); | ||
349 | z >>= 8; | ||
350 | y ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); | ||
351 | z >>= 8; | ||
352 | y ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); | ||
353 | z = expkey[4]; | ||
354 | z ^= y; | ||
355 | x ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); | ||
356 | z >>= 8; | ||
357 | x ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); | ||
358 | z >>= 8; | ||
359 | x ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); | ||
360 | z >>= 8; | ||
361 | x ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); | ||
362 | z = expkey[5]; | ||
363 | z ^= y; | ||
364 | z = z << 4 | z >> 28; | ||
365 | x ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); | ||
366 | z >>= 8; | ||
367 | x ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); | ||
368 | z >>= 8; | ||
369 | x ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); | ||
370 | z >>= 8; | ||
371 | x ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); | ||
372 | z = expkey[6]; | ||
373 | z ^= x; | ||
374 | y ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); | ||
375 | z >>= 8; | ||
376 | y ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); | ||
377 | z >>= 8; | ||
378 | y ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); | ||
379 | z >>= 8; | ||
380 | y ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); | ||
381 | z = expkey[7]; | ||
382 | z ^= x; | ||
383 | z = z << 4 | z >> 28; | ||
384 | y ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); | ||
385 | z >>= 8; | ||
386 | y ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); | ||
387 | z >>= 8; | ||
388 | y ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); | ||
389 | z >>= 8; | ||
390 | y ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); | ||
391 | z = expkey[8]; | ||
392 | z ^= y; | ||
393 | x ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); | ||
394 | z >>= 8; | ||
395 | x ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); | ||
396 | z >>= 8; | ||
397 | x ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); | ||
398 | z >>= 8; | ||
399 | x ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); | ||
400 | z = expkey[9]; | ||
401 | z ^= y; | ||
402 | z = z << 4 | z >> 28; | ||
403 | x ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); | ||
404 | z >>= 8; | ||
405 | x ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); | ||
406 | z >>= 8; | ||
407 | x ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); | ||
408 | z >>= 8; | ||
409 | x ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); | ||
410 | z = expkey[10]; | ||
411 | z ^= x; | ||
412 | y ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); | ||
413 | z >>= 8; | ||
414 | y ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); | ||
415 | z >>= 8; | ||
416 | y ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); | ||
417 | z >>= 8; | ||
418 | y ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); | ||
419 | z = expkey[11]; | ||
420 | z ^= x; | ||
421 | z = z << 4 | z >> 28; | ||
422 | y ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); | ||
423 | z >>= 8; | ||
424 | y ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); | ||
425 | z >>= 8; | ||
426 | y ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); | ||
427 | z >>= 8; | ||
428 | y ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); | ||
429 | z = expkey[12]; | ||
430 | z ^= y; | ||
431 | x ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); | ||
432 | z >>= 8; | ||
433 | x ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); | ||
434 | z >>= 8; | ||
435 | x ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); | ||
436 | z >>= 8; | ||
437 | x ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); | ||
438 | z = expkey[13]; | ||
439 | z ^= y; | ||
440 | z = z << 4 | z >> 28; | ||
441 | x ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); | ||
442 | z >>= 8; | ||
443 | x ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); | ||
444 | z >>= 8; | ||
445 | x ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); | ||
446 | z >>= 8; | ||
447 | x ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); | ||
448 | z = expkey[14]; | ||
449 | z ^= x; | ||
450 | y ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); | ||
451 | z >>= 8; | ||
452 | y ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); | ||
453 | z >>= 8; | ||
454 | y ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); | ||
455 | z >>= 8; | ||
456 | y ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); | ||
457 | z = expkey[15]; | ||
458 | z ^= x; | ||
459 | z = z << 4 | z >> 28; | ||
460 | y ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); | ||
461 | z >>= 8; | ||
462 | y ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); | ||
463 | z >>= 8; | ||
464 | y ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); | ||
465 | z >>= 8; | ||
466 | y ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); | ||
467 | z = expkey[16]; | ||
468 | z ^= y; | ||
469 | x ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); | ||
470 | z >>= 8; | ||
471 | x ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); | ||
472 | z >>= 8; | ||
473 | x ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); | ||
474 | z >>= 8; | ||
475 | x ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); | ||
476 | z = expkey[17]; | ||
477 | z ^= y; | ||
478 | z = z << 4 | z >> 28; | ||
479 | x ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); | ||
480 | z >>= 8; | ||
481 | x ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); | ||
482 | z >>= 8; | ||
483 | x ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); | ||
484 | z >>= 8; | ||
485 | x ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); | ||
486 | z = expkey[18]; | ||
487 | z ^= x; | ||
488 | y ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); | ||
489 | z >>= 8; | ||
490 | y ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); | ||
491 | z >>= 8; | ||
492 | y ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); | ||
493 | z >>= 8; | ||
494 | y ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); | ||
495 | z = expkey[19]; | ||
496 | z ^= x; | ||
497 | z = z << 4 | z >> 28; | ||
498 | y ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); | ||
499 | z >>= 8; | ||
500 | y ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); | ||
501 | z >>= 8; | ||
502 | y ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); | ||
503 | z >>= 8; | ||
504 | y ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); | ||
505 | z = expkey[20]; | ||
506 | z ^= y; | ||
507 | x ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); | ||
508 | z >>= 8; | ||
509 | x ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); | ||
510 | z >>= 8; | ||
511 | x ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); | ||
512 | z >>= 8; | ||
513 | x ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); | ||
514 | z = expkey[21]; | ||
515 | z ^= y; | ||
516 | z = z << 4 | z >> 28; | ||
517 | x ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); | ||
518 | z >>= 8; | ||
519 | x ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); | ||
520 | z >>= 8; | ||
521 | x ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); | ||
522 | z >>= 8; | ||
523 | x ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); | ||
524 | z = expkey[22]; | ||
525 | z ^= x; | ||
526 | y ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); | ||
527 | z >>= 8; | ||
528 | y ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); | ||
529 | z >>= 8; | ||
530 | y ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); | ||
531 | z >>= 8; | ||
532 | y ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); | ||
533 | z = expkey[23]; | ||
534 | z ^= x; | ||
535 | z = z << 4 | z >> 28; | ||
536 | y ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); | ||
537 | z >>= 8; | ||
538 | y ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); | ||
539 | z >>= 8; | ||
540 | y ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); | ||
541 | z >>= 8; | ||
542 | y ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); | ||
543 | z = expkey[24]; | ||
544 | z ^= y; | ||
545 | x ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); | ||
546 | z >>= 8; | ||
547 | x ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); | ||
548 | z >>= 8; | ||
549 | x ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); | ||
550 | z >>= 8; | ||
551 | x ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); | ||
552 | z = expkey[25]; | ||
553 | z ^= y; | ||
554 | z = z << 4 | z >> 28; | ||
555 | x ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); | ||
556 | z >>= 8; | ||
557 | x ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); | ||
558 | z >>= 8; | ||
559 | x ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); | ||
560 | z >>= 8; | ||
561 | x ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); | ||
562 | z = expkey[26]; | ||
563 | z ^= x; | ||
564 | y ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); | ||
565 | z >>= 8; | ||
566 | y ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); | ||
567 | z >>= 8; | ||
568 | y ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); | ||
569 | z >>= 8; | ||
570 | y ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); | ||
571 | z = expkey[27]; | ||
572 | z ^= x; | ||
573 | z = z << 4 | z >> 28; | ||
574 | y ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); | ||
575 | z >>= 8; | ||
576 | y ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); | ||
577 | z >>= 8; | ||
578 | y ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); | ||
579 | z >>= 8; | ||
580 | y ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); | ||
581 | z = expkey[28]; | ||
582 | z ^= y; | ||
583 | x ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); | ||
584 | z >>= 8; | ||
585 | x ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); | ||
586 | z >>= 8; | ||
587 | x ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); | ||
588 | z >>= 8; | ||
589 | x ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); | ||
590 | z = expkey[29]; | ||
591 | z ^= y; | ||
592 | z = z << 4 | z >> 28; | ||
593 | x ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); | ||
594 | z >>= 8; | ||
595 | x ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); | ||
596 | z >>= 8; | ||
597 | x ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); | ||
598 | z >>= 8; | ||
599 | x ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); | ||
600 | z = expkey[30]; | ||
601 | z ^= x; | ||
602 | y ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); | ||
603 | z >>= 8; | ||
604 | y ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); | ||
605 | z >>= 8; | ||
606 | y ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); | ||
607 | z >>= 8; | ||
608 | y ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); | ||
609 | z = expkey[31]; | ||
610 | z ^= x; | ||
611 | z = z << 4 | z >> 28; | ||
612 | y ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); | ||
613 | z >>= 8; | ||
614 | y ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); | ||
615 | z >>= 8; | ||
616 | y ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); | ||
617 | z >>= 8; | ||
618 | y ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); | ||
619 | x = x << 1 | x >> 31; | ||
620 | z = (x ^ y) & 0x55555555L; | ||
621 | y ^= z; | ||
622 | x ^= z; | ||
623 | y = y << 1 | y >> 31; | ||
624 | z = ((x >> 010) ^ y) & 0x00FF00FFL; | ||
625 | x ^= z << 010; | ||
626 | y ^= z; | ||
627 | z = ((y >> 002) ^ x) & 0x33333333L; | ||
628 | y ^= z << 002; | ||
629 | x ^= z; | ||
630 | z = ((x >> 020) ^ y) & 0x0000FFFFL; | ||
631 | x ^= z << 020; | ||
632 | y ^= z; | ||
633 | z = ((y >> 004) ^ x) & 0x0F0F0F0FL; | ||
634 | y ^= z << 004; | ||
635 | x ^= z; | ||
636 | dst[0] = x; | ||
637 | x >>= 8; | ||
638 | dst[1] = x; | ||
639 | x >>= 8; | ||
640 | dst[2] = x; | ||
641 | x >>= 8; | ||
642 | dst[3] = x; | ||
643 | dst[4] = y; | ||
644 | y >>= 8; | ||
645 | dst[5] = y; | ||
646 | y >>= 8; | ||
647 | dst[6] = y; | ||
648 | y >>= 8; | ||
649 | dst[7] = y; | ||
650 | } | ||
651 | 411 | ||
652 | static void des_small_fips_decrypt(u32 *expkey, u8 *dst, const u8 *src) | 412 | static const u32 S3[64] = { |
653 | { | 413 | 0x00000208, 0x08020200, 0x00000000, 0x08020008, |
654 | u32 x, y, z; | 414 | 0x08000200, 0x00000000, 0x00020208, 0x08000200, |
655 | 415 | 0x00020008, 0x08000008, 0x08000008, 0x00020000, | |
656 | x = src[7]; | 416 | 0x08020208, 0x00020008, 0x08020000, 0x00000208, |
657 | x <<= 8; | 417 | 0x08000000, 0x00000008, 0x08020200, 0x00000200, |
658 | x |= src[6]; | 418 | 0x00020200, 0x08020000, 0x08020008, 0x00020208, |
659 | x <<= 8; | 419 | 0x08000208, 0x00020200, 0x00020000, 0x08000208, |
660 | x |= src[5]; | 420 | 0x00000008, 0x08020208, 0x00000200, 0x08000000, |
661 | x <<= 8; | 421 | 0x08020200, 0x08000000, 0x00020008, 0x00000208, |
662 | x |= src[4]; | 422 | 0x00020000, 0x08020200, 0x08000200, 0x00000000, |
663 | y = src[3]; | 423 | 0x00000200, 0x00020008, 0x08020208, 0x08000200, |
664 | y <<= 8; | 424 | 0x08000008, 0x00000200, 0x00000000, 0x08020008, |
665 | y |= src[2]; | 425 | 0x08000208, 0x00020000, 0x08000000, 0x08020208, |
666 | y <<= 8; | 426 | 0x00000008, 0x00020208, 0x00020200, 0x08000008, |
667 | y |= src[1]; | 427 | 0x08020000, 0x08000208, 0x00000208, 0x08020000, |
668 | y <<= 8; | 428 | 0x00020208, 0x00000008, 0x08020008, 0x00020200 |
669 | y |= src[0]; | 429 | }; |
670 | z = ((x >> 004) ^ y) & 0x0F0F0F0FL; | 430 | |
671 | x ^= z << 004; | 431 | static const u32 S4[64] = { |
672 | y ^= z; | 432 | 0x00802001, 0x00002081, 0x00002081, 0x00000080, |
673 | z = ((y >> 020) ^ x) & 0x0000FFFFL; | 433 | 0x00802080, 0x00800081, 0x00800001, 0x00002001, |
674 | y ^= z << 020; | 434 | 0x00000000, 0x00802000, 0x00802000, 0x00802081, |
675 | x ^= z; | 435 | 0x00000081, 0x00000000, 0x00800080, 0x00800001, |
676 | z = ((x >> 002) ^ y) & 0x33333333L; | 436 | 0x00000001, 0x00002000, 0x00800000, 0x00802001, |
677 | x ^= z << 002; | 437 | 0x00000080, 0x00800000, 0x00002001, 0x00002080, |
678 | y ^= z; | 438 | 0x00800081, 0x00000001, 0x00002080, 0x00800080, |
679 | z = ((y >> 010) ^ x) & 0x00FF00FFL; | 439 | 0x00002000, 0x00802080, 0x00802081, 0x00000081, |
680 | y ^= z << 010; | 440 | 0x00800080, 0x00800001, 0x00802000, 0x00802081, |
681 | x ^= z; | 441 | 0x00000081, 0x00000000, 0x00000000, 0x00802000, |
682 | x = x >> 1 | x << 31; | 442 | 0x00002080, 0x00800080, 0x00800081, 0x00000001, |
683 | z = (x ^ y) & 0x55555555L; | 443 | 0x00802001, 0x00002081, 0x00002081, 0x00000080, |
684 | y ^= z; | 444 | 0x00802081, 0x00000081, 0x00000001, 0x00002000, |
685 | x ^= z; | 445 | 0x00800001, 0x00002001, 0x00802080, 0x00800081, |
686 | y = y >> 1 | y << 31; | 446 | 0x00002001, 0x00002080, 0x00800000, 0x00802001, |
687 | z = expkey[31]; | 447 | 0x00000080, 0x00800000, 0x00002000, 0x00802080 |
688 | z ^= y; | 448 | }; |
689 | z = z << 4 | z >> 28; | 449 | |
690 | x ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); | 450 | static const u32 S5[64] = { |
691 | z >>= 8; | 451 | 0x00000100, 0x02080100, 0x02080000, 0x42000100, |
692 | x ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); | 452 | 0x00080000, 0x00000100, 0x40000000, 0x02080000, |
693 | z >>= 8; | 453 | 0x40080100, 0x00080000, 0x02000100, 0x40080100, |
694 | x ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); | 454 | 0x42000100, 0x42080000, 0x00080100, 0x40000000, |
695 | z >>= 8; | 455 | 0x02000000, 0x40080000, 0x40080000, 0x00000000, |
696 | x ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); | 456 | 0x40000100, 0x42080100, 0x42080100, 0x02000100, |
697 | z = expkey[30]; | 457 | 0x42080000, 0x40000100, 0x00000000, 0x42000000, |
698 | z ^= y; | 458 | 0x02080100, 0x02000000, 0x42000000, 0x00080100, |
699 | x ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); | 459 | 0x00080000, 0x42000100, 0x00000100, 0x02000000, |
700 | z >>= 8; | 460 | 0x40000000, 0x02080000, 0x42000100, 0x40080100, |
701 | x ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); | 461 | 0x02000100, 0x40000000, 0x42080000, 0x02080100, |
702 | z >>= 8; | 462 | 0x40080100, 0x00000100, 0x02000000, 0x42080000, |
703 | x ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); | 463 | 0x42080100, 0x00080100, 0x42000000, 0x42080100, |
704 | z >>= 8; | 464 | 0x02080000, 0x00000000, 0x40080000, 0x42000000, |
705 | x ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); | 465 | 0x00080100, 0x02000100, 0x40000100, 0x00080000, |
706 | z = expkey[29]; | 466 | 0x00000000, 0x40080000, 0x02080100, 0x40000100 |
707 | z ^= x; | 467 | }; |
708 | z = z << 4 | z >> 28; | 468 | |
709 | y ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); | 469 | static const u32 S6[64] = { |
710 | z >>= 8; | 470 | 0x20000010, 0x20400000, 0x00004000, 0x20404010, |
711 | y ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); | 471 | 0x20400000, 0x00000010, 0x20404010, 0x00400000, |
712 | z >>= 8; | 472 | 0x20004000, 0x00404010, 0x00400000, 0x20000010, |
713 | y ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); | 473 | 0x00400010, 0x20004000, 0x20000000, 0x00004010, |
714 | z >>= 8; | 474 | 0x00000000, 0x00400010, 0x20004010, 0x00004000, |
715 | y ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); | 475 | 0x00404000, 0x20004010, 0x00000010, 0x20400010, |
716 | z = expkey[28]; | 476 | 0x20400010, 0x00000000, 0x00404010, 0x20404000, |
717 | z ^= x; | 477 | 0x00004010, 0x00404000, 0x20404000, 0x20000000, |
718 | y ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); | 478 | 0x20004000, 0x00000010, 0x20400010, 0x00404000, |
719 | z >>= 8; | 479 | 0x20404010, 0x00400000, 0x00004010, 0x20000010, |
720 | y ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); | 480 | 0x00400000, 0x20004000, 0x20000000, 0x00004010, |
721 | z >>= 8; | 481 | 0x20000010, 0x20404010, 0x00404000, 0x20400000, |
722 | y ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); | 482 | 0x00404010, 0x20404000, 0x00000000, 0x20400010, |
723 | z >>= 8; | 483 | 0x00000010, 0x00004000, 0x20400000, 0x00404010, |
724 | y ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); | 484 | 0x00004000, 0x00400010, 0x20004010, 0x00000000, |
725 | z = expkey[27]; | 485 | 0x20404000, 0x20000000, 0x00400010, 0x20004010 |
726 | z ^= y; | 486 | }; |
727 | z = z << 4 | z >> 28; | 487 | |
728 | x ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); | 488 | static const u32 S7[64] = { |
729 | z >>= 8; | 489 | 0x00200000, 0x04200002, 0x04000802, 0x00000000, |
730 | x ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); | 490 | 0x00000800, 0x04000802, 0x00200802, 0x04200800, |
731 | z >>= 8; | 491 | 0x04200802, 0x00200000, 0x00000000, 0x04000002, |
732 | x ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); | 492 | 0x00000002, 0x04000000, 0x04200002, 0x00000802, |
733 | z >>= 8; | 493 | 0x04000800, 0x00200802, 0x00200002, 0x04000800, |
734 | x ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); | 494 | 0x04000002, 0x04200000, 0x04200800, 0x00200002, |
735 | z = expkey[26]; | 495 | 0x04200000, 0x00000800, 0x00000802, 0x04200802, |
736 | z ^= y; | 496 | 0x00200800, 0x00000002, 0x04000000, 0x00200800, |
737 | x ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); | 497 | 0x04000000, 0x00200800, 0x00200000, 0x04000802, |
738 | z >>= 8; | 498 | 0x04000802, 0x04200002, 0x04200002, 0x00000002, |
739 | x ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); | 499 | 0x00200002, 0x04000000, 0x04000800, 0x00200000, |
740 | z >>= 8; | 500 | 0x04200800, 0x00000802, 0x00200802, 0x04200800, |
741 | x ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); | 501 | 0x00000802, 0x04000002, 0x04200802, 0x04200000, |
742 | z >>= 8; | 502 | 0x00200800, 0x00000000, 0x00000002, 0x04200802, |
743 | x ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); | 503 | 0x00000000, 0x00200802, 0x04200000, 0x00000800, |
744 | z = expkey[25]; | 504 | 0x04000002, 0x04000800, 0x00000800, 0x00200002 |
745 | z ^= x; | 505 | }; |
746 | z = z << 4 | z >> 28; | 506 | |
747 | y ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); | 507 | static const u32 S8[64] = { |
748 | z >>= 8; | 508 | 0x10001040, 0x00001000, 0x00040000, 0x10041040, |
749 | y ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); | 509 | 0x10000000, 0x10001040, 0x00000040, 0x10000000, |
750 | z >>= 8; | 510 | 0x00040040, 0x10040000, 0x10041040, 0x00041000, |
751 | y ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); | 511 | 0x10041000, 0x00041040, 0x00001000, 0x00000040, |
752 | z >>= 8; | 512 | 0x10040000, 0x10000040, 0x10001000, 0x00001040, |
753 | y ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); | 513 | 0x00041000, 0x00040040, 0x10040040, 0x10041000, |
754 | z = expkey[24]; | 514 | 0x00001040, 0x00000000, 0x00000000, 0x10040040, |
755 | z ^= x; | 515 | 0x10000040, 0x10001000, 0x00041040, 0x00040000, |
756 | y ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); | 516 | 0x00041040, 0x00040000, 0x10041000, 0x00001000, |
757 | z >>= 8; | 517 | 0x00000040, 0x10040040, 0x00001000, 0x00041040, |
758 | y ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); | 518 | 0x10001000, 0x00000040, 0x10000040, 0x10040000, |
759 | z >>= 8; | 519 | 0x10040040, 0x10000000, 0x00040000, 0x10001040, |
760 | y ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); | 520 | 0x00000000, 0x10041040, 0x00040040, 0x10000040, |
761 | z >>= 8; | 521 | 0x10040000, 0x10001000, 0x10001040, 0x00000000, |
762 | y ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); | 522 | 0x10041040, 0x00041000, 0x00041000, 0x00001040, |
763 | z = expkey[23]; | 523 | 0x00001040, 0x00040040, 0x10000000, 0x10041000 |
764 | z ^= y; | 524 | }; |
765 | z = z << 4 | z >> 28; | 525 | |
766 | x ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); | 526 | /* Encryption components: IP, FP, and round function */ |
767 | z >>= 8; | 527 | |
768 | x ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); | 528 | #define IP(L, R, T) \ |
769 | z >>= 8; | 529 | ROL(R, 4); \ |
770 | x ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); | 530 | T = L; \ |
771 | z >>= 8; | 531 | L ^= R; \ |
772 | x ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); | 532 | L &= 0xf0f0f0f0; \ |
773 | z = expkey[22]; | 533 | R ^= L; \ |
774 | z ^= y; | 534 | L ^= T; \ |
775 | x ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); | 535 | ROL(R, 12); \ |
776 | z >>= 8; | 536 | T = L; \ |
777 | x ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); | 537 | L ^= R; \ |
778 | z >>= 8; | 538 | L &= 0xffff0000; \ |
779 | x ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); | 539 | R ^= L; \ |
780 | z >>= 8; | 540 | L ^= T; \ |
781 | x ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); | 541 | ROR(R, 14); \ |
782 | z = expkey[21]; | 542 | T = L; \ |
783 | z ^= x; | 543 | L ^= R; \ |
784 | z = z << 4 | z >> 28; | 544 | L &= 0xcccccccc; \ |
785 | y ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); | 545 | R ^= L; \ |
786 | z >>= 8; | 546 | L ^= T; \ |
787 | y ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); | 547 | ROL(R, 6); \ |
788 | z >>= 8; | 548 | T = L; \ |
789 | y ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); | 549 | L ^= R; \ |
790 | z >>= 8; | 550 | L &= 0xff00ff00; \ |
791 | y ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); | 551 | R ^= L; \ |
792 | z = expkey[20]; | 552 | L ^= T; \ |
793 | z ^= x; | 553 | ROR(R, 7); \ |
794 | y ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); | 554 | T = L; \ |
795 | z >>= 8; | 555 | L ^= R; \ |
796 | y ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); | 556 | L &= 0xaaaaaaaa; \ |
797 | z >>= 8; | 557 | R ^= L; \ |
798 | y ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); | 558 | L ^= T; \ |
799 | z >>= 8; | 559 | ROL(L, 1); |
800 | y ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); | 560 | |
801 | z = expkey[19]; | 561 | #define FP(L, R, T) \ |
802 | z ^= y; | 562 | ROR(L, 1); \ |
803 | z = z << 4 | z >> 28; | 563 | T = L; \ |
804 | x ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); | 564 | L ^= R; \ |
805 | z >>= 8; | 565 | L &= 0xaaaaaaaa; \ |
806 | x ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); | 566 | R ^= L; \ |
807 | z >>= 8; | 567 | L ^= T; \ |
808 | x ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); | 568 | ROL(R, 7); \ |
809 | z >>= 8; | 569 | T = L; \ |
810 | x ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); | 570 | L ^= R; \ |
811 | z = expkey[18]; | 571 | L &= 0xff00ff00; \ |
812 | z ^= y; | 572 | R ^= L; \ |
813 | x ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); | 573 | L ^= T; \ |
814 | z >>= 8; | 574 | ROR(R, 6); \ |
815 | x ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); | 575 | T = L; \ |
816 | z >>= 8; | 576 | L ^= R; \ |
817 | x ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); | 577 | L &= 0xcccccccc; \ |
818 | z >>= 8; | 578 | R ^= L; \ |
819 | x ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); | 579 | L ^= T; \ |
820 | z = expkey[17]; | 580 | ROL(R, 14); \ |
821 | z ^= x; | 581 | T = L; \ |
822 | z = z << 4 | z >> 28; | 582 | L ^= R; \ |
823 | y ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); | 583 | L &= 0xffff0000; \ |
824 | z >>= 8; | 584 | R ^= L; \ |
825 | y ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); | 585 | L ^= T; \ |
826 | z >>= 8; | 586 | ROR(R, 12); \ |
827 | y ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); | 587 | T = L; \ |
828 | z >>= 8; | 588 | L ^= R; \ |
829 | y ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); | 589 | L &= 0xf0f0f0f0; \ |
830 | z = expkey[16]; | 590 | R ^= L; \ |
831 | z ^= x; | 591 | L ^= T; \ |
832 | y ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); | 592 | ROR(R, 4); |
833 | z >>= 8; | 593 | |
834 | y ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); | 594 | #define ROUND(L, R, A, B, K, d) \ |
835 | z >>= 8; | 595 | B = K[0]; A = K[1]; K += d; \ |
836 | y ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); | 596 | B ^= R; A ^= R; \ |
837 | z >>= 8; | 597 | B &= 0x3f3f3f3f; ROR(A, 4); \ |
838 | y ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); | 598 | L ^= S8[0xff & B]; A &= 0x3f3f3f3f; \ |
839 | z = expkey[15]; | 599 | L ^= S6[0xff & (B >> 8)]; B >>= 16; \ |
840 | z ^= y; | 600 | L ^= S7[0xff & A]; \ |
841 | z = z << 4 | z >> 28; | 601 | L ^= S5[0xff & (A >> 8)]; A >>= 16; \ |
842 | x ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); | 602 | L ^= S4[0xff & B]; \ |
843 | z >>= 8; | 603 | L ^= S2[0xff & (B >> 8)]; \ |
844 | x ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); | 604 | L ^= S3[0xff & A]; \ |
845 | z >>= 8; | 605 | L ^= S1[0xff & (A >> 8)]; |
846 | x ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); | 606 | |
847 | z >>= 8; | 607 | /* |
848 | x ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); | 608 | * PC2 lookup tables are organized as 2 consecutive sets of 4 interleaved |
849 | z = expkey[14]; | 609 | * tables of 128 elements. One set is for C_i and the other for D_i, while |
850 | z ^= y; | 610 | * the 4 interleaved tables correspond to four 7-bit subsets of C_i or D_i. |
851 | x ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); | 611 | * |
852 | z >>= 8; | 612 | * After PC1 each of the variables a,b,c,d contains a 7 bit subset of C_i |
853 | x ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); | 613 | * or D_i in bits 7-1 (bit 0 being the least significant). |
854 | z >>= 8; | 614 | */ |
855 | x ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); | 615 | |
856 | z >>= 8; | 616 | #define T1(x) pt[2 * (x) + 0] |
857 | x ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); | 617 | #define T2(x) pt[2 * (x) + 1] |
858 | z = expkey[13]; | 618 | #define T3(x) pt[2 * (x) + 2] |
859 | z ^= x; | 619 | #define T4(x) pt[2 * (x) + 3] |
860 | z = z << 4 | z >> 28; | 620 | |
861 | y ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); | 621 | #define PC2(a, b, c, d) (T4(d) | T3(c) | T2(b) | T1(a)) |
862 | z >>= 8; | ||
863 | y ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); | ||
864 | z >>= 8; | ||
865 | y ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); | ||
866 | z >>= 8; | ||
867 | y ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); | ||
868 | z = expkey[12]; | ||
869 | z ^= x; | ||
870 | y ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); | ||
871 | z >>= 8; | ||
872 | y ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); | ||
873 | z >>= 8; | ||
874 | y ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); | ||
875 | z >>= 8; | ||
876 | y ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); | ||
877 | z = expkey[11]; | ||
878 | z ^= y; | ||
879 | z = z << 4 | z >> 28; | ||
880 | x ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); | ||
881 | z >>= 8; | ||
882 | x ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); | ||
883 | z >>= 8; | ||
884 | x ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); | ||
885 | z >>= 8; | ||
886 | x ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); | ||
887 | z = expkey[10]; | ||
888 | z ^= y; | ||
889 | x ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); | ||
890 | z >>= 8; | ||
891 | x ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); | ||
892 | z >>= 8; | ||
893 | x ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); | ||
894 | z >>= 8; | ||
895 | x ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); | ||
896 | z = expkey[9]; | ||
897 | z ^= x; | ||
898 | z = z << 4 | z >> 28; | ||
899 | y ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); | ||
900 | z >>= 8; | ||
901 | y ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); | ||
902 | z >>= 8; | ||
903 | y ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); | ||
904 | z >>= 8; | ||
905 | y ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); | ||
906 | z = expkey[8]; | ||
907 | z ^= x; | ||
908 | y ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); | ||
909 | z >>= 8; | ||
910 | y ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); | ||
911 | z >>= 8; | ||
912 | y ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); | ||
913 | z >>= 8; | ||
914 | y ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); | ||
915 | z = expkey[7]; | ||
916 | z ^= y; | ||
917 | z = z << 4 | z >> 28; | ||
918 | x ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); | ||
919 | z >>= 8; | ||
920 | x ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); | ||
921 | z >>= 8; | ||
922 | x ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); | ||
923 | z >>= 8; | ||
924 | x ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); | ||
925 | z = expkey[6]; | ||
926 | z ^= y; | ||
927 | x ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); | ||
928 | z >>= 8; | ||
929 | x ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); | ||
930 | z >>= 8; | ||
931 | x ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); | ||
932 | z >>= 8; | ||
933 | x ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); | ||
934 | z = expkey[5]; | ||
935 | z ^= x; | ||
936 | z = z << 4 | z >> 28; | ||
937 | y ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); | ||
938 | z >>= 8; | ||
939 | y ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); | ||
940 | z >>= 8; | ||
941 | y ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); | ||
942 | z >>= 8; | ||
943 | y ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); | ||
944 | z = expkey[4]; | ||
945 | z ^= x; | ||
946 | y ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); | ||
947 | z >>= 8; | ||
948 | y ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); | ||
949 | z >>= 8; | ||
950 | y ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); | ||
951 | z >>= 8; | ||
952 | y ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); | ||
953 | z = expkey[3]; | ||
954 | z ^= y; | ||
955 | z = z << 4 | z >> 28; | ||
956 | x ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); | ||
957 | z >>= 8; | ||
958 | x ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); | ||
959 | z >>= 8; | ||
960 | x ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); | ||
961 | z >>= 8; | ||
962 | x ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); | ||
963 | z = expkey[2]; | ||
964 | z ^= y; | ||
965 | x ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); | ||
966 | z >>= 8; | ||
967 | x ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); | ||
968 | z >>= 8; | ||
969 | x ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); | ||
970 | z >>= 8; | ||
971 | x ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); | ||
972 | z = expkey[1]; | ||
973 | z ^= x; | ||
974 | z = z << 4 | z >> 28; | ||
975 | y ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); | ||
976 | z >>= 8; | ||
977 | y ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); | ||
978 | z >>= 8; | ||
979 | y ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); | ||
980 | z >>= 8; | ||
981 | y ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); | ||
982 | z = expkey[0]; | ||
983 | z ^= x; | ||
984 | y ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); | ||
985 | z >>= 8; | ||
986 | y ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); | ||
987 | z >>= 8; | ||
988 | y ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); | ||
989 | z >>= 8; | ||
990 | y ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); | ||
991 | x = x << 1 | x >> 31; | ||
992 | z = (x ^ y) & 0x55555555L; | ||
993 | y ^= z; | ||
994 | x ^= z; | ||
995 | y = y << 1 | y >> 31; | ||
996 | z = ((x >> 010) ^ y) & 0x00FF00FFL; | ||
997 | x ^= z << 010; | ||
998 | y ^= z; | ||
999 | z = ((y >> 002) ^ x) & 0x33333333L; | ||
1000 | y ^= z << 002; | ||
1001 | x ^= z; | ||
1002 | z = ((x >> 020) ^ y) & 0x0000FFFFL; | ||
1003 | x ^= z << 020; | ||
1004 | y ^= z; | ||
1005 | z = ((y >> 004) ^ x) & 0x0F0F0F0FL; | ||
1006 | y ^= z << 004; | ||
1007 | x ^= z; | ||
1008 | dst[0] = x; | ||
1009 | x >>= 8; | ||
1010 | dst[1] = x; | ||
1011 | x >>= 8; | ||
1012 | dst[2] = x; | ||
1013 | x >>= 8; | ||
1014 | dst[3] = x; | ||
1015 | dst[4] = y; | ||
1016 | y >>= 8; | ||
1017 | dst[5] = y; | ||
1018 | y >>= 8; | ||
1019 | dst[6] = y; | ||
1020 | y >>= 8; | ||
1021 | dst[7] = y; | ||
1022 | } | ||
1023 | 622 | ||
1024 | /* | 623 | /* |
624 | * Encryption key expansion | ||
625 | * | ||
1025 | * RFC2451: Weak key checks SHOULD be performed. | 626 | * RFC2451: Weak key checks SHOULD be performed. |
627 | * | ||
628 | * FIPS 74: | ||
629 | * | ||
630 | * Keys having duals are keys which produce all zeros, all ones, or | ||
631 | * alternating zero-one patterns in the C and D registers after Permuted | ||
632 | * Choice 1 has operated on the key. | ||
633 | * | ||
1026 | */ | 634 | */ |
1027 | static int setkey(u32 *expkey, const u8 *key, unsigned int keylen, u32 *flags) | 635 | static unsigned long ekey(u32 *pe, const u8 *k) |
1028 | { | 636 | { |
1029 | const u8 *k; | 637 | /* K&R: long is at least 32 bits */ |
1030 | u8 *b0, *b1; | 638 | unsigned long a, b, c, d, w; |
1031 | u32 n, w; | 639 | const u32 *pt = pc2; |
1032 | u8 bits0[56], bits1[56]; | 640 | |
1033 | 641 | d = k[4]; d &= 0x0e; d <<= 4; d |= k[0] & 0x1e; d = pc1[d]; | |
1034 | n = parity[key[0]]; n <<= 4; | 642 | c = k[5]; c &= 0x0e; c <<= 4; c |= k[1] & 0x1e; c = pc1[c]; |
1035 | n |= parity[key[1]]; n <<= 4; | 643 | b = k[6]; b &= 0x0e; b <<= 4; b |= k[2] & 0x1e; b = pc1[b]; |
1036 | n |= parity[key[2]]; n <<= 4; | 644 | a = k[7]; a &= 0x0e; a <<= 4; a |= k[3] & 0x1e; a = pc1[a]; |
1037 | n |= parity[key[3]]; n <<= 4; | 645 | |
1038 | n |= parity[key[4]]; n <<= 4; | 646 | pe[15 * 2 + 0] = PC2(a, b, c, d); d = rs[d]; |
1039 | n |= parity[key[5]]; n <<= 4; | 647 | pe[14 * 2 + 0] = PC2(d, a, b, c); c = rs[c]; b = rs[b]; |
1040 | n |= parity[key[6]]; n <<= 4; | 648 | pe[13 * 2 + 0] = PC2(b, c, d, a); a = rs[a]; d = rs[d]; |
1041 | n |= parity[key[7]]; | 649 | pe[12 * 2 + 0] = PC2(d, a, b, c); c = rs[c]; b = rs[b]; |
1042 | w = 0x88888888L; | 650 | pe[11 * 2 + 0] = PC2(b, c, d, a); a = rs[a]; d = rs[d]; |
1043 | 651 | pe[10 * 2 + 0] = PC2(d, a, b, c); c = rs[c]; b = rs[b]; | |
1044 | if ((*flags & CRYPTO_TFM_REQ_WEAK_KEY) | 652 | pe[ 9 * 2 + 0] = PC2(b, c, d, a); a = rs[a]; d = rs[d]; |
1045 | && !((n - (w >> 3)) & w)) { /* 1 in 10^10 keys passes this test */ | 653 | pe[ 8 * 2 + 0] = PC2(d, a, b, c); c = rs[c]; |
1046 | if (n < 0x41415151) { | 654 | pe[ 7 * 2 + 0] = PC2(c, d, a, b); b = rs[b]; a = rs[a]; |
1047 | if (n < 0x31312121) { | 655 | pe[ 6 * 2 + 0] = PC2(a, b, c, d); d = rs[d]; c = rs[c]; |
1048 | if (n < 0x14141515) { | 656 | pe[ 5 * 2 + 0] = PC2(c, d, a, b); b = rs[b]; a = rs[a]; |
1049 | /* 01 01 01 01 01 01 01 01 */ | 657 | pe[ 4 * 2 + 0] = PC2(a, b, c, d); d = rs[d]; c = rs[c]; |
1050 | if (n == 0x11111111) goto weak; | 658 | pe[ 3 * 2 + 0] = PC2(c, d, a, b); b = rs[b]; a = rs[a]; |
1051 | /* 01 1F 01 1F 01 0E 01 0E */ | 659 | pe[ 2 * 2 + 0] = PC2(a, b, c, d); d = rs[d]; c = rs[c]; |
1052 | if (n == 0x13131212) goto weak; | 660 | pe[ 1 * 2 + 0] = PC2(c, d, a, b); b = rs[b]; |
1053 | } else { | 661 | pe[ 0 * 2 + 0] = PC2(b, c, d, a); |
1054 | /* 01 E0 01 E0 01 F1 01 F1 */ | 662 | |
1055 | if (n == 0x14141515) goto weak; | 663 | /* Check if first half is weak */ |
1056 | /* 01 FE 01 FE 01 FE 01 FE */ | 664 | w = (a ^ c) | (b ^ d) | (rs[a] ^ c) | (b ^ rs[d]); |
1057 | if (n == 0x16161616) goto weak; | 665 | |
1058 | } | 666 | /* Skip to next table set */ |
1059 | } else { | 667 | pt += 512; |
1060 | if (n < 0x34342525) { | 668 | |
1061 | /* 1F 01 1F 01 0E 01 0E 01 */ | 669 | d = k[0]; d &= 0xe0; d >>= 4; d |= k[4] & 0xf0; d = pc1[d + 1]; |
1062 | if (n == 0x31312121) goto weak; | 670 | c = k[1]; c &= 0xe0; c >>= 4; c |= k[5] & 0xf0; c = pc1[c + 1]; |
1063 | /* 1F 1F 1F 1F 0E 0E 0E 0E (?) */ | 671 | b = k[2]; b &= 0xe0; b >>= 4; b |= k[6] & 0xf0; b = pc1[b + 1]; |
1064 | if (n == 0x33332222) goto weak; | 672 | a = k[3]; a &= 0xe0; a >>= 4; a |= k[7] & 0xf0; a = pc1[a + 1]; |
1065 | } else { | 673 | |
1066 | /* 1F E0 1F E0 0E F1 0E F1 */ | 674 | /* Check if second half is weak */ |
1067 | if (n == 0x34342525) goto weak; | 675 | w |= (a ^ c) | (b ^ d) | (rs[a] ^ c) | (b ^ rs[d]); |
1068 | /* 1F FE 1F FE 0E FE 0E FE */ | 676 | |
1069 | if (n == 0x36362626) goto weak; | 677 | pe[15 * 2 + 1] = PC2(a, b, c, d); d = rs[d]; |
1070 | } | 678 | pe[14 * 2 + 1] = PC2(d, a, b, c); c = rs[c]; b = rs[b]; |
1071 | } | 679 | pe[13 * 2 + 1] = PC2(b, c, d, a); a = rs[a]; d = rs[d]; |
1072 | } else { | 680 | pe[12 * 2 + 1] = PC2(d, a, b, c); c = rs[c]; b = rs[b]; |
1073 | if (n < 0x61616161) { | 681 | pe[11 * 2 + 1] = PC2(b, c, d, a); a = rs[a]; d = rs[d]; |
1074 | if (n < 0x44445555) { | 682 | pe[10 * 2 + 1] = PC2(d, a, b, c); c = rs[c]; b = rs[b]; |
1075 | /* E0 01 E0 01 F1 01 F1 01 */ | 683 | pe[ 9 * 2 + 1] = PC2(b, c, d, a); a = rs[a]; d = rs[d]; |
1076 | if (n == 0x41415151) goto weak; | 684 | pe[ 8 * 2 + 1] = PC2(d, a, b, c); c = rs[c]; |
1077 | /* E0 1F E0 1F F1 0E F1 0E */ | 685 | pe[ 7 * 2 + 1] = PC2(c, d, a, b); b = rs[b]; a = rs[a]; |
1078 | if (n == 0x43435252) goto weak; | 686 | pe[ 6 * 2 + 1] = PC2(a, b, c, d); d = rs[d]; c = rs[c]; |
1079 | } else { | 687 | pe[ 5 * 2 + 1] = PC2(c, d, a, b); b = rs[b]; a = rs[a]; |
1080 | /* E0 E0 E0 E0 F1 F1 F1 F1 (?) */ | 688 | pe[ 4 * 2 + 1] = PC2(a, b, c, d); d = rs[d]; c = rs[c]; |
1081 | if (n == 0x44445555) goto weak; | 689 | pe[ 3 * 2 + 1] = PC2(c, d, a, b); b = rs[b]; a = rs[a]; |
1082 | /* E0 FE E0 FE F1 FE F1 FE */ | 690 | pe[ 2 * 2 + 1] = PC2(a, b, c, d); d = rs[d]; c = rs[c]; |
1083 | if (n == 0x46465656) goto weak; | 691 | pe[ 1 * 2 + 1] = PC2(c, d, a, b); b = rs[b]; |
1084 | } | 692 | pe[ 0 * 2 + 1] = PC2(b, c, d, a); |
1085 | } else { | 693 | |
1086 | if (n < 0x64646565) { | 694 | /* Fixup: 2413 5768 -> 1357 2468 */ |
1087 | /* FE 01 FE 01 FE 01 FE 01 */ | 695 | for (d = 0; d < 16; ++d) { |
1088 | if (n == 0x61616161) goto weak; | 696 | a = pe[2 * d]; |
1089 | /* FE 1F FE 1F FE 0E FE 0E */ | 697 | b = pe[2 * d + 1]; |
1090 | if (n == 0x63636262) goto weak; | 698 | c = a ^ b; |
1091 | } else { | 699 | c &= 0xffff0000; |
1092 | /* FE E0 FE E0 FE F1 FE F1 */ | 700 | a ^= c; |
1093 | if (n == 0x64646565) goto weak; | 701 | b ^= c; |
1094 | /* FE FE FE FE FE FE FE FE */ | 702 | ROL(b, 18); |
1095 | if (n == 0x66666666) goto weak; | 703 | pe[2 * d] = a; |
1096 | } | 704 | pe[2 * d + 1] = b; |
1097 | } | ||
1098 | } | ||
1099 | |||
1100 | goto not_weak; | ||
1101 | weak: | ||
1102 | *flags |= CRYPTO_TFM_RES_WEAK_KEY; | ||
1103 | return -EINVAL; | ||
1104 | } | 705 | } |
1105 | 706 | ||
1106 | not_weak: | 707 | /* Zero if weak key */ |
1107 | 708 | return w; | |
1108 | /* explode the bits */ | 709 | } |
1109 | n = 56; | ||
1110 | b0 = bits0; | ||
1111 | b1 = bits1; | ||
1112 | |||
1113 | do { | ||
1114 | w = (256 | *key++) << 2; | ||
1115 | do { | ||
1116 | --n; | ||
1117 | b1[n] = 8 & w; | ||
1118 | w >>= 1; | ||
1119 | b0[n] = 4 & w; | ||
1120 | } while ( w >= 16 ); | ||
1121 | } while ( n ); | ||
1122 | |||
1123 | /* put the bits in the correct places */ | ||
1124 | n = 16; | ||
1125 | k = rotors; | ||
1126 | |||
1127 | do { | ||
1128 | w = (b1[k[ 0 ]] | b0[k[ 1 ]]) << 4; | ||
1129 | w |= (b1[k[ 2 ]] | b0[k[ 3 ]]) << 2; | ||
1130 | w |= b1[k[ 4 ]] | b0[k[ 5 ]]; | ||
1131 | w <<= 8; | ||
1132 | w |= (b1[k[ 6 ]] | b0[k[ 7 ]]) << 4; | ||
1133 | w |= (b1[k[ 8 ]] | b0[k[ 9 ]]) << 2; | ||
1134 | w |= b1[k[10 ]] | b0[k[11 ]]; | ||
1135 | w <<= 8; | ||
1136 | w |= (b1[k[12 ]] | b0[k[13 ]]) << 4; | ||
1137 | w |= (b1[k[14 ]] | b0[k[15 ]]) << 2; | ||
1138 | w |= b1[k[16 ]] | b0[k[17 ]]; | ||
1139 | w <<= 8; | ||
1140 | w |= (b1[k[18 ]] | b0[k[19 ]]) << 4; | ||
1141 | w |= (b1[k[20 ]] | b0[k[21 ]]) << 2; | ||
1142 | w |= b1[k[22 ]] | b0[k[23 ]]; | ||
1143 | expkey[0] = w; | ||
1144 | |||
1145 | w = (b1[k[ 0+24]] | b0[k[ 1+24]]) << 4; | ||
1146 | w |= (b1[k[ 2+24]] | b0[k[ 3+24]]) << 2; | ||
1147 | w |= b1[k[ 4+24]] | b0[k[ 5+24]]; | ||
1148 | w <<= 8; | ||
1149 | w |= (b1[k[ 6+24]] | b0[k[ 7+24]]) << 4; | ||
1150 | w |= (b1[k[ 8+24]] | b0[k[ 9+24]]) << 2; | ||
1151 | w |= b1[k[10+24]] | b0[k[11+24]]; | ||
1152 | w <<= 8; | ||
1153 | w |= (b1[k[12+24]] | b0[k[13+24]]) << 4; | ||
1154 | w |= (b1[k[14+24]] | b0[k[15+24]]) << 2; | ||
1155 | w |= b1[k[16+24]] | b0[k[17+24]]; | ||
1156 | w <<= 8; | ||
1157 | w |= (b1[k[18+24]] | b0[k[19+24]]) << 4; | ||
1158 | w |= (b1[k[20+24]] | b0[k[21+24]]) << 2; | ||
1159 | w |= b1[k[22+24]] | b0[k[23+24]]; | ||
1160 | |||
1161 | ROR(w, 4, 28); /* could be eliminated */ | ||
1162 | expkey[1] = w; | ||
1163 | |||
1164 | k += 48; | ||
1165 | expkey += 2; | ||
1166 | } while (--n); | ||
1167 | 710 | ||
1168 | return 0; | 711 | /* |
712 | * Decryption key expansion | ||
713 | * | ||
714 | * No weak key checking is performed, as this is only used by triple DES | ||
715 | * | ||
716 | */ | ||
717 | static void dkey(u32 *pe, const u8 *k) | ||
718 | { | ||
719 | /* K&R: long is at least 32 bits */ | ||
720 | unsigned long a, b, c, d; | ||
721 | const u32 *pt = pc2; | ||
722 | |||
723 | d = k[4]; d &= 0x0e; d <<= 4; d |= k[0] & 0x1e; d = pc1[d]; | ||
724 | c = k[5]; c &= 0x0e; c <<= 4; c |= k[1] & 0x1e; c = pc1[c]; | ||
725 | b = k[6]; b &= 0x0e; b <<= 4; b |= k[2] & 0x1e; b = pc1[b]; | ||
726 | a = k[7]; a &= 0x0e; a <<= 4; a |= k[3] & 0x1e; a = pc1[a]; | ||
727 | |||
728 | pe[ 0 * 2] = PC2(a, b, c, d); d = rs[d]; | ||
729 | pe[ 1 * 2] = PC2(d, a, b, c); c = rs[c]; b = rs[b]; | ||
730 | pe[ 2 * 2] = PC2(b, c, d, a); a = rs[a]; d = rs[d]; | ||
731 | pe[ 3 * 2] = PC2(d, a, b, c); c = rs[c]; b = rs[b]; | ||
732 | pe[ 4 * 2] = PC2(b, c, d, a); a = rs[a]; d = rs[d]; | ||
733 | pe[ 5 * 2] = PC2(d, a, b, c); c = rs[c]; b = rs[b]; | ||
734 | pe[ 6 * 2] = PC2(b, c, d, a); a = rs[a]; d = rs[d]; | ||
735 | pe[ 7 * 2] = PC2(d, a, b, c); c = rs[c]; | ||
736 | pe[ 8 * 2] = PC2(c, d, a, b); b = rs[b]; a = rs[a]; | ||
737 | pe[ 9 * 2] = PC2(a, b, c, d); d = rs[d]; c = rs[c]; | ||
738 | pe[10 * 2] = PC2(c, d, a, b); b = rs[b]; a = rs[a]; | ||
739 | pe[11 * 2] = PC2(a, b, c, d); d = rs[d]; c = rs[c]; | ||
740 | pe[12 * 2] = PC2(c, d, a, b); b = rs[b]; a = rs[a]; | ||
741 | pe[13 * 2] = PC2(a, b, c, d); d = rs[d]; c = rs[c]; | ||
742 | pe[14 * 2] = PC2(c, d, a, b); b = rs[b]; | ||
743 | pe[15 * 2] = PC2(b, c, d, a); | ||
744 | |||
745 | /* Skip to next table set */ | ||
746 | pt += 512; | ||
747 | |||
748 | d = k[0]; d &= 0xe0; d >>= 4; d |= k[4] & 0xf0; d = pc1[d + 1]; | ||
749 | c = k[1]; c &= 0xe0; c >>= 4; c |= k[5] & 0xf0; c = pc1[c + 1]; | ||
750 | b = k[2]; b &= 0xe0; b >>= 4; b |= k[6] & 0xf0; b = pc1[b + 1]; | ||
751 | a = k[3]; a &= 0xe0; a >>= 4; a |= k[7] & 0xf0; a = pc1[a + 1]; | ||
752 | |||
753 | pe[ 0 * 2 + 1] = PC2(a, b, c, d); d = rs[d]; | ||
754 | pe[ 1 * 2 + 1] = PC2(d, a, b, c); c = rs[c]; b = rs[b]; | ||
755 | pe[ 2 * 2 + 1] = PC2(b, c, d, a); a = rs[a]; d = rs[d]; | ||
756 | pe[ 3 * 2 + 1] = PC2(d, a, b, c); c = rs[c]; b = rs[b]; | ||
757 | pe[ 4 * 2 + 1] = PC2(b, c, d, a); a = rs[a]; d = rs[d]; | ||
758 | pe[ 5 * 2 + 1] = PC2(d, a, b, c); c = rs[c]; b = rs[b]; | ||
759 | pe[ 6 * 2 + 1] = PC2(b, c, d, a); a = rs[a]; d = rs[d]; | ||
760 | pe[ 7 * 2 + 1] = PC2(d, a, b, c); c = rs[c]; | ||
761 | pe[ 8 * 2 + 1] = PC2(c, d, a, b); b = rs[b]; a = rs[a]; | ||
762 | pe[ 9 * 2 + 1] = PC2(a, b, c, d); d = rs[d]; c = rs[c]; | ||
763 | pe[10 * 2 + 1] = PC2(c, d, a, b); b = rs[b]; a = rs[a]; | ||
764 | pe[11 * 2 + 1] = PC2(a, b, c, d); d = rs[d]; c = rs[c]; | ||
765 | pe[12 * 2 + 1] = PC2(c, d, a, b); b = rs[b]; a = rs[a]; | ||
766 | pe[13 * 2 + 1] = PC2(a, b, c, d); d = rs[d]; c = rs[c]; | ||
767 | pe[14 * 2 + 1] = PC2(c, d, a, b); b = rs[b]; | ||
768 | pe[15 * 2 + 1] = PC2(b, c, d, a); | ||
769 | |||
770 | /* Fixup: 2413 5768 -> 1357 2468 */ | ||
771 | for (d = 0; d < 16; ++d) { | ||
772 | a = pe[2 * d]; | ||
773 | b = pe[2 * d + 1]; | ||
774 | c = a ^ b; | ||
775 | c &= 0xffff0000; | ||
776 | a ^= c; | ||
777 | b ^= c; | ||
778 | ROL(b, 18); | ||
779 | pe[2 * d] = a; | ||
780 | pe[2 * d + 1] = b; | ||
781 | } | ||
1169 | } | 782 | } |
1170 | 783 | ||
1171 | static int des_setkey(void *ctx, const u8 *key, unsigned int keylen, u32 *flags) | 784 | static int des_setkey(void *ctx, const u8 *key, unsigned int keylen, u32 *flags) |
1172 | { | 785 | { |
1173 | return setkey(((struct des_ctx *)ctx)->expkey, key, keylen, flags); | 786 | struct des_ctx *dctx = ctx; |
787 | u32 tmp[DES_EXPKEY_WORDS]; | ||
788 | int ret; | ||
789 | |||
790 | /* Expand to tmp */ | ||
791 | ret = ekey(tmp, key); | ||
792 | |||
793 | if (unlikely(ret == 0) && (*flags & CRYPTO_TFM_REQ_WEAK_KEY)) { | ||
794 | *flags |= CRYPTO_TFM_RES_WEAK_KEY; | ||
795 | return -EINVAL; | ||
796 | } | ||
797 | |||
798 | /* Copy to output */ | ||
799 | memcpy(dctx->expkey, tmp, sizeof(dctx->expkey)); | ||
800 | |||
801 | return 0; | ||
1174 | } | 802 | } |
1175 | 803 | ||
1176 | static void des_encrypt(void *ctx, u8 *dst, const u8 *src) | 804 | static void des_encrypt(void *ctx, u8 *dst, const u8 *src) |
1177 | { | 805 | { |
1178 | des_small_fips_encrypt(((struct des_ctx *)ctx)->expkey, dst, src); | 806 | const u32 *K = ((struct des_ctx *)ctx)->expkey; |
807 | const __le32 *s = (const __le32 *)src; | ||
808 | __le32 *d = (__le32 *)dst; | ||
809 | u32 L, R, A, B; | ||
810 | int i; | ||
811 | |||
812 | L = le32_to_cpu(s[0]); | ||
813 | R = le32_to_cpu(s[1]); | ||
814 | |||
815 | IP(L, R, A); | ||
816 | for (i = 0; i < 8; i++) { | ||
817 | ROUND(L, R, A, B, K, 2); | ||
818 | ROUND(R, L, A, B, K, 2); | ||
819 | } | ||
820 | FP(R, L, A); | ||
821 | |||
822 | d[0] = cpu_to_le32(R); | ||
823 | d[1] = cpu_to_le32(L); | ||
1179 | } | 824 | } |
1180 | 825 | ||
1181 | static void des_decrypt(void *ctx, u8 *dst, const u8 *src) | 826 | static void des_decrypt(void *ctx, u8 *dst, const u8 *src) |
1182 | { | 827 | { |
1183 | des_small_fips_decrypt(((struct des_ctx *)ctx)->expkey, dst, src); | 828 | const u32 *K = ((struct des_ctx *)ctx)->expkey + DES_EXPKEY_WORDS - 2; |
829 | const __le32 *s = (const __le32 *)src; | ||
830 | __le32 *d = (__le32 *)dst; | ||
831 | u32 L, R, A, B; | ||
832 | int i; | ||
833 | |||
834 | L = le32_to_cpu(s[0]); | ||
835 | R = le32_to_cpu(s[1]); | ||
836 | |||
837 | IP(L, R, A); | ||
838 | for (i = 0; i < 8; i++) { | ||
839 | ROUND(L, R, A, B, K, -2); | ||
840 | ROUND(R, L, A, B, K, -2); | ||
841 | } | ||
842 | FP(R, L, A); | ||
843 | |||
844 | d[0] = cpu_to_le32(R); | ||
845 | d[1] = cpu_to_le32(L); | ||
1184 | } | 846 | } |
1185 | 847 | ||
1186 | /* | 848 | /* |
1187 | * RFC2451: | 849 | * RFC2451: |
1188 | * | 850 | * |
1189 | * For DES-EDE3, there is no known need to reject weak or | 851 | * For DES-EDE3, there is no known need to reject weak or |
@@ -1197,44 +859,86 @@ static void des_decrypt(void *ctx, u8 *dst, const u8 *src) | |||
1197 | * | 859 | * |
1198 | */ | 860 | */ |
1199 | static int des3_ede_setkey(void *ctx, const u8 *key, | 861 | static int des3_ede_setkey(void *ctx, const u8 *key, |
1200 | unsigned int keylen, u32 *flags) | 862 | unsigned int keylen, u32 *flags) |
1201 | { | 863 | { |
1202 | unsigned int i, off; | 864 | const u32 *K = (const u32 *)key; |
1203 | struct des3_ede_ctx *dctx = ctx; | 865 | struct des3_ede_ctx *dctx = ctx; |
866 | u32 *expkey = dctx->expkey; | ||
1204 | 867 | ||
1205 | if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) && | 868 | if (unlikely(!((K[0] ^ K[2]) | (K[1] ^ K[3])) || |
1206 | memcmp(&key[DES_KEY_SIZE], &key[DES_KEY_SIZE * 2], | 869 | !((K[2] ^ K[4]) | (K[3] ^ K[5])))) |
1207 | DES_KEY_SIZE))) { | 870 | { |
1208 | |||
1209 | *flags |= CRYPTO_TFM_RES_BAD_KEY_SCHED; | 871 | *flags |= CRYPTO_TFM_RES_BAD_KEY_SCHED; |
1210 | return -EINVAL; | 872 | return -EINVAL; |
1211 | } | 873 | } |
1212 | 874 | ||
1213 | for (i = 0, off = 0; i < 3; i++, off += DES_EXPKEY_WORDS, | 875 | ekey(expkey, key); expkey += DES_EXPKEY_WORDS; key += DES_KEY_SIZE; |
1214 | key += DES_KEY_SIZE) { | 876 | dkey(expkey, key); expkey += DES_EXPKEY_WORDS; key += DES_KEY_SIZE; |
1215 | int ret = setkey(&dctx->expkey[off], key, DES_KEY_SIZE, flags); | 877 | ekey(expkey, key); |
1216 | if (ret < 0) | 878 | |
1217 | return ret; | ||
1218 | } | ||
1219 | return 0; | 879 | return 0; |
1220 | } | 880 | } |
1221 | 881 | ||
1222 | static void des3_ede_encrypt(void *ctx, u8 *dst, const u8 *src) | 882 | static void des3_ede_encrypt(void *ctx, u8 *dst, const u8 *src) |
1223 | { | 883 | { |
1224 | struct des3_ede_ctx *dctx = ctx; | 884 | struct des3_ede_ctx *dctx = ctx; |
1225 | 885 | const u32 *K = dctx->expkey; | |
1226 | des_small_fips_encrypt(dctx->expkey, dst, src); | 886 | const __le32 *s = (const __le32 *)src; |
1227 | des_small_fips_decrypt(&dctx->expkey[DES_EXPKEY_WORDS], dst, dst); | 887 | __le32 *d = (__le32 *)dst; |
1228 | des_small_fips_encrypt(&dctx->expkey[DES_EXPKEY_WORDS * 2], dst, dst); | 888 | u32 L, R, A, B; |
889 | int i; | ||
890 | |||
891 | L = le32_to_cpu(s[0]); | ||
892 | R = le32_to_cpu(s[1]); | ||
893 | |||
894 | IP(L, R, A); | ||
895 | for (i = 0; i < 8; i++) { | ||
896 | ROUND(L, R, A, B, K, 2); | ||
897 | ROUND(R, L, A, B, K, 2); | ||
898 | } | ||
899 | for (i = 0; i < 8; i++) { | ||
900 | ROUND(R, L, A, B, K, 2); | ||
901 | ROUND(L, R, A, B, K, 2); | ||
902 | } | ||
903 | for (i = 0; i < 8; i++) { | ||
904 | ROUND(L, R, A, B, K, 2); | ||
905 | ROUND(R, L, A, B, K, 2); | ||
906 | } | ||
907 | FP(R, L, A); | ||
908 | |||
909 | d[0] = cpu_to_le32(R); | ||
910 | d[1] = cpu_to_le32(L); | ||
1229 | } | 911 | } |
1230 | 912 | ||
1231 | static void des3_ede_decrypt(void *ctx, u8 *dst, const u8 *src) | 913 | static void des3_ede_decrypt(void *ctx, u8 *dst, const u8 *src) |
1232 | { | 914 | { |
1233 | struct des3_ede_ctx *dctx = ctx; | 915 | struct des3_ede_ctx *dctx = ctx; |
916 | const u32 *K = dctx->expkey + DES3_EDE_EXPKEY_WORDS - 2; | ||
917 | const __le32 *s = (const __le32 *)src; | ||
918 | __le32 *d = (__le32 *)dst; | ||
919 | u32 L, R, A, B; | ||
920 | int i; | ||
921 | |||
922 | L = le32_to_cpu(s[0]); | ||
923 | R = le32_to_cpu(s[1]); | ||
924 | |||
925 | IP(L, R, A); | ||
926 | for (i = 0; i < 8; i++) { | ||
927 | ROUND(L, R, A, B, K, -2); | ||
928 | ROUND(R, L, A, B, K, -2); | ||
929 | } | ||
930 | for (i = 0; i < 8; i++) { | ||
931 | ROUND(R, L, A, B, K, -2); | ||
932 | ROUND(L, R, A, B, K, -2); | ||
933 | } | ||
934 | for (i = 0; i < 8; i++) { | ||
935 | ROUND(L, R, A, B, K, -2); | ||
936 | ROUND(R, L, A, B, K, -2); | ||
937 | } | ||
938 | FP(R, L, A); | ||
1234 | 939 | ||
1235 | des_small_fips_decrypt(&dctx->expkey[DES_EXPKEY_WORDS * 2], dst, src); | 940 | d[0] = cpu_to_le32(R); |
1236 | des_small_fips_encrypt(&dctx->expkey[DES_EXPKEY_WORDS], dst, dst); | 941 | d[1] = cpu_to_le32(L); |
1237 | des_small_fips_decrypt(dctx->expkey, dst, dst); | ||
1238 | } | 942 | } |
1239 | 943 | ||
1240 | static struct crypto_alg des_alg = { | 944 | static struct crypto_alg des_alg = { |
@@ -1247,7 +951,7 @@ static struct crypto_alg des_alg = { | |||
1247 | .cra_u = { .cipher = { | 951 | .cra_u = { .cipher = { |
1248 | .cia_min_keysize = DES_KEY_SIZE, | 952 | .cia_min_keysize = DES_KEY_SIZE, |
1249 | .cia_max_keysize = DES_KEY_SIZE, | 953 | .cia_max_keysize = DES_KEY_SIZE, |
1250 | .cia_setkey = des_setkey, | 954 | .cia_setkey = des_setkey, |
1251 | .cia_encrypt = des_encrypt, | 955 | .cia_encrypt = des_encrypt, |
1252 | .cia_decrypt = des_decrypt } } | 956 | .cia_decrypt = des_decrypt } } |
1253 | }; | 957 | }; |
@@ -1262,9 +966,9 @@ static struct crypto_alg des3_ede_alg = { | |||
1262 | .cra_u = { .cipher = { | 966 | .cra_u = { .cipher = { |
1263 | .cia_min_keysize = DES3_EDE_KEY_SIZE, | 967 | .cia_min_keysize = DES3_EDE_KEY_SIZE, |
1264 | .cia_max_keysize = DES3_EDE_KEY_SIZE, | 968 | .cia_max_keysize = DES3_EDE_KEY_SIZE, |
1265 | .cia_setkey = des3_ede_setkey, | 969 | .cia_setkey = des3_ede_setkey, |
1266 | .cia_encrypt = des3_ede_encrypt, | 970 | .cia_encrypt = des3_ede_encrypt, |
1267 | .cia_decrypt = des3_ede_decrypt } } | 971 | .cia_decrypt = des3_ede_decrypt } } |
1268 | }; | 972 | }; |
1269 | 973 | ||
1270 | MODULE_ALIAS("des3_ede"); | 974 | MODULE_ALIAS("des3_ede"); |
@@ -1272,7 +976,7 @@ MODULE_ALIAS("des3_ede"); | |||
1272 | static int __init init(void) | 976 | static int __init init(void) |
1273 | { | 977 | { |
1274 | int ret = 0; | 978 | int ret = 0; |
1275 | 979 | ||
1276 | ret = crypto_register_alg(&des_alg); | 980 | ret = crypto_register_alg(&des_alg); |
1277 | if (ret < 0) | 981 | if (ret < 0) |
1278 | goto out; | 982 | goto out; |
@@ -1280,7 +984,7 @@ static int __init init(void) | |||
1280 | ret = crypto_register_alg(&des3_ede_alg); | 984 | ret = crypto_register_alg(&des3_ede_alg); |
1281 | if (ret < 0) | 985 | if (ret < 0) |
1282 | crypto_unregister_alg(&des_alg); | 986 | crypto_unregister_alg(&des_alg); |
1283 | out: | 987 | out: |
1284 | return ret; | 988 | return ret; |
1285 | } | 989 | } |
1286 | 990 | ||
@@ -1295,3 +999,4 @@ module_exit(fini); | |||
1295 | 999 | ||
1296 | MODULE_LICENSE("GPL"); | 1000 | MODULE_LICENSE("GPL"); |
1297 | MODULE_DESCRIPTION("DES & Triple DES EDE Cipher Algorithms"); | 1001 | MODULE_DESCRIPTION("DES & Triple DES EDE Cipher Algorithms"); |
1002 | MODULE_AUTHOR("Dag Arne Osvik <da@osvik.no>"); | ||