home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2083 / encrypt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-28  |  1.1 KB  |  56 lines

  1. /*
  2.  * Copyright 1990, John F. Haugh II
  3.  * All rights reserved.
  4.  *
  5.  * Use, duplication, and disclosure prohibited without
  6.  * the express written permission of the author.
  7.  */
  8.  
  9. #include <string.h>
  10. #include "config.h"
  11.  
  12. #ifndef lint
  13. static    char    sccsid[] = "@(#)encrypt.c    3.3 01:05:46 11/14/90";
  14. #endif
  15.  
  16. extern    char    *crypt();
  17.  
  18. char *
  19. pw_encrypt (clear, salt)
  20. char    *clear;
  21. char    *salt;
  22. {
  23.     static    char    cipher[32];
  24.     static    int    count;
  25.     char    newsalt[2];
  26.     char    *cp;
  27.     long    now;
  28.  
  29.     /*
  30.      * See if a new salt is needed and get a few random
  31.      * bits of information.  The amount of randomness is
  32.      * probably not all that crucial since the salt only
  33.      * serves to thwart a dictionary attack.
  34.      */
  35.  
  36.     if (salt == (char *) 0) {
  37.         now = time ((long *) 0) + count++;
  38.         now ^= clock ();
  39.         now ^= getpid ();
  40.         now = ((now >> 12) ^ (now)) & 07777;
  41.         newsalt[0] = i64c ((now >> 6) & 077);
  42.         newsalt[1] = i64c (now & 077);
  43.         salt = newsalt;
  44.     }
  45.     cp = crypt (clear, salt);
  46.     strcpy (cipher, cp);
  47.  
  48. #ifdef    DOUBLESIZE
  49.     if (strlen (clear) > 8) {
  50.         cp = crypt (clear + 8, salt);
  51.         strcat (cipher, cp + 2);
  52.     }
  53. #endif
  54.     return cipher;
  55. }
  56.