Annotation of pgp/src/passwd.c, revision 1.1.1.7

1.1.1.6   root        1: /*     passwd.c - Password reading/hashing routines
                      2:        Implemented in Microsoft C.
                      3:        Routines for getting a pass phrase from the user's console.
                      4: 
                      5:        (c) Copyright 1990-1994 by Philip Zimmermann.  All rights reserved.
                      6:        The author assumes no liability for damages resulting from the use
                      7:        of this software, even if the damage results from defects in this
                      8:        software.  No warranty is expressed or implied.
                      9: 
                     10:        Note that while most PGP source modules bear Philip Zimmermann's
                     11:        copyright notice, many of them have been revised or entirely written
                     12:        by contributors who frequently failed to put their names in their
                     13:        code.  Code that has been incorporated into PGP from other authors
                     14:        was either originally published in the public domain or is used with
                     15:        permission from the various authors.
                     16: 
                     17:        PGP is available for free to the public under certain restrictions.
                     18:        See the PGP User's Guide (included in the release package) for
                     19:        important information about licensing, patent restrictions on
                     20:        certain algorithms, trademarks, copyrights, and export controls.
                     21: */
                     22: 
                     23: #include       <stdio.h>       /* for fprintf() */
                     24: #include       <ctype.h>       /* for isdigit(), toupper(), etc. */
                     25: #include       <string.h>      /* for strlen() */
                     26: 
                     27: #include       "random.h"      /* for getstring() */
                     28: #include       "md5.h"
                     29: #include       "language.h"
                     30: #include       "pgp.h"
                     31: 
                     32: #define MAXKEYLEN 254  /* max byte length of pass phrase */
                     33: 
                     34: boolean showpass = FALSE;
                     35: 
                     36: /*
                     37: **     hashpass - Hash pass phrase down to 128 bits (16 bytes).
                     38: **  keylen must be less than 1024.
                     39: **     Use the MD5 algorithm.
                     40: */
                     41: void hashpass (char *keystring, int keylen, byte *hash)
                     42: {
                     43:        struct MD5Context mdContext;
                     44: 
                     45:        /* Calculate the hash */
                     46:        MD5Init(&mdContext);
                     47:        MD5Update(&mdContext, (unsigned char *) keystring, keylen);
                     48:        MD5Final(hash, &mdContext);
                     49: } /* hashpass */
                     50: 
                     51: 
                     52: /*
                     53: **     GetHashedPassPhrase - get pass phrase from user,
                     54:                 hashes it to an IDEA key.
                     55:        Parameters:
                     56:                returns char *keystring as the pass phrase itself
                     57:                return char *hash as the 16-byte hash of the pass phrase
                     58:                                using MD5.
                     59:                byte noecho:  
                     60:                        0=ask once, echo. 
                     61:                        1=ask once, no echo. 
                     62:                        2=ask twice, no echo.
                     63:        Return 0 if no characters are input, else return 1.
                     64:        If we return 0, the hashed key will not be useful.
                     65: */
                     66: int GetHashedPassPhrase(char *hash, boolean noecho)
                     67: {      char keystr1[MAXKEYLEN+2], keystr2[MAXKEYLEN+2];
                     68:        int len;
                     69: 
                     70:        if (showpass)
                     71:                noecho = 0;
                     72:        for (;;) {
                     73:                fprintf(pgpout,LANG("\nEnter pass phrase: "));
                     74:                getstring(keystr1,MAXKEYLEN-1,!noecho);
                     75:                if (noecho<2)   /* no need to ask again if user can see it */
                     76:                        break;
                     77:                fprintf(pgpout,LANG("\nEnter same pass phrase again: "));
                     78:                getstring(keystr2,MAXKEYLEN-1,!noecho);
                     79:                if (strcmp(keystr1,keystr2)==0)
                     80:                        break;
1.1.1.7 ! root       81:                fprintf(pgpout,
        !            82: LANG("\n\007Error: Pass phrases were different.  Try again."));
1.1.1.6   root       83:                memset(keystr2, 0, sizeof(keystr2));
                     84:        }
                     85:        if (noecho && (filter_mode || quietmode))
                     86:                putc('\n', pgpout);
                     87: 
                     88:        len = strlen(keystr1);
                     89:        if (len == 0)
                     90:                return 0;
                     91:        /* We assume ASCII pass phrases, with no charset conversions. */
                     92:        /* This will have to change for EBCDIC */
                     93:        hashpass (keystr1, strlen(keystr1), (byte *) hash);
                     94:        memset(keystr1, 0, sizeof(keystr1));
1.1.1.7 ! root       95:        memset(keystr2, 0, sizeof(keystr2));
1.1.1.6   root       96:        return 1;
                     97: } /* GetHashedPassPhrase */
                     98: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.