home *** CD-ROM | disk | FTP | other *** search
- /* ============================================================================
- Portions of this code:
- Copyright ⌐ 1989 by the Massachusetts Institute of Technology
- ============================================================================ */
- /*
- * Copyright (c) 1990 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software
- * and its documentation for any purpose and without fee is hereby
- * granted, provided that the above copyright notice appears in all
- * copies and that both that copyright notice and this permission
- * notice appear in supporting documentation, and that the name of
- * The University of Michigan not be used in advertising or
- * publicity pertaining to distribution of the software without
- * specific, written prior permission. This software is supplied as
- * is without expressed or implied warranties of any kind.
- *
- * ITD Research Systems
- * University of Michigan
- * 535 W. William Street
- * Ann Arbor, Michigan
- * +1-313-936-2652
- * netatalk@terminator.cc.umich.edu
- */
-
- #include "des.h"
- #include "des_internal.h"
- #include <Types.h>
-
- extern void des_fixup_key_parity( des_cblock key);
- char *crypt( char *pw, char *salt );
- void Andrew_StringToKey(char *str, char *cell, des_cblock key);
-
- /*
- * convert an arbitrary length string to a DES key
- *
- * bug fixed by Mark C Smith 1/91: don't assume length of "str" is zero padded to 8,
- * rather, do padding in this routine!
- */
-
- void Andrew_StringToKey(str, cell, key)
- char *str;
- char *cell; /* cell/realm for password */
- des_cblock key;
- {
- char password[8+1]; /* crypt is limited to 8 chars anyway */
- int i;
- int passlen;
-
- bzero((char *)key, sizeof(des_cblock));
- bzero( password, sizeof( password ));
-
- /*
- * #### strncpy(password, cell, 8);
- * #### passlen = strlen(str);
- * ####if (passlen > 8)
- */
- passlen = 8;
- strncpy( password, str, passlen );
-
- for (i=0; i<passlen; i++)
- password[i] = password[i] ^ cell[i];
-
- for (i=0;i<8;i++)
- if (password[i] == '\0')
- password[i] = 'X';
-
- /* crypt only considers the first 8 characters of password but for some
- reason returns eleven characters of result (plus the two salt chars). */
-
- strncpy((char *)key, crypt(password, "#~") + 2, sizeof(des_cblock));
-
- /* parity is inserted into the LSB so leftshift each byte up one bit. This
- allows ascii characters with a zero MSB to retain as much significance
- as possible. */
-
- {
- char *keybytes = (char *)key;
- unsigned int temp;
-
- for (i = 0; i < 8; i++) {
- temp = (unsigned int) keybytes[i];
- keybytes[i] = (unsigned char) (temp << 1);
- }
- }
-
- des_fixup_key_parity (key);
- }
-