home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1990, John F. Haugh II
- * All rights reserved.
- *
- * Use, duplication, and disclosure prohibited without
- * the express written permission of the author.
- */
-
- #include <string.h>
- #include "config.h"
-
- #ifndef lint
- static char sccsid[] = "@(#)encrypt.c 3.3 01:05:46 11/14/90";
- #endif
-
- extern char *crypt();
-
- char *
- pw_encrypt (clear, salt)
- char *clear;
- char *salt;
- {
- static char cipher[32];
- static int count;
- char newsalt[2];
- char *cp;
- long now;
-
- /*
- * See if a new salt is needed and get a few random
- * bits of information. The amount of randomness is
- * probably not all that crucial since the salt only
- * serves to thwart a dictionary attack.
- */
-
- if (salt == (char *) 0) {
- now = time ((long *) 0) + count++;
- now ^= clock ();
- now ^= getpid ();
- now = ((now >> 12) ^ (now)) & 07777;
- newsalt[0] = i64c ((now >> 6) & 077);
- newsalt[1] = i64c (now & 077);
- salt = newsalt;
- }
- cp = crypt (clear, salt);
- strcpy (cipher, cp);
-
- #ifdef DOUBLESIZE
- if (strlen (clear) > 8) {
- cp = crypt (clear + 8, salt);
- strcat (cipher, cp + 2);
- }
- #endif
- return cipher;
- }
-