Wraphelp.c revision ff559fab
1/*
2 * $Xorg: A8Eq.c,v 1.4 2001/02/09 02:03:48 xorgcvs Exp $
3 *
4 */
5
6#ifdef HAVE_CONFIG_H
7#include <config.h>
8#endif
9#include <sys/types.h>
10#include <X11/Xmd.h>
11#include "Wrap.h"
12
13/* des routines for non-usa - eay 10/9/1991 eay@psych.psy.uq.oz.au
14 * These routines were written for speed not size so they are bigger than
15 * needed.  I have removed some of the loop unrolling, this will reduce
16 * code size at the expense of some speed.
17 * 25/9/1991 eay - much faster _XdmcpAuthSetup (4 times faster).
18 * 19/9/1991 eay - cleaned up the IP and FP code.
19 * 10/9/1991 eay - first release.
20 * The des routines this file has been made from can be found in
21 * ftp.psy.uq.oz.au /pub/DES
22 * This particular version derived from OpenBSD Revsion 1.3.
23 */
24
25/*
26 *
27 * Export Requirements.
28 * You may not export or re-export this software or any copy or
29 * adaptation in violation of any applicable laws or regulations.
30 *
31 * Without limiting the generality of the foregoing, hardware, software,
32 * technology or services provided under this license agreement may not
33 * be exported, reexported, transferred or downloaded to or within (or to
34 * a national resident of) countries under U.S. economic embargo
35 * including the following countries:
36 *
37 * Cuba, Iran, Libya, North Korea, Sudan and Syria. This list is subject
38 * to change.
39 *
40 * Hardware, software, technology or services may not be exported,
41 * reexported, transferred or downloaded to persons or entities listed on
42 * the U.S. Department of Commerce Denied Persons List, Entity List of
43 * proliferation concern or on any U.S. Treasury Department Designated
44 * Nationals exclusion list, or to parties directly or indirectly
45 * involved in the development or production of nuclear, chemical,
46 * biological weapons or in missile technology programs as specified in
47 * the U.S. Export Administration Regulations (15 CFR 744).
48 *
49 * By accepting this license agreement you confirm that you are not
50 * located in (or a national resident of) any country under U.S. economic
51 * embargo, not identified on any U.S. Department of Commerce Denied
52 * Persons List, Entity List or Treasury Department Designated Nationals
53 * exclusion list, and not directly or indirectly involved in the
54 * development or production of nuclear, chemical, biological weapons or
55 * in missile technology programs as specified in the U.S. Export
56 * Administration Regulations.
57 *
58 *
59 * Local Country Import Requirements. The software you are about to
60 * download contains cryptography technology. Some countries regulate the
61 * import, use and/or export of certain products with cryptography. The
62 * X.org Foundation makes no claims as to the applicability of local
63 * country import, use and/or export regulations in relation to the
64 * download of this product. If you are located outside the U.S. and
65 * Canada you are advised to consult your local country regulations to
66 * insure compliance.
67 */
68
69static const CARD32 skb[8][64] = {
70	/* for C bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
71	{ 0x00000000,0x00000010,0x20000000,0x20000010,
72	  0x00010000,0x00010010,0x20010000,0x20010010,
73	  0x00000800,0x00000810,0x20000800,0x20000810,
74	  0x00010800,0x00010810,0x20010800,0x20010810,
75	  0x00000020,0x00000030,0x20000020,0x20000030,
76	  0x00010020,0x00010030,0x20010020,0x20010030,
77	  0x00000820,0x00000830,0x20000820,0x20000830,
78	  0x00010820,0x00010830,0x20010820,0x20010830,
79	  0x00080000,0x00080010,0x20080000,0x20080010,
80	  0x00090000,0x00090010,0x20090000,0x20090010,
81	  0x00080800,0x00080810,0x20080800,0x20080810,
82	  0x00090800,0x00090810,0x20090800,0x20090810,
83	  0x00080020,0x00080030,0x20080020,0x20080030,
84	  0x00090020,0x00090030,0x20090020,0x20090030,
85	  0x00080820,0x00080830,0x20080820,0x20080830,
86	  0x00090820,0x00090830,0x20090820,0x20090830 },
87	/* for C bits (numbered as per FIPS 46) 7 8 10 11 12 13 */
88	{ 0x00000000,0x02000000,0x00002000,0x02002000,
89	  0x00200000,0x02200000,0x00202000,0x02202000,
90	  0x00000004,0x02000004,0x00002004,0x02002004,
91	  0x00200004,0x02200004,0x00202004,0x02202004,
92	  0x00000400,0x02000400,0x00002400,0x02002400,
93	  0x00200400,0x02200400,0x00202400,0x02202400,
94	  0x00000404,0x02000404,0x00002404,0x02002404,
95	  0x00200404,0x02200404,0x00202404,0x02202404,
96	  0x10000000,0x12000000,0x10002000,0x12002000,
97	  0x10200000,0x12200000,0x10202000,0x12202000,
98	  0x10000004,0x12000004,0x10002004,0x12002004,
99	  0x10200004,0x12200004,0x10202004,0x12202004,
100	  0x10000400,0x12000400,0x10002400,0x12002400,
101	  0x10200400,0x12200400,0x10202400,0x12202400,
102	  0x10000404,0x12000404,0x10002404,0x12002404,
103	  0x10200404,0x12200404,0x10202404,0x12202404 },
104	/* for C bits (numbered as per FIPS 46) 14 15 16 17 19 20 */
105	{ 0x00000000,0x00000001,0x00040000,0x00040001,
106	  0x01000000,0x01000001,0x01040000,0x01040001,
107	  0x00000002,0x00000003,0x00040002,0x00040003,
108	  0x01000002,0x01000003,0x01040002,0x01040003,
109	  0x00000200,0x00000201,0x00040200,0x00040201,
110	  0x01000200,0x01000201,0x01040200,0x01040201,
111	  0x00000202,0x00000203,0x00040202,0x00040203,
112	  0x01000202,0x01000203,0x01040202,0x01040203,
113	  0x08000000,0x08000001,0x08040000,0x08040001,
114	  0x09000000,0x09000001,0x09040000,0x09040001,
115	  0x08000002,0x08000003,0x08040002,0x08040003,
116	  0x09000002,0x09000003,0x09040002,0x09040003,
117	  0x08000200,0x08000201,0x08040200,0x08040201,
118	  0x09000200,0x09000201,0x09040200,0x09040201,
119	  0x08000202,0x08000203,0x08040202,0x08040203,
120	  0x09000202,0x09000203,0x09040202,0x09040203 },
121	/* for C bits (numbered as per FIPS 46) 21 23 24 26 27 28 */
122	{ 0x00000000,0x00100000,0x00000100,0x00100100,
123	  0x00000008,0x00100008,0x00000108,0x00100108,
124	  0x00001000,0x00101000,0x00001100,0x00101100,
125	  0x00001008,0x00101008,0x00001108,0x00101108,
126	  0x04000000,0x04100000,0x04000100,0x04100100,
127	  0x04000008,0x04100008,0x04000108,0x04100108,
128	  0x04001000,0x04101000,0x04001100,0x04101100,
129	  0x04001008,0x04101008,0x04001108,0x04101108,
130	  0x00020000,0x00120000,0x00020100,0x00120100,
131	  0x00020008,0x00120008,0x00020108,0x00120108,
132	  0x00021000,0x00121000,0x00021100,0x00121100,
133	  0x00021008,0x00121008,0x00021108,0x00121108,
134	  0x04020000,0x04120000,0x04020100,0x04120100,
135	  0x04020008,0x04120008,0x04020108,0x04120108,
136	  0x04021000,0x04121000,0x04021100,0x04121100,
137	  0x04021008,0x04121008,0x04021108,0x04121108 },
138	/* for D bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
139	{ 0x00000000,0x10000000,0x00010000,0x10010000,
140	  0x00000004,0x10000004,0x00010004,0x10010004,
141	  0x20000000,0x30000000,0x20010000,0x30010000,
142	  0x20000004,0x30000004,0x20010004,0x30010004,
143	  0x00100000,0x10100000,0x00110000,0x10110000,
144	  0x00100004,0x10100004,0x00110004,0x10110004,
145	  0x20100000,0x30100000,0x20110000,0x30110000,
146	  0x20100004,0x30100004,0x20110004,0x30110004,
147	  0x00001000,0x10001000,0x00011000,0x10011000,
148	  0x00001004,0x10001004,0x00011004,0x10011004,
149	  0x20001000,0x30001000,0x20011000,0x30011000,
150	  0x20001004,0x30001004,0x20011004,0x30011004,
151	  0x00101000,0x10101000,0x00111000,0x10111000,
152	  0x00101004,0x10101004,0x00111004,0x10111004,
153	  0x20101000,0x30101000,0x20111000,0x30111000,
154	  0x20101004,0x30101004,0x20111004,0x30111004 },
155	/* for D bits (numbered as per FIPS 46) 8 9 11 12 13 14 */
156	{ 0x00000000,0x08000000,0x00000008,0x08000008,
157	  0x00000400,0x08000400,0x00000408,0x08000408,
158	  0x00020000,0x08020000,0x00020008,0x08020008,
159	  0x00020400,0x08020400,0x00020408,0x08020408,
160	  0x00000001,0x08000001,0x00000009,0x08000009,
161	  0x00000401,0x08000401,0x00000409,0x08000409,
162	  0x00020001,0x08020001,0x00020009,0x08020009,
163	  0x00020401,0x08020401,0x00020409,0x08020409,
164	  0x02000000,0x0A000000,0x02000008,0x0A000008,
165	  0x02000400,0x0A000400,0x02000408,0x0A000408,
166	  0x02020000,0x0A020000,0x02020008,0x0A020008,
167	  0x02020400,0x0A020400,0x02020408,0x0A020408,
168	  0x02000001,0x0A000001,0x02000009,0x0A000009,
169	  0x02000401,0x0A000401,0x02000409,0x0A000409,
170	  0x02020001,0x0A020001,0x02020009,0x0A020009,
171	  0x02020401,0x0A020401,0x02020409,0x0A020409 },
172	/* for D bits (numbered as per FIPS 46) 16 17 18 19 20 21 */
173	{ 0x00000000,0x00000100,0x00080000,0x00080100,
174	  0x01000000,0x01000100,0x01080000,0x01080100,
175	  0x00000010,0x00000110,0x00080010,0x00080110,
176	  0x01000010,0x01000110,0x01080010,0x01080110,
177	  0x00200000,0x00200100,0x00280000,0x00280100,
178	  0x01200000,0x01200100,0x01280000,0x01280100,
179	  0x00200010,0x00200110,0x00280010,0x00280110,
180	  0x01200010,0x01200110,0x01280010,0x01280110,
181	  0x00000200,0x00000300,0x00080200,0x00080300,
182	  0x01000200,0x01000300,0x01080200,0x01080300,
183	  0x00000210,0x00000310,0x00080210,0x00080310,
184	  0x01000210,0x01000310,0x01080210,0x01080310,
185	  0x00200200,0x00200300,0x00280200,0x00280300,
186	  0x01200200,0x01200300,0x01280200,0x01280300,
187	  0x00200210,0x00200310,0x00280210,0x00280310,
188	  0x01200210,0x01200310,0x01280210,0x01280310 },
189	  /* for D bits (numbered as per FIPS 46) 22 23 24 25 27 28 */
190	{ 0x00000000,0x04000000,0x00040000,0x04040000,
191	  0x00000002,0x04000002,0x00040002,0x04040002,
192	  0x00002000,0x04002000,0x00042000,0x04042000,
193	  0x00002002,0x04002002,0x00042002,0x04042002,
194	  0x00000020,0x04000020,0x00040020,0x04040020,
195	  0x00000022,0x04000022,0x00040022,0x04040022,
196	  0x00002020,0x04002020,0x00042020,0x04042020,
197	  0x00002022,0x04002022,0x00042022,0x04042022,
198	  0x00000800,0x04000800,0x00040800,0x04040800,
199	  0x00000802,0x04000802,0x00040802,0x04040802,
200	  0x00002800,0x04002800,0x00042800,0x04042800,
201	  0x00002802,0x04002802,0x00042802,0x04042802,
202	  0x00000820,0x04000820,0x00040820,0x04040820,
203	  0x00000822,0x04000822,0x00040822,0x04040822,
204	  0x00002820,0x04002820,0x00042820,0x04042820,
205	  0x00002822,0x04002822,0x00042822,0x04042822 }
206};
207
208
209static const CARD32 SPtrans[8][64] = {
210	/* nibble 0 */
211	{ 0x00410100, 0x00010000, 0x40400000, 0x40410100,
212	  0x00400000, 0x40010100, 0x40010000, 0x40400000,
213	  0x40010100, 0x00410100, 0x00410000, 0x40000100,
214	  0x40400100, 0x00400000, 0x00000000, 0x40010000,
215	  0x00010000, 0x40000000, 0x00400100, 0x00010100,
216	  0x40410100, 0x00410000, 0x40000100, 0x00400100,
217	  0x40000000, 0x00000100, 0x00010100, 0x40410000,
218	  0x00000100, 0x40400100, 0x40410000, 0x00000000,
219	  0x00000000, 0x40410100, 0x00400100, 0x40010000,
220	  0x00410100, 0x00010000, 0x40000100, 0x00400100,
221	  0x40410000, 0x00000100, 0x00010100, 0x40400000,
222	  0x40010100, 0x40000000, 0x40400000, 0x00410000,
223	  0x40410100, 0x00010100, 0x00410000, 0x40400100,
224	  0x00400000, 0x40000100, 0x40010000, 0x00000000,
225	  0x00010000, 0x00400000, 0x40400100, 0x00410100,
226	  0x40000000, 0x40410000, 0x00000100, 0x40010100 },
227
228	/* nibble 1 */
229	{ 0x08021002, 0x00000000, 0x00021000, 0x08020000,
230	  0x08000002, 0x00001002, 0x08001000, 0x00021000,
231	  0x00001000, 0x08020002, 0x00000002, 0x08001000,
232	  0x00020002, 0x08021000, 0x08020000, 0x00000002,
233	  0x00020000, 0x08001002, 0x08020002, 0x00001000,
234	  0x00021002, 0x08000000, 0x00000000, 0x00020002,
235	  0x08001002, 0x00021002, 0x08021000, 0x08000002,
236	  0x08000000, 0x00020000, 0x00001002, 0x08021002,
237	  0x00020002, 0x08021000, 0x08001000, 0x00021002,
238	  0x08021002, 0x00020002, 0x08000002, 0x00000000,
239	  0x08000000, 0x00001002, 0x00020000, 0x08020002,
240	  0x00001000, 0x08000000, 0x00021002, 0x08001002,
241	  0x08021000, 0x00001000, 0x00000000, 0x08000002,
242	  0x00000002, 0x08021002, 0x00021000, 0x08020000,
243	  0x08020002, 0x00020000, 0x00001002, 0x08001000,
244	  0x08001002, 0x00000002, 0x08020000, 0x00021000 },
245
246	/* nibble 2 */
247	{ 0x20800000, 0x00808020, 0x00000020, 0x20800020,
248	  0x20008000, 0x00800000, 0x20800020, 0x00008020,
249	  0x00800020, 0x00008000, 0x00808000, 0x20000000,
250	  0x20808020, 0x20000020, 0x20000000, 0x20808000,
251	  0x00000000, 0x20008000, 0x00808020, 0x00000020,
252	  0x20000020, 0x20808020, 0x00008000, 0x20800000,
253	  0x20808000, 0x00800020, 0x20008020, 0x00808000,
254	  0x00008020, 0x00000000, 0x00800000, 0x20008020,
255	  0x00808020, 0x00000020, 0x20000000, 0x00008000,
256	  0x20000020, 0x20008000, 0x00808000, 0x20800020,
257	  0x00000000, 0x00808020, 0x00008020, 0x20808000,
258	  0x20008000, 0x00800000, 0x20808020, 0x20000000,
259	  0x20008020, 0x20800000, 0x00800000, 0x20808020,
260	  0x00008000, 0x00800020, 0x20800020, 0x00008020,
261	  0x00800020, 0x00000000, 0x20808000, 0x20000020,
262	  0x20800000, 0x20008020, 0x00000020, 0x00808000 },
263
264	/* nibble 3 */
265	{ 0x00080201, 0x02000200, 0x00000001, 0x02080201,
266	  0x00000000, 0x02080000, 0x02000201, 0x00080001,
267	  0x02080200, 0x02000001, 0x02000000, 0x00000201,
268	  0x02000001, 0x00080201, 0x00080000, 0x02000000,
269	  0x02080001, 0x00080200, 0x00000200, 0x00000001,
270	  0x00080200, 0x02000201, 0x02080000, 0x00000200,
271	  0x00000201, 0x00000000, 0x00080001, 0x02080200,
272	  0x02000200, 0x02080001, 0x02080201, 0x00080000,
273	  0x02080001, 0x00000201, 0x00080000, 0x02000001,
274	  0x00080200, 0x02000200, 0x00000001, 0x02080000,
275	  0x02000201, 0x00000000, 0x00000200, 0x00080001,
276	  0x00000000, 0x02080001, 0x02080200, 0x00000200,
277	  0x02000000, 0x02080201, 0x00080201, 0x00080000,
278	  0x02080201, 0x00000001, 0x02000200, 0x00080201,
279	  0x00080001, 0x00080200, 0x02080000, 0x02000201,
280	  0x00000201, 0x02000000, 0x02000001, 0x02080200 },
281
282	/* nibble 4 */
283	{ 0x01000000, 0x00002000, 0x00000080, 0x01002084,
284	  0x01002004, 0x01000080, 0x00002084, 0x01002000,
285	  0x00002000, 0x00000004, 0x01000004, 0x00002080,
286	  0x01000084, 0x01002004, 0x01002080, 0x00000000,
287	  0x00002080, 0x01000000, 0x00002004, 0x00000084,
288	  0x01000080, 0x00002084, 0x00000000, 0x01000004,
289	  0x00000004, 0x01000084, 0x01002084, 0x00002004,
290	  0x01002000, 0x00000080, 0x00000084, 0x01002080,
291	  0x01002080, 0x01000084, 0x00002004, 0x01002000,
292	  0x00002000, 0x00000004, 0x01000004, 0x01000080,
293	  0x01000000, 0x00002080, 0x01002084, 0x00000000,
294	  0x00002084, 0x01000000, 0x00000080, 0x00002004,
295	  0x01000084, 0x00000080, 0x00000000, 0x01002084,
296	  0x01002004, 0x01002080, 0x00000084, 0x00002000,
297	  0x00002080, 0x01002004, 0x01000080, 0x00000084,
298	  0x00000004, 0x00002084, 0x01002000, 0x01000004 },
299
300	/* nibble 5 */
301	{ 0x10000008, 0x00040008, 0x00000000, 0x10040400,
302	  0x00040008, 0x00000400, 0x10000408, 0x00040000,
303	  0x00000408, 0x10040408, 0x00040400, 0x10000000,
304	  0x10000400, 0x10000008, 0x10040000, 0x00040408,
305	  0x00040000, 0x10000408, 0x10040008, 0x00000000,
306	  0x00000400, 0x00000008, 0x10040400, 0x10040008,
307	  0x10040408, 0x10040000, 0x10000000, 0x00000408,
308	  0x00000008, 0x00040400, 0x00040408, 0x10000400,
309	  0x00000408, 0x10000000, 0x10000400, 0x00040408,
310	  0x10040400, 0x00040008, 0x00000000, 0x10000400,
311	  0x10000000, 0x00000400, 0x10040008, 0x00040000,
312	  0x00040008, 0x10040408, 0x00040400, 0x00000008,
313	  0x10040408, 0x00040400, 0x00040000, 0x10000408,
314	  0x10000008, 0x10040000, 0x00040408, 0x00000000,
315	  0x00000400, 0x10000008, 0x10000408, 0x10040400,
316	  0x10040000, 0x00000408, 0x00000008, 0x10040008 },
317
318	/* nibble 6 */
319	{ 0x00000800, 0x00000040, 0x00200040, 0x80200000,
320	  0x80200840, 0x80000800, 0x00000840, 0x00000000,
321	  0x00200000, 0x80200040, 0x80000040, 0x00200800,
322	  0x80000000, 0x00200840, 0x00200800, 0x80000040,
323	  0x80200040, 0x00000800, 0x80000800, 0x80200840,
324	  0x00000000, 0x00200040, 0x80200000, 0x00000840,
325	  0x80200800, 0x80000840, 0x00200840, 0x80000000,
326	  0x80000840, 0x80200800, 0x00000040, 0x00200000,
327	  0x80000840, 0x00200800, 0x80200800, 0x80000040,
328	  0x00000800, 0x00000040, 0x00200000, 0x80200800,
329	  0x80200040, 0x80000840, 0x00000840, 0x00000000,
330	  0x00000040, 0x80200000, 0x80000000, 0x00200040,
331	  0x00000000, 0x80200040, 0x00200040, 0x00000840,
332	  0x80000040, 0x00000800, 0x80200840, 0x00200000,
333	  0x00200840, 0x80000000, 0x80000800, 0x80200840,
334	  0x80200000, 0x00200840, 0x00200800, 0x80000800 },
335
336	/* nibble 7 */
337	{ 0x04100010, 0x04104000, 0x00004010, 0x00000000,
338	  0x04004000, 0x00100010, 0x04100000, 0x04104010,
339	  0x00000010, 0x04000000, 0x00104000, 0x00004010,
340	  0x00104010, 0x04004010, 0x04000010, 0x04100000,
341	  0x00004000, 0x00104010, 0x00100010, 0x04004000,
342	  0x04104010, 0x04000010, 0x00000000, 0x00104000,
343	  0x04000000, 0x00100000, 0x04004010, 0x04100010,
344	  0x00100000, 0x00004000, 0x04104000, 0x00000010,
345	  0x00100000, 0x00004000, 0x04000010, 0x04104010,
346	  0x00004010, 0x04000000, 0x00000000, 0x00104000,
347	  0x04100010, 0x04004010, 0x04004000, 0x00100010,
348	  0x04104000, 0x00000010, 0x00100010, 0x04004000,
349	  0x04104010, 0x00100000, 0x04100000, 0x04000010,
350	  0x00104000, 0x00004010, 0x04004010, 0x04100000,
351	  0x00000010, 0x04104000, 0x00104010, 0x00000000,
352	  0x04000000, 0x04100010, 0x00004000, 0x00104010}
353};
354
355#define ITERATIONS 16
356#define HALF_ITERATIONS 8
357
358#define c2l(c,l)	(l =((CARD32)(*((c)++)))    , \
359			 l|=((CARD32)(*((c)++)))<< 8, \
360			 l|=((CARD32)(*((c)++)))<<16, \
361			 l|=((CARD32)(*((c)++)))<<24)
362
363#define l2c(l,c)	(*((c)++)=(CARD8)(((l)    )&0xff), \
364			 *((c)++)=(CARD8)(((l)>> 8)&0xff), \
365			 *((c)++)=(CARD8)(((l)>>16)&0xff), \
366			 *((c)++)=(CARD8)(((l)>>24)&0xff))
367
368#define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
369	(b)^=(t),\
370	(a)^=((t)<<(n)))
371
372#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\
373	(a)=(a)^(t)^(t>>(16-(n))))\
374
375static const char shifts2[16] = {0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
376
377void _XdmcpAuthSetup(auth_cblock key, auth_wrapper_schedule schedule)
378{
379	CARD32 c,d,t,s;
380	CARD8 *in;
381	CARD32 *k;
382	int i;
383
384	k=(CARD32 *)schedule;
385	in=(CARD8 *)key;
386
387	c2l(in,c);
388	c2l(in,d);
389
390	/* do PC1 in 60 simple operations */
391	PERM_OP(d,c,t,4,0x0f0f0f0f);
392	HPERM_OP(c,t,-2, 0xcccc0000);
393	HPERM_OP(c,t,-1, 0xaaaa0000);
394	HPERM_OP(c,t, 8, 0x00ff0000);
395	HPERM_OP(c,t,-1, 0xaaaa0000);
396	HPERM_OP(d,t,-8, 0xff000000);
397	HPERM_OP(d,t, 8, 0x00ff0000);
398	HPERM_OP(d,t, 2, 0x33330000);
399	d=((d&0x00aa00aa)<<7)|((d&0x55005500)>>7)|(d&0xaa55aa55);
400	d=(d>>8)|((c&0xf0000000)>>4);
401	c&=0x0fffffff;
402
403	for (i=0; i<ITERATIONS; i++) {
404		if (shifts2[i]) {
405			c=((c>>2)|(c<<26)); d=((d>>2)|(d<<26));
406		} else {
407			c=((c>>1)|(c<<27)); d=((d>>1)|(d<<27));
408		}
409		c&=0x0fffffff;
410		d&=0x0fffffff;
411		/* could be a few less shifts but I am to lazy at this
412		 * point in time to investigate */
413		s=	skb[0][ (c    )&0x3f		    ]|
414			skb[1][((c>> 6)&0x03)|((c>> 7)&0x3c)]|
415			skb[2][((c>>13)&0x0f)|((c>>14)&0x30)]|
416			skb[3][((c>>20)&0x01)|((c>>21)&0x06) |
417					      ((c>>22)&0x38)];
418		t=	skb[4][ (d    )&0x3f		    ]|
419			skb[5][((d>> 7)&0x03)|((d>> 8)&0x3c)]|
420			skb[6][ (d>>15)&0x3f		    ]|
421			skb[7][((d>>21)&0x0f)|((d>>22)&0x30)];
422
423		/* table contained 0213 4657 */
424		*(k++)=((t<<16)|(s&0x0000ffff));
425		s=     ((s>>16)|(t&0xffff0000));
426
427		s=(s<<4)|(s>>28);
428		*(k++)=s;
429	}
430	return;
431}
432
433#define D_ENCRYPT(L,R,S)	\
434	t=(R<<1)|(R>>31); \
435	u=(t^s[S  ]); \
436	t=(t^s[S+1]); \
437	t=(t>>4)|(t<<28); \
438	L^=	SPtrans[1][(t	 )&0x3f]| \
439		SPtrans[3][(t>> 8)&0x3f]| \
440		SPtrans[5][(t>>16)&0x3f]| \
441		SPtrans[7][(t>>24)&0x3f]| \
442		SPtrans[0][(u	 )&0x3f]| \
443		SPtrans[2][(u>> 8)&0x3f]| \
444		SPtrans[4][(u>>16)&0x3f]| \
445		SPtrans[6][(u>>24)&0x3f];
446
447
448void _XdmcpAuthDoIt(auth_cblock input, auth_cblock output,
449    auth_wrapper_schedule ks, int encrypt)
450{
451	CARD32 l,r,t,u;
452	CARD32 *s;
453	CARD8 *in,*out;
454	int i;
455
456	in=(CARD8 *)input;
457	out=(CARD8 *)output;
458	c2l(in,l);
459	c2l(in,r);
460
461	/* do IP */
462	PERM_OP(r,l,t, 4,0x0f0f0f0f);
463	PERM_OP(l,r,t,16,0x0000ffff);
464	PERM_OP(r,l,t, 2,0x33333333);
465	PERM_OP(l,r,t, 8,0x00ff00ff);
466	PERM_OP(r,l,t, 1,0x55555555);
467	/* r and l are reversed - remember that :-) */
468	t=l;
469	l=r;
470	r=t;
471
472	s=(CARD32 *)ks;
473
474	if (encrypt) {
475		for (i=0; i<(ITERATIONS*2); i+=4) {
476			D_ENCRYPT(l,r,	i); /*	1 */
477			D_ENCRYPT(r,l,	i+2); /*  2 */
478		}
479	} else {
480		for (i=(ITERATIONS*2)-2; i >= 0; i-=4) {
481			D_ENCRYPT(l,r,	i); /*	1 */
482			D_ENCRYPT(r,l,	i-2); /*  2 */
483		}
484	}
485
486	/* swap l and r
487	 * we will not do the swap so just remember they are
488	 * reversed for the rest of the subroutine
489	 * luckily by FP fixes this problem :-) */
490
491	PERM_OP(r,l,t, 1,0x55555555);
492	PERM_OP(l,r,t, 8,0x00ff00ff);
493	PERM_OP(r,l,t, 2,0x33333333);
494	PERM_OP(l,r,t,16,0x0000ffff);
495	PERM_OP(r,l,t, 4,0x0f0f0f0f);
496
497	l2c(l,out);
498	l2c(r,out);
499	return;
500}
501