1 /* 2 * This file is part of "The Java Telnet Application". 3 * 4 * (c) Matthias L. Jugel, Marcus Meißner 1996-2002. All Rights Reserved. 5 * The file was changed by Radek Polak to work as midlet in MIDP 1.0 6 * 7 * Please visit http://javatelnet.org/ for updates and contact. 8 * 9 * IMPORTANT NOTICE: 10 * The code herein cannot be placed under GPL or any other license and 11 * is provided as reference and to support DES encryption for communication 12 * with some SSH servers. Please see license notice below for detailled 13 * information. 14 * 15 * --- 16 * Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 17 * All rights reserved. 18 * 19 * This package is an SSL implementation written 20 * by Eric Young (eay@cryptsoft.com). 21 * The implementation was written so as to conform with Netscapes SSL. 22 * 23 * This library is free for commercial and non-commercial use as long as 24 * the following conditions are aheared to. The following conditions 25 * apply to all code found in this distribution, be it the RC4, RSA, 26 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 27 * included with this distribution is covered by the same copyright terms 28 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 29 * 30 * Copyright remains Eric Young's, and as such any Copyright notices in 31 * the code are not to be removed. 32 * If this package is used in a product, Eric Young should be given attribution 33 * as the author of the parts of the library used. 34 * This can be in the form of a textual message at program startup or 35 * in documentation (online or textual) provided with the package. 36 * 37 * Redistribution and use in source and binary forms, with or without 38 * modification, are permitted provided that the following conditions 39 * are met: 40 * 1. Redistributions of source code must retain the copyright 41 * notice, this list of conditions and the following disclaimer. 42 * 2. Redistributions in binary form must reproduce the above copyright 43 * notice, this list of conditions and the following disclaimer in the 44 * documentation and/or other materials provided with the distribution. 45 * 3. All advertising materials mentioning features or use of this software 46 * must display the following acknowledgement: 47 * "This product includes cryptographic software written by 48 * Eric Young (eay@cryptsoft.com)" 49 * The word 'cryptographic' can be left out if the rouines from the library 50 * being used are not cryptographic related :-). 51 * 4. If you include any Windows specific code (or a derivative thereof) from 52 * the apps directory (application code) you must include an acknowledgement: 53 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 54 * 55 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 56 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 58 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 59 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 60 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 61 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 62 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 63 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 64 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 65 * SUCH DAMAGE. 66 * 67 * The licence and distribution terms for any publically available version or 68 * derivative of this code cannot be changed. i.e. this code cannot simply be 69 * copied and put under another distribution licence 70 * [including the GNU Public Licence.] 71 * ---- 72 */ 73 package ssh; 74 75 public final class DES extends Cipher { 76 77 protected int[] key_schedule = new int[32]; 78 protected int IV0 = 0; 79 protected int IV1 = 0; 80 81 public synchronized void encrypt(byte[] src, int srcOff, byte[] dest, int destOff, int len) { 82 int[] out = new int[2]; 83 int iv0 = IV0; 84 int iv1 = IV1; 85 int end = srcOff + len; 86 87 for (int si = srcOff, di = destOff; si < end; si += 8, di += 8) { 88 iv0 ^= ((src[si] & 0xff) | ((src[si + 1] & 0xff) << 8) | 89 ((src[si + 2] & 0xff) << 16) | ((src[si + 3] & 0xff) << 24)); 90 iv1 ^= ((src[si + 4] & 0xff) | ((src[si + 5] & 0xff) << 8) | 91 ((src[si + 6] & 0xff) << 16) | ((src[si + 7] & 0xff) << 24)); 92 encrypt(iv0, iv1, out); 93 iv0 = out[0]; 94 iv1 = out[1]; 95 dest[di] = (byte) (iv0 & 0xff); 96 dest[di + 1] = (byte) ((iv0 >>> 8) & 0xff); 97 dest[di + 2] = (byte) ((iv0 >>> 16) & 0xff); 98 dest[di + 3] = (byte) ((iv0 >>> 24) & 0xff); 99 dest[di + 4] = (byte) (iv1 & 0xff); 100 dest[di + 5] = (byte) ((iv1 >>> 8) & 0xff); 101 dest[di + 6] = (byte) ((iv1 >>> 16) & 0xff); 102 dest[di + 7] = (byte) ((iv1 >>> 24) & 0xff); 103 } 104 IV0 = iv0; 105 IV1 = iv1; 106 } 107 108 public synchronized void decrypt(byte[] src, int srcOff, byte[] dest, int destOff, int len) { 109 int[] out = new int[2]; 110 int iv0 = IV0; 111 int iv1 = IV1; 112 int d0; 113 int d1; 114 int end = srcOff + len; 115 116 for (int si = srcOff, di = destOff; si < end; si += 8, di += 8) { 117 d0 = ((src[si] & 0xff) | ((src[si + 1] & 0xff) << 8) | 118 ((src[si + 2] & 0xff) << 16) | ((src[si + 3] & 0xff) << 24)); 119 d1 = ((src[si + 4] & 0xff) | ((src[si + 5] & 0xff) << 8) | 120 ((src[si + 6] & 0xff) << 16) | ((src[si + 7] & 0xff) << 24)); 121 decrypt(d0, d1, out); 122 iv0 ^= out[0]; 123 iv1 ^= out[1]; 124 dest[di] = (byte) (iv0 & 0xff); 125 dest[di + 1] = (byte) ((iv0 >>> 8) & 0xff); 126 dest[di + 2] = (byte) ((iv0 >>> 16) & 0xff); 127 dest[di + 3] = (byte) ((iv0 >>> 24) & 0xff); 128 dest[di + 4] = (byte) (iv1 & 0xff); 129 dest[di + 5] = (byte) ((iv1 >>> 8) & 0xff); 130 dest[di + 6] = (byte) ((iv1 >>> 16) & 0xff); 131 dest[di + 7] = (byte) ((iv1 >>> 24) & 0xff); 132 iv0 = d0; 133 iv1 = d1; 134 } 135 IV0 = iv0; 136 IV1 = iv1; 137 } 138 139 public void setKey(byte[] key) { 140 int i, c, d, t, s, shifts; 141 142 c = ((key[0] & 0xff) | ((key[1] & 0xff) << 8) | 143 ((key[2] & 0xff) << 16) | ((key[3] & 0xff) << 24)); 144 d = ((key[4] & 0xff) | ((key[5] & 0xff) << 8) | 145 ((key[6] & 0xff) << 16) | ((key[7] & 0xff) << 24)); 146 147 t = ((d >>> 4) ^ c) & 0x0f0f0f0f; 148 c ^= t; 149 d ^= t << 4; 150 t = (((c << (16 - (-2))) ^ c) & 0xcccc0000); 151 c = c ^ t ^ (t >>> (16 - (-2))); 152 t = (((d << (16 - (-2))) ^ d) & 0xcccc0000); 153 d = d ^ t ^ (t >>> (16 - (-2))); 154 t = ((d >>> 1) ^ c) & 0x55555555; 155 c ^= t; 156 d ^= t << 1; 157 t = ((c >>> 8) ^ d) & 0x00ff00ff; 158 d ^= t; 159 c ^= t << 8; 160 t = ((d >>> 1) ^ c) & 0x55555555; 161 c ^= t; 162 d ^= t << 1; 163 164 d = ((d & 0xff) << 16) | (d & 0xff00) | 165 ((d >>> 16) & 0xff) | ((c >>> 4) & 0xf000000); 166 c &= 0x0fffffff; 167 shifts = 0x7efc; 168 169 for (i = 0; i < 16; i++) { 170 if ((shifts & 1) != 0) { 171 c = ((c >>> 2) | (c << 26)); 172 d = ((d >>> 2) | (d << 26)); 173 } else { 174 c = ((c >>> 1) | (c << 27)); 175 d = ((d >>> 1) | (d << 27)); 176 } 177 shifts >>>= 1; 178 c &= 0x0fffffff; 179 d &= 0x0fffffff; 180 181 s = des_skb[0][(c) & 0x3f] | 182 des_skb[1][((c >>> 6) & 0x03) | ((c >>> 7) & 0x3c)] | 183 des_skb[2][((c >>> 13) & 0x0f) | ((c >>> 14) & 0x30)] | 184 des_skb[3][((c >>> 20) & 0x01) | ((c >>> 21) & 0x06) | ((c >>> 22) & 0x38)]; 185 186 t = des_skb[4][(d) & 0x3f] | 187 des_skb[5][((d >>> 7) & 0x03) | ((d >>> 8) & 0x3c)] | 188 des_skb[6][(d >>> 15) & 0x3f] | 189 des_skb[7][((d >>> 21) & 0x0f) | ((d >>> 22) & 0x30)]; 190 191 key_schedule[i * 2] = ((t << 16) | (s & 0xffff)); 192 s = ((s >>> 16) | (t & 0xffff0000)); 193 key_schedule[(i * 2) + 1] = (s << 4) | (s >>> 28); 194 } 195 } 196 197 public void encrypt(int l, int r, int[] out) { 198 int t = 0, u = 0, i; 199 200 t = ((r >>> 4) ^ l) & 0x0f0f0f0f; 201 l ^= t; 202 r ^= t << 4; 203 t = ((l >>> 16) ^ r) & 0x0000ffff; 204 r ^= t; 205 l ^= t << 16; 206 t = ((r >>> 2) ^ l) & 0x33333333; 207 l ^= t; 208 r ^= t << 2; 209 t = ((l >>> 8) ^ r) & 0x00ff00ff; 210 r ^= t; 211 l ^= t << 8; 212 t = ((r >>> 1) ^ l) & 0x55555555; 213 l ^= t; 214 r ^= t << 1; 215 216 t = (r << 1) | (r >>> 31); 217 r = (l << 1) | (l >>> 31); 218 l = t; 219 220 for (i = 0; i < 32; i += 4) { 221 u = r ^ key_schedule[i]; 222 t = r ^ key_schedule[i + 1]; 223 t = ((t >>> 4) + (t << 28)); 224 l ^= 225 (des_SPtrans[1][(t) & 0x3f] | des_SPtrans[3][(t >>> 8) & 0x3f] | 226 des_SPtrans[5][(t >>> 16) & 0x3f] | des_SPtrans[7][(t >>> 24) & 0x3f] | 227 des_SPtrans[0][(u) & 0x3f] | des_SPtrans[2][(u >>> 8) & 0x3f] | 228 des_SPtrans[4][(u >>> 16) & 0x3f] | des_SPtrans[6][(u >>> 24) & 0x3f]); 229 230 u = l ^ key_schedule[i + 2]; 231 t = l ^ key_schedule[i + 3]; 232 t = ((t >>> 4) + (t << 28)); 233 r ^= 234 (des_SPtrans[1][(t) & 0x3f] | des_SPtrans[3][(t >>> 8) & 0x3f] | 235 des_SPtrans[5][(t >>> 16) & 0x3f] | des_SPtrans[7][(t >>> 24) & 0x3f] | 236 des_SPtrans[0][(u) & 0x3f] | des_SPtrans[2][(u >>> 8) & 0x3f] | 237 des_SPtrans[4][(u >>> 16) & 0x3f] | des_SPtrans[6][(u >>> 24) & 0x3f]); 238 } 239 240 l = (l >>> 1) | (l << 31); 241 r = (r >>> 1) | (r << 31); 242 243 t = ((r >>> 1) ^ l) & 0x55555555; 244 l ^= t; 245 r ^= t << 1; 246 t = ((l >>> 8) ^ r) & 0x00ff00ff; 247 r ^= t; 248 l ^= t << 8; 249 t = ((r >>> 2) ^ l) & 0x33333333; 250 l ^= t; 251 r ^= t << 2; 252 t = ((l >>> 16) ^ r) & 0x0000ffff; 253 r ^= t; 254 l ^= t << 16; 255 t = ((r >>> 4) ^ l) & 0x0f0f0f0f; 256 l ^= t; 257 r ^= t << 4; 258 259 out[0] = l; 260 out[1] = r; 261 } 262 263 public void decrypt(int l, int r, int[] out) { 264 int t, u, i; 265 266 t = ((r >>> 4) ^ l) & 0x0f0f0f0f; 267 l ^= t; 268 r ^= t << 4; 269 t = ((l >>> 16) ^ r) & 0x0000ffff; 270 r ^= t; 271 l ^= t << 16; 272 t = ((r >>> 2) ^ l) & 0x33333333; 273 l ^= t; 274 r ^= t << 2; 275 t = ((l >>> 8) ^ r) & 0x00ff00ff; 276 r ^= t; 277 l ^= t << 8; 278 t = ((r >>> 1) ^ l) & 0x55555555; 279 l ^= t; 280 r ^= t << 1; 281 282 t = (r << 1) | (r >>> 31); 283 r = (l << 1) | (l >>> 31); 284 l = t; 285 286 for (i = 30; i > 0; i -= 4) { 287 u = r ^ key_schedule[i]; 288 t = r ^ key_schedule[i + 1]; 289 t = ((t >>> 4) + (t << 28)); 290 l ^= 291 (des_SPtrans[1][(t) & 0x3f] | des_SPtrans[3][(t >>> 8) & 0x3f] | 292 des_SPtrans[5][(t >>> 16) & 0x3f] | des_SPtrans[7][(t >>> 24) & 0x3f] | 293 des_SPtrans[0][(u) & 0x3f] | des_SPtrans[2][(u >>> 8) & 0x3f] | 294 des_SPtrans[4][(u >>> 16) & 0x3f] | des_SPtrans[6][(u >>> 24) & 0x3f]); 295 296 u = l ^ key_schedule[i - 2]; 297 t = l ^ key_schedule[i - 1]; 298 t = ((t >>> 4) + (t << 28)); 299 r ^= 300 (des_SPtrans[1][(t) & 0x3f] | des_SPtrans[3][(t >>> 8) & 0x3f] | 301 des_SPtrans[5][(t >>> 16) & 0x3f] | des_SPtrans[7][(t >>> 24) & 0x3f] | 302 des_SPtrans[0][(u) & 0x3f] | des_SPtrans[2][(u >>> 8) & 0x3f] | 303 des_SPtrans[4][(u >>> 16) & 0x3f] | des_SPtrans[6][(u >>> 24) & 0x3f]); 304 } 305 306 l = (l >>> 1) | (l << 31); 307 r = (r >>> 1) | (r << 31); 308 309 t = ((r >>> 1) ^ l) & 0x55555555; 310 l ^= t; 311 r ^= t << 1; 312 t = ((l >>> 8) ^ r) & 0x00ff00ff; 313 r ^= t; 314 l ^= t << 8; 315 t = ((r >>> 2) ^ l) & 0x33333333; 316 l ^= t; 317 r ^= t << 2; 318 t = ((l >>> 16) ^ r) & 0x0000ffff; 319 r ^= t; 320 l ^= t << 16; 321 t = ((r >>> 4) ^ l) & 0x0f0f0f0f; 322 l ^= t; 323 r ^= t << 4; 324 325 out[0] = l; 326 out[1] = r; 327 } 328 329 /* Table for key generation. This used to be in sk.h. 330 * Copyright (C) 1993 Eric Young - see README for more details 331 */ 332 final static int des_skb[][] = { 333 /* for C bits (numbered as per FIPS 46) 1 2 3 4 5 6 */ 334 {0x00000000, 0x00000010, 0x20000000, 0x20000010, 335 0x00010000, 0x00010010, 0x20010000, 0x20010010, 336 0x00000800, 0x00000810, 0x20000800, 0x20000810, 337 0x00010800, 0x00010810, 0x20010800, 0x20010810, 338 0x00000020, 0x00000030, 0x20000020, 0x20000030, 339 0x00010020, 0x00010030, 0x20010020, 0x20010030, 340 0x00000820, 0x00000830, 0x20000820, 0x20000830, 341 0x00010820, 0x00010830, 0x20010820, 0x20010830, 342 0x00080000, 0x00080010, 0x20080000, 0x20080010, 343 0x00090000, 0x00090010, 0x20090000, 0x20090010, 344 0x00080800, 0x00080810, 0x20080800, 0x20080810, 345 0x00090800, 0x00090810, 0x20090800, 0x20090810, 346 0x00080020, 0x00080030, 0x20080020, 0x20080030, 347 0x00090020, 0x00090030, 0x20090020, 0x20090030, 348 0x00080820, 0x00080830, 0x20080820, 0x20080830, 349 0x00090820, 0x00090830, 0x20090820, 0x20090830}, 350 /* for C bits (numbered as per FIPS 46) 7 8 10 11 12 13 */ 351 {0x00000000, 0x02000000, 0x00002000, 0x02002000, 352 0x00200000, 0x02200000, 0x00202000, 0x02202000, 353 0x00000004, 0x02000004, 0x00002004, 0x02002004, 354 0x00200004, 0x02200004, 0x00202004, 0x02202004, 355 0x00000400, 0x02000400, 0x00002400, 0x02002400, 356 0x00200400, 0x02200400, 0x00202400, 0x02202400, 357 0x00000404, 0x02000404, 0x00002404, 0x02002404, 358 0x00200404, 0x02200404, 0x00202404, 0x02202404, 359 0x10000000, 0x12000000, 0x10002000, 0x12002000, 360 0x10200000, 0x12200000, 0x10202000, 0x12202000, 361 0x10000004, 0x12000004, 0x10002004, 0x12002004, 362 0x10200004, 0x12200004, 0x10202004, 0x12202004, 363 0x10000400, 0x12000400, 0x10002400, 0x12002400, 364 0x10200400, 0x12200400, 0x10202400, 0x12202400, 365 0x10000404, 0x12000404, 0x10002404, 0x12002404, 366 0x10200404, 0x12200404, 0x10202404, 0x12202404}, 367 /* for C bits (numbered as per FIPS 46) 14 15 16 17 19 20 */ 368 {0x00000000, 0x00000001, 0x00040000, 0x00040001, 369 0x01000000, 0x01000001, 0x01040000, 0x01040001, 370 0x00000002, 0x00000003, 0x00040002, 0x00040003, 371 0x01000002, 0x01000003, 0x01040002, 0x01040003, 372 0x00000200, 0x00000201, 0x00040200, 0x00040201, 373 0x01000200, 0x01000201, 0x01040200, 0x01040201, 374 0x00000202, 0x00000203, 0x00040202, 0x00040203, 375 0x01000202, 0x01000203, 0x01040202, 0x01040203, 376 0x08000000, 0x08000001, 0x08040000, 0x08040001, 377 0x09000000, 0x09000001, 0x09040000, 0x09040001, 378 0x08000002, 0x08000003, 0x08040002, 0x08040003, 379 0x09000002, 0x09000003, 0x09040002, 0x09040003, 380 0x08000200, 0x08000201, 0x08040200, 0x08040201, 381 0x09000200, 0x09000201, 0x09040200, 0x09040201, 382 0x08000202, 0x08000203, 0x08040202, 0x08040203, 383 0x09000202, 0x09000203, 0x09040202, 0x09040203}, 384 /* for C bits (numbered as per FIPS 46) 21 23 24 26 27 28 */ 385 {0x00000000, 0x00100000, 0x00000100, 0x00100100, 386 0x00000008, 0x00100008, 0x00000108, 0x00100108, 387 0x00001000, 0x00101000, 0x00001100, 0x00101100, 388 0x00001008, 0x00101008, 0x00001108, 0x00101108, 389 0x04000000, 0x04100000, 0x04000100, 0x04100100, 390 0x04000008, 0x04100008, 0x04000108, 0x04100108, 391 0x04001000, 0x04101000, 0x04001100, 0x04101100, 392 0x04001008, 0x04101008, 0x04001108, 0x04101108, 393 0x00020000, 0x00120000, 0x00020100, 0x00120100, 394 0x00020008, 0x00120008, 0x00020108, 0x00120108, 395 0x00021000, 0x00121000, 0x00021100, 0x00121100, 396 0x00021008, 0x00121008, 0x00021108, 0x00121108, 397 0x04020000, 0x04120000, 0x04020100, 0x04120100, 398 0x04020008, 0x04120008, 0x04020108, 0x04120108, 399 0x04021000, 0x04121000, 0x04021100, 0x04121100, 400 0x04021008, 0x04121008, 0x04021108, 0x04121108}, 401 /* for D bits (numbered as per FIPS 46) 1 2 3 4 5 6 */ 402 {0x00000000, 0x10000000, 0x00010000, 0x10010000, 403 0x00000004, 0x10000004, 0x00010004, 0x10010004, 404 0x20000000, 0x30000000, 0x20010000, 0x30010000, 405 0x20000004, 0x30000004, 0x20010004, 0x30010004, 406 0x00100000, 0x10100000, 0x00110000, 0x10110000, 407 0x00100004, 0x10100004, 0x00110004, 0x10110004, 408 0x20100000, 0x30100000, 0x20110000, 0x30110000, 409 0x20100004, 0x30100004, 0x20110004, 0x30110004, 410 0x00001000, 0x10001000, 0x00011000, 0x10011000, 411 0x00001004, 0x10001004, 0x00011004, 0x10011004, 412 0x20001000, 0x30001000, 0x20011000, 0x30011000, 413 0x20001004, 0x30001004, 0x20011004, 0x30011004, 414 0x00101000, 0x10101000, 0x00111000, 0x10111000, 415 0x00101004, 0x10101004, 0x00111004, 0x10111004, 416 0x20101000, 0x30101000, 0x20111000, 0x30111000, 417 0x20101004, 0x30101004, 0x20111004, 0x30111004}, 418 /* for D bits (numbered as per FIPS 46) 8 9 11 12 13 14 */ 419 {0x00000000, 0x08000000, 0x00000008, 0x08000008, 420 0x00000400, 0x08000400, 0x00000408, 0x08000408, 421 0x00020000, 0x08020000, 0x00020008, 0x08020008, 422 0x00020400, 0x08020400, 0x00020408, 0x08020408, 423 0x00000001, 0x08000001, 0x00000009, 0x08000009, 424 0x00000401, 0x08000401, 0x00000409, 0x08000409, 425 0x00020001, 0x08020001, 0x00020009, 0x08020009, 426 0x00020401, 0x08020401, 0x00020409, 0x08020409, 427 0x02000000, 0x0A000000, 0x02000008, 0x0A000008, 428 0x02000400, 0x0A000400, 0x02000408, 0x0A000408, 429 0x02020000, 0x0A020000, 0x02020008, 0x0A020008, 430 0x02020400, 0x0A020400, 0x02020408, 0x0A020408, 431 0x02000001, 0x0A000001, 0x02000009, 0x0A000009, 432 0x02000401, 0x0A000401, 0x02000409, 0x0A000409, 433 0x02020001, 0x0A020001, 0x02020009, 0x0A020009, 434 0x02020401, 0x0A020401, 0x02020409, 0x0A020409}, 435 /* for D bits (numbered as per FIPS 46) 16 17 18 19 20 21 */ 436 {0x00000000, 0x00000100, 0x00080000, 0x00080100, 437 0x01000000, 0x01000100, 0x01080000, 0x01080100, 438 0x00000010, 0x00000110, 0x00080010, 0x00080110, 439 0x01000010, 0x01000110, 0x01080010, 0x01080110, 440 0x00200000, 0x00200100, 0x00280000, 0x00280100, 441 0x01200000, 0x01200100, 0x01280000, 0x01280100, 442 0x00200010, 0x00200110, 0x00280010, 0x00280110, 443 0x01200010, 0x01200110, 0x01280010, 0x01280110, 444 0x00000200, 0x00000300, 0x00080200, 0x00080300, 445 0x01000200, 0x01000300, 0x01080200, 0x01080300, 446 0x00000210, 0x00000310, 0x00080210, 0x00080310, 447 0x01000210, 0x01000310, 0x01080210, 0x01080310, 448 0x00200200, 0x00200300, 0x00280200, 0x00280300, 449 0x01200200, 0x01200300, 0x01280200, 0x01280300, 450 0x00200210, 0x00200310, 0x00280210, 0x00280310, 451 0x01200210, 0x01200310, 0x01280210, 0x01280310}, 452 /* for D bits (numbered as per FIPS 46) 22 23 24 25 27 28 */ 453 {0x00000000, 0x04000000, 0x00040000, 0x04040000, 454 0x00000002, 0x04000002, 0x00040002, 0x04040002, 455 0x00002000, 0x04002000, 0x00042000, 0x04042000, 456 0x00002002, 0x04002002, 0x00042002, 0x04042002, 457 0x00000020, 0x04000020, 0x00040020, 0x04040020, 458 0x00000022, 0x04000022, 0x00040022, 0x04040022, 459 0x00002020, 0x04002020, 0x00042020, 0x04042020, 460 0x00002022, 0x04002022, 0x00042022, 0x04042022, 461 0x00000800, 0x04000800, 0x00040800, 0x04040800, 462 0x00000802, 0x04000802, 0x00040802, 0x04040802, 463 0x00002800, 0x04002800, 0x00042800, 0x04042800, 464 0x00002802, 0x04002802, 0x00042802, 0x04042802, 465 0x00000820, 0x04000820, 0x00040820, 0x04040820, 466 0x00000822, 0x04000822, 0x00040822, 0x04040822, 467 0x00002820, 0x04002820, 0x00042820, 0x04042820, 468 0x00002822, 0x04002822, 0x00042822, 0x04042822} 469 }; 470 471 /* Tables used for executing des. This used to be in spr.h. 472 * Copyright (C) 1993 Eric Young - see README for more details 473 */ 474 final static int des_SPtrans[][] = { 475 /* nibble 0 */ 476 {0x00820200, 0x00020000, 0x80800000, 0x80820200, 477 0x00800000, 0x80020200, 0x80020000, 0x80800000, 478 0x80020200, 0x00820200, 0x00820000, 0x80000200, 479 0x80800200, 0x00800000, 0x00000000, 0x80020000, 480 0x00020000, 0x80000000, 0x00800200, 0x00020200, 481 0x80820200, 0x00820000, 0x80000200, 0x00800200, 482 0x80000000, 0x00000200, 0x00020200, 0x80820000, 483 0x00000200, 0x80800200, 0x80820000, 0x00000000, 484 0x00000000, 0x80820200, 0x00800200, 0x80020000, 485 0x00820200, 0x00020000, 0x80000200, 0x00800200, 486 0x80820000, 0x00000200, 0x00020200, 0x80800000, 487 0x80020200, 0x80000000, 0x80800000, 0x00820000, 488 0x80820200, 0x00020200, 0x00820000, 0x80800200, 489 0x00800000, 0x80000200, 0x80020000, 0x00000000, 490 0x00020000, 0x00800000, 0x80800200, 0x00820200, 491 0x80000000, 0x80820000, 0x00000200, 0x80020200}, 492 493 /* nibble 1 */ 494 {0x10042004, 0x00000000, 0x00042000, 0x10040000, 495 0x10000004, 0x00002004, 0x10002000, 0x00042000, 496 0x00002000, 0x10040004, 0x00000004, 0x10002000, 497 0x00040004, 0x10042000, 0x10040000, 0x00000004, 498 0x00040000, 0x10002004, 0x10040004, 0x00002000, 499 0x00042004, 0x10000000, 0x00000000, 0x00040004, 500 0x10002004, 0x00042004, 0x10042000, 0x10000004, 501 0x10000000, 0x00040000, 0x00002004, 0x10042004, 502 0x00040004, 0x10042000, 0x10002000, 0x00042004, 503 0x10042004, 0x00040004, 0x10000004, 0x00000000, 504 0x10000000, 0x00002004, 0x00040000, 0x10040004, 505 0x00002000, 0x10000000, 0x00042004, 0x10002004, 506 0x10042000, 0x00002000, 0x00000000, 0x10000004, 507 0x00000004, 0x10042004, 0x00042000, 0x10040000, 508 0x10040004, 0x00040000, 0x00002004, 0x10002000, 509 0x10002004, 0x00000004, 0x10040000, 0x00042000}, 510 511 /* nibble 2 */ 512 {0x41000000, 0x01010040, 0x00000040, 0x41000040, 513 0x40010000, 0x01000000, 0x41000040, 0x00010040, 514 0x01000040, 0x00010000, 0x01010000, 0x40000000, 515 0x41010040, 0x40000040, 0x40000000, 0x41010000, 516 0x00000000, 0x40010000, 0x01010040, 0x00000040, 517 0x40000040, 0x41010040, 0x00010000, 0x41000000, 518 0x41010000, 0x01000040, 0x40010040, 0x01010000, 519 0x00010040, 0x00000000, 0x01000000, 0x40010040, 520 0x01010040, 0x00000040, 0x40000000, 0x00010000, 521 0x40000040, 0x40010000, 0x01010000, 0x41000040, 522 0x00000000, 0x01010040, 0x00010040, 0x41010000, 523 0x40010000, 0x01000000, 0x41010040, 0x40000000, 524 0x40010040, 0x41000000, 0x01000000, 0x41010040, 525 0x00010000, 0x01000040, 0x41000040, 0x00010040, 526 0x01000040, 0x00000000, 0x41010000, 0x40000040, 527 0x41000000, 0x40010040, 0x00000040, 0x01010000}, 528 529 /* nibble 3 */ 530 {0x00100402, 0x04000400, 0x00000002, 0x04100402, 531 0x00000000, 0x04100000, 0x04000402, 0x00100002, 532 0x04100400, 0x04000002, 0x04000000, 0x00000402, 533 0x04000002, 0x00100402, 0x00100000, 0x04000000, 534 0x04100002, 0x00100400, 0x00000400, 0x00000002, 535 0x00100400, 0x04000402, 0x04100000, 0x00000400, 536 0x00000402, 0x00000000, 0x00100002, 0x04100400, 537 0x04000400, 0x04100002, 0x04100402, 0x00100000, 538 0x04100002, 0x00000402, 0x00100000, 0x04000002, 539 0x00100400, 0x04000400, 0x00000002, 0x04100000, 540 0x04000402, 0x00000000, 0x00000400, 0x00100002, 541 0x00000000, 0x04100002, 0x04100400, 0x00000400, 542 0x04000000, 0x04100402, 0x00100402, 0x00100000, 543 0x04100402, 0x00000002, 0x04000400, 0x00100402, 544 0x00100002, 0x00100400, 0x04100000, 0x04000402, 545 0x00000402, 0x04000000, 0x04000002, 0x04100400}, 546 547 /* nibble 4 */ 548 {0x02000000, 0x00004000, 0x00000100, 0x02004108, 549 0x02004008, 0x02000100, 0x00004108, 0x02004000, 550 0x00004000, 0x00000008, 0x02000008, 0x00004100, 551 0x02000108, 0x02004008, 0x02004100, 0x00000000, 552 0x00004100, 0x02000000, 0x00004008, 0x00000108, 553 0x02000100, 0x00004108, 0x00000000, 0x02000008, 554 0x00000008, 0x02000108, 0x02004108, 0x00004008, 555 0x02004000, 0x00000100, 0x00000108, 0x02004100, 556 0x02004100, 0x02000108, 0x00004008, 0x02004000, 557 0x00004000, 0x00000008, 0x02000008, 0x02000100, 558 0x02000000, 0x00004100, 0x02004108, 0x00000000, 559 0x00004108, 0x02000000, 0x00000100, 0x00004008, 560 0x02000108, 0x00000100, 0x00000000, 0x02004108, 561 0x02004008, 0x02004100, 0x00000108, 0x00004000, 562 0x00004100, 0x02004008, 0x02000100, 0x00000108, 563 0x00000008, 0x00004108, 0x02004000, 0x02000008}, 564 565 /* nibble 5 */ 566 {0x20000010, 0x00080010, 0x00000000, 0x20080800, 567 0x00080010, 0x00000800, 0x20000810, 0x00080000, 568 0x00000810, 0x20080810, 0x00080800, 0x20000000, 569 0x20000800, 0x20000010, 0x20080000, 0x00080810, 570 0x00080000, 0x20000810, 0x20080010, 0x00000000, 571 0x00000800, 0x00000010, 0x20080800, 0x20080010, 572 0x20080810, 0x20080000, 0x20000000, 0x00000810, 573 0x00000010, 0x00080800, 0x00080810, 0x20000800, 574 0x00000810, 0x20000000, 0x20000800, 0x00080810, 575 0x20080800, 0x00080010, 0x00000000, 0x20000800, 576 0x20000000, 0x00000800, 0x20080010, 0x00080000, 577 0x00080010, 0x20080810, 0x00080800, 0x00000010, 578 0x20080810, 0x00080800, 0x00080000, 0x20000810, 579 0x20000010, 0x20080000, 0x00080810, 0x00000000, 580 0x00000800, 0x20000010, 0x20000810, 0x20080800, 581 0x20080000, 0x00000810, 0x00000010, 0x20080010}, 582 583 /* nibble 6 */ 584 {0x00001000, 0x00000080, 0x00400080, 0x00400001, 585 0x00401081, 0x00001001, 0x00001080, 0x00000000, 586 0x00400000, 0x00400081, 0x00000081, 0x00401000, 587 0x00000001, 0x00401080, 0x00401000, 0x00000081, 588 0x00400081, 0x00001000, 0x00001001, 0x00401081, 589 0x00000000, 0x00400080, 0x00400001, 0x00001080, 590 0x00401001, 0x00001081, 0x00401080, 0x00000001, 591 0x00001081, 0x00401001, 0x00000080, 0x00400000, 592 0x00001081, 0x00401000, 0x00401001, 0x00000081, 593 0x00001000, 0x00000080, 0x00400000, 0x00401001, 594 0x00400081, 0x00001081, 0x00001080, 0x00000000, 595 0x00000080, 0x00400001, 0x00000001, 0x00400080, 596 0x00000000, 0x00400081, 0x00400080, 0x00001080, 597 0x00000081, 0x00001000, 0x00401081, 0x00400000, 598 0x00401080, 0x00000001, 0x00001001, 0x00401081, 599 0x00400001, 0x00401080, 0x00401000, 0x00001001}, 600 601 /* nibble 7 */ 602 {0x08200020, 0x08208000, 0x00008020, 0x00000000, 603 0x08008000, 0x00200020, 0x08200000, 0x08208020, 604 0x00000020, 0x08000000, 0x00208000, 0x00008020, 605 0x00208020, 0x08008020, 0x08000020, 0x08200000, 606 0x00008000, 0x00208020, 0x00200020, 0x08008000, 607 0x08208020, 0x08000020, 0x00000000, 0x00208000, 608 0x08000000, 0x00200000, 0x08008020, 0x08200020, 609 0x00200000, 0x00008000, 0x08208000, 0x00000020, 610 0x00200000, 0x00008000, 0x08000020, 0x08208020, 611 0x00008020, 0x08000000, 0x00000000, 0x00208000, 612 0x08200020, 0x08008020, 0x08008000, 0x00200020, 613 0x08208000, 0x00000020, 0x00200020, 0x08008000, 614 0x08208020, 0x00200000, 0x08200000, 0x08000020, 615 0x00208000, 0x00008020, 0x08008020, 0x08200000, 616 0x00000020, 0x08208000, 0x00208020, 0x00000000, 617 0x08000000, 0x08200020, 0x00008000, 0x00208020} 618 }; 619 620 } |