xref: /onnv-gate/usr/src/uts/common/des/des_soft.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  *
22*0Sstevel@tonic-gate  * Copyright 1989 Sun Microsystems, Inc.  All rights reserved.
23*0Sstevel@tonic-gate  * Use is subject to license terms.
24*0Sstevel@tonic-gate  */
25*0Sstevel@tonic-gate 
26*0Sstevel@tonic-gate /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
27*0Sstevel@tonic-gate /*	  All Rights Reserved  	*/
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate /*
30*0Sstevel@tonic-gate  * Portions of this source code were derived from Berkeley 4.3 BSD
31*0Sstevel@tonic-gate  * under license from the Regents of the University of California.
32*0Sstevel@tonic-gate  */
33*0Sstevel@tonic-gate 
34*0Sstevel@tonic-gate #ident	"%Z%%M%	%I%	%E% SMI"
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate /*
37*0Sstevel@tonic-gate  * Warning!  Things are arranged very carefully in this file to
38*0Sstevel@tonic-gate  * allow read-only data to be moved to the text segment.  The
39*0Sstevel@tonic-gate  * various DES tables must appear before any function definitions
40*0Sstevel@tonic-gate  * (this is arranged by including them immediately below) and partab
41*0Sstevel@tonic-gate  * must also appear before and function definitions
42*0Sstevel@tonic-gate  * This arrangement allows all data up through the first text to
43*0Sstevel@tonic-gate  * be moved to text.
44*0Sstevel@tonic-gate  */
45*0Sstevel@tonic-gate 
46*0Sstevel@tonic-gate /*
47*0Sstevel@tonic-gate  * Fast (?) software implementation of DES
48*0Sstevel@tonic-gate  * Has been seen going at 2000 bytes/sec on a Sun-2
49*0Sstevel@tonic-gate  * Works on a VAX too.
50*0Sstevel@tonic-gate  * Won't work without 8 bit chars and 32 bit longs
51*0Sstevel@tonic-gate  */
52*0Sstevel@tonic-gate 
53*0Sstevel@tonic-gate #include <sys/types.h>
54*0Sstevel@tonic-gate #include <des/des.h>
55*0Sstevel@tonic-gate #include <des/softdes.h>
56*0Sstevel@tonic-gate #include <des/desdata.h>
57*0Sstevel@tonic-gate #include <sys/debug.h>
58*0Sstevel@tonic-gate 
59*0Sstevel@tonic-gate static void des_setkey(u_char userkey[8], struct deskeydata *kd,
60*0Sstevel@tonic-gate     unsigned int dir);
61*0Sstevel@tonic-gate static void des_encrypt(u_char *data, struct deskeydata *kd);
62*0Sstevel@tonic-gate 
63*0Sstevel@tonic-gate /* EXPORT DELETE START */
64*0Sstevel@tonic-gate #define	btst(k, b)	(k[b >> 3] & (0x80 >> (b & 07)))
65*0Sstevel@tonic-gate #define	BIT28	(1<<28)
66*0Sstevel@tonic-gate /* EXPORT DELETE END */
67*0Sstevel@tonic-gate 
68*0Sstevel@tonic-gate /*
69*0Sstevel@tonic-gate  * Software encrypt or decrypt a block of data (multiple of 8 bytes)
70*0Sstevel@tonic-gate  * Do the CBC ourselves if needed.
71*0Sstevel@tonic-gate  */
72*0Sstevel@tonic-gate /* ARGSUSED */
73*0Sstevel@tonic-gate int
_des_crypt(char * buf,size_t len,struct desparams * desp)74*0Sstevel@tonic-gate _des_crypt(char *buf, size_t len, struct desparams *desp)
75*0Sstevel@tonic-gate {
76*0Sstevel@tonic-gate /* EXPORT DELETE START */
77*0Sstevel@tonic-gate 	short i;
78*0Sstevel@tonic-gate 	uint_t mode;
79*0Sstevel@tonic-gate 	uint_t dir;
80*0Sstevel@tonic-gate 	char nextiv[8];
81*0Sstevel@tonic-gate 	struct deskeydata softkey;
82*0Sstevel@tonic-gate 
83*0Sstevel@tonic-gate 	mode = desp->des_mode;
84*0Sstevel@tonic-gate 	dir = desp->des_dir;
85*0Sstevel@tonic-gate 	des_setkey(desp->des_key, &softkey, dir);
86*0Sstevel@tonic-gate 	while (len != 0) {
87*0Sstevel@tonic-gate 		switch (mode) {
88*0Sstevel@tonic-gate 		case CBC:
89*0Sstevel@tonic-gate 			switch (dir) {
90*0Sstevel@tonic-gate 			case ENCRYPT:
91*0Sstevel@tonic-gate 				for (i = 0; i < 8; i++)
92*0Sstevel@tonic-gate 					buf[i] ^= desp->des_ivec[i];
93*0Sstevel@tonic-gate 				des_encrypt((u_char *)buf, &softkey);
94*0Sstevel@tonic-gate 				for (i = 0; i < 8; i++)
95*0Sstevel@tonic-gate 					desp->des_ivec[i] = buf[i];
96*0Sstevel@tonic-gate 				break;
97*0Sstevel@tonic-gate 			case DECRYPT:
98*0Sstevel@tonic-gate 				for (i = 0; i < 8; i++)
99*0Sstevel@tonic-gate 					nextiv[i] = buf[i];
100*0Sstevel@tonic-gate 				des_encrypt((u_char *)buf, &softkey);
101*0Sstevel@tonic-gate 				for (i = 0; i < 8; i++) {
102*0Sstevel@tonic-gate 					buf[i] ^= desp->des_ivec[i];
103*0Sstevel@tonic-gate 					desp->des_ivec[i] = nextiv[i];
104*0Sstevel@tonic-gate 				}
105*0Sstevel@tonic-gate 				break;
106*0Sstevel@tonic-gate 			}
107*0Sstevel@tonic-gate 			break;
108*0Sstevel@tonic-gate 		case ECB:
109*0Sstevel@tonic-gate 			des_encrypt((u_char *)buf, &softkey);
110*0Sstevel@tonic-gate 			break;
111*0Sstevel@tonic-gate 		}
112*0Sstevel@tonic-gate 		buf += 8;
113*0Sstevel@tonic-gate 		len -= 8;
114*0Sstevel@tonic-gate 	}
115*0Sstevel@tonic-gate /* EXPORT DELETE END */
116*0Sstevel@tonic-gate 	return (1);
117*0Sstevel@tonic-gate }
118*0Sstevel@tonic-gate 
119*0Sstevel@tonic-gate 
120*0Sstevel@tonic-gate /*
121*0Sstevel@tonic-gate  * Set the key and direction for an encryption operation
122*0Sstevel@tonic-gate  * We build the 16 key entries here
123*0Sstevel@tonic-gate  */
124*0Sstevel@tonic-gate /* ARGSUSED */
125*0Sstevel@tonic-gate static void
des_setkey(u_char userkey[8],struct deskeydata * kd,unsigned int dir)126*0Sstevel@tonic-gate des_setkey(u_char userkey[8], struct deskeydata *kd, unsigned int dir)
127*0Sstevel@tonic-gate {
128*0Sstevel@tonic-gate /* EXPORT DELETE START */
129*0Sstevel@tonic-gate 	int32_t C, D;
130*0Sstevel@tonic-gate 	short i;
131*0Sstevel@tonic-gate 
132*0Sstevel@tonic-gate 	/*
133*0Sstevel@tonic-gate 	 * First, generate C and D by permuting
134*0Sstevel@tonic-gate 	 * the key. The low order bit of each
135*0Sstevel@tonic-gate 	 * 8-bit char is not used, so C and D are only 28
136*0Sstevel@tonic-gate 	 * bits apiece.
137*0Sstevel@tonic-gate 	 */
138*0Sstevel@tonic-gate 	{
139*0Sstevel@tonic-gate 		short bit;
140*0Sstevel@tonic-gate 		short *pcc = (short *)PC1_C, *pcd = (short *)PC1_D;
141*0Sstevel@tonic-gate 
142*0Sstevel@tonic-gate 		C = D = 0;
143*0Sstevel@tonic-gate 		for (i = 0; i < 28; i++) {
144*0Sstevel@tonic-gate 			C <<= 1;
145*0Sstevel@tonic-gate 			D <<= 1;
146*0Sstevel@tonic-gate 			bit = *pcc++;
147*0Sstevel@tonic-gate 			if (btst(userkey, bit))
148*0Sstevel@tonic-gate 				C |= 1;
149*0Sstevel@tonic-gate 			bit = *pcd++;
150*0Sstevel@tonic-gate 			if (btst(userkey, bit))
151*0Sstevel@tonic-gate 				D |= 1;
152*0Sstevel@tonic-gate 		}
153*0Sstevel@tonic-gate 	}
154*0Sstevel@tonic-gate 	/*
155*0Sstevel@tonic-gate 	 * To generate Ki, rotate C and D according
156*0Sstevel@tonic-gate 	 * to schedule and pick up a permutation
157*0Sstevel@tonic-gate 	 * using PC2.
158*0Sstevel@tonic-gate 	 */
159*0Sstevel@tonic-gate 	for (i = 0; i < 16; i++) {
160*0Sstevel@tonic-gate 		chunk_t *c;
161*0Sstevel@tonic-gate 		short j, k, bit;
162*0Sstevel@tonic-gate 		int bbit;
163*0Sstevel@tonic-gate 
164*0Sstevel@tonic-gate 		/*
165*0Sstevel@tonic-gate 		 * Do the "left shift" (rotate)
166*0Sstevel@tonic-gate 		 * We know we always rotate by either 1 or 2 bits
167*0Sstevel@tonic-gate 		 * the shifts table tells us if its 2
168*0Sstevel@tonic-gate 		 */
169*0Sstevel@tonic-gate 		C <<= 1;
170*0Sstevel@tonic-gate 		if (C & BIT28)
171*0Sstevel@tonic-gate 			C |= 1;
172*0Sstevel@tonic-gate 		D <<= 1;
173*0Sstevel@tonic-gate 		if (D & BIT28)
174*0Sstevel@tonic-gate 			D |= 1;
175*0Sstevel@tonic-gate 		if (shifts[i]) {
176*0Sstevel@tonic-gate 			C <<= 1;
177*0Sstevel@tonic-gate 			if (C & BIT28)
178*0Sstevel@tonic-gate 				C |= 1;
179*0Sstevel@tonic-gate 			D <<= 1;
180*0Sstevel@tonic-gate 			if (D & BIT28)
181*0Sstevel@tonic-gate 				D |= 1;
182*0Sstevel@tonic-gate 		}
183*0Sstevel@tonic-gate 		/*
184*0Sstevel@tonic-gate 		 * get Ki. Note C and D are concatenated.
185*0Sstevel@tonic-gate 		 */
186*0Sstevel@tonic-gate 		bit = 0;
187*0Sstevel@tonic-gate 		switch (dir) {
188*0Sstevel@tonic-gate 		case ENCRYPT:
189*0Sstevel@tonic-gate 			c = &kd->keyval[i];
190*0Sstevel@tonic-gate 			break;
191*0Sstevel@tonic-gate 		case DECRYPT:
192*0Sstevel@tonic-gate 			c = &kd->keyval[15 - i];
193*0Sstevel@tonic-gate 			break;
194*0Sstevel@tonic-gate 		}
195*0Sstevel@tonic-gate 		c->long0 = 0;
196*0Sstevel@tonic-gate 		c->long1 = 0;
197*0Sstevel@tonic-gate 		bbit = (1 << 5) << 24;
198*0Sstevel@tonic-gate 		for (j = 0; j < 4; j++) {
199*0Sstevel@tonic-gate 			for (k = 0; k < 6; k++) {
200*0Sstevel@tonic-gate 				if (C & (BIT28 >> PC2_C[bit]))
201*0Sstevel@tonic-gate 					c->long0 |= bbit >> k;
202*0Sstevel@tonic-gate 				if (D & (BIT28 >> PC2_D[bit]))
203*0Sstevel@tonic-gate 					c->long1 |= bbit >> k;
204*0Sstevel@tonic-gate 				bit++;
205*0Sstevel@tonic-gate 			}
206*0Sstevel@tonic-gate 			bbit >>= 8;
207*0Sstevel@tonic-gate 		}
208*0Sstevel@tonic-gate 	}
209*0Sstevel@tonic-gate /* EXPORT DELETE END */
210*0Sstevel@tonic-gate }
211*0Sstevel@tonic-gate 
212*0Sstevel@tonic-gate 
213*0Sstevel@tonic-gate 
214*0Sstevel@tonic-gate /*
215*0Sstevel@tonic-gate  * Do an encryption operation
216*0Sstevel@tonic-gate  * Much pain is taken (with preprocessor) to avoid loops so the compiler
217*0Sstevel@tonic-gate  * can do address arithmetic instead of doing it at runtime.
218*0Sstevel@tonic-gate  * Note that the byte-to-chunk conversion is necessary to guarantee
219*0Sstevel@tonic-gate  * processor byte-order independence.
220*0Sstevel@tonic-gate  */
221*0Sstevel@tonic-gate /* ARGSUSED */
222*0Sstevel@tonic-gate static void
des_encrypt(u_char * data,struct deskeydata * kd)223*0Sstevel@tonic-gate des_encrypt(u_char *data, struct deskeydata *kd)
224*0Sstevel@tonic-gate {
225*0Sstevel@tonic-gate /* EXPORT DELETE START */
226*0Sstevel@tonic-gate 	chunk_t work1, work2;
227*0Sstevel@tonic-gate 
228*0Sstevel@tonic-gate 	/*
229*0Sstevel@tonic-gate 	 * Initial permutation
230*0Sstevel@tonic-gate 	 * and byte to chunk conversion
231*0Sstevel@tonic-gate 	 */
232*0Sstevel@tonic-gate 	{
233*0Sstevel@tonic-gate 		const uint32_t *lp;
234*0Sstevel@tonic-gate 		uint32_t l0, l1, w;
235*0Sstevel@tonic-gate 		short i, pbit;
236*0Sstevel@tonic-gate 
237*0Sstevel@tonic-gate 		work1.byte0 = data[0];
238*0Sstevel@tonic-gate 		work1.byte1 = data[1];
239*0Sstevel@tonic-gate 		work1.byte2 = data[2];
240*0Sstevel@tonic-gate 		work1.byte3 = data[3];
241*0Sstevel@tonic-gate 		work1.byte4 = data[4];
242*0Sstevel@tonic-gate 		work1.byte5 = data[5];
243*0Sstevel@tonic-gate 		work1.byte6 = data[6];
244*0Sstevel@tonic-gate 		work1.byte7 = data[7];
245*0Sstevel@tonic-gate 		l0 = l1 = 0;
246*0Sstevel@tonic-gate 		w = work1.long0;
247*0Sstevel@tonic-gate 		for (lp = &longtab[0], i = 0; i < 32; i++) {
248*0Sstevel@tonic-gate 			if (w & *lp++) {
249*0Sstevel@tonic-gate 				pbit = IPtab[i];
250*0Sstevel@tonic-gate 				if (pbit < 32)
251*0Sstevel@tonic-gate 					l0 |= longtab[pbit];
252*0Sstevel@tonic-gate 				else
253*0Sstevel@tonic-gate 					l1 |= longtab[pbit-32];
254*0Sstevel@tonic-gate 			}
255*0Sstevel@tonic-gate 		}
256*0Sstevel@tonic-gate 		w = work1.long1;
257*0Sstevel@tonic-gate 		for (lp = &longtab[0], i = 32; i < 64; i++) {
258*0Sstevel@tonic-gate 			if (w & *lp++) {
259*0Sstevel@tonic-gate 				pbit = IPtab[i];
260*0Sstevel@tonic-gate 				if (pbit < 32)
261*0Sstevel@tonic-gate 					l0 |= longtab[pbit];
262*0Sstevel@tonic-gate 				else
263*0Sstevel@tonic-gate 					l1 |= longtab[pbit-32];
264*0Sstevel@tonic-gate 			}
265*0Sstevel@tonic-gate 		}
266*0Sstevel@tonic-gate 		work2.long0 = l0;
267*0Sstevel@tonic-gate 		work2.long1 = l1;
268*0Sstevel@tonic-gate 	}
269*0Sstevel@tonic-gate 
270*0Sstevel@tonic-gate /*
271*0Sstevel@tonic-gate  * Expand 8 bits of 32 bit R to 48 bit R
272*0Sstevel@tonic-gate  */
273*0Sstevel@tonic-gate #ifdef __STDC__
274*0Sstevel@tonic-gate #define	do_R_to_ER(op, b) {					\
275*0Sstevel@tonic-gate 	struct R_to_ER *p =					\
276*0Sstevel@tonic-gate 	    (struct R_to_ER *)&R_to_ER_tab[b][R.byte##b];	\
277*0Sstevel@tonic-gate 	e0 op p->l0;						\
278*0Sstevel@tonic-gate 	e1 op p->l1;						\
279*0Sstevel@tonic-gate }
280*0Sstevel@tonic-gate #else
281*0Sstevel@tonic-gate #define	do_R_to_ER(op, b)	{				\
282*0Sstevel@tonic-gate 	/*CSTYLED*/						\
283*0Sstevel@tonic-gate 	struct R_to_ER *p = &R_to_ER_tab[b][R.byte/**/b];	\
284*0Sstevel@tonic-gate 	e0 op p->l0;						\
285*0Sstevel@tonic-gate 	e1 op p->l1;						\
286*0Sstevel@tonic-gate }
287*0Sstevel@tonic-gate #endif
288*0Sstevel@tonic-gate 
289*0Sstevel@tonic-gate /*
290*0Sstevel@tonic-gate  * Inner part of the algorithm:
291*0Sstevel@tonic-gate  * Expand R from 32 to 48 bits; xor key value;
292*0Sstevel@tonic-gate  * apply S boxes; permute 32 bits of output
293*0Sstevel@tonic-gate  */
294*0Sstevel@tonic-gate #define	do_F(iter, inR, outR) 	{			\
295*0Sstevel@tonic-gate 	chunk_t R, ER;					\
296*0Sstevel@tonic-gate 	u_int e0, e1;					\
297*0Sstevel@tonic-gate 	R.long0 = inR;					\
298*0Sstevel@tonic-gate 	/*CSTYLED*/					\
299*0Sstevel@tonic-gate 	do_R_to_ER(=,0);				\
300*0Sstevel@tonic-gate 	/*CSTYLED*/					\
301*0Sstevel@tonic-gate 	do_R_to_ER(|=,1);				\
302*0Sstevel@tonic-gate 	/*CSTYLED*/					\
303*0Sstevel@tonic-gate 	do_R_to_ER(|=,2);				\
304*0Sstevel@tonic-gate 	/*CSTYLED*/					\
305*0Sstevel@tonic-gate 	do_R_to_ER(|=,3);				\
306*0Sstevel@tonic-gate 	ER.long0 = e0 ^ kd->keyval[iter].long0;		\
307*0Sstevel@tonic-gate 	ER.long1 = e1 ^ kd->keyval[iter].long1;		\
308*0Sstevel@tonic-gate 	R.long0 =					\
309*0Sstevel@tonic-gate 		S_tab[0][ER.byte0] +			\
310*0Sstevel@tonic-gate 		S_tab[1][ER.byte1] +			\
311*0Sstevel@tonic-gate 		S_tab[2][ER.byte2] +			\
312*0Sstevel@tonic-gate 		S_tab[3][ER.byte3] +			\
313*0Sstevel@tonic-gate 		S_tab[4][ER.byte4] +			\
314*0Sstevel@tonic-gate 		S_tab[5][ER.byte5] +			\
315*0Sstevel@tonic-gate 		S_tab[6][ER.byte6] +			\
316*0Sstevel@tonic-gate 		S_tab[7][ER.byte7]; 			\
317*0Sstevel@tonic-gate 	outR =						\
318*0Sstevel@tonic-gate 		P_tab[0][R.byte0] +			\
319*0Sstevel@tonic-gate 		P_tab[1][R.byte1] +			\
320*0Sstevel@tonic-gate 		P_tab[2][R.byte2] +			\
321*0Sstevel@tonic-gate 		P_tab[3][R.byte3]; 			\
322*0Sstevel@tonic-gate }
323*0Sstevel@tonic-gate 
324*0Sstevel@tonic-gate /*
325*0Sstevel@tonic-gate  * Do a cipher step
326*0Sstevel@tonic-gate  * Apply inner part; do xor and exchange of 32 bit parts
327*0Sstevel@tonic-gate  */
328*0Sstevel@tonic-gate #define	cipher(iter, inR, inL, outR, outL)	{	\
329*0Sstevel@tonic-gate 	do_F(iter, inR, outR);				\
330*0Sstevel@tonic-gate 	outR ^= inL;					\
331*0Sstevel@tonic-gate 	outL = inR;					\
332*0Sstevel@tonic-gate }
333*0Sstevel@tonic-gate 
334*0Sstevel@tonic-gate 	/*
335*0Sstevel@tonic-gate 	 * Apply the 16 ciphering steps
336*0Sstevel@tonic-gate 	 */
337*0Sstevel@tonic-gate 	{
338*0Sstevel@tonic-gate 		u_int r0, l0, r1, l1;
339*0Sstevel@tonic-gate 
340*0Sstevel@tonic-gate 		l0 = work2.long0;
341*0Sstevel@tonic-gate 		r0 = work2.long1;
342*0Sstevel@tonic-gate 		cipher(0, r0, l0, r1, l1);
343*0Sstevel@tonic-gate 		cipher(1, r1, l1, r0, l0);
344*0Sstevel@tonic-gate 		cipher(2, r0, l0, r1, l1);
345*0Sstevel@tonic-gate 		cipher(3, r1, l1, r0, l0);
346*0Sstevel@tonic-gate 		cipher(4, r0, l0, r1, l1);
347*0Sstevel@tonic-gate 		cipher(5, r1, l1, r0, l0);
348*0Sstevel@tonic-gate 		cipher(6, r0, l0, r1, l1);
349*0Sstevel@tonic-gate 		cipher(7, r1, l1, r0, l0);
350*0Sstevel@tonic-gate 		cipher(8, r0, l0, r1, l1);
351*0Sstevel@tonic-gate 		cipher(9, r1, l1, r0, l0);
352*0Sstevel@tonic-gate 		cipher(10, r0, l0, r1, l1);
353*0Sstevel@tonic-gate 		cipher(11, r1, l1, r0, l0);
354*0Sstevel@tonic-gate 		cipher(12, r0, l0, r1, l1);
355*0Sstevel@tonic-gate 		cipher(13, r1, l1, r0, l0);
356*0Sstevel@tonic-gate 		cipher(14, r0, l0, r1, l1);
357*0Sstevel@tonic-gate 		cipher(15, r1, l1, r0, l0);
358*0Sstevel@tonic-gate 		work1.long0 = r0;
359*0Sstevel@tonic-gate 		work1.long1 = l0;
360*0Sstevel@tonic-gate 	}
361*0Sstevel@tonic-gate 
362*0Sstevel@tonic-gate 	/*
363*0Sstevel@tonic-gate 	 * Final permutation
364*0Sstevel@tonic-gate 	 * and chunk to byte conversion
365*0Sstevel@tonic-gate 	 */
366*0Sstevel@tonic-gate 	{
367*0Sstevel@tonic-gate 		const uint32_t *lp;
368*0Sstevel@tonic-gate 		uint32_t l0, l1, w;
369*0Sstevel@tonic-gate 		short i, pbit;
370*0Sstevel@tonic-gate 
371*0Sstevel@tonic-gate 		l0 = l1 = 0;
372*0Sstevel@tonic-gate 		w = work1.long0;
373*0Sstevel@tonic-gate 		for (lp = &longtab[0], i = 0; i < 32; i++) {
374*0Sstevel@tonic-gate 			if (w & *lp++) {
375*0Sstevel@tonic-gate 				pbit = FPtab[i];
376*0Sstevel@tonic-gate 				if (pbit < 32)
377*0Sstevel@tonic-gate 					l0 |= longtab[pbit];
378*0Sstevel@tonic-gate 				else
379*0Sstevel@tonic-gate 					l1 |= longtab[pbit-32];
380*0Sstevel@tonic-gate 			}
381*0Sstevel@tonic-gate 		}
382*0Sstevel@tonic-gate 		w = work1.long1;
383*0Sstevel@tonic-gate 		for (lp = &longtab[0], i = 32; i < 64; i++) {
384*0Sstevel@tonic-gate 			if (w & *lp++) {
385*0Sstevel@tonic-gate 				pbit = FPtab[i];
386*0Sstevel@tonic-gate 				if (pbit < 32)
387*0Sstevel@tonic-gate 					l0 |= longtab[pbit];
388*0Sstevel@tonic-gate 				else
389*0Sstevel@tonic-gate 					l1 |= longtab[pbit-32];
390*0Sstevel@tonic-gate 			}
391*0Sstevel@tonic-gate 		}
392*0Sstevel@tonic-gate 		work2.long0 = l0;
393*0Sstevel@tonic-gate 		work2.long1 = l1;
394*0Sstevel@tonic-gate 	}
395*0Sstevel@tonic-gate 	data[0] = work2.byte0;
396*0Sstevel@tonic-gate 	data[1] = work2.byte1;
397*0Sstevel@tonic-gate 	data[2] = work2.byte2;
398*0Sstevel@tonic-gate 	data[3] = work2.byte3;
399*0Sstevel@tonic-gate 	data[4] = work2.byte4;
400*0Sstevel@tonic-gate 	data[5] = work2.byte5;
401*0Sstevel@tonic-gate 	data[6] = work2.byte6;
402*0Sstevel@tonic-gate 	data[7] = work2.byte7;
403*0Sstevel@tonic-gate /* EXPORT DELETE END */
404*0Sstevel@tonic-gate }
405