home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3348 / encrypt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-17  |  1.3 KB  |  59 lines

  1. /*
  2.  * Copyright 1990, John F. Haugh II
  3.  * All rights reserved.
  4.  *
  5.  * Permission is granted to copy and create derivative works for any
  6.  * non-commercial purpose, provided this copyright notice is preserved
  7.  * in all copies of source code, or included in human readable form
  8.  * and conspicuously displayed on all copies of object code or
  9.  * distribution media.
  10.  */
  11.  
  12. #include <string.h>
  13. #include "config.h"
  14.  
  15. #ifndef lint
  16. static    char    sccsid[] = "@(#)encrypt.c    3.4    19:44:23    12/10/90";
  17. #endif
  18.  
  19. extern    char    *crypt();
  20.  
  21. char *
  22. pw_encrypt (clear, salt)
  23. char    *clear;
  24. char    *salt;
  25. {
  26.     static    char    cipher[32];
  27.     static    int    count;
  28.     char    newsalt[2];
  29.     char    *cp;
  30.     long    now;
  31.  
  32.     /*
  33.      * See if a new salt is needed and get a few random
  34.      * bits of information.  The amount of randomness is
  35.      * probably not all that crucial since the salt only
  36.      * serves to thwart a dictionary attack.
  37.      */
  38.  
  39.     if (salt == (char *) 0) {
  40.         now = time ((long *) 0) + count++;
  41.         now ^= clock ();
  42.         now ^= getpid ();
  43.         now = ((now >> 12) ^ (now)) & 07777;
  44.         newsalt[0] = i64c ((now >> 6) & 077);
  45.         newsalt[1] = i64c (now & 077);
  46.         salt = newsalt;
  47.     }
  48.     cp = crypt (clear, salt);
  49.     strcpy (cipher, cp);
  50.  
  51. #ifdef    DOUBLESIZE
  52.     if (strlen (clear) > 8) {
  53.         cp = crypt (clear + 8, salt);
  54.         strcat (cipher, cp + 2);
  55.     }
  56. #endif
  57.     return cipher;
  58. }
  59.