1*c9496f6bSchristos /* crypto/des/des_enc.c */
2*c9496f6bSchristos /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3*c9496f6bSchristos * All rights reserved.
4*c9496f6bSchristos *
5*c9496f6bSchristos * This package is an SSL implementation written
6*c9496f6bSchristos * by Eric Young (eay@cryptsoft.com).
7*c9496f6bSchristos * The implementation was written so as to conform with Netscapes SSL.
8*c9496f6bSchristos *
9*c9496f6bSchristos * This library is free for commercial and non-commercial use as long as
10*c9496f6bSchristos * the following conditions are aheared to. The following conditions
11*c9496f6bSchristos * apply to all code found in this distribution, be it the RC4, RSA,
12*c9496f6bSchristos * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13*c9496f6bSchristos * included with this distribution is covered by the same copyright terms
14*c9496f6bSchristos * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15*c9496f6bSchristos *
16*c9496f6bSchristos * Copyright remains Eric Young's, and as such any Copyright notices in
17*c9496f6bSchristos * the code are not to be removed.
18*c9496f6bSchristos * If this package is used in a product, Eric Young should be given attribution
19*c9496f6bSchristos * as the author of the parts of the library used.
20*c9496f6bSchristos * This can be in the form of a textual message at program startup or
21*c9496f6bSchristos * in documentation (online or textual) provided with the package.
22*c9496f6bSchristos *
23*c9496f6bSchristos * Redistribution and use in source and binary forms, with or without
24*c9496f6bSchristos * modification, are permitted provided that the following conditions
25*c9496f6bSchristos * are met:
26*c9496f6bSchristos * 1. Redistributions of source code must retain the copyright
27*c9496f6bSchristos * notice, this list of conditions and the following disclaimer.
28*c9496f6bSchristos * 2. Redistributions in binary form must reproduce the above copyright
29*c9496f6bSchristos * notice, this list of conditions and the following disclaimer in the
30*c9496f6bSchristos * documentation and/or other materials provided with the distribution.
31*c9496f6bSchristos * 3. All advertising materials mentioning features or use of this software
32*c9496f6bSchristos * must display the following acknowledgement:
33*c9496f6bSchristos * "This product includes cryptographic software written by
34*c9496f6bSchristos * Eric Young (eay@cryptsoft.com)"
35*c9496f6bSchristos * The word 'cryptographic' can be left out if the rouines from the library
36*c9496f6bSchristos * being used are not cryptographic related :-).
37*c9496f6bSchristos * 4. If you include any Windows specific code (or a derivative thereof) from
38*c9496f6bSchristos * the apps directory (application code) you must include an acknowledgement:
39*c9496f6bSchristos * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40*c9496f6bSchristos *
41*c9496f6bSchristos * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42*c9496f6bSchristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43*c9496f6bSchristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44*c9496f6bSchristos * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45*c9496f6bSchristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46*c9496f6bSchristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47*c9496f6bSchristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48*c9496f6bSchristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49*c9496f6bSchristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50*c9496f6bSchristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51*c9496f6bSchristos * SUCH DAMAGE.
52*c9496f6bSchristos *
53*c9496f6bSchristos * The licence and distribution terms for any publically available version or
54*c9496f6bSchristos * derivative of this code cannot be changed. i.e. this code cannot simply be
55*c9496f6bSchristos * copied and put under another distribution licence
56*c9496f6bSchristos * [including the GNU Public Licence.]
57*c9496f6bSchristos */
58*c9496f6bSchristos
59*c9496f6bSchristos #include "des_locl.h"
60*c9496f6bSchristos
des_encrypt1(DES_LONG * data,des_key_schedule ks,int enc)61*c9496f6bSchristos void des_encrypt1(DES_LONG *data, des_key_schedule ks, int enc)
62*c9496f6bSchristos {
63*c9496f6bSchristos register DES_LONG l,r,t,u;
64*c9496f6bSchristos #ifdef DES_PTR
65*c9496f6bSchristos register const unsigned char *des_SP=(const unsigned char *)des_SPtrans;
66*c9496f6bSchristos #endif
67*c9496f6bSchristos #ifndef DES_UNROLL
68*c9496f6bSchristos register int i;
69*c9496f6bSchristos #endif
70*c9496f6bSchristos register DES_LONG *s;
71*c9496f6bSchristos
72*c9496f6bSchristos r=data[0];
73*c9496f6bSchristos l=data[1];
74*c9496f6bSchristos
75*c9496f6bSchristos IP(r,l);
76*c9496f6bSchristos /* Things have been modified so that the initial rotate is
77*c9496f6bSchristos * done outside the loop. This required the
78*c9496f6bSchristos * des_SPtrans values in sp.h to be rotated 1 bit to the right.
79*c9496f6bSchristos * One perl script later and things have a 5% speed up on a sparc2.
80*c9496f6bSchristos * Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
81*c9496f6bSchristos * for pointing this out. */
82*c9496f6bSchristos /* clear the top bits on machines with 8byte longs */
83*c9496f6bSchristos /* shift left by 2 */
84*c9496f6bSchristos r=ROTATE(r,29)&0xffffffffL;
85*c9496f6bSchristos l=ROTATE(l,29)&0xffffffffL;
86*c9496f6bSchristos
87*c9496f6bSchristos s=ks;
88*c9496f6bSchristos /* I don't know if it is worth the effort of loop unrolling the
89*c9496f6bSchristos * inner loop */
90*c9496f6bSchristos if (enc)
91*c9496f6bSchristos {
92*c9496f6bSchristos #ifdef DES_UNROLL
93*c9496f6bSchristos D_ENCRYPT(l,r, 0); /* 1 */
94*c9496f6bSchristos D_ENCRYPT(r,l, 2); /* 2 */
95*c9496f6bSchristos D_ENCRYPT(l,r, 4); /* 3 */
96*c9496f6bSchristos D_ENCRYPT(r,l, 6); /* 4 */
97*c9496f6bSchristos D_ENCRYPT(l,r, 8); /* 5 */
98*c9496f6bSchristos D_ENCRYPT(r,l,10); /* 6 */
99*c9496f6bSchristos D_ENCRYPT(l,r,12); /* 7 */
100*c9496f6bSchristos D_ENCRYPT(r,l,14); /* 8 */
101*c9496f6bSchristos D_ENCRYPT(l,r,16); /* 9 */
102*c9496f6bSchristos D_ENCRYPT(r,l,18); /* 10 */
103*c9496f6bSchristos D_ENCRYPT(l,r,20); /* 11 */
104*c9496f6bSchristos D_ENCRYPT(r,l,22); /* 12 */
105*c9496f6bSchristos D_ENCRYPT(l,r,24); /* 13 */
106*c9496f6bSchristos D_ENCRYPT(r,l,26); /* 14 */
107*c9496f6bSchristos D_ENCRYPT(l,r,28); /* 15 */
108*c9496f6bSchristos D_ENCRYPT(r,l,30); /* 16 */
109*c9496f6bSchristos #else
110*c9496f6bSchristos for (i=0; i<32; i+=8)
111*c9496f6bSchristos {
112*c9496f6bSchristos D_ENCRYPT(l,r,i+0); /* 1 */
113*c9496f6bSchristos D_ENCRYPT(r,l,i+2); /* 2 */
114*c9496f6bSchristos D_ENCRYPT(l,r,i+4); /* 3 */
115*c9496f6bSchristos D_ENCRYPT(r,l,i+6); /* 4 */
116*c9496f6bSchristos }
117*c9496f6bSchristos #endif
118*c9496f6bSchristos }
119*c9496f6bSchristos else
120*c9496f6bSchristos {
121*c9496f6bSchristos #ifdef DES_UNROLL
122*c9496f6bSchristos D_ENCRYPT(l,r,30); /* 16 */
123*c9496f6bSchristos D_ENCRYPT(r,l,28); /* 15 */
124*c9496f6bSchristos D_ENCRYPT(l,r,26); /* 14 */
125*c9496f6bSchristos D_ENCRYPT(r,l,24); /* 13 */
126*c9496f6bSchristos D_ENCRYPT(l,r,22); /* 12 */
127*c9496f6bSchristos D_ENCRYPT(r,l,20); /* 11 */
128*c9496f6bSchristos D_ENCRYPT(l,r,18); /* 10 */
129*c9496f6bSchristos D_ENCRYPT(r,l,16); /* 9 */
130*c9496f6bSchristos D_ENCRYPT(l,r,14); /* 8 */
131*c9496f6bSchristos D_ENCRYPT(r,l,12); /* 7 */
132*c9496f6bSchristos D_ENCRYPT(l,r,10); /* 6 */
133*c9496f6bSchristos D_ENCRYPT(r,l, 8); /* 5 */
134*c9496f6bSchristos D_ENCRYPT(l,r, 6); /* 4 */
135*c9496f6bSchristos D_ENCRYPT(r,l, 4); /* 3 */
136*c9496f6bSchristos D_ENCRYPT(l,r, 2); /* 2 */
137*c9496f6bSchristos D_ENCRYPT(r,l, 0); /* 1 */
138*c9496f6bSchristos #else
139*c9496f6bSchristos for (i=30; i>0; i-=8)
140*c9496f6bSchristos {
141*c9496f6bSchristos D_ENCRYPT(l,r,i-0); /* 16 */
142*c9496f6bSchristos D_ENCRYPT(r,l,i-2); /* 15 */
143*c9496f6bSchristos D_ENCRYPT(l,r,i-4); /* 14 */
144*c9496f6bSchristos D_ENCRYPT(r,l,i-6); /* 13 */
145*c9496f6bSchristos }
146*c9496f6bSchristos #endif
147*c9496f6bSchristos }
148*c9496f6bSchristos
149*c9496f6bSchristos /* rotate and clear the top bits on machines with 8byte longs */
150*c9496f6bSchristos l=ROTATE(l,3)&0xffffffffL;
151*c9496f6bSchristos r=ROTATE(r,3)&0xffffffffL;
152*c9496f6bSchristos
153*c9496f6bSchristos FP(r,l);
154*c9496f6bSchristos data[0]=l;
155*c9496f6bSchristos data[1]=r;
156*c9496f6bSchristos l=r=t=u=0;
157*c9496f6bSchristos }
158*c9496f6bSchristos
des_encrypt2(DES_LONG * data,des_key_schedule ks,int enc)159*c9496f6bSchristos void des_encrypt2(DES_LONG *data, des_key_schedule ks, int enc)
160*c9496f6bSchristos {
161*c9496f6bSchristos register DES_LONG l,r,t,u;
162*c9496f6bSchristos #ifdef DES_PTR
163*c9496f6bSchristos register const unsigned char *des_SP=(const unsigned char *)des_SPtrans;
164*c9496f6bSchristos #endif
165*c9496f6bSchristos #ifndef DES_UNROLL
166*c9496f6bSchristos register int i;
167*c9496f6bSchristos #endif
168*c9496f6bSchristos register DES_LONG *s;
169*c9496f6bSchristos
170*c9496f6bSchristos r=data[0];
171*c9496f6bSchristos l=data[1];
172*c9496f6bSchristos
173*c9496f6bSchristos /* Things have been modified so that the initial rotate is
174*c9496f6bSchristos * done outside the loop. This required the
175*c9496f6bSchristos * des_SPtrans values in sp.h to be rotated 1 bit to the right.
176*c9496f6bSchristos * One perl script later and things have a 5% speed up on a sparc2.
177*c9496f6bSchristos * Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
178*c9496f6bSchristos * for pointing this out. */
179*c9496f6bSchristos /* clear the top bits on machines with 8byte longs */
180*c9496f6bSchristos r=ROTATE(r,29)&0xffffffffL;
181*c9496f6bSchristos l=ROTATE(l,29)&0xffffffffL;
182*c9496f6bSchristos
183*c9496f6bSchristos s=ks;
184*c9496f6bSchristos /* I don't know if it is worth the effort of loop unrolling the
185*c9496f6bSchristos * inner loop */
186*c9496f6bSchristos if (enc)
187*c9496f6bSchristos {
188*c9496f6bSchristos #ifdef DES_UNROLL
189*c9496f6bSchristos D_ENCRYPT(l,r, 0); /* 1 */
190*c9496f6bSchristos D_ENCRYPT(r,l, 2); /* 2 */
191*c9496f6bSchristos D_ENCRYPT(l,r, 4); /* 3 */
192*c9496f6bSchristos D_ENCRYPT(r,l, 6); /* 4 */
193*c9496f6bSchristos D_ENCRYPT(l,r, 8); /* 5 */
194*c9496f6bSchristos D_ENCRYPT(r,l,10); /* 6 */
195*c9496f6bSchristos D_ENCRYPT(l,r,12); /* 7 */
196*c9496f6bSchristos D_ENCRYPT(r,l,14); /* 8 */
197*c9496f6bSchristos D_ENCRYPT(l,r,16); /* 9 */
198*c9496f6bSchristos D_ENCRYPT(r,l,18); /* 10 */
199*c9496f6bSchristos D_ENCRYPT(l,r,20); /* 11 */
200*c9496f6bSchristos D_ENCRYPT(r,l,22); /* 12 */
201*c9496f6bSchristos D_ENCRYPT(l,r,24); /* 13 */
202*c9496f6bSchristos D_ENCRYPT(r,l,26); /* 14 */
203*c9496f6bSchristos D_ENCRYPT(l,r,28); /* 15 */
204*c9496f6bSchristos D_ENCRYPT(r,l,30); /* 16 */
205*c9496f6bSchristos #else
206*c9496f6bSchristos for (i=0; i<32; i+=8)
207*c9496f6bSchristos {
208*c9496f6bSchristos D_ENCRYPT(l,r,i+0); /* 1 */
209*c9496f6bSchristos D_ENCRYPT(r,l,i+2); /* 2 */
210*c9496f6bSchristos D_ENCRYPT(l,r,i+4); /* 3 */
211*c9496f6bSchristos D_ENCRYPT(r,l,i+6); /* 4 */
212*c9496f6bSchristos }
213*c9496f6bSchristos #endif
214*c9496f6bSchristos }
215*c9496f6bSchristos else
216*c9496f6bSchristos {
217*c9496f6bSchristos #ifdef DES_UNROLL
218*c9496f6bSchristos D_ENCRYPT(l,r,30); /* 16 */
219*c9496f6bSchristos D_ENCRYPT(r,l,28); /* 15 */
220*c9496f6bSchristos D_ENCRYPT(l,r,26); /* 14 */
221*c9496f6bSchristos D_ENCRYPT(r,l,24); /* 13 */
222*c9496f6bSchristos D_ENCRYPT(l,r,22); /* 12 */
223*c9496f6bSchristos D_ENCRYPT(r,l,20); /* 11 */
224*c9496f6bSchristos D_ENCRYPT(l,r,18); /* 10 */
225*c9496f6bSchristos D_ENCRYPT(r,l,16); /* 9 */
226*c9496f6bSchristos D_ENCRYPT(l,r,14); /* 8 */
227*c9496f6bSchristos D_ENCRYPT(r,l,12); /* 7 */
228*c9496f6bSchristos D_ENCRYPT(l,r,10); /* 6 */
229*c9496f6bSchristos D_ENCRYPT(r,l, 8); /* 5 */
230*c9496f6bSchristos D_ENCRYPT(l,r, 6); /* 4 */
231*c9496f6bSchristos D_ENCRYPT(r,l, 4); /* 3 */
232*c9496f6bSchristos D_ENCRYPT(l,r, 2); /* 2 */
233*c9496f6bSchristos D_ENCRYPT(r,l, 0); /* 1 */
234*c9496f6bSchristos #else
235*c9496f6bSchristos for (i=30; i>0; i-=8)
236*c9496f6bSchristos {
237*c9496f6bSchristos D_ENCRYPT(l,r,i-0); /* 16 */
238*c9496f6bSchristos D_ENCRYPT(r,l,i-2); /* 15 */
239*c9496f6bSchristos D_ENCRYPT(l,r,i-4); /* 14 */
240*c9496f6bSchristos D_ENCRYPT(r,l,i-6); /* 13 */
241*c9496f6bSchristos }
242*c9496f6bSchristos #endif
243*c9496f6bSchristos }
244*c9496f6bSchristos /* rotate and clear the top bits on machines with 8byte longs */
245*c9496f6bSchristos data[0]=ROTATE(l,3)&0xffffffffL;
246*c9496f6bSchristos data[1]=ROTATE(r,3)&0xffffffffL;
247*c9496f6bSchristos l=r=t=u=0;
248*c9496f6bSchristos }
249*c9496f6bSchristos
des_encrypt3(DES_LONG * data,des_key_schedule ks1,des_key_schedule ks2,des_key_schedule ks3)250*c9496f6bSchristos void des_encrypt3(DES_LONG *data, des_key_schedule ks1, des_key_schedule ks2,
251*c9496f6bSchristos des_key_schedule ks3)
252*c9496f6bSchristos {
253*c9496f6bSchristos register DES_LONG l,r;
254*c9496f6bSchristos
255*c9496f6bSchristos l=data[0];
256*c9496f6bSchristos r=data[1];
257*c9496f6bSchristos IP(l,r);
258*c9496f6bSchristos data[0]=l;
259*c9496f6bSchristos data[1]=r;
260*c9496f6bSchristos des_encrypt2((DES_LONG *)data,ks1,DES_ENCRYPT);
261*c9496f6bSchristos des_encrypt2((DES_LONG *)data,ks2,DES_DECRYPT);
262*c9496f6bSchristos des_encrypt2((DES_LONG *)data,ks3,DES_ENCRYPT);
263*c9496f6bSchristos l=data[0];
264*c9496f6bSchristos r=data[1];
265*c9496f6bSchristos FP(r,l);
266*c9496f6bSchristos data[0]=l;
267*c9496f6bSchristos data[1]=r;
268*c9496f6bSchristos }
269*c9496f6bSchristos
des_decrypt3(DES_LONG * data,des_key_schedule ks1,des_key_schedule ks2,des_key_schedule ks3)270*c9496f6bSchristos void des_decrypt3(DES_LONG *data, des_key_schedule ks1, des_key_schedule ks2,
271*c9496f6bSchristos des_key_schedule ks3)
272*c9496f6bSchristos {
273*c9496f6bSchristos register DES_LONG l,r;
274*c9496f6bSchristos
275*c9496f6bSchristos l=data[0];
276*c9496f6bSchristos r=data[1];
277*c9496f6bSchristos IP(l,r);
278*c9496f6bSchristos data[0]=l;
279*c9496f6bSchristos data[1]=r;
280*c9496f6bSchristos des_encrypt2((DES_LONG *)data,ks3,DES_DECRYPT);
281*c9496f6bSchristos des_encrypt2((DES_LONG *)data,ks2,DES_ENCRYPT);
282*c9496f6bSchristos des_encrypt2((DES_LONG *)data,ks1,DES_DECRYPT);
283*c9496f6bSchristos l=data[0];
284*c9496f6bSchristos r=data[1];
285*c9496f6bSchristos FP(r,l);
286*c9496f6bSchristos data[0]=l;
287*c9496f6bSchristos data[1]=r;
288*c9496f6bSchristos }
289*c9496f6bSchristos
290*c9496f6bSchristos #ifndef DES_DEFAULT_OPTIONS
291*c9496f6bSchristos
292*c9496f6bSchristos #undef CBC_ENC_C__DONT_UPDATE_IV
293*c9496f6bSchristos #include "oncbc_enc.c" /* des_ncbc_encrypt */
294*c9496f6bSchristos
des_ede3_cbc_encrypt(const unsigned char * input,unsigned char * output,long length,des_key_schedule ks1,des_key_schedule ks2,des_key_schedule ks3,des_cblock * ivec,int enc)295*c9496f6bSchristos void des_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output,
296*c9496f6bSchristos long length, des_key_schedule ks1, des_key_schedule ks2,
297*c9496f6bSchristos des_key_schedule ks3, des_cblock *ivec, int enc)
298*c9496f6bSchristos {
299*c9496f6bSchristos register DES_LONG tin0,tin1;
300*c9496f6bSchristos register DES_LONG tout0,tout1,xor0,xor1;
301*c9496f6bSchristos register const unsigned char *in;
302*c9496f6bSchristos unsigned char *out;
303*c9496f6bSchristos register long l=length;
304*c9496f6bSchristos DES_LONG tin[2];
305*c9496f6bSchristos unsigned char *iv;
306*c9496f6bSchristos
307*c9496f6bSchristos in=input;
308*c9496f6bSchristos out=output;
309*c9496f6bSchristos iv = &(*ivec)[0];
310*c9496f6bSchristos
311*c9496f6bSchristos if (enc)
312*c9496f6bSchristos {
313*c9496f6bSchristos c2l(iv,tout0);
314*c9496f6bSchristos c2l(iv,tout1);
315*c9496f6bSchristos for (l-=8; l>=0; l-=8)
316*c9496f6bSchristos {
317*c9496f6bSchristos c2l(in,tin0);
318*c9496f6bSchristos c2l(in,tin1);
319*c9496f6bSchristos tin0^=tout0;
320*c9496f6bSchristos tin1^=tout1;
321*c9496f6bSchristos
322*c9496f6bSchristos tin[0]=tin0;
323*c9496f6bSchristos tin[1]=tin1;
324*c9496f6bSchristos des_encrypt3((DES_LONG *)tin,ks1,ks2,ks3);
325*c9496f6bSchristos tout0=tin[0];
326*c9496f6bSchristos tout1=tin[1];
327*c9496f6bSchristos
328*c9496f6bSchristos l2c(tout0,out);
329*c9496f6bSchristos l2c(tout1,out);
330*c9496f6bSchristos }
331*c9496f6bSchristos if (l != -8)
332*c9496f6bSchristos {
333*c9496f6bSchristos c2ln(in,tin0,tin1,l+8);
334*c9496f6bSchristos tin0^=tout0;
335*c9496f6bSchristos tin1^=tout1;
336*c9496f6bSchristos
337*c9496f6bSchristos tin[0]=tin0;
338*c9496f6bSchristos tin[1]=tin1;
339*c9496f6bSchristos des_encrypt3((DES_LONG *)tin,ks1,ks2,ks3);
340*c9496f6bSchristos tout0=tin[0];
341*c9496f6bSchristos tout1=tin[1];
342*c9496f6bSchristos
343*c9496f6bSchristos l2c(tout0,out);
344*c9496f6bSchristos l2c(tout1,out);
345*c9496f6bSchristos }
346*c9496f6bSchristos iv = &(*ivec)[0];
347*c9496f6bSchristos l2c(tout0,iv);
348*c9496f6bSchristos l2c(tout1,iv);
349*c9496f6bSchristos }
350*c9496f6bSchristos else
351*c9496f6bSchristos {
352*c9496f6bSchristos register DES_LONG t0,t1;
353*c9496f6bSchristos
354*c9496f6bSchristos c2l(iv,xor0);
355*c9496f6bSchristos c2l(iv,xor1);
356*c9496f6bSchristos for (l-=8; l>=0; l-=8)
357*c9496f6bSchristos {
358*c9496f6bSchristos c2l(in,tin0);
359*c9496f6bSchristos c2l(in,tin1);
360*c9496f6bSchristos
361*c9496f6bSchristos t0=tin0;
362*c9496f6bSchristos t1=tin1;
363*c9496f6bSchristos
364*c9496f6bSchristos tin[0]=tin0;
365*c9496f6bSchristos tin[1]=tin1;
366*c9496f6bSchristos des_decrypt3((DES_LONG *)tin,ks1,ks2,ks3);
367*c9496f6bSchristos tout0=tin[0];
368*c9496f6bSchristos tout1=tin[1];
369*c9496f6bSchristos
370*c9496f6bSchristos tout0^=xor0;
371*c9496f6bSchristos tout1^=xor1;
372*c9496f6bSchristos l2c(tout0,out);
373*c9496f6bSchristos l2c(tout1,out);
374*c9496f6bSchristos xor0=t0;
375*c9496f6bSchristos xor1=t1;
376*c9496f6bSchristos }
377*c9496f6bSchristos if (l != -8)
378*c9496f6bSchristos {
379*c9496f6bSchristos c2l(in,tin0);
380*c9496f6bSchristos c2l(in,tin1);
381*c9496f6bSchristos
382*c9496f6bSchristos t0=tin0;
383*c9496f6bSchristos t1=tin1;
384*c9496f6bSchristos
385*c9496f6bSchristos tin[0]=tin0;
386*c9496f6bSchristos tin[1]=tin1;
387*c9496f6bSchristos des_decrypt3((DES_LONG *)tin,ks1,ks2,ks3);
388*c9496f6bSchristos tout0=tin[0];
389*c9496f6bSchristos tout1=tin[1];
390*c9496f6bSchristos
391*c9496f6bSchristos tout0^=xor0;
392*c9496f6bSchristos tout1^=xor1;
393*c9496f6bSchristos l2cn(tout0,tout1,out,l+8);
394*c9496f6bSchristos xor0=t0;
395*c9496f6bSchristos xor1=t1;
396*c9496f6bSchristos }
397*c9496f6bSchristos
398*c9496f6bSchristos iv = &(*ivec)[0];
399*c9496f6bSchristos l2c(xor0,iv);
400*c9496f6bSchristos l2c(xor1,iv);
401*c9496f6bSchristos }
402*c9496f6bSchristos tin0=tin1=tout0=tout1=xor0=xor1=0;
403*c9496f6bSchristos tin[0]=tin[1]=0;
404*c9496f6bSchristos }
405*c9496f6bSchristos
406*c9496f6bSchristos #endif /* DES_DEFAULT_OPTIONS */
407