patches: update lighttpd patches
[git-osx-installer.git] / src / ccccrypt.c
blob987258677e71506a8a369b8f1d5e50c79ddca595
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
6 * The library is free for all purposes without any express
7 * guarantee it works.
9 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
12 #include <stdint.h>
13 #include <string.h>
15 #define XMEMCPY memcpy
16 #define XMEMCMP memcmp
18 typedef uint32_t ulong32;
20 #define LOAD32H(x, y) \
21 { x = ((ulong32)((y)[0] & 255)<<24) | \
22 ((ulong32)((y)[1] & 255)<<16) | \
23 ((ulong32)((y)[2] & 255)<<8) | \
24 ((ulong32)((y)[3] & 255)); }
26 #define STORE32H(x, y) \
27 { (y)[0] = (unsigned char)(((x)>>24)&255); (y)[1] = (unsigned char)(((x)>>16)&255); \
28 (y)[2] = (unsigned char)(((x)>>8)&255); (y)[3] = (unsigned char)((x)&255); }
30 #define ROLc(x, y) ( (((ulong32)(x)<<(ulong32)((y)&31)) | \
31 (((ulong32)(x)&0xFFFFFFFFU)>>(ulong32)(32-((y)&31)))) & 0xFFFFFFFFU )
33 #define RORc(x, y) ( ((((ulong32)(x)&0xFFFFFFFFU)>>(ulong32)((y)&31)) | \
34 ((ulong32)(x)<<(ulong32)(32-((y)&31)))) & 0xFFFFFFFFU )
36 #define LTC_ARGCHK(x)
37 #define CRYPT_OK 0
38 #define CRYPT_INVALID_ROUNDS -1
39 #define CRYPT_INVALID_KEYSIZE -1
41 struct des_key {
42 ulong32 ek[32], dk[32];
45 typedef union Symmetric_key {
46 struct des_key des;
47 } symmetric_key;
49 /**
50 @file des.c
51 LTC_DES code submitted by Dobes Vandermeer
54 #define EN0 0
55 #define DE1 1
57 static const ulong32 bytebit[8] =
59 0200, 0100, 040, 020, 010, 04, 02, 01
62 static const ulong32 bigbyte[24] =
64 0x800000UL, 0x400000UL, 0x200000UL, 0x100000UL,
65 0x80000UL, 0x40000UL, 0x20000UL, 0x10000UL,
66 0x8000UL, 0x4000UL, 0x2000UL, 0x1000UL,
67 0x800UL, 0x400UL, 0x200UL, 0x100UL,
68 0x80UL, 0x40UL, 0x20UL, 0x10UL,
69 0x8UL, 0x4UL, 0x2UL, 0x1L
72 /* Use the key schedule specific in the standard (ANSI X3.92-1981) */
74 static const unsigned char pc1[56] = {
75 56, 48, 40, 32, 24, 16, 8, 0, 57, 49, 41, 33, 25, 17,
76 9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59, 51, 43, 35,
77 62, 54, 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21,
78 13, 5, 60, 52, 44, 36, 28, 20, 12, 4, 27, 19, 11, 3
81 static const unsigned char totrot[16] = {
82 1, 2, 4, 6,
83 8, 10, 12, 14,
84 15, 17, 19, 21,
85 23, 25, 27, 28
88 static const unsigned char pc2[48] = {
89 13, 16, 10, 23, 0, 4, 2, 27, 14, 5, 20, 9,
90 22, 18, 11, 3, 25, 7, 15, 6, 26, 19, 12, 1,
91 40, 51, 30, 36, 46, 54, 29, 39, 50, 44, 32, 47,
92 43, 48, 38, 55, 33, 52, 45, 41, 49, 35, 28, 31
95 static const ulong32 SP1[64] =
97 0x01010400UL, 0x00000000UL, 0x00010000UL, 0x01010404UL,
98 0x01010004UL, 0x00010404UL, 0x00000004UL, 0x00010000UL,
99 0x00000400UL, 0x01010400UL, 0x01010404UL, 0x00000400UL,
100 0x01000404UL, 0x01010004UL, 0x01000000UL, 0x00000004UL,
101 0x00000404UL, 0x01000400UL, 0x01000400UL, 0x00010400UL,
102 0x00010400UL, 0x01010000UL, 0x01010000UL, 0x01000404UL,
103 0x00010004UL, 0x01000004UL, 0x01000004UL, 0x00010004UL,
104 0x00000000UL, 0x00000404UL, 0x00010404UL, 0x01000000UL,
105 0x00010000UL, 0x01010404UL, 0x00000004UL, 0x01010000UL,
106 0x01010400UL, 0x01000000UL, 0x01000000UL, 0x00000400UL,
107 0x01010004UL, 0x00010000UL, 0x00010400UL, 0x01000004UL,
108 0x00000400UL, 0x00000004UL, 0x01000404UL, 0x00010404UL,
109 0x01010404UL, 0x00010004UL, 0x01010000UL, 0x01000404UL,
110 0x01000004UL, 0x00000404UL, 0x00010404UL, 0x01010400UL,
111 0x00000404UL, 0x01000400UL, 0x01000400UL, 0x00000000UL,
112 0x00010004UL, 0x00010400UL, 0x00000000UL, 0x01010004UL
115 static const ulong32 SP2[64] =
117 0x80108020UL, 0x80008000UL, 0x00008000UL, 0x00108020UL,
118 0x00100000UL, 0x00000020UL, 0x80100020UL, 0x80008020UL,
119 0x80000020UL, 0x80108020UL, 0x80108000UL, 0x80000000UL,
120 0x80008000UL, 0x00100000UL, 0x00000020UL, 0x80100020UL,
121 0x00108000UL, 0x00100020UL, 0x80008020UL, 0x00000000UL,
122 0x80000000UL, 0x00008000UL, 0x00108020UL, 0x80100000UL,
123 0x00100020UL, 0x80000020UL, 0x00000000UL, 0x00108000UL,
124 0x00008020UL, 0x80108000UL, 0x80100000UL, 0x00008020UL,
125 0x00000000UL, 0x00108020UL, 0x80100020UL, 0x00100000UL,
126 0x80008020UL, 0x80100000UL, 0x80108000UL, 0x00008000UL,
127 0x80100000UL, 0x80008000UL, 0x00000020UL, 0x80108020UL,
128 0x00108020UL, 0x00000020UL, 0x00008000UL, 0x80000000UL,
129 0x00008020UL, 0x80108000UL, 0x00100000UL, 0x80000020UL,
130 0x00100020UL, 0x80008020UL, 0x80000020UL, 0x00100020UL,
131 0x00108000UL, 0x00000000UL, 0x80008000UL, 0x00008020UL,
132 0x80000000UL, 0x80100020UL, 0x80108020UL, 0x00108000UL
135 static const ulong32 SP3[64] =
137 0x00000208UL, 0x08020200UL, 0x00000000UL, 0x08020008UL,
138 0x08000200UL, 0x00000000UL, 0x00020208UL, 0x08000200UL,
139 0x00020008UL, 0x08000008UL, 0x08000008UL, 0x00020000UL,
140 0x08020208UL, 0x00020008UL, 0x08020000UL, 0x00000208UL,
141 0x08000000UL, 0x00000008UL, 0x08020200UL, 0x00000200UL,
142 0x00020200UL, 0x08020000UL, 0x08020008UL, 0x00020208UL,
143 0x08000208UL, 0x00020200UL, 0x00020000UL, 0x08000208UL,
144 0x00000008UL, 0x08020208UL, 0x00000200UL, 0x08000000UL,
145 0x08020200UL, 0x08000000UL, 0x00020008UL, 0x00000208UL,
146 0x00020000UL, 0x08020200UL, 0x08000200UL, 0x00000000UL,
147 0x00000200UL, 0x00020008UL, 0x08020208UL, 0x08000200UL,
148 0x08000008UL, 0x00000200UL, 0x00000000UL, 0x08020008UL,
149 0x08000208UL, 0x00020000UL, 0x08000000UL, 0x08020208UL,
150 0x00000008UL, 0x00020208UL, 0x00020200UL, 0x08000008UL,
151 0x08020000UL, 0x08000208UL, 0x00000208UL, 0x08020000UL,
152 0x00020208UL, 0x00000008UL, 0x08020008UL, 0x00020200UL
155 static const ulong32 SP4[64] =
157 0x00802001UL, 0x00002081UL, 0x00002081UL, 0x00000080UL,
158 0x00802080UL, 0x00800081UL, 0x00800001UL, 0x00002001UL,
159 0x00000000UL, 0x00802000UL, 0x00802000UL, 0x00802081UL,
160 0x00000081UL, 0x00000000UL, 0x00800080UL, 0x00800001UL,
161 0x00000001UL, 0x00002000UL, 0x00800000UL, 0x00802001UL,
162 0x00000080UL, 0x00800000UL, 0x00002001UL, 0x00002080UL,
163 0x00800081UL, 0x00000001UL, 0x00002080UL, 0x00800080UL,
164 0x00002000UL, 0x00802080UL, 0x00802081UL, 0x00000081UL,
165 0x00800080UL, 0x00800001UL, 0x00802000UL, 0x00802081UL,
166 0x00000081UL, 0x00000000UL, 0x00000000UL, 0x00802000UL,
167 0x00002080UL, 0x00800080UL, 0x00800081UL, 0x00000001UL,
168 0x00802001UL, 0x00002081UL, 0x00002081UL, 0x00000080UL,
169 0x00802081UL, 0x00000081UL, 0x00000001UL, 0x00002000UL,
170 0x00800001UL, 0x00002001UL, 0x00802080UL, 0x00800081UL,
171 0x00002001UL, 0x00002080UL, 0x00800000UL, 0x00802001UL,
172 0x00000080UL, 0x00800000UL, 0x00002000UL, 0x00802080UL
175 static const ulong32 SP5[64] =
177 0x00000100UL, 0x02080100UL, 0x02080000UL, 0x42000100UL,
178 0x00080000UL, 0x00000100UL, 0x40000000UL, 0x02080000UL,
179 0x40080100UL, 0x00080000UL, 0x02000100UL, 0x40080100UL,
180 0x42000100UL, 0x42080000UL, 0x00080100UL, 0x40000000UL,
181 0x02000000UL, 0x40080000UL, 0x40080000UL, 0x00000000UL,
182 0x40000100UL, 0x42080100UL, 0x42080100UL, 0x02000100UL,
183 0x42080000UL, 0x40000100UL, 0x00000000UL, 0x42000000UL,
184 0x02080100UL, 0x02000000UL, 0x42000000UL, 0x00080100UL,
185 0x00080000UL, 0x42000100UL, 0x00000100UL, 0x02000000UL,
186 0x40000000UL, 0x02080000UL, 0x42000100UL, 0x40080100UL,
187 0x02000100UL, 0x40000000UL, 0x42080000UL, 0x02080100UL,
188 0x40080100UL, 0x00000100UL, 0x02000000UL, 0x42080000UL,
189 0x42080100UL, 0x00080100UL, 0x42000000UL, 0x42080100UL,
190 0x02080000UL, 0x00000000UL, 0x40080000UL, 0x42000000UL,
191 0x00080100UL, 0x02000100UL, 0x40000100UL, 0x00080000UL,
192 0x00000000UL, 0x40080000UL, 0x02080100UL, 0x40000100UL
195 static const ulong32 SP6[64] =
197 0x20000010UL, 0x20400000UL, 0x00004000UL, 0x20404010UL,
198 0x20400000UL, 0x00000010UL, 0x20404010UL, 0x00400000UL,
199 0x20004000UL, 0x00404010UL, 0x00400000UL, 0x20000010UL,
200 0x00400010UL, 0x20004000UL, 0x20000000UL, 0x00004010UL,
201 0x00000000UL, 0x00400010UL, 0x20004010UL, 0x00004000UL,
202 0x00404000UL, 0x20004010UL, 0x00000010UL, 0x20400010UL,
203 0x20400010UL, 0x00000000UL, 0x00404010UL, 0x20404000UL,
204 0x00004010UL, 0x00404000UL, 0x20404000UL, 0x20000000UL,
205 0x20004000UL, 0x00000010UL, 0x20400010UL, 0x00404000UL,
206 0x20404010UL, 0x00400000UL, 0x00004010UL, 0x20000010UL,
207 0x00400000UL, 0x20004000UL, 0x20000000UL, 0x00004010UL,
208 0x20000010UL, 0x20404010UL, 0x00404000UL, 0x20400000UL,
209 0x00404010UL, 0x20404000UL, 0x00000000UL, 0x20400010UL,
210 0x00000010UL, 0x00004000UL, 0x20400000UL, 0x00404010UL,
211 0x00004000UL, 0x00400010UL, 0x20004010UL, 0x00000000UL,
212 0x20404000UL, 0x20000000UL, 0x00400010UL, 0x20004010UL
215 static const ulong32 SP7[64] =
217 0x00200000UL, 0x04200002UL, 0x04000802UL, 0x00000000UL,
218 0x00000800UL, 0x04000802UL, 0x00200802UL, 0x04200800UL,
219 0x04200802UL, 0x00200000UL, 0x00000000UL, 0x04000002UL,
220 0x00000002UL, 0x04000000UL, 0x04200002UL, 0x00000802UL,
221 0x04000800UL, 0x00200802UL, 0x00200002UL, 0x04000800UL,
222 0x04000002UL, 0x04200000UL, 0x04200800UL, 0x00200002UL,
223 0x04200000UL, 0x00000800UL, 0x00000802UL, 0x04200802UL,
224 0x00200800UL, 0x00000002UL, 0x04000000UL, 0x00200800UL,
225 0x04000000UL, 0x00200800UL, 0x00200000UL, 0x04000802UL,
226 0x04000802UL, 0x04200002UL, 0x04200002UL, 0x00000002UL,
227 0x00200002UL, 0x04000000UL, 0x04000800UL, 0x00200000UL,
228 0x04200800UL, 0x00000802UL, 0x00200802UL, 0x04200800UL,
229 0x00000802UL, 0x04000002UL, 0x04200802UL, 0x04200000UL,
230 0x00200800UL, 0x00000000UL, 0x00000002UL, 0x04200802UL,
231 0x00000000UL, 0x00200802UL, 0x04200000UL, 0x00000800UL,
232 0x04000002UL, 0x04000800UL, 0x00000800UL, 0x00200002UL
235 static const ulong32 SP8[64] =
237 0x10001040UL, 0x00001000UL, 0x00040000UL, 0x10041040UL,
238 0x10000000UL, 0x10001040UL, 0x00000040UL, 0x10000000UL,
239 0x00040040UL, 0x10040000UL, 0x10041040UL, 0x00041000UL,
240 0x10041000UL, 0x00041040UL, 0x00001000UL, 0x00000040UL,
241 0x10040000UL, 0x10000040UL, 0x10001000UL, 0x00001040UL,
242 0x00041000UL, 0x00040040UL, 0x10040040UL, 0x10041000UL,
243 0x00001040UL, 0x00000000UL, 0x00000000UL, 0x10040040UL,
244 0x10000040UL, 0x10001000UL, 0x00041040UL, 0x00040000UL,
245 0x00041040UL, 0x00040000UL, 0x10041000UL, 0x00001000UL,
246 0x00000040UL, 0x10040040UL, 0x00001000UL, 0x00041040UL,
247 0x10001000UL, 0x00000040UL, 0x10000040UL, 0x10040000UL,
248 0x10040040UL, 0x10000000UL, 0x00040000UL, 0x10001040UL,
249 0x00000000UL, 0x10041040UL, 0x00040040UL, 0x10000040UL,
250 0x10040000UL, 0x10001000UL, 0x10001040UL, 0x00000000UL,
251 0x10041040UL, 0x00041000UL, 0x00041000UL, 0x00001040UL,
252 0x00001040UL, 0x00040040UL, 0x10000000UL, 0x10041000UL
255 static void cookey(const ulong32 *raw1, ulong32 *keyout);
257 static void deskey(const unsigned char *key, short edf, ulong32 *keyout)
259 ulong32 i, j, l, m, n, kn[32];
260 unsigned char pc1m[56], pcr[56];
262 for (j=0; j < 56; j++) {
263 l = (ulong32)pc1[j];
264 m = l & 7;
265 pc1m[j] = (unsigned char)((key[l >> 3U] & bytebit[m]) == bytebit[m] ? 1 : 0);
268 for (i=0; i < 16; i++) {
269 if (edf == DE1) {
270 m = (15 - i) << 1;
271 } else {
272 m = i << 1;
274 n = m + 1;
275 kn[m] = kn[n] = 0L;
276 for (j=0; j < 28; j++) {
277 l = j + (ulong32)totrot[i];
278 if (l < 28) {
279 pcr[j] = pc1m[l];
280 } else {
281 pcr[j] = pc1m[l - 28];
284 for (/*j = 28*/; j < 56; j++) {
285 l = j + (ulong32)totrot[i];
286 if (l < 56) {
287 pcr[j] = pc1m[l];
288 } else {
289 pcr[j] = pc1m[l - 28];
292 for (j=0; j < 24; j++) {
293 if ((int)pcr[(int)pc2[j]] != 0) {
294 kn[m] |= bigbyte[j];
296 if ((int)pcr[(int)pc2[j+24]] != 0) {
297 kn[n] |= bigbyte[j];
302 cookey(kn, keyout);
305 static void cookey(const ulong32 *raw1, ulong32 *keyout)
307 ulong32 *cook;
308 const ulong32 *raw0;
309 ulong32 dough[32];
310 int i;
312 cook = dough;
313 for(i=0; i < 16; i++, raw1++)
315 raw0 = raw1++;
316 *cook = (*raw0 & 0x00fc0000L) << 6;
317 *cook |= (*raw0 & 0x00000fc0L) << 10;
318 *cook |= (*raw1 & 0x00fc0000L) >> 10;
319 *cook++ |= (*raw1 & 0x00000fc0L) >> 6;
320 *cook = (*raw0 & 0x0003f000L) << 12;
321 *cook |= (*raw0 & 0x0000003fL) << 16;
322 *cook |= (*raw1 & 0x0003f000L) >> 4;
323 *cook++ |= (*raw1 & 0x0000003fL);
326 XMEMCPY(keyout, dough, sizeof dough);
329 static void desfunc(ulong32 *block, const ulong32 *keys)
331 ulong32 work, right, leftt;
332 int cur_round;
334 leftt = block[0];
335 right = block[1];
337 work = ((leftt >> 4) ^ right) & 0x0f0f0f0fL;
338 right ^= work;
339 leftt ^= (work << 4);
341 work = ((leftt >> 16) ^ right) & 0x0000ffffL;
342 right ^= work;
343 leftt ^= (work << 16);
345 work = ((right >> 2) ^ leftt) & 0x33333333L;
346 leftt ^= work;
347 right ^= (work << 2);
349 work = ((right >> 8) ^ leftt) & 0x00ff00ffL;
350 leftt ^= work;
351 right ^= (work << 8);
353 right = ROLc(right, 1);
354 work = (leftt ^ right) & 0xaaaaaaaaL;
356 leftt ^= work;
357 right ^= work;
358 leftt = ROLc(leftt, 1);
360 for (cur_round = 0; cur_round < 8; cur_round++) {
361 work = RORc(right, 4) ^ *keys++;
362 leftt ^= SP7[work & 0x3fL]
363 ^ SP5[(work >> 8) & 0x3fL]
364 ^ SP3[(work >> 16) & 0x3fL]
365 ^ SP1[(work >> 24) & 0x3fL];
366 work = right ^ *keys++;
367 leftt ^= SP8[ work & 0x3fL]
368 ^ SP6[(work >> 8) & 0x3fL]
369 ^ SP4[(work >> 16) & 0x3fL]
370 ^ SP2[(work >> 24) & 0x3fL];
372 work = RORc(leftt, 4) ^ *keys++;
373 right ^= SP7[ work & 0x3fL]
374 ^ SP5[(work >> 8) & 0x3fL]
375 ^ SP3[(work >> 16) & 0x3fL]
376 ^ SP1[(work >> 24) & 0x3fL];
377 work = leftt ^ *keys++;
378 right ^= SP8[ work & 0x3fL]
379 ^ SP6[(work >> 8) & 0x3fL]
380 ^ SP4[(work >> 16) & 0x3fL]
381 ^ SP2[(work >> 24) & 0x3fL];
384 right = RORc(right, 1);
385 work = (leftt ^ right) & 0xaaaaaaaaL;
386 leftt ^= work;
387 right ^= work;
388 leftt = RORc(leftt, 1);
389 work = ((leftt >> 8) ^ right) & 0x00ff00ffL;
390 right ^= work;
391 leftt ^= (work << 8);
392 /* -- */
393 work = ((leftt >> 2) ^ right) & 0x33333333L;
394 right ^= work;
395 leftt ^= (work << 2);
396 work = ((right >> 16) ^ leftt) & 0x0000ffffL;
397 leftt ^= work;
398 right ^= (work << 16);
399 work = ((right >> 4) ^ leftt) & 0x0f0f0f0fL;
400 leftt ^= work;
401 right ^= (work << 4);
403 block[0] = right;
404 block[1] = leftt;
408 Initialize the LTC_DES block cipher
409 @param key The symmetric key you wish to pass
410 @param keylen The key length in bytes
411 @param num_rounds The number of rounds desired (0 for default)
412 @param skey The key in as scheduled by this function.
413 @return CRYPT_OK if successful
415 static int des_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
417 LTC_ARGCHK(key != NULL);
418 LTC_ARGCHK(skey != NULL);
420 if (num_rounds != 0 && num_rounds != 16) {
421 return CRYPT_INVALID_ROUNDS;
424 if (keylen != 8) {
425 return CRYPT_INVALID_KEYSIZE;
428 deskey(key, EN0, skey->des.ek);
429 deskey(key, DE1, skey->des.dk);
431 return CRYPT_OK;
435 Encrypts a block of text with LTC_DES
436 @param pt The input plaintext (8 bytes)
437 @param ct The output ciphertext (8 bytes)
438 @param skey The key as scheduled
439 @return CRYPT_OK if successful
441 static int des_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
443 ulong32 work[2];
444 LTC_ARGCHK(pt != NULL);
445 LTC_ARGCHK(ct != NULL);
446 LTC_ARGCHK(skey != NULL);
447 LOAD32H(work[0], pt+0);
448 LOAD32H(work[1], pt+4);
449 desfunc(work, skey->des.ek);
450 STORE32H(work[0],ct+0);
451 STORE32H(work[1],ct+4);
452 return CRYPT_OK;
456 Decrypts a block of text with LTC_DES
457 @param ct The input ciphertext (8 bytes)
458 @param pt The output plaintext (8 bytes)
459 @param skey The key as scheduled
460 @return CRYPT_OK if successful
462 static int des_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
464 ulong32 work[2];
465 LTC_ARGCHK(pt != NULL);
466 LTC_ARGCHK(ct != NULL);
467 LTC_ARGCHK(skey != NULL);
468 LOAD32H(work[0], ct+0);
469 LOAD32H(work[1], ct+4);
470 desfunc(work, skey->des.dk);
471 STORE32H(work[0],pt+0);
472 STORE32H(work[1],pt+4);
473 return CRYPT_OK;
476 /* $Source: /cvs/libtom/libtomcrypt/src/ciphers/des.c,v $ */
477 /* $Revision: 1.15 $ */
478 /* $Date: 2007/05/12 14:20:27 $ */
481 @file ccccrypt.c
482 CommonCryptor compatibility
485 #define kCCSuccess 0
486 #define kCCParamError -4300
487 #define kCCUnimplemented -4305
488 #define kCCEncrypt 0
489 #define kCCDecrypt 1
490 #define kCCAlgorithmDES 1
491 #define kCCOptionECBMode 2
492 #define kCCKeySizeDES 8
494 int cCCCrypt(int, int, int, const void *, size_t, const void *,
495 const void *, size_t, void *, size_t, size_t *);
497 int cCCCrypt(int op, int alg, int opt, const void *key, size_t keylen,
498 const void *iv, const void *in, size_t inlen,
499 void *out, size_t outsize, size_t *outlen)
501 symmetric_key des;
503 if ((op != kCCEncrypt && op != kCCDecrypt) || alg != kCCAlgorithmDES ||
504 opt != kCCOptionECBMode)
505 return kCCUnimplemented;
506 if (!key || keylen != kCCKeySizeDES || iv || !in || inlen != 8 || !out ||
507 outsize < 8 || !outlen)
508 return kCCParamError;
510 des_setup(key, 8, 0, &des);
511 if (op == kCCEncrypt)
512 des_ecb_encrypt(in, out, &des);
513 else
514 des_ecb_decrypt(in, out, &des);
515 *outlen = 8;
517 return kCCSuccess;