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