Annotation of pgp/src/basslib2.c, revision 1.1

1.1     ! root        1: /*     basslib2.c - Bassomatic encryption password routines.
        !             2:        (c) 1989 Philip Zimmermann.  All rights reserved.
        !             3:        Implemented in Microsoft C.
        !             4:        Routines for getting a Bassomatic-specific pass phrase from the 
        !             5:        user's console.
        !             6: */
        !             7: 
        !             8: #include       <stdio.h>       /* for fprintf() */
        !             9: #include       <ctype.h>       /* for isdigit(), toupper(), etc. */
        !            10: #include       <string.h>      /* for strlen() */
        !            11: 
        !            12: #include       "random.h"      /* for getstring() */
        !            13: #include       "basslib.h"
        !            14: #include       "basslib2.h"
        !            15: 
        !            16: 
        !            17: #define hexdigit(c) (isdigit((c))) ? ((c)-'0') : \
        !            18:        ( isxdigit((c)) ? (toupper((c))-'A'+10) : 0 )
        !            19: 
        !            20: static unsigned int gethex(char *p)
        !            21:        /* Evaluate hex digit string */
        !            22: {      unsigned int n;
        !            23:        n = 0;
        !            24:        while (isxdigit(*p)) {
        !            25:                n = (n << 4) | ((int) hexdigit(*p));
        !            26:                p++;
        !            27:        }
        !            28:        return (n);
        !            29: } /* gethex */
        !            30: 
        !            31: 
        !            32: /*
        !            33: **     getpassword - get Bassomatic pass phrase from user.
        !            34:        Parameters:
        !            35:                returns char *keystring
        !            36:                byte noecho:  
        !            37:                        0=ask once, echo. 
        !            38:                        1=ask once, no echo. 
        !            39:                        2=ask twice, no echo.
        !            40:                int defaultc:  default key control byte, or -1 to prompt
        !            41:        returns length of resulting keystring
        !            42: */
        !            43: int getpassword(char *keystring, byte noecho, int defaultc)
        !            44: {      char keystr2[256];
        !            45:        char c;
        !            46:        if (defaultc == -1) {
        !            47:                fprintf(stderr,"\nEnter the Bassomatic key control byte in hex: ");
        !            48:                fprintf(stderr,"\n(default = 12 hex): ");
        !            49:                getstring(keystr2,48,TRUE);
        !            50:                c = (strlen(keystr2)==0) ? 0x12 : gethex(keystr2);
        !            51:        }
        !            52:        else    c = defaultc;
        !            53: 
        !            54:        *keystring++ = c;
        !            55: 
        !            56:        while (TRUE) {
        !            57:                fprintf(stderr,"\nEnter pass phrase: ");
        !            58:                if (!noecho) fputc('\n',stderr);
        !            59:                getstring(keystring,MAXKEYLEN-1,!noecho);
        !            60:                if (noecho<2)   /* no need to ask again if user can see it */
        !            61:                        break;
        !            62:                fprintf(stderr,"\nEnter same pass phrase again: ");
        !            63:                if (!noecho) fputc('\n',stderr);
        !            64:                getstring(keystr2,MAXKEYLEN-1,!noecho);
        !            65:                if (strcmp(keystring,keystr2)==0)
        !            66:                        break;
        !            67:                fprintf(stderr,"\n\aError: Pass phrases were different.  Try again.");
        !            68:        }
        !            69: 
        !            70:        /* if (strlen(keystring)==0)
        !            71:                strcpy(keystring," "); */ /* guarantee nonzero length */
        !            72: 
        !            73:        return(strlen(keystring));
        !            74: }      /* getpassword */
        !            75: 

unix.superglobalmegacorp.com

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