Print this page
4896 Performance improvements for KCF AES modes
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/common/crypto/des/des_impl.c
+++ new/usr/src/common/crypto/des/des_impl.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 +/*
26 + * Copyright 2015 by Saso Kiselkov. All rights reserved.
27 + */
25 28
26 29 #include <sys/types.h>
27 30 #include <sys/systm.h>
28 31 #include <sys/ddi.h>
29 32 #include <sys/sysmacros.h>
30 33 #include <sys/strsun.h>
31 34 #include <sys/crypto/spi.h>
32 35 #include <modes/modes.h>
33 36 #include <sys/crypto/common.h>
34 37 #include "des_impl.h"
35 38 #ifndef _KERNEL
36 39 #include <strings.h>
37 40 #include <stdlib.h>
38 41 #endif /* !_KERNEL */
39 42
40 43 #if defined(__i386) || defined(__amd64)
41 44 #include <sys/byteorder.h>
42 45 #define UNALIGNED_POINTERS_PERMITTED
43 46 #endif
44 47
45 48 typedef struct keysched_s {
46 49 uint64_t ksch_encrypt[16];
47 50 uint64_t ksch_decrypt[16];
48 51 } keysched_t;
49 52
50 53 typedef struct keysched3_s {
51 54 uint64_t ksch_encrypt[48];
52 55 uint64_t ksch_decrypt[48];
53 56 } keysched3_t;
54 57
55 58 static void fix_des_parity(uint64_t *);
56 59
57 60 #ifndef sun4u
58 61
59 62 static const uint64_t sbox_table[8][64]=
60 63 {
61 64 /* BEGIN CSTYLED */
62 65 {
63 66 0x0000140140020000ULL, 0x0000000000000000ULL, 0x0000000140000000ULL, 0x0000140140020020ULL,
64 67 0x0000140140000020ULL, 0x0000000140020020ULL, 0x0000000000000020ULL, 0x0000000140000000ULL,
65 68 0x0000000000020000ULL, 0x0000140140020000ULL, 0x0000140140020020ULL, 0x0000000000020000ULL,
66 69 0x0000140000020020ULL, 0x0000140140000020ULL, 0x0000140000000000ULL, 0x0000000000000020ULL,
67 70 0x0000000000020020ULL, 0x0000140000020000ULL, 0x0000140000020000ULL, 0x0000000140020000ULL,
68 71 0x0000000140020000ULL, 0x0000140140000000ULL, 0x0000140140000000ULL, 0x0000140000020020ULL,
69 72 0x0000000140000020ULL, 0x0000140000000020ULL, 0x0000140000000020ULL, 0x0000000140000020ULL,
70 73 0x0000000000000000ULL, 0x0000000000020020ULL, 0x0000000140020020ULL, 0x0000140000000000ULL,
71 74 0x0000000140000000ULL, 0x0000140140020020ULL, 0x0000000000000020ULL, 0x0000140140000000ULL,
72 75 0x0000140140020000ULL, 0x0000140000000000ULL, 0x0000140000000000ULL, 0x0000000000020000ULL,
73 76 0x0000140140000020ULL, 0x0000000140000000ULL, 0x0000000140020000ULL, 0x0000140000000020ULL,
74 77 0x0000000000020000ULL, 0x0000000000000020ULL, 0x0000140000020020ULL, 0x0000000140020020ULL,
75 78 0x0000140140020020ULL, 0x0000000140000020ULL, 0x0000140140000000ULL, 0x0000140000020020ULL,
76 79 0x0000140000000020ULL, 0x0000000000020020ULL, 0x0000000140020020ULL, 0x0000140140020000ULL,
77 80 0x0000000000020020ULL, 0x0000140000020000ULL, 0x0000140000020000ULL, 0x0000000000000000ULL,
78 81 0x0000000140000020ULL, 0x0000000140020000ULL, 0x0000000000000000ULL, 0x0000140140000020ULL
79 82 },
80 83 {
81 84 0x2000005020000500ULL, 0x2000000020000000ULL, 0x0000000020000000ULL, 0x0000005020000500ULL,
82 85 0x0000005000000000ULL, 0x0000000000000500ULL, 0x2000005000000500ULL, 0x2000000020000500ULL,
83 86 0x2000000000000500ULL, 0x2000005020000500ULL, 0x2000005020000000ULL, 0x2000000000000000ULL,
84 87 0x2000000020000000ULL, 0x0000005000000000ULL, 0x0000000000000500ULL, 0x2000005000000500ULL,
85 88 0x0000005020000000ULL, 0x0000005000000500ULL, 0x2000000020000500ULL, 0x0000000000000000ULL,
86 89 0x2000000000000000ULL, 0x0000000020000000ULL, 0x0000005020000500ULL, 0x2000005000000000ULL,
87 90 0x0000005000000500ULL, 0x2000000000000500ULL, 0x0000000000000000ULL, 0x0000005020000000ULL,
88 91 0x0000000020000500ULL, 0x2000005020000000ULL, 0x2000005000000000ULL, 0x0000000020000500ULL,
89 92 0x0000000000000000ULL, 0x0000005020000500ULL, 0x2000005000000500ULL, 0x0000005000000000ULL,
90 93 0x2000000020000500ULL, 0x2000005000000000ULL, 0x2000005020000000ULL, 0x0000000020000000ULL,
91 94 0x2000005000000000ULL, 0x2000000020000000ULL, 0x0000000000000500ULL, 0x2000005020000500ULL,
92 95 0x0000005020000500ULL, 0x0000000000000500ULL, 0x0000000020000000ULL, 0x2000000000000000ULL,
93 96 0x0000000020000500ULL, 0x2000005020000000ULL, 0x0000005000000000ULL, 0x2000000000000500ULL,
94 97 0x0000005000000500ULL, 0x2000000020000500ULL, 0x2000000000000500ULL, 0x0000005000000500ULL,
95 98 0x0000005020000000ULL, 0x0000000000000000ULL, 0x2000000020000000ULL, 0x0000000020000500ULL,
96 99 0x2000000000000000ULL, 0x2000005000000500ULL, 0x2000005020000500ULL, 0x0000005020000000ULL
97 100 },
98 101 {
99 102 0x0000000000014040ULL, 0x0000800280014000ULL, 0x0000000000000000ULL, 0x0000800280000040ULL,
100 103 0x0000800000014000ULL, 0x0000000000000000ULL, 0x0000000280014040ULL, 0x0000800000014000ULL,
101 104 0x0000000280000040ULL, 0x0000800000000040ULL, 0x0000800000000040ULL, 0x0000000280000000ULL,
102 105 0x0000800280014040ULL, 0x0000000280000040ULL, 0x0000800280000000ULL, 0x0000000000014040ULL,
103 106 0x0000800000000000ULL, 0x0000000000000040ULL, 0x0000800280014000ULL, 0x0000000000014000ULL,
104 107 0x0000000280014000ULL, 0x0000800280000000ULL, 0x0000800280000040ULL, 0x0000000280014040ULL,
105 108 0x0000800000014040ULL, 0x0000000280014000ULL, 0x0000000280000000ULL, 0x0000800000014040ULL,
106 109 0x0000000000000040ULL, 0x0000800280014040ULL, 0x0000000000014000ULL, 0x0000800000000000ULL,
107 110 0x0000800280014000ULL, 0x0000800000000000ULL, 0x0000000280000040ULL, 0x0000000000014040ULL,
108 111 0x0000000280000000ULL, 0x0000800280014000ULL, 0x0000800000014000ULL, 0x0000000000000000ULL,
109 112 0x0000000000014000ULL, 0x0000000280000040ULL, 0x0000800280014040ULL, 0x0000800000014000ULL,
110 113 0x0000800000000040ULL, 0x0000000000014000ULL, 0x0000000000000000ULL, 0x0000800280000040ULL,
111 114 0x0000800000014040ULL, 0x0000000280000000ULL, 0x0000800000000000ULL, 0x0000800280014040ULL,
112 115 0x0000000000000040ULL, 0x0000000280014040ULL, 0x0000000280014000ULL, 0x0000800000000040ULL,
113 116 0x0000800280000000ULL, 0x0000800000014040ULL, 0x0000000000014040ULL, 0x0000800280000000ULL,
114 117 0x0000000280014040ULL, 0x0000000000000040ULL, 0x0000800280000040ULL, 0x0000000280014000ULL
115 118 },
116 119 {
117 120 0x4000020008100008ULL, 0x4000000008101008ULL, 0x4000000008101008ULL, 0x0000000000001000ULL,
118 121 0x0000020008101000ULL, 0x4000020000001008ULL, 0x4000020000000008ULL, 0x4000000008100008ULL,
119 122 0x0000000000000000ULL, 0x0000020008100000ULL, 0x0000020008100000ULL, 0x4000020008101008ULL,
120 123 0x4000000000001008ULL, 0x0000000000000000ULL, 0x0000020000001000ULL, 0x4000020000000008ULL,
121 124 0x4000000000000008ULL, 0x0000000008100000ULL, 0x0000020000000000ULL, 0x4000020008100008ULL,
122 125 0x0000000000001000ULL, 0x0000020000000000ULL, 0x4000000008100008ULL, 0x0000000008101000ULL,
123 126 0x4000020000001008ULL, 0x4000000000000008ULL, 0x0000000008101000ULL, 0x0000020000001000ULL,
124 127 0x0000000008100000ULL, 0x0000020008101000ULL, 0x4000020008101008ULL, 0x4000000000001008ULL,
125 128 0x0000020000001000ULL, 0x4000020000000008ULL, 0x0000020008100000ULL, 0x4000020008101008ULL,
126 129 0x4000000000001008ULL, 0x0000000000000000ULL, 0x0000000000000000ULL, 0x0000020008100000ULL,
127 130 0x0000000008101000ULL, 0x0000020000001000ULL, 0x4000020000001008ULL, 0x4000000000000008ULL,
128 131 0x4000020008100008ULL, 0x4000000008101008ULL, 0x4000000008101008ULL, 0x0000000000001000ULL,
129 132 0x4000020008101008ULL, 0x4000000000001008ULL, 0x4000000000000008ULL, 0x0000000008100000ULL,
130 133 0x4000020000000008ULL, 0x4000000008100008ULL, 0x0000020008101000ULL, 0x4000020000001008ULL,
131 134 0x4000000008100008ULL, 0x0000000008101000ULL, 0x0000020000000000ULL, 0x4000020008100008ULL,
132 135 0x0000000000001000ULL, 0x0000020000000000ULL, 0x0000000008100000ULL, 0x0000020008101000ULL
133 136 },
134 137 {
135 138 0x000000000000a000ULL, 0x000028080000a000ULL, 0x0000280800000000ULL, 0x100028000000a000ULL,
136 139 0x0000000800000000ULL, 0x000000000000a000ULL, 0x1000000000000000ULL, 0x0000280800000000ULL,
137 140 0x100000080000a000ULL, 0x0000000800000000ULL, 0x000028000000a000ULL, 0x100000080000a000ULL,
138 141 0x100028000000a000ULL, 0x1000280800000000ULL, 0x000000080000a000ULL, 0x1000000000000000ULL,
139 142 0x0000280000000000ULL, 0x1000000800000000ULL, 0x1000000800000000ULL, 0x0000000000000000ULL,
140 143 0x100000000000a000ULL, 0x100028080000a000ULL, 0x100028080000a000ULL, 0x000028000000a000ULL,
141 144 0x1000280800000000ULL, 0x100000000000a000ULL, 0x0000000000000000ULL, 0x1000280000000000ULL,
142 145 0x000028080000a000ULL, 0x0000280000000000ULL, 0x1000280000000000ULL, 0x000000080000a000ULL,
143 146 0x0000000800000000ULL, 0x100028000000a000ULL, 0x000000000000a000ULL, 0x0000280000000000ULL,
144 147 0x1000000000000000ULL, 0x0000280800000000ULL, 0x100028000000a000ULL, 0x100000080000a000ULL,
145 148 0x000028000000a000ULL, 0x1000000000000000ULL, 0x1000280800000000ULL, 0x000028080000a000ULL,
146 149 0x100000080000a000ULL, 0x000000000000a000ULL, 0x0000280000000000ULL, 0x1000280800000000ULL,
147 150 0x100028080000a000ULL, 0x000000080000a000ULL, 0x1000280000000000ULL, 0x100028080000a000ULL,
148 151 0x0000280800000000ULL, 0x0000000000000000ULL, 0x1000000800000000ULL, 0x1000280000000000ULL,
149 152 0x000000080000a000ULL, 0x000028000000a000ULL, 0x100000000000a000ULL, 0x0000000800000000ULL,
150 153 0x0000000000000000ULL, 0x1000000800000000ULL, 0x000028080000a000ULL, 0x100000000000a000ULL
151 154 },
152 155 {
153 156 0x0802000000000280ULL, 0x0802010000000000ULL, 0x0000000010000000ULL, 0x0802010010000280ULL,
154 157 0x0802010000000000ULL, 0x0000000000000280ULL, 0x0802010010000280ULL, 0x0000010000000000ULL,
155 158 0x0802000010000000ULL, 0x0000010010000280ULL, 0x0000010000000000ULL, 0x0802000000000280ULL,
156 159 0x0000010000000280ULL, 0x0802000010000000ULL, 0x0802000000000000ULL, 0x0000000010000280ULL,
157 160 0x0000000000000000ULL, 0x0000010000000280ULL, 0x0802000010000280ULL, 0x0000000010000000ULL,
158 161 0x0000010010000000ULL, 0x0802000010000280ULL, 0x0000000000000280ULL, 0x0802010000000280ULL,
159 162 0x0802010000000280ULL, 0x0000000000000000ULL, 0x0000010010000280ULL, 0x0802010010000000ULL,
160 163 0x0000000010000280ULL, 0x0000010010000000ULL, 0x0802010010000000ULL, 0x0802000000000000ULL,
161 164 0x0802000010000000ULL, 0x0000000000000280ULL, 0x0802010000000280ULL, 0x0000010010000000ULL,
162 165 0x0802010010000280ULL, 0x0000010000000000ULL, 0x0000000010000280ULL, 0x0802000000000280ULL,
163 166 0x0000010000000000ULL, 0x0802000010000000ULL, 0x0802000000000000ULL, 0x0000000010000280ULL,
164 167 0x0802000000000280ULL, 0x0802010010000280ULL, 0x0000010010000000ULL, 0x0802010000000000ULL,
165 168 0x0000010010000280ULL, 0x0802010010000000ULL, 0x0000000000000000ULL, 0x0802010000000280ULL,
166 169 0x0000000000000280ULL, 0x0000000010000000ULL, 0x0802010000000000ULL, 0x0000010010000280ULL,
167 170 0x0000000010000000ULL, 0x0000010000000280ULL, 0x0802000010000280ULL, 0x0000000000000000ULL,
168 171 0x0802010010000000ULL, 0x0802000000000000ULL, 0x0000010000000280ULL, 0x0802000010000280ULL
169 172 },
170 173 {
171 174 0x000000a000000000ULL, 0x800040a000000010ULL, 0x8000400000040010ULL, 0x0000000000000000ULL,
172 175 0x0000000000040000ULL, 0x8000400000040010ULL, 0x800000a000040010ULL, 0x000040a000040000ULL,
173 176 0x800040a000040010ULL, 0x000000a000000000ULL, 0x0000000000000000ULL, 0x8000400000000010ULL,
174 177 0x8000000000000010ULL, 0x0000400000000000ULL, 0x800040a000000010ULL, 0x8000000000040010ULL,
175 178 0x0000400000040000ULL, 0x800000a000040010ULL, 0x800000a000000010ULL, 0x0000400000040000ULL,
176 179 0x8000400000000010ULL, 0x000040a000000000ULL, 0x000040a000040000ULL, 0x800000a000000010ULL,
177 180 0x000040a000000000ULL, 0x0000000000040000ULL, 0x8000000000040010ULL, 0x800040a000040010ULL,
178 181 0x000000a000040000ULL, 0x8000000000000010ULL, 0x0000400000000000ULL, 0x000000a000040000ULL,
179 182 0x0000400000000000ULL, 0x000000a000040000ULL, 0x000000a000000000ULL, 0x8000400000040010ULL,
180 183 0x8000400000040010ULL, 0x800040a000000010ULL, 0x800040a000000010ULL, 0x8000000000000010ULL,
181 184 0x800000a000000010ULL, 0x0000400000000000ULL, 0x0000400000040000ULL, 0x000000a000000000ULL,
182 185 0x000040a000040000ULL, 0x8000000000040010ULL, 0x800000a000040010ULL, 0x000040a000040000ULL,
183 186 0x8000000000040010ULL, 0x8000400000000010ULL, 0x800040a000040010ULL, 0x000040a000000000ULL,
184 187 0x000000a000040000ULL, 0x0000000000000000ULL, 0x8000000000000010ULL, 0x800040a000040010ULL,
185 188 0x0000000000000000ULL, 0x800000a000040010ULL, 0x000040a000000000ULL, 0x0000000000040000ULL,
186 189 0x8000400000000010ULL, 0x0000400000040000ULL, 0x0000000000040000ULL, 0x800000a000000010ULL
187 190 },
188 191 {
189 192 0x0401000004080800ULL, 0x0000000004080000ULL, 0x0000000400000000ULL, 0x0401000404080800ULL,
190 193 0x0401000000000000ULL, 0x0401000004080800ULL, 0x0000000000000800ULL, 0x0401000000000000ULL,
191 194 0x0000000400000800ULL, 0x0401000400000000ULL, 0x0401000404080800ULL, 0x0000000404080000ULL,
192 195 0x0401000404080000ULL, 0x0000000404080800ULL, 0x0000000004080000ULL, 0x0000000000000800ULL,
193 196 0x0401000400000000ULL, 0x0401000000000800ULL, 0x0401000004080000ULL, 0x0000000004080800ULL,
194 197 0x0000000404080000ULL, 0x0000000400000800ULL, 0x0401000400000800ULL, 0x0401000404080000ULL,
195 198 0x0000000004080800ULL, 0x0000000000000000ULL, 0x0000000000000000ULL, 0x0401000400000800ULL,
196 199 0x0401000000000800ULL, 0x0401000004080000ULL, 0x0000000404080800ULL, 0x0000000400000000ULL,
197 200 0x0000000404080800ULL, 0x0000000400000000ULL, 0x0401000404080000ULL, 0x0000000004080000ULL,
198 201 0x0000000000000800ULL, 0x0401000400000800ULL, 0x0000000004080000ULL, 0x0000000404080800ULL,
199 202 0x0401000004080000ULL, 0x0000000000000800ULL, 0x0401000000000800ULL, 0x0401000400000000ULL,
200 203 0x0401000400000800ULL, 0x0401000000000000ULL, 0x0000000400000000ULL, 0x0401000004080800ULL,
201 204 0x0000000000000000ULL, 0x0401000404080800ULL, 0x0000000400000800ULL, 0x0401000000000800ULL,
202 205 0x0401000400000000ULL, 0x0401000004080000ULL, 0x0401000004080800ULL, 0x0000000000000000ULL,
203 206 0x0401000404080800ULL, 0x0000000404080000ULL, 0x0000000404080000ULL, 0x0000000004080800ULL,
204 207 0x0000000004080800ULL, 0x0000000400000800ULL, 0x0401000000000000ULL, 0x0401000404080000ULL
205 208 }
206 209 /* END CSTYLED */
207 210 };
208 211
209 212
210 213 static const uint64_t ip_table[2][256]=
211 214 {
212 215 /* BEGIN CSTYLED */
213 216 {
214 217 0x0000000000000000ULL, 0x0000000000000400ULL, 0x0080000000000280ULL, 0x0080000000000680ULL,
215 218 0x0000000000400000ULL, 0x0000000000400400ULL, 0x0080000000400280ULL, 0x0080000000400680ULL,
216 219 0x0000000000280000ULL, 0x0000000000280400ULL, 0x0080000000280280ULL, 0x0080000000280680ULL,
217 220 0x0000000000680000ULL, 0x0000000000680400ULL, 0x0080000000680280ULL, 0x0080000000680680ULL,
218 221 0x0000000400000000ULL, 0x0000000400000400ULL, 0x0080000400000280ULL, 0x0080000400000680ULL,
219 222 0x0000000400400000ULL, 0x0000000400400400ULL, 0x0080000400400280ULL, 0x0080000400400680ULL,
220 223 0x0000000400280000ULL, 0x0000000400280400ULL, 0x0080000400280280ULL, 0x0080000400280680ULL,
221 224 0x0000000400680000ULL, 0x0000000400680400ULL, 0x0080000400680280ULL, 0x0080000400680680ULL,
222 225 0x0000000280000000ULL, 0x0000000280000400ULL, 0x0080000280000280ULL, 0x0080000280000680ULL,
223 226 0x0000000280400000ULL, 0x0000000280400400ULL, 0x0080000280400280ULL, 0x0080000280400680ULL,
224 227 0x0000000280280000ULL, 0x0000000280280400ULL, 0x0080000280280280ULL, 0x0080000280280680ULL,
225 228 0x0000000280680000ULL, 0x0000000280680400ULL, 0x0080000280680280ULL, 0x0080000280680680ULL,
226 229 0x0000000680000000ULL, 0x0000000680000400ULL, 0x0080000680000280ULL, 0x0080000680000680ULL,
227 230 0x0000000680400000ULL, 0x0000000680400400ULL, 0x0080000680400280ULL, 0x0080000680400680ULL,
228 231 0x0000000680280000ULL, 0x0000000680280400ULL, 0x0080000680280280ULL, 0x0080000680280680ULL,
229 232 0x0000000680680000ULL, 0x0000000680680400ULL, 0x0080000680680280ULL, 0x0080000680680680ULL,
230 233 0x0000400000000000ULL, 0x0000400000000400ULL, 0x0080400000000280ULL, 0x0080400000000680ULL,
231 234 0x0000400000400000ULL, 0x0000400000400400ULL, 0x0080400000400280ULL, 0x0080400000400680ULL,
232 235 0x0000400000280000ULL, 0x0000400000280400ULL, 0x0080400000280280ULL, 0x0080400000280680ULL,
233 236 0x0000400000680000ULL, 0x0000400000680400ULL, 0x0080400000680280ULL, 0x0080400000680680ULL,
234 237 0x0000400400000000ULL, 0x0000400400000400ULL, 0x0080400400000280ULL, 0x0080400400000680ULL,
235 238 0x0000400400400000ULL, 0x0000400400400400ULL, 0x0080400400400280ULL, 0x0080400400400680ULL,
236 239 0x0000400400280000ULL, 0x0000400400280400ULL, 0x0080400400280280ULL, 0x0080400400280680ULL,
237 240 0x0000400400680000ULL, 0x0000400400680400ULL, 0x0080400400680280ULL, 0x0080400400680680ULL,
238 241 0x0000400280000000ULL, 0x0000400280000400ULL, 0x0080400280000280ULL, 0x0080400280000680ULL,
239 242 0x0000400280400000ULL, 0x0000400280400400ULL, 0x0080400280400280ULL, 0x0080400280400680ULL,
240 243 0x0000400280280000ULL, 0x0000400280280400ULL, 0x0080400280280280ULL, 0x0080400280280680ULL,
241 244 0x0000400280680000ULL, 0x0000400280680400ULL, 0x0080400280680280ULL, 0x0080400280680680ULL,
242 245 0x0000400680000000ULL, 0x0000400680000400ULL, 0x0080400680000280ULL, 0x0080400680000680ULL,
243 246 0x0000400680400000ULL, 0x0000400680400400ULL, 0x0080400680400280ULL, 0x0080400680400680ULL,
244 247 0x0000400680280000ULL, 0x0000400680280400ULL, 0x0080400680280280ULL, 0x0080400680280680ULL,
245 248 0x0000400680680000ULL, 0x0000400680680400ULL, 0x0080400680680280ULL, 0x0080400680680680ULL,
246 249 0x0000280000000000ULL, 0x0000280000000400ULL, 0x0080280000000280ULL, 0x0080280000000680ULL,
247 250 0x0000280000400000ULL, 0x0000280000400400ULL, 0x0080280000400280ULL, 0x0080280000400680ULL,
248 251 0x0000280000280000ULL, 0x0000280000280400ULL, 0x0080280000280280ULL, 0x0080280000280680ULL,
249 252 0x0000280000680000ULL, 0x0000280000680400ULL, 0x0080280000680280ULL, 0x0080280000680680ULL,
250 253 0x0000280400000000ULL, 0x0000280400000400ULL, 0x0080280400000280ULL, 0x0080280400000680ULL,
251 254 0x0000280400400000ULL, 0x0000280400400400ULL, 0x0080280400400280ULL, 0x0080280400400680ULL,
252 255 0x0000280400280000ULL, 0x0000280400280400ULL, 0x0080280400280280ULL, 0x0080280400280680ULL,
253 256 0x0000280400680000ULL, 0x0000280400680400ULL, 0x0080280400680280ULL, 0x0080280400680680ULL,
254 257 0x0000280280000000ULL, 0x0000280280000400ULL, 0x0080280280000280ULL, 0x0080280280000680ULL,
255 258 0x0000280280400000ULL, 0x0000280280400400ULL, 0x0080280280400280ULL, 0x0080280280400680ULL,
256 259 0x0000280280280000ULL, 0x0000280280280400ULL, 0x0080280280280280ULL, 0x0080280280280680ULL,
257 260 0x0000280280680000ULL, 0x0000280280680400ULL, 0x0080280280680280ULL, 0x0080280280680680ULL,
258 261 0x0000280680000000ULL, 0x0000280680000400ULL, 0x0080280680000280ULL, 0x0080280680000680ULL,
259 262 0x0000280680400000ULL, 0x0000280680400400ULL, 0x0080280680400280ULL, 0x0080280680400680ULL,
260 263 0x0000280680280000ULL, 0x0000280680280400ULL, 0x0080280680280280ULL, 0x0080280680280680ULL,
261 264 0x0000280680680000ULL, 0x0000280680680400ULL, 0x0080280680680280ULL, 0x0080280680680680ULL,
262 265 0x0000680000000000ULL, 0x0000680000000400ULL, 0x0080680000000280ULL, 0x0080680000000680ULL,
263 266 0x0000680000400000ULL, 0x0000680000400400ULL, 0x0080680000400280ULL, 0x0080680000400680ULL,
264 267 0x0000680000280000ULL, 0x0000680000280400ULL, 0x0080680000280280ULL, 0x0080680000280680ULL,
265 268 0x0000680000680000ULL, 0x0000680000680400ULL, 0x0080680000680280ULL, 0x0080680000680680ULL,
266 269 0x0000680400000000ULL, 0x0000680400000400ULL, 0x0080680400000280ULL, 0x0080680400000680ULL,
267 270 0x0000680400400000ULL, 0x0000680400400400ULL, 0x0080680400400280ULL, 0x0080680400400680ULL,
268 271 0x0000680400280000ULL, 0x0000680400280400ULL, 0x0080680400280280ULL, 0x0080680400280680ULL,
269 272 0x0000680400680000ULL, 0x0000680400680400ULL, 0x0080680400680280ULL, 0x0080680400680680ULL,
270 273 0x0000680280000000ULL, 0x0000680280000400ULL, 0x0080680280000280ULL, 0x0080680280000680ULL,
271 274 0x0000680280400000ULL, 0x0000680280400400ULL, 0x0080680280400280ULL, 0x0080680280400680ULL,
272 275 0x0000680280280000ULL, 0x0000680280280400ULL, 0x0080680280280280ULL, 0x0080680280280680ULL,
273 276 0x0000680280680000ULL, 0x0000680280680400ULL, 0x0080680280680280ULL, 0x0080680280680680ULL,
274 277 0x0000680680000000ULL, 0x0000680680000400ULL, 0x0080680680000280ULL, 0x0080680680000680ULL,
275 278 0x0000680680400000ULL, 0x0000680680400400ULL, 0x0080680680400280ULL, 0x0080680680400680ULL,
276 279 0x0000680680280000ULL, 0x0000680680280400ULL, 0x0080680680280280ULL, 0x0080680680280680ULL,
277 280 0x0000680680680000ULL, 0x0000680680680400ULL, 0x0080680680680280ULL, 0x0080680680680680ULL
278 281 },
279 282 {
280 283 0x0000000000000000ULL, 0x0000000000005000ULL, 0x0000000000000800ULL, 0x0000000000005800ULL,
281 284 0x0000000005000000ULL, 0x0000000005005000ULL, 0x0000000005000800ULL, 0x0000000005005800ULL,
282 285 0x0000000000800000ULL, 0x0000000000805000ULL, 0x0000000000800800ULL, 0x0000000000805800ULL,
283 286 0x0000000005800000ULL, 0x0000000005805000ULL, 0x0000000005800800ULL, 0x0000000005805800ULL,
284 287 0x0000005000000000ULL, 0x0000005000005000ULL, 0x0000005000000800ULL, 0x0000005000005800ULL,
285 288 0x0000005005000000ULL, 0x0000005005005000ULL, 0x0000005005000800ULL, 0x0000005005005800ULL,
286 289 0x0000005000800000ULL, 0x0000005000805000ULL, 0x0000005000800800ULL, 0x0000005000805800ULL,
287 290 0x0000005005800000ULL, 0x0000005005805000ULL, 0x0000005005800800ULL, 0x0000005005805800ULL,
288 291 0x0000000800000000ULL, 0x0000000800005000ULL, 0x0000000800000800ULL, 0x0000000800005800ULL,
289 292 0x0000000805000000ULL, 0x0000000805005000ULL, 0x0000000805000800ULL, 0x0000000805005800ULL,
290 293 0x0000000800800000ULL, 0x0000000800805000ULL, 0x0000000800800800ULL, 0x0000000800805800ULL,
291 294 0x0000000805800000ULL, 0x0000000805805000ULL, 0x0000000805800800ULL, 0x0000000805805800ULL,
292 295 0x0000005800000000ULL, 0x0000005800005000ULL, 0x0000005800000800ULL, 0x0000005800005800ULL,
293 296 0x0000005805000000ULL, 0x0000005805005000ULL, 0x0000005805000800ULL, 0x0000005805005800ULL,
294 297 0x0000005800800000ULL, 0x0000005800805000ULL, 0x0000005800800800ULL, 0x0000005800805800ULL,
295 298 0x0000005805800000ULL, 0x0000005805805000ULL, 0x0000005805800800ULL, 0x0000005805805800ULL,
296 299 0x0005000000000004ULL, 0x0005000000005004ULL, 0x0005000000000804ULL, 0x0005000000005804ULL,
297 300 0x0005000005000004ULL, 0x0005000005005004ULL, 0x0005000005000804ULL, 0x0005000005005804ULL,
298 301 0x0005000000800004ULL, 0x0005000000805004ULL, 0x0005000000800804ULL, 0x0005000000805804ULL,
299 302 0x0005000005800004ULL, 0x0005000005805004ULL, 0x0005000005800804ULL, 0x0005000005805804ULL,
300 303 0x0005005000000004ULL, 0x0005005000005004ULL, 0x0005005000000804ULL, 0x0005005000005804ULL,
301 304 0x0005005005000004ULL, 0x0005005005005004ULL, 0x0005005005000804ULL, 0x0005005005005804ULL,
302 305 0x0005005000800004ULL, 0x0005005000805004ULL, 0x0005005000800804ULL, 0x0005005000805804ULL,
303 306 0x0005005005800004ULL, 0x0005005005805004ULL, 0x0005005005800804ULL, 0x0005005005805804ULL,
304 307 0x0005000800000004ULL, 0x0005000800005004ULL, 0x0005000800000804ULL, 0x0005000800005804ULL,
305 308 0x0005000805000004ULL, 0x0005000805005004ULL, 0x0005000805000804ULL, 0x0005000805005804ULL,
306 309 0x0005000800800004ULL, 0x0005000800805004ULL, 0x0005000800800804ULL, 0x0005000800805804ULL,
307 310 0x0005000805800004ULL, 0x0005000805805004ULL, 0x0005000805800804ULL, 0x0005000805805804ULL,
308 311 0x0005005800000004ULL, 0x0005005800005004ULL, 0x0005005800000804ULL, 0x0005005800005804ULL,
309 312 0x0005005805000004ULL, 0x0005005805005004ULL, 0x0005005805000804ULL, 0x0005005805005804ULL,
310 313 0x0005005800800004ULL, 0x0005005800805004ULL, 0x0005005800800804ULL, 0x0005005800805804ULL,
311 314 0x0005005805800004ULL, 0x0005005805805004ULL, 0x0005005805800804ULL, 0x0005005805805804ULL,
312 315 0x0000800000000000ULL, 0x0000800000005000ULL, 0x0000800000000800ULL, 0x0000800000005800ULL,
313 316 0x0000800005000000ULL, 0x0000800005005000ULL, 0x0000800005000800ULL, 0x0000800005005800ULL,
314 317 0x0000800000800000ULL, 0x0000800000805000ULL, 0x0000800000800800ULL, 0x0000800000805800ULL,
315 318 0x0000800005800000ULL, 0x0000800005805000ULL, 0x0000800005800800ULL, 0x0000800005805800ULL,
316 319 0x0000805000000000ULL, 0x0000805000005000ULL, 0x0000805000000800ULL, 0x0000805000005800ULL,
317 320 0x0000805005000000ULL, 0x0000805005005000ULL, 0x0000805005000800ULL, 0x0000805005005800ULL,
318 321 0x0000805000800000ULL, 0x0000805000805000ULL, 0x0000805000800800ULL, 0x0000805000805800ULL,
319 322 0x0000805005800000ULL, 0x0000805005805000ULL, 0x0000805005800800ULL, 0x0000805005805800ULL,
320 323 0x0000800800000000ULL, 0x0000800800005000ULL, 0x0000800800000800ULL, 0x0000800800005800ULL,
321 324 0x0000800805000000ULL, 0x0000800805005000ULL, 0x0000800805000800ULL, 0x0000800805005800ULL,
322 325 0x0000800800800000ULL, 0x0000800800805000ULL, 0x0000800800800800ULL, 0x0000800800805800ULL,
323 326 0x0000800805800000ULL, 0x0000800805805000ULL, 0x0000800805800800ULL, 0x0000800805805800ULL,
324 327 0x0000805800000000ULL, 0x0000805800005000ULL, 0x0000805800000800ULL, 0x0000805800005800ULL,
325 328 0x0000805805000000ULL, 0x0000805805005000ULL, 0x0000805805000800ULL, 0x0000805805005800ULL,
326 329 0x0000805800800000ULL, 0x0000805800805000ULL, 0x0000805800800800ULL, 0x0000805800805800ULL,
327 330 0x0000805805800000ULL, 0x0000805805805000ULL, 0x0000805805800800ULL, 0x0000805805805800ULL,
328 331 0x0005800000000004ULL, 0x0005800000005004ULL, 0x0005800000000804ULL, 0x0005800000005804ULL,
329 332 0x0005800005000004ULL, 0x0005800005005004ULL, 0x0005800005000804ULL, 0x0005800005005804ULL,
330 333 0x0005800000800004ULL, 0x0005800000805004ULL, 0x0005800000800804ULL, 0x0005800000805804ULL,
331 334 0x0005800005800004ULL, 0x0005800005805004ULL, 0x0005800005800804ULL, 0x0005800005805804ULL,
332 335 0x0005805000000004ULL, 0x0005805000005004ULL, 0x0005805000000804ULL, 0x0005805000005804ULL,
333 336 0x0005805005000004ULL, 0x0005805005005004ULL, 0x0005805005000804ULL, 0x0005805005005804ULL,
334 337 0x0005805000800004ULL, 0x0005805000805004ULL, 0x0005805000800804ULL, 0x0005805000805804ULL,
335 338 0x0005805005800004ULL, 0x0005805005805004ULL, 0x0005805005800804ULL, 0x0005805005805804ULL,
336 339 0x0005800800000004ULL, 0x0005800800005004ULL, 0x0005800800000804ULL, 0x0005800800005804ULL,
337 340 0x0005800805000004ULL, 0x0005800805005004ULL, 0x0005800805000804ULL, 0x0005800805005804ULL,
338 341 0x0005800800800004ULL, 0x0005800800805004ULL, 0x0005800800800804ULL, 0x0005800800805804ULL,
339 342 0x0005800805800004ULL, 0x0005800805805004ULL, 0x0005800805800804ULL, 0x0005800805805804ULL,
340 343 0x0005805800000004ULL, 0x0005805800005004ULL, 0x0005805800000804ULL, 0x0005805800005804ULL,
341 344 0x0005805805000004ULL, 0x0005805805005004ULL, 0x0005805805000804ULL, 0x0005805805005804ULL,
342 345 0x0005805800800004ULL, 0x0005805800805004ULL, 0x0005805800800804ULL, 0x0005805800805804ULL,
343 346 0x0005805805800004ULL, 0x0005805805805004ULL, 0x0005805805800804ULL, 0x0005805805805804ULL
344 347 }
345 348 /* END CSTYLED */
346 349 };
347 350
348 351 static const uint32_t fp_table[256]=
349 352 {
350 353 0x00000000, 0x80000000, 0x00800000, 0x80800000,
351 354 0x00008000, 0x80008000, 0x00808000, 0x80808000,
352 355 0x00000080, 0x80000080, 0x00800080, 0x80800080,
353 356 0x00008080, 0x80008080, 0x00808080, 0x80808080,
354 357 0x40000000, 0xc0000000, 0x40800000, 0xc0800000,
355 358 0x40008000, 0xc0008000, 0x40808000, 0xc0808000,
356 359 0x40000080, 0xc0000080, 0x40800080, 0xc0800080,
357 360 0x40008080, 0xc0008080, 0x40808080, 0xc0808080,
358 361 0x00400000, 0x80400000, 0x00c00000, 0x80c00000,
359 362 0x00408000, 0x80408000, 0x00c08000, 0x80c08000,
360 363 0x00400080, 0x80400080, 0x00c00080, 0x80c00080,
361 364 0x00408080, 0x80408080, 0x00c08080, 0x80c08080,
362 365 0x40400000, 0xc0400000, 0x40c00000, 0xc0c00000,
363 366 0x40408000, 0xc0408000, 0x40c08000, 0xc0c08000,
364 367 0x40400080, 0xc0400080, 0x40c00080, 0xc0c00080,
365 368 0x40408080, 0xc0408080, 0x40c08080, 0xc0c08080,
366 369 0x00004000, 0x80004000, 0x00804000, 0x80804000,
367 370 0x0000c000, 0x8000c000, 0x0080c000, 0x8080c000,
368 371 0x00004080, 0x80004080, 0x00804080, 0x80804080,
369 372 0x0000c080, 0x8000c080, 0x0080c080, 0x8080c080,
370 373 0x40004000, 0xc0004000, 0x40804000, 0xc0804000,
371 374 0x4000c000, 0xc000c000, 0x4080c000, 0xc080c000,
372 375 0x40004080, 0xc0004080, 0x40804080, 0xc0804080,
373 376 0x4000c080, 0xc000c080, 0x4080c080, 0xc080c080,
374 377 0x00404000, 0x80404000, 0x00c04000, 0x80c04000,
375 378 0x0040c000, 0x8040c000, 0x00c0c000, 0x80c0c000,
376 379 0x00404080, 0x80404080, 0x00c04080, 0x80c04080,
377 380 0x0040c080, 0x8040c080, 0x00c0c080, 0x80c0c080,
378 381 0x40404000, 0xc0404000, 0x40c04000, 0xc0c04000,
379 382 0x4040c000, 0xc040c000, 0x40c0c000, 0xc0c0c000,
380 383 0x40404080, 0xc0404080, 0x40c04080, 0xc0c04080,
381 384 0x4040c080, 0xc040c080, 0x40c0c080, 0xc0c0c080,
382 385 0x00000040, 0x80000040, 0x00800040, 0x80800040,
383 386 0x00008040, 0x80008040, 0x00808040, 0x80808040,
384 387 0x000000c0, 0x800000c0, 0x008000c0, 0x808000c0,
385 388 0x000080c0, 0x800080c0, 0x008080c0, 0x808080c0,
386 389 0x40000040, 0xc0000040, 0x40800040, 0xc0800040,
387 390 0x40008040, 0xc0008040, 0x40808040, 0xc0808040,
388 391 0x400000c0, 0xc00000c0, 0x408000c0, 0xc08000c0,
389 392 0x400080c0, 0xc00080c0, 0x408080c0, 0xc08080c0,
390 393 0x00400040, 0x80400040, 0x00c00040, 0x80c00040,
391 394 0x00408040, 0x80408040, 0x00c08040, 0x80c08040,
392 395 0x004000c0, 0x804000c0, 0x00c000c0, 0x80c000c0,
393 396 0x004080c0, 0x804080c0, 0x00c080c0, 0x80c080c0,
394 397 0x40400040, 0xc0400040, 0x40c00040, 0xc0c00040,
395 398 0x40408040, 0xc0408040, 0x40c08040, 0xc0c08040,
396 399 0x404000c0, 0xc04000c0, 0x40c000c0, 0xc0c000c0,
397 400 0x404080c0, 0xc04080c0, 0x40c080c0, 0xc0c080c0,
398 401 0x00004040, 0x80004040, 0x00804040, 0x80804040,
399 402 0x0000c040, 0x8000c040, 0x0080c040, 0x8080c040,
400 403 0x000040c0, 0x800040c0, 0x008040c0, 0x808040c0,
401 404 0x0000c0c0, 0x8000c0c0, 0x0080c0c0, 0x8080c0c0,
402 405 0x40004040, 0xc0004040, 0x40804040, 0xc0804040,
403 406 0x4000c040, 0xc000c040, 0x4080c040, 0xc080c040,
404 407 0x400040c0, 0xc00040c0, 0x408040c0, 0xc08040c0,
405 408 0x4000c0c0, 0xc000c0c0, 0x4080c0c0, 0xc080c0c0,
406 409 0x00404040, 0x80404040, 0x00c04040, 0x80c04040,
407 410 0x0040c040, 0x8040c040, 0x00c0c040, 0x80c0c040,
408 411 0x004040c0, 0x804040c0, 0x00c040c0, 0x80c040c0,
409 412 0x0040c0c0, 0x8040c0c0, 0x00c0c0c0, 0x80c0c0c0,
410 413 0x40404040, 0xc0404040, 0x40c04040, 0xc0c04040,
411 414 0x4040c040, 0xc040c040, 0x40c0c040, 0xc0c0c040,
412 415 0x404040c0, 0xc04040c0, 0x40c040c0, 0xc0c040c0,
413 416 0x4040c0c0, 0xc040c0c0, 0x40c0c0c0, 0xc0c0c0c0
414 417 };
415 418
416 419 static const uint64_t all_a = 0xaaaaaaaaaaaaaaaaULL;
417 420 static const uint64_t all_5 = 0x5555555555555555ULL;
418 421 static const uint64_t top_1 = 0xfc000000000000ULL;
419 422 static const uint64_t mid_4 = 0x3fffffc000000ULL;
420 423 static const uint64_t low_3 = 0x3ffff00ULL;
421 424
422 425
423 426 static void
424 427 des_ip(uint64_t *l, uint64_t *r, uint64_t pt)
425 428 {
426 429 uint64_t a, b;
427 430
428 431 a = pt & all_a;
429 432 b = pt & all_5;
430 433 a = a | (a << 7);
431 434 b = b | (b >> 7);
432 435
433 436 b = (ip_table[0][(b >> 48) & 255ULL]) |
434 437 (ip_table[1][(b >> 32) & 255ULL]) |
435 438 (ip_table[0][(b >> 16) & 255ULL] << 6) |
436 439 (ip_table[1][b & 255ULL] << 6);
437 440
438 441 a = (ip_table[0][(a >> 56) & 255]) |
439 442 (ip_table[1][(a >> 40) & 255]) |
440 443 (ip_table[0][(a >> 24) & 255] << 6) |
441 444 (ip_table[1][(a >> 8) & 255] << 6);
442 445
443 446 *l = ((b & top_1) << 8) |
444 447 (b & mid_4) |
445 448 ((b & low_3) >> 5);
446 449
447 450 *r = ((a & top_1) << 8) |
448 451 (a & mid_4) |
449 452 ((a & low_3) >> 5);
450 453 }
451 454
452 455
453 456 static uint64_t
454 457 des_fp(uint64_t l, uint64_t r)
455 458 {
456 459 uint32_t upper, lower;
457 460
458 461 lower = fp_table[((l >> 55) & 240) | ((r >> 59) & 15)] |
459 462 (fp_table[((l >> 35) & 240) | ((r>>39) & 15)] >> 2) |
460 463 (fp_table[((l >> 23) & 240) | ((r >> 27) & 15)] >> 4) |
461 464 (fp_table[((l >> 6) & 240) | ((r >> 10) & 15)] >> 6);
462 465
463 466 upper = fp_table[((l >> 41) & 240) | ((r >> 45) & 15)] |
464 467 (fp_table[((l >> 29) & 240) | ((r >> 33) & 15)] >> 2) |
465 468 (fp_table[((l >> 12) & 240) | ((r >> 16) & 15)] >> 4) |
466 469 (fp_table[(l & 240) | (r >> 4) & 15] >> 6);
467 470
468 471 return ((((uint64_t)upper) << 32) | (uint64_t)lower);
469 472
470 473 }
471 474
472 475 uint64_t
473 476 des_crypt_impl(uint64_t *ks, uint64_t block, int one_or_three)
474 477 {
475 478 int i, j;
476 479 uint64_t l, r, t;
477 480
478 481 des_ip(&l, &r, block);
479 482 for (j = 0; j < one_or_three; j++) {
480 483 for (i = j * 16; i < (j + 1) * 16; i++) {
481 484 t = r ^ ks[i];
482 485 t = sbox_table[0][t >> 58] |
483 486 sbox_table[1][(t >> 44) & 63] |
484 487 sbox_table[2][(t >> 38) & 63] |
485 488 sbox_table[3][(t >> 32) & 63] |
486 489 sbox_table[4][(t >> 26) & 63] |
487 490 sbox_table[5][(t >> 15) & 63] |
488 491 sbox_table[6][(t >> 9) & 63] |
489 492 sbox_table[7][(t >> 3) & 63];
490 493 t = t^l;
491 494 l = r;
492 495 r = t;
493 496 }
494 497 r = l;
495 498 l = t;
496 499 }
497 500
498 501 return (des_fp(l, r));
499 502 }
500 503 #endif /* !sun4u */
501 504
502 505 int
503 506 des3_crunch_block(const void *cookie, const uint8_t block[DES_BLOCK_LEN],
504 507 uint8_t out_block[DES_BLOCK_LEN], boolean_t decrypt)
505 508 {
506 509 keysched3_t *ksch = (keysched3_t *)cookie;
507 510
508 511 /*
509 512 * The code below, that is always executed on LITTLE_ENDIAN machines,
510 513 * reverses bytes in the block. On BIG_ENDIAN, the same code
511 514 * copies the block without reversing bytes.
512 515 */
513 516 #ifdef _BIG_ENDIAN
514 517 if (IS_P2ALIGNED(block, sizeof (uint64_t)) &&
515 518 IS_P2ALIGNED(out_block, sizeof (uint64_t))) {
516 519 if (decrypt == B_TRUE)
517 520 /* LINTED */
518 521 *(uint64_t *)out_block = des_crypt_impl(
519 522 ksch->ksch_decrypt, /* LINTED */
520 523 *(uint64_t *)block, 3);
521 524 else
522 525 /* LINTED */
523 526 *(uint64_t *)out_block = des_crypt_impl(
524 527 ksch->ksch_encrypt, /* LINTED */
525 528 *(uint64_t *)block, 3);
526 529 } else
527 530 #endif /* _BIG_ENDIAN */
528 531 {
529 532 uint64_t tmp;
530 533
531 534 #ifdef UNALIGNED_POINTERS_PERMITTED
532 535 tmp = htonll(*(uint64_t *)(void *)&block[0]);
533 536 #else
534 537 tmp = (((uint64_t)block[0] << 56) | ((uint64_t)block[1] << 48) |
535 538 ((uint64_t)block[2] << 40) | ((uint64_t)block[3] << 32) |
536 539 ((uint64_t)block[4] << 24) | ((uint64_t)block[5] << 16) |
537 540 ((uint64_t)block[6] << 8) | (uint64_t)block[7]);
538 541 #endif /* UNALIGNED_POINTERS_PERMITTED */
539 542
540 543 if (decrypt == B_TRUE)
541 544 tmp = des_crypt_impl(ksch->ksch_decrypt, tmp, 3);
542 545 else
543 546 tmp = des_crypt_impl(ksch->ksch_encrypt, tmp, 3);
544 547
545 548 #ifdef UNALIGNED_POINTERS_PERMITTED
546 549 *(uint64_t *)(void *)&out_block[0] = htonll(tmp);
547 550 #else
548 551 out_block[0] = tmp >> 56;
549 552 out_block[1] = tmp >> 48;
550 553 out_block[2] = tmp >> 40;
551 554 out_block[3] = tmp >> 32;
552 555 out_block[4] = tmp >> 24;
553 556 out_block[5] = tmp >> 16;
554 557 out_block[6] = tmp >> 8;
555 558 out_block[7] = (uint8_t)tmp;
556 559 #endif /* UNALIGNED_POINTERS_PERMITTED */
557 560 }
558 561 return (CRYPTO_SUCCESS);
559 562 }
560 563
561 564 int
562 565 des_crunch_block(const void *cookie, const uint8_t block[DES_BLOCK_LEN],
563 566 uint8_t out_block[DES_BLOCK_LEN], boolean_t decrypt)
564 567 {
565 568 keysched_t *ksch = (keysched_t *)cookie;
566 569
567 570 /*
568 571 * The code below, that is always executed on LITTLE_ENDIAN machines,
569 572 * reverses bytes in the block. On BIG_ENDIAN, the same code
570 573 * copies the block without reversing bytes.
571 574 */
572 575 #ifdef _BIG_ENDIAN
573 576 if (IS_P2ALIGNED(block, sizeof (uint64_t)) &&
574 577 IS_P2ALIGNED(out_block, sizeof (uint64_t))) {
575 578 if (decrypt == B_TRUE)
576 579 /* LINTED */
577 580 *(uint64_t *)out_block = des_crypt_impl(
578 581 ksch->ksch_decrypt, /* LINTED */
579 582 *(uint64_t *)block, 1);
580 583 else
581 584 /* LINTED */
582 585 *(uint64_t *)out_block = des_crypt_impl(
583 586 ksch->ksch_encrypt, /* LINTED */
584 587 *(uint64_t *)block, 1);
585 588
586 589 } else
587 590 #endif /* _BIG_ENDIAN */
588 591 {
589 592 uint64_t tmp;
590 593
591 594 #ifdef UNALIGNED_POINTERS_PERMITTED
592 595 tmp = htonll(*(uint64_t *)(void *)&block[0]);
593 596 #else
594 597 tmp = (((uint64_t)block[0] << 56) | ((uint64_t)block[1] << 48) |
595 598 ((uint64_t)block[2] << 40) | ((uint64_t)block[3] << 32) |
596 599 ((uint64_t)block[4] << 24) | ((uint64_t)block[5] << 16) |
597 600 ((uint64_t)block[6] << 8) | (uint64_t)block[7]);
598 601 #endif /* UNALIGNED_POINTERS_PERMITTED */
599 602
600 603
601 604 if (decrypt == B_TRUE)
602 605 tmp = des_crypt_impl(ksch->ksch_decrypt, tmp, 1);
603 606 else
604 607 tmp = des_crypt_impl(ksch->ksch_encrypt, tmp, 1);
605 608
606 609 #ifdef UNALIGNED_POINTERS_PERMITTED
607 610 *(uint64_t *)(void *)&out_block[0] = htonll(tmp);
608 611 #else
609 612 out_block[0] = tmp >> 56;
610 613 out_block[1] = tmp >> 48;
611 614 out_block[2] = tmp >> 40;
612 615 out_block[3] = tmp >> 32;
613 616 out_block[4] = tmp >> 24;
614 617 out_block[5] = tmp >> 16;
615 618 out_block[6] = tmp >> 8;
616 619 out_block[7] = (uint8_t)tmp;
617 620 #endif /* UNALIGNED_POINTERS_PERMITTED */
618 621 }
619 622 return (CRYPTO_SUCCESS);
620 623 }
621 624
622 625 static boolean_t
623 626 keycheck(uint8_t *key, uint8_t *corrected_key)
624 627 {
625 628 uint64_t key_so_far;
626 629 uint_t i;
627 630 /*
628 631 * Table of weak and semi-weak keys. Fortunately, weak keys are
629 632 * endian-independent, and some semi-weak keys can be paired up in
630 633 * endian-opposite order. Since keys are stored as uint64_t's,
631 634 * use the ifdef _LITTLE_ENDIAN where appropriate.
632 635 */
633 636 static uint64_t des_weak_keys[] = {
634 637 /* Really weak keys. Byte-order independent values. */
635 638 0x0101010101010101ULL,
636 639 0x1f1f1f1f0e0e0e0eULL,
637 640 0xe0e0e0e0f1f1f1f1ULL,
638 641 0xfefefefefefefefeULL,
639 642
640 643 /* Semi-weak (and a few possibly-weak) keys. */
641 644
642 645 /* Byte-order independent semi-weak keys. */
643 646 0x01fe01fe01fe01feULL, 0xfe01fe01fe01fe01ULL,
644 647
645 648 /* Byte-order dependent semi-weak keys. */
646 649 #ifdef _LITTLE_ENDIAN
647 650 0xf10ef10ee01fe01fULL, 0x0ef10ef11fe01fe0ULL,
648 651 0x01f101f101e001e0ULL, 0xf101f101e001e001ULL,
649 652 0x0efe0efe1ffe1ffeULL, 0xfe0efe0efe1ffe1fULL,
650 653 0x010e010e011f011fULL, 0x0e010e011f011f01ULL,
651 654 0xf1fef1fee0fee0feULL, 0xfef1fef1fee0fee0ULL,
652 655 #else /* Big endian */
653 656 0x1fe01fe00ef10ef1ULL, 0xe01fe01ff10ef10eULL,
654 657 0x01e001e001f101f1ULL, 0xe001e001f101f101ULL,
655 658 0x1ffe1ffe0efe0efeULL, 0xfe1ffe1ffe0efe0eULL,
656 659 0x011f011f010e010eULL, 0x1f011f010e010e01ULL,
657 660 0xe0fee0fef1fef1feULL, 0xfee0fee0fef1fef1ULL,
658 661 #endif /* _LITTLE_ENDIAN */
659 662
660 663 /* We'll save the other possibly-weak keys for the future. */
661 664 };
662 665
663 666 if (key == NULL)
664 667 return (B_FALSE);
665 668
666 669 #ifdef UNALIGNED_POINTERS_PERMITTED
667 670 key_so_far = htonll(*(uint64_t *)(void *)&key[0]);
668 671 #else
669 672 /*
670 673 * The code below reverses the bytes on LITTLE_ENDIAN machines.
671 674 * On BIG_ENDIAN, the same code copies without reversing
672 675 * the bytes.
673 676 */
674 677 key_so_far = (((uint64_t)key[0] << 56) | ((uint64_t)key[1] << 48) |
675 678 ((uint64_t)key[2] << 40) | ((uint64_t)key[3] << 32) |
676 679 ((uint64_t)key[4] << 24) | ((uint64_t)key[5] << 16) |
677 680 ((uint64_t)key[6] << 8) | (uint64_t)key[7]);
678 681 #endif /* UNALIGNED_POINTERS_PERMITTED */
679 682
680 683 /*
681 684 * Fix parity.
682 685 */
683 686 fix_des_parity(&key_so_far);
684 687
685 688 /* Do weak key check itself. */
686 689 for (i = 0; i < (sizeof (des_weak_keys) / sizeof (uint64_t)); i++)
687 690 if (key_so_far == des_weak_keys[i]) {
688 691 return (B_FALSE);
689 692 }
690 693
691 694 if (corrected_key != NULL) {
692 695 #ifdef UNALIGNED_POINTERS_PERMITTED
693 696 *(uint64_t *)(void *)&corrected_key[0] = htonll(key_so_far);
694 697 #else
695 698 /*
696 699 * The code below reverses the bytes on LITTLE_ENDIAN machines.
697 700 * On BIG_ENDIAN, the same code copies without reversing
698 701 * the bytes.
699 702 */
700 703 corrected_key[0] = key_so_far >> 56;
701 704 corrected_key[1] = key_so_far >> 48;
702 705 corrected_key[2] = key_so_far >> 40;
703 706 corrected_key[3] = key_so_far >> 32;
704 707 corrected_key[4] = key_so_far >> 24;
705 708 corrected_key[5] = key_so_far >> 16;
706 709 corrected_key[6] = key_so_far >> 8;
707 710 corrected_key[7] = (uint8_t)key_so_far;
708 711 #endif /* UNALIGNED_POINTERS_PERMITTED */
709 712 }
710 713 return (B_TRUE);
711 714 }
712 715
713 716 static boolean_t
714 717 des23_keycheck(uint8_t *key, uint8_t *corrected_key, boolean_t des3)
715 718 {
716 719 uint64_t aligned_key[DES3_KEYSIZE / sizeof (uint64_t)];
717 720 uint64_t key_so_far, scratch, *currentkey;
718 721 uint_t j, num_weakkeys = 0;
719 722 uint8_t keysize = DES3_KEYSIZE;
720 723 uint8_t checks = 3;
721 724
722 725 if (key == NULL) {
723 726 return (B_FALSE);
724 727 }
725 728
726 729 if (des3 == B_FALSE) {
727 730 keysize = DES2_KEYSIZE;
728 731 checks = 2;
729 732 }
730 733
731 734 if (!IS_P2ALIGNED(key, sizeof (uint64_t))) {
732 735 bcopy(key, aligned_key, keysize);
733 736 currentkey = (uint64_t *)aligned_key;
734 737 } else {
735 738 /* LINTED */
736 739 currentkey = (uint64_t *)key;
737 740 }
738 741
739 742 for (j = 0; j < checks; j++) {
740 743 key_so_far = currentkey[j];
741 744
742 745 if (!keycheck((uint8_t *)&key_so_far, (uint8_t *)&scratch)) {
743 746 if (++num_weakkeys > 1) {
744 747 return (B_FALSE);
745 748 }
746 749 /*
747 750 * We found a weak key, but since
748 751 * we've only found one weak key,
749 752 * we can not reject the whole 3DES
750 753 * set of keys as weak.
751 754 *
752 755 * Break from the weak key loop
753 756 * (since this DES key is weak) and
754 757 * continue on.
755 758 */
756 759 }
757 760
758 761 currentkey[j] = scratch;
759 762 }
760 763
761 764 /*
762 765 * Perform key equivalence checks, now that parity is properly set.
763 766 * 1st and 2nd keys must be unique, the 3rd key can be the same as
764 767 * the 1st key for the 2 key variant of 3DES.
765 768 */
766 769 if (currentkey[0] == currentkey[1] || currentkey[1] == currentkey[2])
767 770 return (B_FALSE);
768 771
769 772 if (corrected_key != NULL) {
770 773 bcopy(currentkey, corrected_key, keysize);
771 774 }
772 775
773 776 return (B_TRUE);
774 777 }
775 778
776 779 boolean_t
777 780 des_keycheck(uint8_t *key, des_strength_t strength, uint8_t *corrected_key)
778 781 {
779 782 if (strength == DES) {
780 783 return (keycheck(key, corrected_key));
781 784 } else if (strength == DES2) {
782 785 return (des23_keycheck(key, corrected_key, B_FALSE));
783 786 } else if (strength == DES3) {
784 787 return (des23_keycheck(key, corrected_key, B_TRUE));
785 788 } else {
786 789 return (B_FALSE);
787 790 }
788 791 }
789 792
790 793 void
791 794 des_parity_fix(uint8_t *key, des_strength_t strength, uint8_t *corrected_key)
792 795 {
793 796 uint64_t aligned_key[DES3_KEYSIZE / sizeof (uint64_t)];
794 797 uint8_t *paritied_key;
795 798 uint64_t key_so_far;
796 799 int i = 0, offset = 0;
797 800
798 801 if (strength == DES)
799 802 bcopy(key, aligned_key, DES_KEYSIZE);
800 803 else
801 804 bcopy(key, aligned_key, DES3_KEYSIZE);
802 805
803 806 paritied_key = (uint8_t *)aligned_key;
804 807 while (strength > i) {
805 808 offset = 8 * i;
806 809 #ifdef UNALIGNED_POINTERS_PERMITTED
807 810 key_so_far = htonll(*(uint64_t *)(void *)&paritied_key[offset]);
808 811 #else
809 812 key_so_far = (((uint64_t)paritied_key[offset + 0] << 56) |
810 813 ((uint64_t)paritied_key[offset + 1] << 48) |
811 814 ((uint64_t)paritied_key[offset + 2] << 40) |
812 815 ((uint64_t)paritied_key[offset + 3] << 32) |
813 816 ((uint64_t)paritied_key[offset + 4] << 24) |
814 817 ((uint64_t)paritied_key[offset + 5] << 16) |
815 818 ((uint64_t)paritied_key[offset + 6] << 8) |
816 819 (uint64_t)paritied_key[offset + 7]);
817 820 #endif /* UNALIGNED_POINTERS_PERMITTED */
818 821
819 822 fix_des_parity(&key_so_far);
820 823
821 824 #ifdef UNALIGNED_POINTERS_PERMITTED
822 825 *(uint64_t *)(void *)&paritied_key[offset] = htonll(key_so_far);
823 826 #else
824 827 paritied_key[offset + 0] = key_so_far >> 56;
825 828 paritied_key[offset + 1] = key_so_far >> 48;
826 829 paritied_key[offset + 2] = key_so_far >> 40;
827 830 paritied_key[offset + 3] = key_so_far >> 32;
828 831 paritied_key[offset + 4] = key_so_far >> 24;
829 832 paritied_key[offset + 5] = key_so_far >> 16;
830 833 paritied_key[offset + 6] = key_so_far >> 8;
831 834 paritied_key[offset + 7] = (uint8_t)key_so_far;
832 835 #endif /* UNALIGNED_POINTERS_PERMITTED */
833 836
834 837 i++;
835 838 }
836 839
837 840 bcopy(paritied_key, corrected_key, DES_KEYSIZE * strength);
838 841 }
839 842
840 843
841 844 /*
842 845 * Initialize key schedule for DES, DES2, and DES3
843 846 */
844 847 void
845 848 des_init_keysched(uint8_t *cipherKey, des_strength_t strength, void *ks)
846 849 {
847 850 uint64_t *encryption_ks;
848 851 uint64_t *decryption_ks;
849 852 uint64_t keysched[48];
850 853 uint64_t key_uint64[3];
851 854 uint64_t tmp;
852 855 uint_t keysize, i, j;
853 856
854 857 switch (strength) {
855 858 case DES:
856 859 keysize = DES_KEYSIZE;
857 860 encryption_ks = ((keysched_t *)ks)->ksch_encrypt;
858 861 decryption_ks = ((keysched_t *)ks)->ksch_decrypt;
859 862 break;
860 863 case DES2:
861 864 keysize = DES2_KEYSIZE;
862 865 encryption_ks = ((keysched3_t *)ks)->ksch_encrypt;
863 866 decryption_ks = ((keysched3_t *)ks)->ksch_decrypt;
864 867 break;
865 868 case DES3:
866 869 keysize = DES3_KEYSIZE;
867 870 encryption_ks = ((keysched3_t *)ks)->ksch_encrypt;
868 871 decryption_ks = ((keysched3_t *)ks)->ksch_decrypt;
869 872 }
870 873
871 874 /*
872 875 * The code below, that is always executed on LITTLE_ENDIAN machines,
873 876 * reverses every 8 bytes in the key. On BIG_ENDIAN, the same code
874 877 * copies the key without reversing bytes.
875 878 */
876 879 #ifdef _BIG_ENDIAN
877 880 if (IS_P2ALIGNED(cipherKey, sizeof (uint64_t))) {
878 881 for (i = 0, j = 0; j < keysize; i++, j += 8) {
879 882 /* LINTED: pointer alignment */
880 883 key_uint64[i] = *((uint64_t *)&cipherKey[j]);
881 884 }
882 885 } else
883 886 #endif /* _BIG_ENDIAN */
884 887 {
885 888 for (i = 0, j = 0; j < keysize; i++, j += 8) {
886 889 #ifdef UNALIGNED_POINTERS_PERMITTED
887 890 key_uint64[i] =
888 891 htonll(*(uint64_t *)(void *)&cipherKey[j]);
889 892 #else
890 893 key_uint64[i] = (((uint64_t)cipherKey[j] << 56) |
891 894 ((uint64_t)cipherKey[j + 1] << 48) |
892 895 ((uint64_t)cipherKey[j + 2] << 40) |
893 896 ((uint64_t)cipherKey[j + 3] << 32) |
894 897 ((uint64_t)cipherKey[j + 4] << 24) |
895 898 ((uint64_t)cipherKey[j + 5] << 16) |
896 899 ((uint64_t)cipherKey[j + 6] << 8) |
897 900 (uint64_t)cipherKey[j + 7]);
898 901 #endif /* UNALIGNED_POINTERS_PERMITTED */
899 902 }
900 903 }
901 904
902 905 switch (strength) {
903 906 case DES:
904 907 des_ks(keysched, key_uint64[0]);
905 908 break;
906 909
907 910 case DES2:
908 911 /* DES2 is just DES3 with the first and third keys the same */
909 912 bcopy(key_uint64, key_uint64 + 2, DES_KEYSIZE);
910 913 /* FALLTHRU */
911 914 case DES3:
912 915 des_ks(keysched, key_uint64[0]);
913 916 des_ks(keysched + 16, key_uint64[1]);
914 917 for (i = 0; i < 8; i++) {
915 918 tmp = keysched[16+i];
916 919 keysched[16+i] = keysched[31-i];
917 920 keysched[31-i] = tmp;
918 921 }
919 922 des_ks(keysched+32, key_uint64[2]);
920 923 keysize = DES3_KEYSIZE;
921 924 }
922 925
923 926 /* save the encryption keyschedule */
924 927 bcopy(keysched, encryption_ks, keysize * 16);
925 928
926 929 /* reverse the key schedule */
927 930 for (i = 0; i < keysize; i++) {
928 931 tmp = keysched[i];
929 932 keysched[i] = keysched[2 * keysize - 1 - i];
930 933 keysched[2 * keysize -1 -i] = tmp;
931 934 }
932 935
933 936 /* save the decryption keyschedule */
934 937 bcopy(keysched, decryption_ks, keysize * 16);
935 938 }
936 939
937 940 /*
938 941 * Allocate key schedule.
939 942 */
940 943 /*ARGSUSED*/
941 944 void *
942 945 des_alloc_keysched(size_t *keysched_size, des_strength_t strength, int kmflag)
943 946 {
944 947 void *keysched;
945 948
946 949 size_t size;
947 950
948 951 switch (strength) {
949 952 case DES:
950 953 size = sizeof (keysched_t);
951 954 break;
952 955 case DES2:
953 956 case DES3:
954 957 size = sizeof (keysched3_t);
955 958 }
956 959
957 960 #ifdef _KERNEL
958 961 keysched = (keysched_t *)kmem_alloc(size, kmflag);
959 962 #else /* !_KERNEL */
960 963 keysched = (keysched_t *)malloc(size);
961 964 #endif /* _KERNEL */
962 965
963 966 if (keysched == NULL)
964 967 return (NULL);
965 968
966 969 if (keysched_size != NULL)
967 970 *keysched_size = size;
968 971
969 972 return (keysched);
970 973 }
971 974
972 975 /*
973 976 * Replace the LSB of each byte by the xor of the other
974 977 * 7 bits. The tricky thing is that the original contents of the LSBs
975 978 * are nullified by including them twice in the xor computation.
976 979 */
977 980 static void
978 981 fix_des_parity(uint64_t *keyp)
↓ open down ↓ |
944 lines elided |
↑ open up ↑ |
979 982 {
980 983 uint64_t k = *keyp;
981 984 k ^= k >> 1;
982 985 k ^= k >> 2;
983 986 k ^= k >> 4;
984 987 *keyp ^= (k & 0x0101010101010101ULL);
985 988 *keyp ^= 0x0101010101010101ULL;
986 989 }
987 990
988 991 void
989 -des_copy_block(uint8_t *in, uint8_t *out)
992 +des_copy_block(const uint8_t *in, uint8_t *out)
990 993 {
991 994 if (IS_P2ALIGNED(in, sizeof (uint32_t)) &&
992 995 IS_P2ALIGNED(out, sizeof (uint32_t))) {
993 996 /* LINTED: pointer alignment */
994 997 *(uint32_t *)&out[0] = *(uint32_t *)&in[0];
995 998 /* LINTED: pointer alignment */
996 999 *(uint32_t *)&out[4] = *(uint32_t *)&in[4];
997 1000 } else {
998 1001 DES_COPY_BLOCK(in, out);
999 1002 }
1000 1003 }
1001 1004
1002 1005 /* XOR block of data into dest */
1003 1006 void
1004 -des_xor_block(uint8_t *data, uint8_t *dst)
1007 +des_xor_block(const uint8_t *data, uint8_t *dst)
1005 1008 {
1006 1009 if (IS_P2ALIGNED(dst, sizeof (uint32_t)) &&
1007 1010 IS_P2ALIGNED(data, sizeof (uint32_t))) {
1008 1011 /* LINTED: pointer alignment */
1009 1012 *(uint32_t *)&dst[0] ^=
1010 1013 /* LINTED: pointer alignment */
1011 1014 *(uint32_t *)&data[0];
1012 1015 /* LINTED: pointer alignment */
1013 1016 *(uint32_t *)&dst[4] ^=
1014 1017 /* LINTED: pointer alignment */
1015 1018 *(uint32_t *)&data[4];
1016 1019 } else {
1017 1020 DES_XOR_BLOCK(data, dst);
1018 1021 }
1019 1022 }
1020 1023
1021 1024 int
1022 1025 des_encrypt_block(const void *keysched, const uint8_t *in, uint8_t *out)
1023 1026 {
1024 1027 return (des_crunch_block(keysched, in, out, B_FALSE));
1025 1028 }
1026 1029
1027 1030 int
1028 1031 des3_encrypt_block(const void *keysched, const uint8_t *in, uint8_t *out)
1029 1032 {
1030 1033 return (des3_crunch_block(keysched, in, out, B_FALSE));
1031 1034 }
1032 1035
1033 1036 int
1034 1037 des_decrypt_block(const void *keysched, const uint8_t *in, uint8_t *out)
1035 1038 {
1036 1039 return (des_crunch_block(keysched, in, out, B_TRUE));
1037 1040 }
1038 1041
1039 1042 int
1040 1043 des3_decrypt_block(const void *keysched, const uint8_t *in, uint8_t *out)
1041 1044 {
1042 1045 return (des3_crunch_block(keysched, in, out, B_TRUE));
1043 1046 }
1044 1047
1045 1048 /*
1046 1049 * Encrypt multiple blocks of data according to mode.
1047 1050 */
1048 1051 int
↓ open down ↓ |
34 lines elided |
↑ open up ↑ |
1049 1052 des_encrypt_contiguous_blocks(void *ctx, char *data, size_t length,
1050 1053 crypto_data_t *out)
1051 1054 {
1052 1055 des_ctx_t *des_ctx = ctx;
1053 1056 int rv;
1054 1057
1055 1058 if (des_ctx->dc_flags & DES3_STRENGTH) {
1056 1059 if (des_ctx->dc_flags & CBC_MODE) {
1057 1060 rv = cbc_encrypt_contiguous_blocks(ctx, data,
1058 1061 length, out, DES_BLOCK_LEN, des3_encrypt_block,
1059 - des_copy_block, des_xor_block);
1062 + des_copy_block, des_xor_block, NULL);
1060 1063 } else {
1061 1064 rv = ecb_cipher_contiguous_blocks(ctx, data, length,
1062 - out, DES_BLOCK_LEN, des3_encrypt_block);
1065 + out, DES_BLOCK_LEN, des3_encrypt_block, NULL);
1063 1066 }
1064 1067 } else {
1065 1068 if (des_ctx->dc_flags & CBC_MODE) {
1066 1069 rv = cbc_encrypt_contiguous_blocks(ctx, data,
1067 1070 length, out, DES_BLOCK_LEN, des_encrypt_block,
1068 - des_copy_block, des_xor_block);
1071 + des_copy_block, des_xor_block, NULL);
1069 1072 } else {
1070 1073 rv = ecb_cipher_contiguous_blocks(ctx, data, length,
1071 - out, DES_BLOCK_LEN, des_encrypt_block);
1074 + out, DES_BLOCK_LEN, des_encrypt_block, NULL);
1072 1075 }
1073 1076 }
1074 1077 return (rv);
1075 1078 }
1076 1079
1077 1080 /*
1078 1081 * Decrypt multiple blocks of data according to mode.
1079 1082 */
1080 1083 int
1081 1084 des_decrypt_contiguous_blocks(void *ctx, char *data, size_t length,
1082 1085 crypto_data_t *out)
1083 1086 {
1084 1087 des_ctx_t *des_ctx = ctx;
1085 1088 int rv;
1086 1089
1087 1090 if (des_ctx->dc_flags & DES3_STRENGTH) {
1088 1091 if (des_ctx->dc_flags & CBC_MODE) {
1089 1092 rv = cbc_decrypt_contiguous_blocks(ctx, data,
1090 1093 length, out, DES_BLOCK_LEN, des3_decrypt_block,
1091 - des_copy_block, des_xor_block);
1094 + des_copy_block, des_xor_block, NULL, NULL);
1092 1095 } else {
1093 1096 rv = ecb_cipher_contiguous_blocks(ctx, data, length,
1094 - out, DES_BLOCK_LEN, des3_decrypt_block);
1097 + out, DES_BLOCK_LEN, des3_decrypt_block, NULL);
1095 1098 if (rv == CRYPTO_DATA_LEN_RANGE)
1096 1099 rv = CRYPTO_ENCRYPTED_DATA_LEN_RANGE;
1097 1100 }
1098 1101 } else {
1099 1102 if (des_ctx->dc_flags & CBC_MODE) {
1100 1103 rv = cbc_decrypt_contiguous_blocks(ctx, data,
1101 1104 length, out, DES_BLOCK_LEN, des_decrypt_block,
1102 - des_copy_block, des_xor_block);
1105 + des_copy_block, des_xor_block, NULL, NULL);
1103 1106 } else {
1104 1107 rv = ecb_cipher_contiguous_blocks(ctx, data, length,
1105 - out, DES_BLOCK_LEN, des_decrypt_block);
1108 + out, DES_BLOCK_LEN, des_decrypt_block, NULL);
1106 1109 if (rv == CRYPTO_DATA_LEN_RANGE)
1107 1110 rv = CRYPTO_ENCRYPTED_DATA_LEN_RANGE;
1108 1111 }
1109 1112 }
1110 1113 return (rv);
1111 1114 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX