static char sccsid
[] = "@(#)xcrypt.c 2.2 88/08/10 4.0 RPCSRC";
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
* unrestricted use provided that this legend is included on all tape
* media and as a part of the software program in whole or part. Users
* may copy or modify Sun RPC without charge, but are not authorized
* to license or distribute it to anyone else except as part of a product or
* program developed by the user.
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
* Sun RPC is provided with no support and without any obligation on the
* part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
* Mountain View, California 94043
* Hex encryption/decryption and utility routines
* Copyright (C) 1986, Sun Microsystems, Inc.
extern char hex
[]; /* forward */
* Encrypt a secret key given passwd
* The secret key is passed and returned in hex notation.
* Its length must be a multiple of 16 hex digits (64 bits).
len
= strlen(secret
) / 2;
buf
= malloc((unsigned)len
);
hex2bin(len
, secret
, buf
);
err
= cbc_crypt(key
, buf
, len
, DES_ENCRYPT
| DES_HW
, ivec
);
bin2hex(len
, (unsigned char *) buf
, secret
);
* Decrypt secret key using passwd
* The secret key is passed and returned in hex notation.
* Once again, the length is a multiple of 16 hex digits
len
= strlen(secret
) / 2;
buf
= malloc((unsigned)len
);
hex2bin(len
, secret
, buf
);
err
= cbc_crypt(key
, buf
, len
, DES_DECRYPT
| DES_HW
, ivec
);
bin2hex(len
, (unsigned char *) buf
, secret
);
* Turn password into DES key
for (i
= 0; *pw
; i
= (i
+1)%8) {
* Hex to binary conversion
hex2bin(len
, hexnum
, binnum
)
for (i
= 0; i
< len
; i
++) {
*binnum
++ = 16 * hexval(hexnum
[2*i
]) + hexval(hexnum
[2*i
+1]);
* Binary to hex conversion
bin2hex(len
, binnum
, hexnum
)
for (i
= 0; i
< len
; i
++) {
hexnum
[i
*2] = hex
[val
>> 4];
hexnum
[i
*2+1] = hex
[val
& 0xf];
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f',
if (c
>= '0' && c
<= '9') {
} else if (c
>= 'a' && c
<= 'z') {
} else if (c
>= 'A' && c
<= 'Z') {