10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*3864Sraf  * Common Development and Distribution License (the "License").
6*3864Sraf  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
211219Sraf 
22*3864Sraf /*
23*3864Sraf  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24*3864Sraf  * Use is subject to license terms.
25*3864Sraf  */
26*3864Sraf 
270Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
280Sstevel@tonic-gate /*	  All Rights Reserved  	*/
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
310Sstevel@tonic-gate /*LINTLIBRARY*/
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #pragma weak des_crypt = _des_crypt
340Sstevel@tonic-gate #pragma weak des_encrypt = _des_encrypt
350Sstevel@tonic-gate #pragma weak des_setkey = _des_setkey
360Sstevel@tonic-gate 
371219Sraf #include "des_synonyms.h"
380Sstevel@tonic-gate #include <sys/types.h>
390Sstevel@tonic-gate #include <crypt.h>
400Sstevel@tonic-gate #include "des_soft.h"
410Sstevel@tonic-gate 
420Sstevel@tonic-gate #include <stdlib.h>
430Sstevel@tonic-gate #include <thread.h>
44*3864Sraf #include <pthread.h>
450Sstevel@tonic-gate #include <sys/types.h>
460Sstevel@tonic-gate 
470Sstevel@tonic-gate /* EXPORT DELETE START */
480Sstevel@tonic-gate /*
490Sstevel@tonic-gate  * This program implements the
500Sstevel@tonic-gate  * Proposed Federal Information Processing
510Sstevel@tonic-gate  *  Data Encryption Standard.
520Sstevel@tonic-gate  * See Federal Register, March 17, 1975 (40FR12134)
530Sstevel@tonic-gate  */
540Sstevel@tonic-gate 
550Sstevel@tonic-gate /*
560Sstevel@tonic-gate  * Initial permutation,
570Sstevel@tonic-gate  */
580Sstevel@tonic-gate static char IP[] = {
590Sstevel@tonic-gate 	58, 50, 42, 34, 26, 18, 10, 2,
600Sstevel@tonic-gate 	60, 52, 44, 36, 28, 20, 12, 4,
610Sstevel@tonic-gate 	62, 54, 46, 38, 30, 22, 14, 6,
620Sstevel@tonic-gate 	64, 56, 48, 40, 32, 24, 16, 8,
630Sstevel@tonic-gate 	57, 49, 41, 33, 25, 17, 9, 1,
640Sstevel@tonic-gate 	59, 51, 43, 35, 27, 19, 11, 3,
650Sstevel@tonic-gate 	61, 53, 45, 37, 29, 21, 13, 5,
660Sstevel@tonic-gate 	63, 55, 47, 39, 31, 23, 15, 7,
670Sstevel@tonic-gate };
680Sstevel@tonic-gate 
690Sstevel@tonic-gate /*
700Sstevel@tonic-gate  * Final permutation, FP = IP^(-1)
710Sstevel@tonic-gate  */
720Sstevel@tonic-gate static char FP[] = {
730Sstevel@tonic-gate 	40, 8, 48, 16, 56, 24, 64, 32,
740Sstevel@tonic-gate 	39, 7, 47, 15, 55, 23, 63, 31,
750Sstevel@tonic-gate 	38, 6, 46, 14, 54, 22, 62, 30,
760Sstevel@tonic-gate 	37, 5, 45, 13, 53, 21, 61, 29,
770Sstevel@tonic-gate 	36, 4, 44, 12, 52, 20, 60, 28,
780Sstevel@tonic-gate 	35, 3, 43, 11, 51, 19, 59, 27,
790Sstevel@tonic-gate 	34, 2, 42, 10, 50, 18, 58, 26,
800Sstevel@tonic-gate 	33, 1, 41, 9, 49, 17, 57, 25,
810Sstevel@tonic-gate };
820Sstevel@tonic-gate 
830Sstevel@tonic-gate /*
840Sstevel@tonic-gate  * Permuted-choice 1 from the key bits
850Sstevel@tonic-gate  * to yield C and D.
860Sstevel@tonic-gate  * Note that bits 8, 16... are left out:
870Sstevel@tonic-gate  * They are intended for a parity check.
880Sstevel@tonic-gate  */
890Sstevel@tonic-gate static char PC1_C[] = {
900Sstevel@tonic-gate 	57, 49, 41, 33, 25, 17, 9,
910Sstevel@tonic-gate 	1, 58, 50, 42, 34, 26, 18,
920Sstevel@tonic-gate 	10, 2, 59, 51, 43, 35, 27,
930Sstevel@tonic-gate 	19, 11, 3, 60, 52, 44, 36,
940Sstevel@tonic-gate };
950Sstevel@tonic-gate 
960Sstevel@tonic-gate static char PC1_D[] = {
970Sstevel@tonic-gate 	63, 55, 47, 39, 31, 23, 15,
980Sstevel@tonic-gate 	7, 62, 54, 46, 38, 30, 22,
990Sstevel@tonic-gate 	14, 6, 61, 53, 45, 37, 29,
1000Sstevel@tonic-gate 	21, 13, 5, 28, 20, 12, 4,
1010Sstevel@tonic-gate };
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate /*
1040Sstevel@tonic-gate  * Sequence of shifts used for the key schedule.
1050Sstevel@tonic-gate  */
1060Sstevel@tonic-gate static char shifts[] = {1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1, };
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate /*
1090Sstevel@tonic-gate  * Permuted-choice 2, to pick out the bits from
1100Sstevel@tonic-gate  * the CD array that generate the key schedule.
1110Sstevel@tonic-gate  */
1120Sstevel@tonic-gate static char PC2_C[] = {
1130Sstevel@tonic-gate 	14, 17, 11, 24, 1, 5,
1140Sstevel@tonic-gate 	3, 28, 15, 6, 21, 10,
1150Sstevel@tonic-gate 	23, 19, 12, 4, 26, 8,
1160Sstevel@tonic-gate 	16, 7, 27, 20, 13, 2,
1170Sstevel@tonic-gate };
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate static char PC2_D[] = {
1200Sstevel@tonic-gate 	41, 52, 31, 37, 47, 55,
1210Sstevel@tonic-gate 	30, 40, 51, 45, 33, 48,
1220Sstevel@tonic-gate 	44, 49, 39, 56, 34, 53,
1230Sstevel@tonic-gate 	46, 42, 50, 36, 29, 32,
1240Sstevel@tonic-gate };
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate /*
1270Sstevel@tonic-gate  * The C and D arrays used to calculate the key schedule.
1280Sstevel@tonic-gate  */
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate static char C[28];
1310Sstevel@tonic-gate static char D[28];
1320Sstevel@tonic-gate /*
1330Sstevel@tonic-gate  * The key schedule.
1340Sstevel@tonic-gate  * Generated from the key.
1350Sstevel@tonic-gate  */
1360Sstevel@tonic-gate static char KS[16][48];
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate /*
1390Sstevel@tonic-gate  * The E bit-selection table.
1400Sstevel@tonic-gate  */
1410Sstevel@tonic-gate static char E[48];
1420Sstevel@tonic-gate static char e2[] = {
1430Sstevel@tonic-gate 	32, 1, 2, 3, 4, 5,
1440Sstevel@tonic-gate 	4, 5, 6, 7, 8, 9,
1450Sstevel@tonic-gate 	8, 9, 10, 11, 12, 13,
1460Sstevel@tonic-gate 	12, 13, 14, 15, 16, 17,
1470Sstevel@tonic-gate 	16, 17, 18, 19, 20, 21,
1480Sstevel@tonic-gate 	20, 21, 22, 23, 24, 25,
1490Sstevel@tonic-gate 	24, 25, 26, 27, 28, 29,
1500Sstevel@tonic-gate 	28, 29, 30, 31, 32, 1,
1510Sstevel@tonic-gate };
1520Sstevel@tonic-gate 
1530Sstevel@tonic-gate /*
1540Sstevel@tonic-gate  * Set up the key schedule from the key.
1550Sstevel@tonic-gate  */
1560Sstevel@tonic-gate 
1570Sstevel@tonic-gate static mutex_t lock = DEFAULTMUTEX;
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate /* EXPORT DELETE END */
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate 
1620Sstevel@tonic-gate static void
1630Sstevel@tonic-gate des_setkey_nolock(const char *key)
1640Sstevel@tonic-gate {
1650Sstevel@tonic-gate /* EXPORT DELETE START */
1660Sstevel@tonic-gate 	int i, j, k;
1670Sstevel@tonic-gate 	char t;
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate 	/*
1700Sstevel@tonic-gate 	 * First, generate C and D by permuting
1710Sstevel@tonic-gate 	 * the key.  The low order bit of each
1720Sstevel@tonic-gate 	 * 8-bit char is not used, so C and D are only 28
1730Sstevel@tonic-gate 	 * bits apiece.
1740Sstevel@tonic-gate 	 */
1750Sstevel@tonic-gate 	for (i = 0; i < 28; i++) {
1760Sstevel@tonic-gate 		C[i] = key[PC1_C[i]-1];
1770Sstevel@tonic-gate 		D[i] = key[PC1_D[i]-1];
1780Sstevel@tonic-gate 	}
1790Sstevel@tonic-gate 	/*
1800Sstevel@tonic-gate 	 * To generate Ki, rotate C and D according
1810Sstevel@tonic-gate 	 * to schedule and pick up a permutation
1820Sstevel@tonic-gate 	 * using PC2.
1830Sstevel@tonic-gate 	 */
1840Sstevel@tonic-gate 	for (i = 0; i < 16; i++) {
1850Sstevel@tonic-gate 		/*
1860Sstevel@tonic-gate 		 * rotate.
1870Sstevel@tonic-gate 		 */
1880Sstevel@tonic-gate 		for (k = 0; k < shifts[i]; k++) {
1890Sstevel@tonic-gate 			t = C[0];
1900Sstevel@tonic-gate 			for (j = 0; j < 28-1; j++)
1910Sstevel@tonic-gate 				C[j] = C[j+1];
1920Sstevel@tonic-gate 			C[27] = (char)t;
1930Sstevel@tonic-gate 			t = D[0];
1940Sstevel@tonic-gate 			for (j = 0; j < 28-1; j++)
1950Sstevel@tonic-gate 				D[j] = D[j+1];
1960Sstevel@tonic-gate 			D[27] = (char)t;
1970Sstevel@tonic-gate 		}
1980Sstevel@tonic-gate 		/*
1990Sstevel@tonic-gate 		 * get Ki. Note C and D are concatenated.
2000Sstevel@tonic-gate 		 */
2010Sstevel@tonic-gate 		for (j = 0; j < 24; j++) {
2020Sstevel@tonic-gate 			KS[i][j] = C[PC2_C[j]-1];
2030Sstevel@tonic-gate 			KS[i][j+24] = D[PC2_D[j]-28-1];
2040Sstevel@tonic-gate 		}
2050Sstevel@tonic-gate 	}
2060Sstevel@tonic-gate 
2070Sstevel@tonic-gate 	for (i = 0; i < 48; i++)
2080Sstevel@tonic-gate 		E[i] = e2[i];
2090Sstevel@tonic-gate /* EXPORT DELETE END */
2100Sstevel@tonic-gate }
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate void
2130Sstevel@tonic-gate des_setkey(const char *key)
2140Sstevel@tonic-gate {
2150Sstevel@tonic-gate /* EXPORT DELETE START */
2160Sstevel@tonic-gate 	(void) mutex_lock(&lock);
2170Sstevel@tonic-gate 	des_setkey_nolock(key);
2180Sstevel@tonic-gate 	(void) mutex_unlock(&lock);
2190Sstevel@tonic-gate /* EXPORT DELETE END */
2200Sstevel@tonic-gate }
2210Sstevel@tonic-gate 
2220Sstevel@tonic-gate /* EXPORT DELETE START */
2230Sstevel@tonic-gate /*
2240Sstevel@tonic-gate  * The 8 selection functions.
2250Sstevel@tonic-gate  * For some reason, they give a 0-origin
2260Sstevel@tonic-gate  * index, unlike everything else.
2270Sstevel@tonic-gate  */
2280Sstevel@tonic-gate static char S[8][64] = {
2290Sstevel@tonic-gate 	14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
2300Sstevel@tonic-gate 	0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
2310Sstevel@tonic-gate 	4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
2320Sstevel@tonic-gate 	15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13,
2330Sstevel@tonic-gate 
2340Sstevel@tonic-gate 	15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10,
2350Sstevel@tonic-gate 	3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5,
2360Sstevel@tonic-gate 	0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15,
2370Sstevel@tonic-gate 	13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9,
2380Sstevel@tonic-gate 
2390Sstevel@tonic-gate 	10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8,
2400Sstevel@tonic-gate 	13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1,
2410Sstevel@tonic-gate 	13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7,
2420Sstevel@tonic-gate 	1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12,
2430Sstevel@tonic-gate 
2440Sstevel@tonic-gate 	7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15,
2450Sstevel@tonic-gate 	13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9,
2460Sstevel@tonic-gate 	10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4,
2470Sstevel@tonic-gate 	3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14,
2480Sstevel@tonic-gate 
2490Sstevel@tonic-gate 	2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9,
2500Sstevel@tonic-gate 	14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6,
2510Sstevel@tonic-gate 	4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14,
2520Sstevel@tonic-gate 	11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3,
2530Sstevel@tonic-gate 
2540Sstevel@tonic-gate 	12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11,
2550Sstevel@tonic-gate 	10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8,
2560Sstevel@tonic-gate 	9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6,
2570Sstevel@tonic-gate 	4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13,
2580Sstevel@tonic-gate 
2590Sstevel@tonic-gate 	4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1,
2600Sstevel@tonic-gate 	13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6,
2610Sstevel@tonic-gate 	1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2,
2620Sstevel@tonic-gate 	6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12,
2630Sstevel@tonic-gate 
2640Sstevel@tonic-gate 	13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7,
2650Sstevel@tonic-gate 	1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2,
2660Sstevel@tonic-gate 	7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8,
2670Sstevel@tonic-gate 	2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11,
2680Sstevel@tonic-gate };
2690Sstevel@tonic-gate 
2700Sstevel@tonic-gate /*
2710Sstevel@tonic-gate  * P is a permutation on the selected combination
2720Sstevel@tonic-gate  * of the current L and key.
2730Sstevel@tonic-gate  */
2740Sstevel@tonic-gate static char P[] = {
2750Sstevel@tonic-gate 	16, 7, 20, 21,
2760Sstevel@tonic-gate 	29, 12, 28, 17,
2770Sstevel@tonic-gate 	1, 15, 23, 26,
2780Sstevel@tonic-gate 	5, 18, 31, 10,
2790Sstevel@tonic-gate 	2, 8, 24, 14,
2800Sstevel@tonic-gate 	32, 27, 3, 9,
2810Sstevel@tonic-gate 	19, 13, 30, 6,
2820Sstevel@tonic-gate 	22, 11, 4, 25,
2830Sstevel@tonic-gate };
2840Sstevel@tonic-gate 
2850Sstevel@tonic-gate /*
2860Sstevel@tonic-gate  * The current block, divided into 2 halves.
2870Sstevel@tonic-gate  */
2880Sstevel@tonic-gate static char L[64];
2890Sstevel@tonic-gate static char tempL[32];
2900Sstevel@tonic-gate static char f[32];
2910Sstevel@tonic-gate 
2920Sstevel@tonic-gate /*
2930Sstevel@tonic-gate  * The combination of the key and the input, before selection.
2940Sstevel@tonic-gate  */
2950Sstevel@tonic-gate static char preS[48];
2960Sstevel@tonic-gate 
2970Sstevel@tonic-gate /*
2980Sstevel@tonic-gate  * The payoff: encrypt a block.
2990Sstevel@tonic-gate  */
3000Sstevel@tonic-gate /* EXPORT DELETE END */
3010Sstevel@tonic-gate 
3020Sstevel@tonic-gate static void
3030Sstevel@tonic-gate des_encrypt_nolock(char *block, int edflag)
3040Sstevel@tonic-gate {
3050Sstevel@tonic-gate /* EXPORT DELETE START */
3060Sstevel@tonic-gate 
3070Sstevel@tonic-gate 	if (edflag)
3080Sstevel@tonic-gate 		(void) des_decrypt1(block, L, IP, &L[32],
3090Sstevel@tonic-gate 		    preS, E, KS, S, f, tempL, P, FP);
3100Sstevel@tonic-gate 	else
3110Sstevel@tonic-gate 		(void) des_encrypt1(block, L, IP, &L[32],
3120Sstevel@tonic-gate 		    preS, E, KS, S, f, tempL, P, FP);
3130Sstevel@tonic-gate 
3140Sstevel@tonic-gate /* EXPORT DELETE END */
3150Sstevel@tonic-gate }
3160Sstevel@tonic-gate 
3170Sstevel@tonic-gate void
3180Sstevel@tonic-gate des_encrypt(char *block, int edflag)
3190Sstevel@tonic-gate {
3200Sstevel@tonic-gate /* EXPORT DELETE START */
3210Sstevel@tonic-gate 	(void) mutex_lock(&lock);
3220Sstevel@tonic-gate 	des_encrypt_nolock(block, edflag);
3230Sstevel@tonic-gate 	(void) mutex_unlock(&lock);
3240Sstevel@tonic-gate /* EXPORT DELETE END */
3250Sstevel@tonic-gate }
3260Sstevel@tonic-gate 
3270Sstevel@tonic-gate 
3280Sstevel@tonic-gate 
3290Sstevel@tonic-gate #define	IOBUF_SIZE	16
3300Sstevel@tonic-gate 
3310Sstevel@tonic-gate static char *
332*3864Sraf _get_iobuf(thread_key_t *keyp, unsigned size)
3330Sstevel@tonic-gate {
334*3864Sraf 	char *iobuf;
3350Sstevel@tonic-gate 
336*3864Sraf 	if (thr_keycreate_once(keyp, free) != 0)
337*3864Sraf 		return (NULL);
338*3864Sraf 	iobuf = pthread_getspecific(*keyp);
339*3864Sraf 	if (iobuf == NULL) {
340*3864Sraf 		if (thr_setspecific(*keyp, (iobuf = malloc(size))) != 0) {
3410Sstevel@tonic-gate 			if (iobuf)
3420Sstevel@tonic-gate 				(void) free(iobuf);
343*3864Sraf 			iobuf = NULL;
3440Sstevel@tonic-gate 		}
3450Sstevel@tonic-gate 	}
3460Sstevel@tonic-gate 	return (iobuf);
3470Sstevel@tonic-gate }
3480Sstevel@tonic-gate 
3490Sstevel@tonic-gate char *
3500Sstevel@tonic-gate des_crypt(const char *pw, const char *salt)
3510Sstevel@tonic-gate {
3520Sstevel@tonic-gate /* EXPORT DELETE START */
3530Sstevel@tonic-gate 	int	i, j;
3540Sstevel@tonic-gate 	char	c, temp;
355*3864Sraf 	char block[66];
356*3864Sraf 	static thread_key_t key = THR_ONCE_KEY;
357*3864Sraf 	char *iobuf = _get_iobuf(&key, IOBUF_SIZE);
3580Sstevel@tonic-gate 
3590Sstevel@tonic-gate 	(void) mutex_lock(&lock);
3600Sstevel@tonic-gate 	for (i = 0; i < 66; i++)
3610Sstevel@tonic-gate 		block[i] = 0;
3620Sstevel@tonic-gate 	for (i = 0; (c = *pw) && (i < 64); pw++) {
3630Sstevel@tonic-gate 		for (j = 0; j < 7; j++, i++)
3640Sstevel@tonic-gate 			block[i] = (c>>(6-j)) & 01;
3650Sstevel@tonic-gate 		i++;
3660Sstevel@tonic-gate 	}
3670Sstevel@tonic-gate 
3680Sstevel@tonic-gate 	des_setkey_nolock(block);
3690Sstevel@tonic-gate 
3700Sstevel@tonic-gate 	for (i = 0; i < 66; i++)
3710Sstevel@tonic-gate 		block[i] = 0;
3720Sstevel@tonic-gate 
3730Sstevel@tonic-gate 	for (i = 0; i < 2; i++) {
3740Sstevel@tonic-gate 		c = *salt++;
3750Sstevel@tonic-gate 		iobuf[i] = (char)c;
3760Sstevel@tonic-gate 		if (c > 'Z')
3770Sstevel@tonic-gate 			c -= 6;
3780Sstevel@tonic-gate 		if (c > '9')
3790Sstevel@tonic-gate 			c -= 7;
3800Sstevel@tonic-gate 		c -= '.';
3810Sstevel@tonic-gate 		for (j = 0; j < 6; j++) {
3820Sstevel@tonic-gate 			if ((c>>j) & 01) {
3830Sstevel@tonic-gate 				temp = E[6*i+j];
3840Sstevel@tonic-gate 				E[6*i+j] = E[6*i+j+24];
3850Sstevel@tonic-gate 				E[6*i+j+24] = (char)temp;
3860Sstevel@tonic-gate 			}
3870Sstevel@tonic-gate 		}
3880Sstevel@tonic-gate 	}
3890Sstevel@tonic-gate 
3900Sstevel@tonic-gate 	for (i = 0; i < 25; i++)
3910Sstevel@tonic-gate 		(void) des_encrypt_nolock(block, 0);
3920Sstevel@tonic-gate 
3930Sstevel@tonic-gate 	for (i = 0; i < 11; i++) {
3940Sstevel@tonic-gate 		c = 0;
3950Sstevel@tonic-gate 		for (j = 0; j < 6; j++) {
3960Sstevel@tonic-gate 			c <<= 1;
3970Sstevel@tonic-gate 			c |= block[6*i+j];
3980Sstevel@tonic-gate 		}
3990Sstevel@tonic-gate 		c += '.';
4000Sstevel@tonic-gate 		if (c > '9')
4010Sstevel@tonic-gate 			c += 7;
4020Sstevel@tonic-gate 		if (c > 'Z')
4030Sstevel@tonic-gate 			c += 6;
4040Sstevel@tonic-gate 		iobuf[i+2] = (char)c;
4050Sstevel@tonic-gate 	}
4060Sstevel@tonic-gate 	iobuf[i+2] = 0;
4070Sstevel@tonic-gate 	if (iobuf[1] == 0)
4080Sstevel@tonic-gate 		iobuf[1] = iobuf[0];
4090Sstevel@tonic-gate 	(void) mutex_unlock(&lock);
4100Sstevel@tonic-gate 	return (iobuf);
4110Sstevel@tonic-gate #if 0
4120Sstevel@tonic-gate /* EXPORT DELETE END */
4130Sstevel@tonic-gate 	return (0);
4140Sstevel@tonic-gate /* EXPORT DELETE START */
4150Sstevel@tonic-gate #endif
4160Sstevel@tonic-gate /* EXPORT DELETE END */
4170Sstevel@tonic-gate }
418