001: // DesCipher - the DES encryption method
002: //
003: // The meat of this code is by Dave Zimmerman <dzimm@widget.com>, and is:
004: //
005: // Copyright (c) 1996 Widget Workshop, Inc. All Rights Reserved.
006: //
007: // Permission to use, copy, modify, and distribute this software
008: // and its documentation for NON-COMMERCIAL or COMMERCIAL purposes and
009: // without fee is hereby granted, provided that this copyright notice is kept
010: // intact.
011: //
012: // WIDGET WORKSHOP MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY
013: // OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
014: // TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
015: // PARTICULAR PURPOSE, OR NON-INFRINGEMENT. WIDGET WORKSHOP SHALL NOT BE LIABLE
016: // FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
017: // DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
018: //
019: // THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
020: // CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
021: // PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
022: // NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
023: // SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
024: // SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
025: // PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES"). WIDGET WORKSHOP
026: // SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
027: // HIGH RISK ACTIVITIES.
028: //
029: //
030: // The rest is:
031: //
032: // Copyright (C) 1996 by Jef Poskanzer <jef@acme.com>. All rights reserved.
033: //
034: // Copyright (C) 1996 by Wolfgang Platzer
035: // email: wplatzer@iaik.tu-graz.ac.at
036: //
037: // All rights reserved.
038: //
039: // Redistribution and use in source and binary forms, with or without
040: // modification, are permitted provided that the following conditions
041: // are met:
042: // 1. Redistributions of source code must retain the above copyright
043: // notice, this list of conditions and the following disclaimer.
044: // 2. Redistributions in binary form must reproduce the above copyright
045: // notice, this list of conditions and the following disclaimer in the
046: // documentation and/or other materials provided with the distribution.
047: //
048: // THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
049: // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
050: // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
051: // ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
052: // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
053: // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
054: // OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
055: // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
056: // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
057: // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
058: // SUCH DAMAGE.
059: //
060:
061: package com.knowgate.jcifs.util;
062:
063: /**
064: * This code is derived from the above source
065: * JCIFS API
066: * Norbert Hranitzky
067: *
068: * <p>and modified again by Michael B. Allen
069: */
070:
071: public class DES {
072:
073: private int[] encryptKeys = new int[32];
074: private int[] decryptKeys = new int[32];
075:
076: private int[] tempInts = new int[2];
077:
078: public DES() {
079:
080: }
081:
082: // Constructor, byte-array key.
083: public DES(byte[] key) {
084: if (key.length == 7) {
085: byte[] key8 = new byte[8];
086: makeSMBKey(key, key8);
087: setKey(key8);
088: } else {
089: setKey(key);
090: }
091: }
092:
093: public static void makeSMBKey(byte[] key7, byte[] key8) {
094:
095: int i;
096:
097: key8[0] = (byte) ((key7[0] >> 1) & 0xff);
098: key8[1] = (byte) ((((key7[0] & 0x01) << 6) | (((key7[1] & 0xff) >> 2) & 0xff)) & 0xff);
099: key8[2] = (byte) ((((key7[1] & 0x03) << 5) | (((key7[2] & 0xff) >> 3) & 0xff)) & 0xff);
100: key8[3] = (byte) ((((key7[2] & 0x07) << 4) | (((key7[3] & 0xff) >> 4) & 0xff)) & 0xff);
101: key8[4] = (byte) ((((key7[3] & 0x0F) << 3) | (((key7[4] & 0xff) >> 5) & 0xff)) & 0xff);
102: key8[5] = (byte) ((((key7[4] & 0x1F) << 2) | (((key7[5] & 0xff) >> 6) & 0xff)) & 0xff);
103: key8[6] = (byte) ((((key7[5] & 0x3F) << 1) | (((key7[6] & 0xff) >> 7) & 0xff)) & 0xff);
104: key8[7] = (byte) (key7[6] & 0x7F);
105: for (i = 0; i < 8; i++) {
106: key8[i] = (byte) (key8[i] << 1);
107: }
108: }
109:
110: /// Set the key.
111: public void setKey(byte[] key) {
112:
113: // CHECK PAROTY TBD
114: deskey(key, true, encryptKeys);
115: deskey(key, false, decryptKeys);
116: }
117:
118: // Turn an 8-byte key into internal keys.
119: private void deskey(byte[] keyBlock, boolean encrypting, int[] KnL) {
120:
121: int i, j, l, m, n;
122: int[] pc1m = new int[56];
123: int[] pcr = new int[56];
124: int[] kn = new int[32];
125:
126: for (j = 0; j < 56; ++j) {
127: l = pc1[j];
128: m = l & 07;
129: pc1m[j] = ((keyBlock[l >>> 3] & bytebit[m]) != 0) ? 1 : 0;
130: }
131:
132: for (i = 0; i < 16; ++i) {
133:
134: if (encrypting)
135: m = i << 1;
136: else
137: m = (15 - i) << 1;
138: n = m + 1;
139: kn[m] = kn[n] = 0;
140: for (j = 0; j < 28; ++j) {
141: l = j + totrot[i];
142: if (l < 28)
143: pcr[j] = pc1m[l];
144: else
145: pcr[j] = pc1m[l - 28];
146: }
147: for (j = 28; j < 56; ++j) {
148: l = j + totrot[i];
149: if (l < 56)
150: pcr[j] = pc1m[l];
151: else
152: pcr[j] = pc1m[l - 28];
153: }
154: for (j = 0; j < 24; ++j) {
155: if (pcr[pc2[j]] != 0)
156: kn[m] |= bigbyte[j];
157: if (pcr[pc2[j + 24]] != 0)
158: kn[n] |= bigbyte[j];
159: }
160: }
161: cookey(kn, KnL);
162: }
163:
164: private void cookey(int[] raw, int KnL[]) {
165: int raw0, raw1;
166: int rawi, KnLi;
167: int i;
168:
169: for (i = 0, rawi = 0, KnLi = 0; i < 16; ++i) {
170: raw0 = raw[rawi++];
171: raw1 = raw[rawi++];
172: KnL[KnLi] = (raw0 & 0x00fc0000) << 6;
173: KnL[KnLi] |= (raw0 & 0x00000fc0) << 10;
174: KnL[KnLi] |= (raw1 & 0x00fc0000) >>> 10;
175: KnL[KnLi] |= (raw1 & 0x00000fc0) >>> 6;
176: ++KnLi;
177: KnL[KnLi] = (raw0 & 0x0003f000) << 12;
178: KnL[KnLi] |= (raw0 & 0x0000003f) << 16;
179: KnL[KnLi] |= (raw1 & 0x0003f000) >>> 4;
180: KnL[KnLi] |= (raw1 & 0x0000003f);
181: ++KnLi;
182: }
183: }
184:
185: /// Encrypt a block of eight bytes.
186: private void encrypt(byte[] clearText, int clearOff,
187: byte[] cipherText, int cipherOff) {
188:
189: squashBytesToInts(clearText, clearOff, tempInts, 0, 2);
190: des(tempInts, tempInts, encryptKeys);
191: spreadIntsToBytes(tempInts, 0, cipherText, cipherOff, 2);
192: }
193:
194: /// Decrypt a block of eight bytes.
195: private void decrypt(byte[] cipherText, int cipherOff,
196: byte[] clearText, int clearOff) {
197:
198: squashBytesToInts(cipherText, cipherOff, tempInts, 0, 2);
199: des(tempInts, tempInts, decryptKeys);
200: spreadIntsToBytes(tempInts, 0, clearText, clearOff, 2);
201: }
202:
203: // The DES function.
204: private void des(int[] inInts, int[] outInts, int[] keys) {
205:
206: int fval, work, right, leftt;
207: int round;
208: int keysi = 0;
209:
210: leftt = inInts[0];
211: right = inInts[1];
212:
213: work = ((leftt >>> 4) ^ right) & 0x0f0f0f0f;
214: right ^= work;
215: leftt ^= (work << 4);
216:
217: work = ((leftt >>> 16) ^ right) & 0x0000ffff;
218: right ^= work;
219: leftt ^= (work << 16);
220:
221: work = ((right >>> 2) ^ leftt) & 0x33333333;
222: leftt ^= work;
223: right ^= (work << 2);
224:
225: work = ((right >>> 8) ^ leftt) & 0x00ff00ff;
226: leftt ^= work;
227: right ^= (work << 8);
228: right = (right << 1) | ((right >>> 31) & 1);
229:
230: work = (leftt ^ right) & 0xaaaaaaaa;
231: leftt ^= work;
232: right ^= work;
233: leftt = (leftt << 1) | ((leftt >>> 31) & 1);
234:
235: for (round = 0; round < 8; ++round) {
236: work = (right << 28) | (right >>> 4);
237: work ^= keys[keysi++];
238: fval = SP7[work & 0x0000003f];
239: fval |= SP5[(work >>> 8) & 0x0000003f];
240: fval |= SP3[(work >>> 16) & 0x0000003f];
241: fval |= SP1[(work >>> 24) & 0x0000003f];
242: work = right ^ keys[keysi++];
243: fval |= SP8[work & 0x0000003f];
244: fval |= SP6[(work >>> 8) & 0x0000003f];
245: fval |= SP4[(work >>> 16) & 0x0000003f];
246: fval |= SP2[(work >>> 24) & 0x0000003f];
247: leftt ^= fval;
248: work = (leftt << 28) | (leftt >>> 4);
249: work ^= keys[keysi++];
250: fval = SP7[work & 0x0000003f];
251: fval |= SP5[(work >>> 8) & 0x0000003f];
252: fval |= SP3[(work >>> 16) & 0x0000003f];
253: fval |= SP1[(work >>> 24) & 0x0000003f];
254: work = leftt ^ keys[keysi++];
255: fval |= SP8[work & 0x0000003f];
256: fval |= SP6[(work >>> 8) & 0x0000003f];
257: fval |= SP4[(work >>> 16) & 0x0000003f];
258: fval |= SP2[(work >>> 24) & 0x0000003f];
259: right ^= fval;
260: }
261:
262: right = (right << 31) | (right >>> 1);
263: work = (leftt ^ right) & 0xaaaaaaaa;
264: leftt ^= work;
265: right ^= work;
266: leftt = (leftt << 31) | (leftt >>> 1);
267: work = ((leftt >>> 8) ^ right) & 0x00ff00ff;
268: right ^= work;
269: leftt ^= (work << 8);
270: work = ((leftt >>> 2) ^ right) & 0x33333333;
271: right ^= work;
272: leftt ^= (work << 2);
273: work = ((right >>> 16) ^ leftt) & 0x0000ffff;
274: leftt ^= work;
275: right ^= (work << 16);
276: work = ((right >>> 4) ^ leftt) & 0x0f0f0f0f;
277: leftt ^= work;
278: right ^= (work << 4);
279: outInts[0] = right;
280: outInts[1] = leftt;
281: }
282:
283: /// Encrypt a block of bytes.
284: public void encrypt(byte[] clearText, byte[] cipherText) {
285: encrypt(clearText, 0, cipherText, 0);
286: }
287:
288: /// Decrypt a block of bytes.
289: public void decrypt(byte[] cipherText, byte[] clearText) {
290:
291: decrypt(cipherText, 0, clearText, 0);
292: }
293:
294: /**
295: * encrypts an array where the length must be a multiple of 8
296: */
297: public byte[] encrypt(byte[] clearText) {
298:
299: int length = clearText.length;
300:
301: if (length % 8 != 0) {
302: System.out.println("Array must be a multiple of 8");
303: return null;
304: }
305:
306: byte[] cipherText = new byte[length];
307: int count = length / 8;
308:
309: for (int i = 0; i < count; i++)
310: encrypt(clearText, i * 8, cipherText, i * 8);
311:
312: return cipherText;
313: }
314:
315: /**
316: * decrypts an array where the length must be a multiple of 8
317: */
318: public byte[] decrypt(byte[] cipherText) {
319:
320: int length = cipherText.length;
321:
322: if (length % 8 != 0) {
323: System.out.println("Array must be a multiple of 8");
324: return null;
325: }
326:
327: byte[] clearText = new byte[length];
328: int count = length / 8;
329:
330: for (int i = 0; i < count; i++)
331: encrypt(cipherText, i * 8, clearText, i * 8);
332:
333: return clearText;
334: }
335:
336: // Tables, permutations, S-boxes, etc.
337:
338: private static byte[] bytebit = { (byte) 0x80, (byte) 0x40,
339: (byte) 0x20, (byte) 0x10, (byte) 0x08, (byte) 0x04,
340: (byte) 0x02, (byte) 0x01 };
341: private static int[] bigbyte = { 0x800000, 0x400000, 0x200000,
342: 0x100000, 0x080000, 0x040000, 0x020000, 0x010000, 0x008000,
343: 0x004000, 0x002000, 0x001000, 0x000800, 0x000400, 0x000200,
344: 0x000100, 0x000080, 0x000040, 0x000020, 0x000010, 0x000008,
345: 0x000004, 0x000002, 0x000001 };
346: private static byte[] pc1 = { (byte) 56, (byte) 48, (byte) 40,
347: (byte) 32, (byte) 24, (byte) 16, (byte) 8, (byte) 0,
348: (byte) 57, (byte) 49, (byte) 41, (byte) 33, (byte) 25,
349: (byte) 17, (byte) 9, (byte) 1, (byte) 58, (byte) 50,
350: (byte) 42, (byte) 34, (byte) 26, (byte) 18, (byte) 10,
351: (byte) 2, (byte) 59, (byte) 51, (byte) 43, (byte) 35,
352: (byte) 62, (byte) 54, (byte) 46, (byte) 38, (byte) 30,
353: (byte) 22, (byte) 14, (byte) 6, (byte) 61, (byte) 53,
354: (byte) 45, (byte) 37, (byte) 29, (byte) 21, (byte) 13,
355: (byte) 5, (byte) 60, (byte) 52, (byte) 44, (byte) 36,
356: (byte) 28, (byte) 20, (byte) 12, (byte) 4, (byte) 27,
357: (byte) 19, (byte) 11, (byte) 3 };
358: private static int[] totrot = { 1, 2, 4, 6, 8, 10, 12, 14, 15, 17,
359: 19, 21, 23, 25, 27, 28 };
360:
361: private static byte[] pc2 = { (byte) 13, (byte) 16, (byte) 10,
362: (byte) 23, (byte) 0, (byte) 4, (byte) 2, (byte) 27,
363: (byte) 14, (byte) 5, (byte) 20, (byte) 9, (byte) 22,
364: (byte) 18, (byte) 11, (byte) 3, (byte) 25, (byte) 7,
365: (byte) 15, (byte) 6, (byte) 26, (byte) 19, (byte) 12,
366: (byte) 1, (byte) 40, (byte) 51, (byte) 30, (byte) 36,
367: (byte) 46, (byte) 54, (byte) 29, (byte) 39, (byte) 50,
368: (byte) 44, (byte) 32, (byte) 47, (byte) 43, (byte) 48,
369: (byte) 38, (byte) 55, (byte) 33, (byte) 52, (byte) 45,
370: (byte) 41, (byte) 49, (byte) 35, (byte) 28, (byte) 31, };
371:
372: private static int[] SP1 = { 0x01010400, 0x00000000, 0x00010000,
373: 0x01010404, 0x01010004, 0x00010404, 0x00000004, 0x00010000,
374: 0x00000400, 0x01010400, 0x01010404, 0x00000400, 0x01000404,
375: 0x01010004, 0x01000000, 0x00000004, 0x00000404, 0x01000400,
376: 0x01000400, 0x00010400, 0x00010400, 0x01010000, 0x01010000,
377: 0x01000404, 0x00010004, 0x01000004, 0x01000004, 0x00010004,
378: 0x00000000, 0x00000404, 0x00010404, 0x01000000, 0x00010000,
379: 0x01010404, 0x00000004, 0x01010000, 0x01010400, 0x01000000,
380: 0x01000000, 0x00000400, 0x01010004, 0x00010000, 0x00010400,
381: 0x01000004, 0x00000400, 0x00000004, 0x01000404, 0x00010404,
382: 0x01010404, 0x00010004, 0x01010000, 0x01000404, 0x01000004,
383: 0x00000404, 0x00010404, 0x01010400, 0x00000404, 0x01000400,
384: 0x01000400, 0x00000000, 0x00010004, 0x00010400, 0x00000000,
385: 0x01010004 };
386: private static int[] SP2 = { 0x80108020, 0x80008000, 0x00008000,
387: 0x00108020, 0x00100000, 0x00000020, 0x80100020, 0x80008020,
388: 0x80000020, 0x80108020, 0x80108000, 0x80000000, 0x80008000,
389: 0x00100000, 0x00000020, 0x80100020, 0x00108000, 0x00100020,
390: 0x80008020, 0x00000000, 0x80000000, 0x00008000, 0x00108020,
391: 0x80100000, 0x00100020, 0x80000020, 0x00000000, 0x00108000,
392: 0x00008020, 0x80108000, 0x80100000, 0x00008020, 0x00000000,
393: 0x00108020, 0x80100020, 0x00100000, 0x80008020, 0x80100000,
394: 0x80108000, 0x00008000, 0x80100000, 0x80008000, 0x00000020,
395: 0x80108020, 0x00108020, 0x00000020, 0x00008000, 0x80000000,
396: 0x00008020, 0x80108000, 0x00100000, 0x80000020, 0x00100020,
397: 0x80008020, 0x80000020, 0x00100020, 0x00108000, 0x00000000,
398: 0x80008000, 0x00008020, 0x80000000, 0x80100020, 0x80108020,
399: 0x00108000 };
400: private static int[] SP3 = { 0x00000208, 0x08020200, 0x00000000,
401: 0x08020008, 0x08000200, 0x00000000, 0x00020208, 0x08000200,
402: 0x00020008, 0x08000008, 0x08000008, 0x00020000, 0x08020208,
403: 0x00020008, 0x08020000, 0x00000208, 0x08000000, 0x00000008,
404: 0x08020200, 0x00000200, 0x00020200, 0x08020000, 0x08020008,
405: 0x00020208, 0x08000208, 0x00020200, 0x00020000, 0x08000208,
406: 0x00000008, 0x08020208, 0x00000200, 0x08000000, 0x08020200,
407: 0x08000000, 0x00020008, 0x00000208, 0x00020000, 0x08020200,
408: 0x08000200, 0x00000000, 0x00000200, 0x00020008, 0x08020208,
409: 0x08000200, 0x08000008, 0x00000200, 0x00000000, 0x08020008,
410: 0x08000208, 0x00020000, 0x08000000, 0x08020208, 0x00000008,
411: 0x00020208, 0x00020200, 0x08000008, 0x08020000, 0x08000208,
412: 0x00000208, 0x08020000, 0x00020208, 0x00000008, 0x08020008,
413: 0x00020200 };
414: private static int[] SP4 = { 0x00802001, 0x00002081, 0x00002081,
415: 0x00000080, 0x00802080, 0x00800081, 0x00800001, 0x00002001,
416: 0x00000000, 0x00802000, 0x00802000, 0x00802081, 0x00000081,
417: 0x00000000, 0x00800080, 0x00800001, 0x00000001, 0x00002000,
418: 0x00800000, 0x00802001, 0x00000080, 0x00800000, 0x00002001,
419: 0x00002080, 0x00800081, 0x00000001, 0x00002080, 0x00800080,
420: 0x00002000, 0x00802080, 0x00802081, 0x00000081, 0x00800080,
421: 0x00800001, 0x00802000, 0x00802081, 0x00000081, 0x00000000,
422: 0x00000000, 0x00802000, 0x00002080, 0x00800080, 0x00800081,
423: 0x00000001, 0x00802001, 0x00002081, 0x00002081, 0x00000080,
424: 0x00802081, 0x00000081, 0x00000001, 0x00002000, 0x00800001,
425: 0x00002001, 0x00802080, 0x00800081, 0x00002001, 0x00002080,
426: 0x00800000, 0x00802001, 0x00000080, 0x00800000, 0x00002000,
427: 0x00802080 };
428: private static int[] SP5 = { 0x00000100, 0x02080100, 0x02080000,
429: 0x42000100, 0x00080000, 0x00000100, 0x40000000, 0x02080000,
430: 0x40080100, 0x00080000, 0x02000100, 0x40080100, 0x42000100,
431: 0x42080000, 0x00080100, 0x40000000, 0x02000000, 0x40080000,
432: 0x40080000, 0x00000000, 0x40000100, 0x42080100, 0x42080100,
433: 0x02000100, 0x42080000, 0x40000100, 0x00000000, 0x42000000,
434: 0x02080100, 0x02000000, 0x42000000, 0x00080100, 0x00080000,
435: 0x42000100, 0x00000100, 0x02000000, 0x40000000, 0x02080000,
436: 0x42000100, 0x40080100, 0x02000100, 0x40000000, 0x42080000,
437: 0x02080100, 0x40080100, 0x00000100, 0x02000000, 0x42080000,
438: 0x42080100, 0x00080100, 0x42000000, 0x42080100, 0x02080000,
439: 0x00000000, 0x40080000, 0x42000000, 0x00080100, 0x02000100,
440: 0x40000100, 0x00080000, 0x00000000, 0x40080000, 0x02080100,
441: 0x40000100 };
442: private static int[] SP6 = { 0x20000010, 0x20400000, 0x00004000,
443: 0x20404010, 0x20400000, 0x00000010, 0x20404010, 0x00400000,
444: 0x20004000, 0x00404010, 0x00400000, 0x20000010, 0x00400010,
445: 0x20004000, 0x20000000, 0x00004010, 0x00000000, 0x00400010,
446: 0x20004010, 0x00004000, 0x00404000, 0x20004010, 0x00000010,
447: 0x20400010, 0x20400010, 0x00000000, 0x00404010, 0x20404000,
448: 0x00004010, 0x00404000, 0x20404000, 0x20000000, 0x20004000,
449: 0x00000010, 0x20400010, 0x00404000, 0x20404010, 0x00400000,
450: 0x00004010, 0x20000010, 0x00400000, 0x20004000, 0x20000000,
451: 0x00004010, 0x20000010, 0x20404010, 0x00404000, 0x20400000,
452: 0x00404010, 0x20404000, 0x00000000, 0x20400010, 0x00000010,
453: 0x00004000, 0x20400000, 0x00404010, 0x00004000, 0x00400010,
454: 0x20004010, 0x00000000, 0x20404000, 0x20000000, 0x00400010,
455: 0x20004010 };
456: private static int[] SP7 = { 0x00200000, 0x04200002, 0x04000802,
457: 0x00000000, 0x00000800, 0x04000802, 0x00200802, 0x04200800,
458: 0x04200802, 0x00200000, 0x00000000, 0x04000002, 0x00000002,
459: 0x04000000, 0x04200002, 0x00000802, 0x04000800, 0x00200802,
460: 0x00200002, 0x04000800, 0x04000002, 0x04200000, 0x04200800,
461: 0x00200002, 0x04200000, 0x00000800, 0x00000802, 0x04200802,
462: 0x00200800, 0x00000002, 0x04000000, 0x00200800, 0x04000000,
463: 0x00200800, 0x00200000, 0x04000802, 0x04000802, 0x04200002,
464: 0x04200002, 0x00000002, 0x00200002, 0x04000000, 0x04000800,
465: 0x00200000, 0x04200800, 0x00000802, 0x00200802, 0x04200800,
466: 0x00000802, 0x04000002, 0x04200802, 0x04200000, 0x00200800,
467: 0x00000000, 0x00000002, 0x04200802, 0x00000000, 0x00200802,
468: 0x04200000, 0x00000800, 0x04000002, 0x04000800, 0x00000800,
469: 0x00200002 };
470: private static int[] SP8 = { 0x10001040, 0x00001000, 0x00040000,
471: 0x10041040, 0x10000000, 0x10001040, 0x00000040, 0x10000000,
472: 0x00040040, 0x10040000, 0x10041040, 0x00041000, 0x10041000,
473: 0x00041040, 0x00001000, 0x00000040, 0x10040000, 0x10000040,
474: 0x10001000, 0x00001040, 0x00041000, 0x00040040, 0x10040040,
475: 0x10041000, 0x00001040, 0x00000000, 0x00000000, 0x10040040,
476: 0x10000040, 0x10001000, 0x00041040, 0x00040000, 0x00041040,
477: 0x00040000, 0x10041000, 0x00001000, 0x00000040, 0x10040040,
478: 0x00001000, 0x00041040, 0x10001000, 0x00000040, 0x10000040,
479: 0x10040000, 0x10040040, 0x10000000, 0x00040000, 0x10001040,
480: 0x00000000, 0x10041040, 0x00040040, 0x10000040, 0x10040000,
481: 0x10001000, 0x10001040, 0x00000000, 0x10041040, 0x00041000,
482: 0x00041000, 0x00001040, 0x00001040, 0x00040040, 0x10000000,
483: 0x10041000 };
484:
485: /// Squash bytes down to ints.
486: public static void squashBytesToInts(byte[] inBytes, int inOff,
487: int[] outInts, int outOff, int intLen) {
488:
489: for (int i = 0; i < intLen; ++i)
490: outInts[outOff + i] = ((inBytes[inOff + i * 4] & 0xff) << 24)
491: | ((inBytes[inOff + i * 4 + 1] & 0xff) << 16)
492: | ((inBytes[inOff + i * 4 + 2] & 0xff) << 8)
493: | (inBytes[inOff + i * 4 + 3] & 0xff);
494: }
495:
496: /// Spread ints into bytes.
497: public static void spreadIntsToBytes(int[] inInts, int inOff,
498: byte[] outBytes, int outOff, int intLen) {
499:
500: for (int i = 0; i < intLen; ++i) {
501:
502: outBytes[outOff + i * 4] = (byte) (inInts[inOff + i] >>> 24);
503: outBytes[outOff + i * 4 + 1] = (byte) (inInts[inOff + i] >>> 16);
504: outBytes[outOff + i * 4 + 2] = (byte) (inInts[inOff + i] >>> 8);
505: outBytes[outOff + i * 4 + 3] = (byte) inInts[inOff + i];
506: }
507: }
508: }
|