--- pgp/src/crypto.c 2018/04/24 16:42:34 1.1.1.6 +++ pgp/src/crypto.c 2018/04/24 16:43:50 1.1.1.7 @@ -1,37 +1,37 @@ /* crypto.c - Cryptographic routines for PGP. PGP: Pretty Good(tm) Privacy - public key cryptography for the masses. - + (c) Copyright 1990-1994 by Philip Zimmermann. All rights reserved. The author assumes no liability for damages resulting from the use of this software, even if the damage results from defects in this software. No warranty is expressed or implied. - + Note that while most PGP source modules bear Philip Zimmermann's copyright notice, many of them have been revised or entirely written by contributors who frequently failed to put their names in their code. Code that has been incorporated into PGP from other authors was either originally published in the public domain or is used with permission from the various authors. - + PGP is available for free to the public under certain restrictions. See the PGP User's Guide (included in the release package) for important information about licensing, patent restrictions on certain algorithms, trademarks, copyrights, and export controls. - + Modified: 12-Nov-92 HAJK Add FDL stuff for VAX/VMS local mode. Reopen temporary files rather than create new version. - + Modified: 13-Dec-92 Derek Atkins #include @@ -119,7 +119,6 @@ void PascalToC( char *s ) set TZFIX=-1 in config.pgp if you live in Colorado and the TZ variable is undefined. */ - word32 get_timestamp(byte *timestamp) /* Return current timestamp as a byte array in internal byteorder, and as a 32-bit word */ @@ -135,7 +134,8 @@ word32 get_timestamp(byte *timestamp) * 6/19/92 rgb */ #define LEAP_DAYS (((unsigned long)70L/4)+1) -#define CALENDAR_KLUDGE ((unsigned long)86400L * (((unsigned long)365L * 70L) + LEAP_DAYS)) +#define CALENDAR_KLUDGE ((unsigned long)86400L * (((unsigned long)365L \ + * 70L) + LEAP_DAYS)) t -= CALENDAR_KLUDGE; #endif #endif @@ -145,19 +145,20 @@ word32 get_timestamp(byte *timestamp) if (timestamp != NULL) { /* first, fill array in external byte order: */ put_word32(t, timestamp); - convert_byteorder(timestamp,4); /* convert to internal byteorder */ + convert_byteorder(timestamp,4); + /* convert to internal byteorder */ } return t; /* return 32-bit timestamp integer */ } /* get_timestamp */ -static int date_ymd(word32 *tstamp, int *year, int *month, int *day) /* Given timestamp as seconds elapsed since 1970 Jan 1 00:00:00, returns year (1970-2106), month (1-12), day (1-31). Not valid for dates after 2100 Feb 28 (no leap day that year). Also returns day of week (0-6) as functional return. */ +static int date_ymd(word32 *tstamp, int *year, int *month, int *day) { word32 days,y; int m,d,i; @@ -178,13 +179,13 @@ static int date_ymd(word32 *tstamp, int } *month = m+1; *day = d+1; - i = (int)((days-2) % (unsigned long)7L); /* compute day of week 0-6 */ + i = (int)((days-2) % (unsigned long)7L); /* compute day of week 0-6 */ return i; /* returns weekday 0-6; 0=Sunday, 6=Saturday */ } /* date_ymd */ -char *cdate(word32 *tstamp) /* Return date string, given pointer to 32-bit timestamp */ +char *cdate(word32 *tstamp) { int month,day,year; static char datebuf[20]; @@ -196,16 +197,18 @@ char *cdate(word32 *tstamp) } /* cdate */ -char *ctdate(word32 *tstamp) /* Return date and time string, given pointer to 32-bit timestamp */ +char *ctdate(word32 *tstamp) { int hours,minutes; static char tdatebuf[40]; long seconds; - seconds = (*tstamp) % (unsigned long)86400L; /* seconds past midnight today */ - minutes = (int)((seconds+30L) / 60L); /* round off to minutes past midnight */ - hours = minutes / 60; /* hours past midnight */ - minutes = minutes % 60; /* minutes past the hour */ + seconds = (*tstamp) % (unsigned long)86400L; + /* seconds past midnight today */ + minutes = (int)((seconds+30L) / 60L); + /* round off to minutes past midnight */ + hours = minutes / 60; /* hours past midnight */ + minutes = minutes % 60; /* minutes past the hour */ sprintf(tdatebuf,"%s %02d:%02d GMT", cdate(tstamp), hours, minutes); return (tdatebuf); } /* ctdate */ @@ -215,72 +218,87 @@ char *ctdate(word32 *tstamp) /* Warn user he if key in keyfile at position fp of length pktlen, belonging * to userid, is untrusted. Return -1 if the user doesn't want to proceed. */ -static int warn_signatures(char *keyfile, long fp, char *userid, boolean warn_only) +static int warn_signatures(char *keyfile, long fp, + char *userid, boolean warn_only) { - FILE *f; - long fpusr; - int usrpktlen; - byte keyctrl; - int trust_status = -1; - - keyctrl = KC_LEGIT_UNKNOWN; /* Assume the worst */ - if (getpubuserid (keyfile, fp, (byte *) userid, &fpusr, &usrpktlen, FALSE) >= 0) - { - f = fopen(keyfile, FOPRBIN); - fseek (f, fpusr+usrpktlen, SEEK_SET); - /* Read trust byte */ - trust_status = read_trust(f, &keyctrl); - fseek(f, fp, SEEK_SET); - if (is_compromised(f)) { - CToPascal(userid); - fprintf(pgpout, "\n"); - show_key(f, fp, 0); - fclose (f); - fprintf(pgpout, LANG("\007\nWARNING: This key has been revoked by its owner,\n\ + FILE *f; + long fpusr; + int usrpktlen; + byte keyctrl; + int trust_status = -1; + + keyctrl = KC_LEGIT_UNKNOWN; /* Assume the worst */ + if (getpubuserid (keyfile, fp, (byte *) userid, &fpusr, + &usrpktlen, FALSE) >= 0) + { + f = fopen(keyfile, FOPRBIN); + fseek (f, fpusr+usrpktlen, SEEK_SET); + /* Read trust byte */ + trust_status = read_trust(f, &keyctrl); + fseek(f, fp, SEEK_SET); + if (is_compromised(f)) { + CToPascal(userid); + fprintf(pgpout, "\n"); + show_key(f, fp, 0); + fclose (f); + fprintf(pgpout, + LANG("\007\nWARNING: This key has been revoked by its owner,\n\ possibly because the secret key was compromised.\n")); - if (warn_only) { - /* this is only for checking signatures */ - fprintf(pgpout, LANG("This could mean that this signature is a forgery.\n")); - return 1; - } else { /* don't use it for encryption */ - fprintf(pgpout, LANG("You cannot use this revoked key.\n")); - return -1; - } - } - fclose (f); - } - CToPascal(userid); - if ((keyctrl & KC_LEGIT_MASK) != KC_LEGIT_COMPLETE) { - byte userid0[256]; - PascalToC(userid); - strcpy ((char *) userid0, userid); - CToPascal(userid); - - if ((keyctrl & KC_LEGIT_MASK) == KC_LEGIT_UNKNOWN) - fprintf(pgpout,LANG("\007\nWARNING: Because this public key is not certified with a trusted\n\ -signature, it is not known with high confidence that this public key\n\ -actually belongs to: \"%s\".\n"), LOCAL_CHARSET((char *)userid0)); - - if ((keyctrl & KC_LEGIT_MASK) == KC_LEGIT_UNTRUSTED) - fprintf(pgpout, LANG("\007\nWARNING: This public key is not trusted to actually belong to:\n\ -\"%s\".\n"), LOCAL_CHARSET((char *)userid0)); + if (warn_only) { + /* this is only for checking signatures */ + fprintf(pgpout, + LANG("This could mean that this signature is a forgery.\n")); + return 1; + } else { /* don't use it for encryption */ + fprintf(pgpout, + LANG("You cannot use this revoked key.\n")); + return -1; + } + } + fclose (f); + } + CToPascal(userid); + if ((keyctrl & KC_LEGIT_MASK) != KC_LEGIT_COMPLETE) { + byte userid0[256]; + PascalToC(userid); + strcpy ((char *) userid0, userid); + CToPascal(userid); + + if ((keyctrl & KC_LEGIT_MASK) == KC_LEGIT_UNKNOWN) + fprintf(pgpout, + LANG("\007\nWARNING: Because this public key is not certified with \ +a trusted\nsignature, it is not known with high confidence that this \ +public key\nactually belongs to: \"%s\".\n"), + LOCAL_CHARSET((char *)userid0)); + + if ((keyctrl & KC_LEGIT_MASK) == KC_LEGIT_UNTRUSTED) + fprintf(pgpout, + LANG("\007\nWARNING: This public key is not trusted to actually belong \ +to:\n\"%s\".\n"), LOCAL_CHARSET((char *)userid0)); if ((keyctrl & KC_LEGIT_MASK) == KC_LEGIT_MARGINAL) - fprintf(pgpout,LANG("\007\nWARNING: Because this public key is not certified with enough trusted\n\ -signatures, it is not known with high confidence that this public key\n\ -actually belongs to: \"%s\".\n"), LOCAL_CHARSET((char *)userid0)); + fprintf(pgpout, + LANG("\007\nWARNING: Because this public key is not certified with enough \ +trusted\nsignatures, it is not known with high confidence that this \ +public key\nactually belongs to: \"%s\".\n"), + LOCAL_CHARSET((char *)userid0)); if (keyctrl & KC_WARNONLY) { - /* KC_WARNONLY bit already set, user must have approved before. */ - fprintf(pgpout, LANG("But you previously approved using this public key anyway.\n")); + /* KC_WARNONLY bit already set, + user must have approved before. */ + fprintf(pgpout, + LANG("But you previously approved using this public key anyway.\n")); } - if (!filter_mode && !batchmode && !warn_only && !(keyctrl & KC_WARNONLY)) + if (!filter_mode && !batchmode && !warn_only + && !(keyctrl & KC_WARNONLY)) { - fprintf(pgpout,LANG("\nAre you sure you want to use this public key (y/N)? ")); + fprintf(pgpout, + LANG("\nAre you sure you want to use this public key (y/N)? ")); if (!getyesno('n')) return -1; - if (trust_status == 0 && (f = fopen(keyfile, FOPRWBIN)) != NULL) + if (trust_status == 0 + && (f = fopen(keyfile, FOPRWBIN)) != NULL) { fseek (f, fpusr+usrpktlen, SEEK_SET); keyctrl |= KC_WARNONLY; @@ -293,8 +311,8 @@ actually belongs to: \"%s\".\n"), LOCAL_ } /* warn_signatures */ -boolean legal_ctb(byte ctb) /* Used to determine if nesting should be allowed. */ +boolean legal_ctb(byte ctb) { boolean legal; byte ctbtype; @@ -323,7 +341,9 @@ int version_error(int val, int checkval) { if (val != checkval) { - fprintf (pgpout, LANG("\n\007Unsupported packet format - you need a newer version of PGP for this file.\n")); + fprintf (pgpout, +LANG("\n\007Unsupported packet format - you need a newer version of PGP \ +for this file.\n")); return 1; } return 0; @@ -333,7 +353,9 @@ int version_byte_error(int val) { if (val != VERSION_BYTE_OLD && val != VERSION_BYTE_KLUDGE) { - fprintf (pgpout, LANG("\n\007Unsupported packet format - you need a newer version of PGP for this file.\n")); + fprintf (pgpout, +LANG("\n\007Unsupported packet format - you need a newer version of PGP \ +for this file.\n")); return 1; } return 0; @@ -344,7 +366,6 @@ version_byte_error(int val) #define RAND_PREFIX_LENGTH 8 /* Length of IV for IDEA encryption */ -static int make_random_ideakey(byte key[IDEAKEYSIZE+RAND_PREFIX_LENGTH], int skip) /* * Make a random IDEA key. Returns its length (the constant 16). * It also generates a random IV, which is placed in the key array @@ -365,6 +386,8 @@ static int make_random_ideakey(byte key[ * The "skip" parameter says to skip that many bytes at the beginning, * used to generate a random IV only for conventional encryption. */ +static int make_random_ideakey(byte key[IDEAKEYSIZE+RAND_PREFIX_LENGTH], + int skip) { int count; @@ -402,9 +425,9 @@ static int make_random_ideakey(byte key[ } -word32 getpastlength(byte ctb, FILE *f) /* Returns the length of a packet according to the CTB and the length field. */ +word32 getpastlength(byte ctb, FILE *f) { word32 length; unsigned int llength; /* length of length */ @@ -414,7 +437,7 @@ word32 getpastlength(byte ctb, FILE *f) length = 0L; /* Use ctb length-of-length field... */ llength = ctb_llength(ctb); /* either 1, 2, 4, or 8 */ - if (llength==8) /* 8 means no length field, assume huge length */ + if (llength==8) /* 8 means no length field, assume huge length */ return -1L; /* return huge length */ /* now read in the actual length field... */ @@ -462,9 +485,6 @@ void write_ctb_len (FILE *f, byte ctb_ty fwrite( buf, 1, llength, f ); } /* write_ctb_len */ - -static -int idea_file(byte *ideakey, boolean decryp, FILE *f, FILE *g, word32 lenfile) /* * Use IDEA in cipher feedback (CFB) mode to encrypt or decrypt a file. * The encrypted material starts out with a 64-bit random prefix, which @@ -473,6 +493,8 @@ int idea_file(byte *ideakey, boolean dec * duplicate of the last 2 bytes of the random prefix. Encrypted key * check bytes detect if correct IDEA key was used to decrypt ciphertext. */ +static +int idea_file(byte *ideakey, boolean decryp, FILE *f, FILE *g, word32 lenfile) { int count, status = 0; extern byte textbuf[DISKBUFSIZE]; @@ -486,7 +508,7 @@ int idea_file(byte *ideakey, boolean dec /* There is a random prefix followed by 2 key check bytes */ memcpy(textbuf, ideakey+IDEAKEYSIZE, RAND_PREFIX_LENGTH); - /* key check bytes are simply duplicates of final 2 random bytes */ + /* key check bytes are simply duplicates of final 2 random bytes */ textbuf[RAND_PREFIX_LENGTH] = textbuf[RAND_PREFIX_LENGTH-2]; textbuf[RAND_PREFIX_LENGTH+1] = textbuf[RAND_PREFIX_LENGTH-1]; @@ -497,9 +519,12 @@ int idea_file(byte *ideakey, boolean dec count = fread(textbuf,1,RAND_PREFIX_LENGTH+2,f); lenfile -= count; if (count==(RAND_PREFIX_LENGTH+2)) { - ideaCfbDecrypt(&cfb, textbuf, textbuf, RAND_PREFIX_LENGTH+2); - if ((textbuf[RAND_PREFIX_LENGTH] != textbuf[RAND_PREFIX_LENGTH-2]) - || (textbuf[RAND_PREFIX_LENGTH+1] != textbuf[RAND_PREFIX_LENGTH-1])) + ideaCfbDecrypt(&cfb, textbuf, textbuf, + RAND_PREFIX_LENGTH+2); + if ((textbuf[RAND_PREFIX_LENGTH] != + textbuf[RAND_PREFIX_LENGTH-2]) + || (textbuf[RAND_PREFIX_LENGTH+1] != + textbuf[RAND_PREFIX_LENGTH-1])) { status = -2; /* bad key error */ } @@ -539,8 +564,6 @@ int idea_file(byte *ideakey, boolean dec */ word16 mpi_checksum; -int read_mpi(unitptr r, FILE *f, boolean adjust_precision, - struct IdeaCfbContext *cfb) /* * Read a mutiprecision integer from a file. * adjust_precision is TRUE iff we should call set_precision to the @@ -549,6 +572,8 @@ int read_mpi(unitptr r, FILE *f, boolean * Returns the bitcount of the number read in, or returns a negative * number if an error is detected. */ +int read_mpi(unitptr r, FILE *f, boolean adjust_precision, + struct IdeaCfbContext *cfb) { byte buf[MAX_BYTE_PRECISION+2]; unsigned int count; @@ -599,12 +624,12 @@ int read_mpi(unitptr r, FILE *f, boolean -void write_mpi(unitptr n, FILE *f, struct IdeaCfbContext *cfb) /* * Write a multiprecision integer to a file. * scrambled is TRUE iff we should scramble field on the way out, * which is used to protect secret key fields. */ +void write_mpi(unitptr n, FILE *f, struct IdeaCfbContext *cfb) { byte buf[MAX_BYTE_PRECISION+2]; short bytecount; @@ -618,12 +643,10 @@ void write_mpi(unitptr n, FILE *f, struc burn(buf); /* burn sensitive data on stack */ } /* write_mpi */ - /*======================================================================*/ - -int get_header_info_from_file(char *infile, byte *header, int count) /* Reads the first count bytes from infile into header. */ +int get_header_info_from_file(char *infile, byte *header, int count) { FILE *f; fill0(header,count); @@ -641,13 +664,14 @@ int get_header_info_from_file(char *infi #define REASONABLE_DATE ((unsigned long) 0x27804180L) /* 91 Jan 01 00:00:00 */ -static -int make_signature_certificate(byte *certificate, struct MD5Context *MD, - byte class, unitptr e, unitptr d, unitptr p, unitptr q, unitptr u, unitptr n) /* Constructs a signed message digest in a signature certificate. Returns total certificate length in bytes, or returns negative error status. */ +static +int make_signature_certificate(byte *certificate, struct MD5Context *MD, + byte class, unitptr e, unitptr d, unitptr p, unitptr q, unitptr u, + unitptr n) { byte inbuf[MAX_BYTE_PRECISION], outbuf[MAX_BYTE_PRECISION]; int i, j, certificate_length, blocksize,bytecount; @@ -662,19 +686,22 @@ int make_signature_certificate(byte *cer blocksize = countbytes(n)-1; /* size of a plaintext block */ if (blocksize < 31) { - fprintf(pgpout,"\n\007Error: RSA key length must be at least 256 bits.\n"); + fprintf(pgpout, + "\n\007Error: RSA key length must be at least 256 bits.\n"); return -1; } - get_timestamp(timestamp); /* Timestamp when signature was made */ + get_timestamp(timestamp); /* Timestamp when signature was + made */ if (tstamp < REASONABLE_DATE) { /* complain about bad time/date setting */ - fprintf(pgpout,LANG("\n\007Error: System clock/calendar is set wrong.\n")); + fprintf(pgpout, + LANG("\n\007Error: System clock/calendar is set wrong.\n")); return -1; } convert_byteorder(timestamp,4); /* convert to external form */ - /* Finish off message digest calculation with this information */ + /* Finish off message digest calculation with this information */ MD_addbuffer (MD, &class, 1, 0); MD_addbuffer (MD, timestamp, 4, md5buf); /* We wrote the digest to a static variable because we want to keep it around @@ -682,7 +709,8 @@ int make_signature_certificate(byte *cer already_have_md5 = 1; if (!quietmode) { - fprintf(pgpout,LANG("Just a moment...")); /* RSA will take a while. */ + fprintf(pgpout,LANG("Just a moment...")); /* RSA will take + a while. */ fflush(pgpout); } @@ -691,18 +719,21 @@ int make_signature_certificate(byte *cer e, d, p, q, u, n); if (i < 0) { if (i == -4) { - fprintf(pgpout,"\n\007Error: RSA key length must be at least 256 bits.\n"); + fprintf(pgpout, + "\n\007Error: RSA key length must be at least 256 bits.\n"); } else if (i == -3) { - fputs(LANG("\a\nError: key is too large. RSA keys may be no longer than 1024 bits,\n\ -due to limitations imposed by software provided by RSADSI.\n"), pgpout); + fputs( + LANG("\a\nError: key is too large. RSA keys may be no longer than 1024 \ +bits,\ndue to limitations imposed by software provided by RSADSI.\n"), pgpout); } else { - fprintf(pgpout, "\a\nUnexpected error %d signing\n", i); + fprintf(pgpout,"\a\nUnexpected error %d signing\n", i); } return i; } /* bytecount does not include the 2 prefix bytes */ - bytecount = reg2mpi(outbuf,(unitptr)outbuf); /* convert to external format */ + bytecount = reg2mpi(outbuf,(unitptr)outbuf); /* convert to external + format */ /* outbuf now contains a message digest in external byteorder form. Now make a complete signature certificate from this. (Note that the first two bytes of md5buf are used below as @@ -711,14 +742,14 @@ due to limitations imposed by software p certificate_length = 0; - /* SKE is Secret Key Encryption (signed). Append CTB for signed msg. */ + /* SKE is Secret Key Encryption (signed). Append CTB for signed msg. */ certificate[certificate_length++] = CTB_SKE; - /* SKE packet length does not include itself or CTB prefix: */ - ske_length = 1 + 1 /* version and mdlen byte */ - + mdlen /* class, timestamp and validation period */ - + KEYFRAGSIZE + 1 + 1 /* Key ID and 2 algorithm bytes */ - + 2 + bytecount+2; /* 2 MD bytes and RSA MPI w/bitcount */ + /* SKE packet length does not include itself or CTB prefix: */ + ske_length = 1 + 1 /* version and mdlen byte */ + + mdlen /* class, timestamp and validation period */ + + KEYFRAGSIZE + 1 + 1 /* Key ID and 2 algorithm bytes */ + + 2 + bytecount+2; /* 2 MD bytes and RSA MPI w/bitcount */ put_word16((word16) ske_length, certificate+certificate_length); certificate_length+=2; /* advance past word */ @@ -726,7 +757,8 @@ due to limitations imposed by software p /* Begin fields that are included in MD calculation... */ - certificate[certificate_length++] = mdlen; /* mdlen is length of MD-extras */ + certificate[certificate_length++] = mdlen; /* mdlen is length + of MD-extras */ certificate[certificate_length++] = class & 0xff; @@ -758,22 +790,23 @@ due to limitations imposed by software p burn(inbuf); /* burn sensitive data on stack */ burn(outbuf); /* burn sensitive data on stack */ - return certificate_length; /* return length of certificate in bytes */ + return certificate_length; /* return length of certificate in bytes */ } /* make_signature_certificate */ #ifdef VMS -void write_litlocal(FILE *g, char *fdl, short fdl_len) -{ /* - * Local mode VMS, we write out the word VMS to say who owns the data then we follow - * that with the file's FDL generated earlier by fdl_generate(). This FDL is preceded - * by a sixteen bit size. The file follows. + * Local mode VMS, we write out the word VMS to say who owns the data then + * we follow that with the file's FDL generated earlier by fdl_generate(). + * This FDL is preceded by a sixteen bit size. The file follows. */ +void write_litlocal(FILE *g, char *fdl, short fdl_len) +{ fputc('\0', g); /* Kludge for null literal file name (supplied by FDL) */ fputs("VMS ", g); - fwrite(&fdl_len, 2, 1, g); /* Byte order *not* important, only VMS reads this!*/ + fwrite(&fdl_len, 2, 1, g); /* Byte order *not* important, + only VMS reads this!*/ fwrite(fdl, 1, fdl_len, g); } #endif /* VMS */ @@ -781,9 +814,6 @@ void write_litlocal(FILE *g, char *fdl, /*======================================================================*/ -int signfile(boolean nested, boolean separate_signature, - char *mcguffin, char *infile, char *outfile, - char lit_mode, char *literalfile) /* Write an RSA-signed message digest of input file to specified output file, and append input file to output file. separate_signature is TRUE iff we should not append the @@ -791,6 +821,9 @@ int signfile(boolean nested, boolean sep If lit_mode is MODE_TEXT, we know the infile is in canonical form. We create a CTB_LITERAL packet for the plaintext data. */ +int signfile(boolean nested, boolean separate_signature, + char *mcguffin, char *infile, char *outfile, + char lit_mode, char *literalfile) { FILE *f; FILE *g; @@ -811,58 +844,71 @@ int signfile(boolean nested, boolean sep int status; struct MD5Context MD; byte keyID[KEYFRAGSIZE]; - unit n[MAX_UNIT_PRECISION], e[MAX_UNIT_PRECISION], d[MAX_UNIT_PRECISION]; - unit p[MAX_UNIT_PRECISION], q[MAX_UNIT_PRECISION], u[MAX_UNIT_PRECISION]; + unit n[MAX_UNIT_PRECISION], e[MAX_UNIT_PRECISION]; + unit d[MAX_UNIT_PRECISION]; + unit p[MAX_UNIT_PRECISION], q[MAX_UNIT_PRECISION]; + unit u[MAX_UNIT_PRECISION]; - set_precision(MAX_UNIT_PRECISION); /* safest opening assumption */ + set_precision(MAX_UNIT_PRECISION);/* safest opening + assumption */ if (verbose) - fprintf(pgpout,"signfile: infile = '%s', outfile = '%s', mode = '%c', literalfile = '%s'\n", + fprintf(pgpout, + "signfile: infile = '%s', outfile = '%s', mode = '%c', literalfile = '%s'\n", infile,outfile,lit_mode,literalfile); if (MDfile(&MD, infile) < 0) - return -1; /* problem with input file. error return */ + return -1; /* problem with input file. error return */ userid[0] = '\0'; if (mcguffin) - strcpy((char *) userid,mcguffin); /* Who we are looking for */ + strcpy((char *) userid,mcguffin); /* Who we are + looking for */ if (getsecretkey(0, NULL, NULL, timestamp, NULL, NULL, userid, n, e, d, p, q, u) < 0) - return -1; /* problem with secret key file. error return. */ + return -1; /* problem with secret key file. + error return. */ extract_keyID(keyID, n); strcpy(keyfile, globalPubringName); /* use default pathname */ - if ((status = getpublickey(GPK_SHOW|GPK_NORVK, keyfile, NULL, NULL, keyID, + if ((status = getpublickey(GPK_SHOW|GPK_NORVK, keyfile, + NULL, NULL, keyID, timestamp, userid, n, e)) < 0) - return -1; /* problem with public key file. error return. */ + return -1; /* problem with public key file. + error return. */ if (lit_mode==MODE_TEXT) signature_class = SM_SIGNATURE_BYTE; else signature_class = SB_SIGNATURE_BYTE; - certificate_length = make_signature_certificate(certificate, &MD, + certificate_length = make_signature_certificate(certificate, + &MD, signature_class, e, d, p, q, u, n); if (certificate_length < 0) - return -1; /* error return from make_signature_certificate() */ + return -1; /* error return from + make_signature_certificate() */ } /* end of scope for some buffers */ /* open file f for read, in binary (not text) mode...*/ #ifdef VMS if (lit_mode == MODE_LOCAL) { if (!(fdl_generate(infile, &fdl, &fdl_len ) & 01)) { - fprintf(pgpout,LANG("\n\007Can't open input plaintext file '%s'\n"),infile); + fprintf(pgpout, + LANG("\n\007Can't open input plaintext file '%s'\n"),infile); return -1; } } #endif /* VMS */ if ((f = fopen(infile,FOPRBIN)) == NULL) { - fprintf(pgpout,LANG("\n\007Can't open plaintext file '%s'\n"),infile); + fprintf(pgpout, + LANG("\n\007Can't open plaintext file '%s'\n"),infile); return -1; } /* open file g for write, in binary (not text) mode...*/ if ((g = fopen(outfile,FOPWBIN)) == NULL) { - fprintf(pgpout,LANG("\n\007Can't create signature file '%s'\n"),outfile); + fprintf(pgpout, + LANG("\n\007Can't create signature file '%s'\n"),outfile); fclose(f); return -1; } @@ -886,14 +932,17 @@ int signfile(boolean nested, boolean sep if (lit_mode == MODE_LOCAL) #ifdef VMS write_ctb_len(g, CTB_LITERAL2_TYPE, - flen + fdl_len + sizeof(fdl_len) + 6, TRUE); + flen + fdl_len + sizeof(fdl_len) + 6, + TRUE); #else /* debug check: should never get here */ fprintf(pgpout, "signfile: invalid mode\n"); #endif else { #ifdef USE_LITERAL2 - write_ctb_len (g, CTB_LITERAL2_TYPE, flen + (unsigned char) lfile[0] + 6, FALSE); + write_ctb_len (g, CTB_LITERAL2_TYPE, + flen + (unsigned char) lfile[0] + + 6, FALSE); #else write_ctb_len (g, CTB_LITERAL_TYPE, flen, FALSE); #endif /* USE_LITERAL2 */ @@ -906,12 +955,13 @@ int signfile(boolean nested, boolean sep #endif /* VMS */ } else { /* write literalfile name */ - fwrite (lfile, 1, (unsigned char) lfile[0]+1, g); + fwrite (lfile, 1, (unsigned char) lfile[0]+1, + g); /* Dummy file creation timestamp */ fwrite ( &dummystamp, 1, sizeof(dummystamp), g); } } - copyfile(f,g,-1L); /* copy rest of file from file f to g */ + copyfile(f,g,-1L); /* copy rest of file from file f to g */ } fclose(f); @@ -924,10 +974,8 @@ int signfile(boolean nested, boolean sep } /* signfile */ - /*======================================================================*/ - int compromise(byte *keyID, char *keyfile) { FILE *f, *g; @@ -939,7 +987,8 @@ int compromise(byte *keyID, char *keyfil unit n[MAX_UNIT_PRECISION], e[MAX_UNIT_PRECISION]; struct MD5Context MD; unit d[MAX_UNIT_PRECISION]; - unit p[MAX_UNIT_PRECISION], q[MAX_UNIT_PRECISION], u[MAX_UNIT_PRECISION]; + unit p[MAX_UNIT_PRECISION], q[MAX_UNIT_PRECISION]; + unit u[MAX_UNIT_PRECISION]; long fp, insertpos; int pktlen; int prec; @@ -950,7 +999,8 @@ int compromise(byte *keyID, char *keyfil if (getsecretkey(0, NULL, keyID, timestamp, NULL, NULL, userid, n, e, d, p, q, u) < 0) - return -1; /* problem with secret key file. error return. */ + return -1; /* problem with secret key file. + error return. */ if (getpublickey(0, keyfile, &fp, &pktlen, keyID, timestamp, userid, n, e) < 0) @@ -958,7 +1008,8 @@ int compromise(byte *keyID, char *keyfil /* open file f for read, in binary (not text) mode...*/ if ((f = fopen(keyfile,FOPRBIN)) == NULL) { - fprintf(pgpout,LANG("\n\007Can't open key ring file '%s'\n"),keyfile); + fprintf(pgpout, + LANG("\n\007Can't open key ring file '%s'\n"),keyfile); return -1; } @@ -992,13 +1043,15 @@ int compromise(byte *keyID, char *keyfil KC_SIGNATURE_BYTE, e, d, p, q, u, n); if (certificate_length < 0) { fclose(f); - return -1; /* error return from make_signature_certificate() */ + return -1; /* error return from + make_signature_certificate() */ } /* open file g for write, in binary (not text) mode...*/ if ((g = fopen(scratchf,FOPWBIN)) == NULL) { - fprintf(pgpout,LANG("\n\007Can't create output file to update key ring.\n")); + fprintf(pgpout, + LANG("\n\007Can't create output file to update key ring.\n")); fclose(f); return -1; } @@ -1027,13 +1080,12 @@ int compromise(byte *keyID, char *keyfil /*======================================================================*/ - -int signkey(char *keyguffin, char *sigguffin, char *keyfile) /* * Write an RSA-signed message digest of key for user keyguffin in * keyfile, using signature from user sigguffin. Append * the signature right after the key. */ +int signkey(char *keyguffin, char *sigguffin, char *keyfile) { FILE *f; FILE *g; @@ -1066,7 +1118,8 @@ int signkey(char *keyguffin, char *siggu does not appear in public keyring '%s'.\n\ Thus, a signature made with this key cannot be checked on this keyring.\n"), userid, keyfile); - return -1; /* problem with public key file. error return. */ + return -1; /* problem with public key file. + error return. */ } strcpy((char *)userid, keyguffin); @@ -1075,6 +1128,7 @@ Thus, a signature made with this key can status = getpublickey(GPK_SHOW|GPK_NORVK, keyfile, &fp, &pktlen, NULL, timestamp, userid, n, e); + showKeyHash(n, e); if (status < 0) return -1; PascalToC((char *) userid); @@ -1086,7 +1140,8 @@ Thus, a signature made with this key can /* open file f for read, in binary (not text) mode...*/ f = fopen(keyfile,FOPRBIN); if (f == NULL) { - fprintf(pgpout,LANG("\n\007Can't open key ring file '%s'\n"),keyfile); + fprintf(pgpout, + LANG("\n\007Can't open key ring file '%s'\n"),keyfile); return -1; } @@ -1104,7 +1159,8 @@ Thus, a signature made with this key can if (status < 0 || is_key_ctb (ctb) || ctb==CTB_USERID) break; if (equal_buffers(keyID, keyID2, KEYFRAGSIZE)) { - fprintf(pgpout,LANG("\n\007Key is already signed by user '%s'.\n"), + fprintf(pgpout, + LANG("\n\007Key is already signed by user '%s'.\n"), LOCAL_CHARSET(sigguffin)); fclose(f); return -1; @@ -1114,10 +1170,10 @@ Thus, a signature made with this key can if (!batchmode) { fprintf(pgpout, -LANG("\n\nREAD CAREFULLY: Based on your own direct first-hand knowledge, are\n\ -you absolutely certain that you are prepared to solemnly certify that\n\ -the above public key actually belongs to the user specified by the\n\ -above user ID (y/N)? ")); +LANG("\n\nREAD CAREFULLY: Based on your own direct first-hand knowledge, \ +are\nyou absolutely certain that you are prepared to solemnly certify \ +that\nthe above public key actually belongs to the user specified by \ +the\nabove user ID (y/N)? ")); if (!getyesno('n')) { fclose(f); return -1; @@ -1129,10 +1185,12 @@ above user ID (y/N)? ")); unit d[MAX_UNIT_PRECISION], p[MAX_UNIT_PRECISION]; unit q[MAX_UNIT_PRECISION], u[MAX_UNIT_PRECISION]; - set_precision(MAX_UNIT_PRECISION); /* safest opening assumption */ + set_precision(MAX_UNIT_PRECISION); /* safest opening + assumption */ if ((g = fopen(keyfile,FOPRBIN)) == NULL) { - fprintf(pgpout,LANG("\n\007Can't open key ring file '%s'\n"),keyfile); + fprintf(pgpout, + LANG("\n\007Can't open key ring file '%s'\n"),keyfile); return -1; } fseek(g, fp, SEEK_SET); @@ -1140,7 +1198,8 @@ above user ID (y/N)? ")); if (MDfile0_len(&MD, g, pktlen) < 0) { fclose(g); fclose(f); - return -1; /* problem with input file. error return */ + return -1; /* problem with input file. + error return */ } fclose(g); @@ -1148,31 +1207,41 @@ above user ID (y/N)? ")); CToPascal((char *)userid); MD5Update(&MD, userid+1, (int)(unsigned char)userid[0]); - strcpy((char *)userid,sigguffin); /* Who we are looking for */ + strcpy((char *)userid,sigguffin); /* Who we are looking for */ /* Make sure that we DONT use the internal password to * get the secret key! This way you need to type your * pass phrase every time you come to this point! * Derek Atkins 93-02-25 + * + * If batchmode, then let it use the passed-in password, + * for signing agents. + * Derek Atkins 94-06-20 */ - if (getsecretkey(GPK_ASKPASS, NULL, NULL, timestamp, NULL, NULL, + if (getsecretkey((batchmode ? 0 : GPK_ASKPASS), NULL, NULL, + timestamp, NULL, NULL, userid, n, e, d, p, q, u) < 0) { fclose(f); - return -1; /* problem with secret key file. error return. */ + return -1; /* problem with secret key file. + error return. */ } - certificate_length = make_signature_certificate(certificate, &MD, - K0_SIGNATURE_BYTE, e, d, p, q, u, n); + certificate_length = + make_signature_certificate(certificate, &MD, + K0_SIGNATURE_BYTE, e, d, p, q, + u, n); if (certificate_length < 0) - return -1; /* error return from make_signature_certificate() */ + return -1; /* error return from + make_signature_certificate() */ } /* end of scope for some buffers */ /* open file g for write, in binary (not text) mode...*/ tempring = tempfile(TMP_TMPDIR); if ((g = fopen(tempring,FOPWBIN)) == NULL) { - fprintf(pgpout,LANG("\n\007Can't create output file to update key ring.\n")); + fprintf(pgpout, + LANG("\n\007Can't create output file to update key ring.\n")); fclose(f); return -1; } @@ -1203,16 +1272,15 @@ above user ID (y/N)? ")); } /* signkey */ - /*======================================================================*/ -int check_signaturefile(char *infile, char *outfile, boolean strip_signature, - char *preserved_name) /* Check signature in infile for validity. Strip off the signature * and write the remaining packet to outfile. If strip_signature, * also write the signature to outfile.sig. * the original filename is stored in preserved_name */ +int check_signaturefile(char *infile, char *outfile, boolean strip_signature, + char *preserved_name) { byte ctb,ctb2=0; /* Cipher Type Bytes */ char keyfile[MAX_PATH]; /* for getpublickey */ @@ -1235,13 +1303,14 @@ int check_signaturefile(char *infile, ch byte outbuf[MAX_BYTE_PRECISION]; byte keyID[KEYFRAGSIZE]; word32 tstamp; - byte *timestamp = (byte *) &tstamp; /* key certificate timestamp */ + byte *timestamp = (byte *) &tstamp; /* key certificate timestamp */ word32 dummystamp; byte userid[256]; struct MD5Context MD; byte digest[16]; boolean separate_signature; - boolean fixedLiteral = FALSE; /* Whether it's a fixed literal2 packet */ + boolean fixedLiteral = FALSE; /* Whether it's a fixed literal2 + packet */ extern char **myArgv; extern int myArgc; char lit_mode = MODE_BINARY; @@ -1269,7 +1338,8 @@ int check_signaturefile(char *infile, ch strcpy(keyfile, globalPubringName); /* use default pathname */ if (verbose) - fprintf(pgpout,"check_signaturefile: infile = '%s', outfile = '%s'\n", + fprintf(pgpout, + "check_signaturefile: infile = '%s', outfile = '%s'\n", infile,outfile); if (preserved_name) @@ -1277,11 +1347,12 @@ int check_signaturefile(char *infile, ch /* open file f for read, in binary (not text) mode...*/ if ((f = fopen(infile,FOPRBIN)) == NULL) { - fprintf(pgpout,LANG("\n\007Can't open ciphertext file '%s'\n"),infile); + fprintf(pgpout, + LANG("\n\007Can't open ciphertext file '%s'\n"),infile); return -1; } - /******************** Read header CTB and length field ******************/ + /******************** Read header CTB and length field ******************/ fread(&ctb,1,1,f); /* read certificate CTB byte */ certificate = certbuf; @@ -1304,8 +1375,10 @@ int check_signaturefile(char *infile, ch if (version_byte_error(version)) goto err1; - mdlensave = mdlen = *certificate++; /* length of material to be added to MD */ - mdextras = certificate; /* pointer to extra material for MD calculation */ + mdlensave = mdlen = *certificate++; /* length of material to + be added to MD */ + mdextras = certificate; /* pointer to extra material for + MD calculation */ class = *certificate++; if (class != SM_SIGNATURE_BYTE && class != SB_SIGNATURE_BYTE) { @@ -1344,9 +1417,11 @@ int check_signaturefile(char *infile, ch maximum precision to avoid error return from mpi2reg() */ if (getpublickey(0, keyfile, &fp, NULL, keyID, (byte *)&dummystamp, userid, n, e) < 0) - set_precision(MAX_UNIT_PRECISION); /* safest opening assumption */ + set_precision(MAX_UNIT_PRECISION); /* safest opening + assumption */ - if (mpi2reg((unitptr)inbuf,certificate) == -1) /* get signed message digest */ + if (mpi2reg((unitptr)inbuf,certificate) == -1) /* get signed message + digest */ goto err1; certificate += countbytes((unitptr)inbuf)+2; @@ -1361,64 +1436,80 @@ int check_signaturefile(char *infile, ch /* Signature certificate has no plaintext following it. Must be in another file. Go look. */ separate_signature = TRUE; - if (preserved_name) /* let caller know there is no output file */ + if (preserved_name) /* let caller know there is + no output file */ strcpy(preserved_name, "/dev/null"); fclose(f); - fprintf(pgpout,LANG("\nFile '%s' has signature, but with no text."),infile); + fprintf(pgpout, + LANG("\nFile '%s' has signature, but with no text."),infile); if (myArgc > 3 && file_exists(myArgv[3])) { outfile = myArgv[3]; - fprintf(pgpout,LANG("\nText is assumed to be in file '%s'.\n"),outfile); + fprintf(pgpout, + LANG("\nText is assumed to be in file '%s'.\n"),outfile); } else { strcpy(plainfile, outfile); outfile = plainfile; drop_extension(outfile); if (file_exists(outfile)) { - fprintf(pgpout,LANG("\nText is assumed to be in file '%s'.\n"),outfile); + fprintf(pgpout, + LANG("\nText is assumed to be in file '%s'.\n"),outfile); } else { if (batchmode) return -1; - fprintf(pgpout,LANG("\nPlease enter filename of material that signature applies to: ")); - getstring(outfile,59,TRUE); /* echo keyboard */ + fprintf(pgpout, + LANG("\nPlease enter filename of material that signature applies to: ")); + getstring(outfile,59,TRUE); /* echo keyboard */ if ((int)strlen(outfile) == 0) return -1; } } /* open file f for read, in binary (not text) mode...*/ if ((f = fopen(outfile,FOPRBIN)) == NULL) { - fprintf(pgpout,LANG("\n\007Can't open file '%s'\n"),outfile); + fprintf(pgpout, + LANG("\n\007Can't open file '%s'\n"),outfile); return -1; } start_text = ftell(f); /* mark position of text for later */ text_len = fsize(f); /* remember length of text */ } else { separate_signature = FALSE; - /* We just read 1 byte, so outbuf[0] should contain a ctb, - maybe a CTB_LITERAL byte. */ + /* We just read 1 byte, so outbuf[0] should contain a ctb, + maybe a CTB_LITERAL byte. */ ctb2 = outbuf[0]; fixedLiteral = is_ctb_type(ctb2,CTB_LITERAL2_TYPE); - if (is_ctb(ctb2) && (is_ctb_type(ctb2,CTB_LITERAL_TYPE)||fixedLiteral)) + if (is_ctb(ctb2) && (is_ctb_type(ctb2,CTB_LITERAL_TYPE) + ||fixedLiteral)) { /* Read literal data */ - text_len = getpastlength(ctb2, f); /* read packet length */ + text_len = getpastlength(ctb2, f); /* read packet + length */ lit_mode = '\0'; - fread (&lit_mode,1,1,f); /* get literal packet mode byte */ - if (lit_mode != MODE_TEXT && lit_mode != MODE_BINARY && + fread (&lit_mode,1,1,f); /* get literal packet + mode byte */ + if (lit_mode != MODE_TEXT + && lit_mode != MODE_BINARY && lit_mode != MODE_LOCAL) { - fprintf(pgpout,"\n\007Error: Illegal mode byte %02x in literal packet.\n", - lit_mode); /* English-only diagnostic for debugging */ + fprintf(pgpout, + "\n\007Error: Illegal mode byte %02x in literal packet.\n", + lit_mode); /* English-only diagnostic + for debugging */ (void) version_error(lit_mode, MODE_BINARY); goto err1; } if (verbose) - fprintf(pgpout, LANG("File type: '%c'\n"), lit_mode); + fprintf(pgpout, + LANG("File type: '%c'\n"), lit_mode); /* Read literal file name, use it if possible */ litfile[0] = 0; fread (litfile,1,1,f); if( fixedLiteral ) - /* Get corrected text_len value by subtracting the length of - the filename and the timestamp and mode byte and litfile length byte */ - text_len -= litfile[0] + sizeof(dummystamp) + 2; + /* Get corrected text_len value by subtracting + the length of the filename and the + timestamp and mode byte and litfile + length byte */ + text_len -= litfile[0] + + sizeof(dummystamp) + 2; if (litfile[0] > 0) { if ((int)litfile[0] >= MAX_PATH) { @@ -1428,13 +1519,16 @@ int check_signaturefile(char *infile, ch fread (litfile+1,1,litfile[0],f); } } - /* Use litfile if it's writeable and he didn't say an outfile */ + /* Use litfile if it's writeable and he + didn't say an outfile */ if (litfile[0]) { PascalToC( (char *)litfile ); if (verbose) - fprintf(pgpout, LANG("Original plaintext file name was: '%s'\n"), litfile); + fprintf(pgpout, + LANG("Original plaintext file name was: '%s'\n"), litfile); if (preserved_name) - strcpy(preserved_name, (char *) litfile); + strcpy(preserved_name, + (char *) litfile); } if (lit_mode == MODE_LOCAL) { fread(org_sys, 1, 4, f); org_sys[4] = '\0'; @@ -1448,25 +1542,34 @@ int check_signaturefile(char *infile, ch fread(&fdl_len, 2, 1, f); fdl = (char *) malloc(fdl_len); fread(fdl, 1, fdl_len, f); - if ((g = fdl_create( fdl, fdl_len, outfile, (char *) litfile)) == NULL) + if ((g = + fdl_create( fdl, fdl_len, + outfile, + (char *) litfile)) + == NULL) { - fprintf(pgpout,"\n\007Unable to create file %s\n", outfile); + fprintf(pgpout, + "\n\007Unable to create file %s\n", outfile); return -1; } free(fdl); if (preserved_name) - strcpy(preserved_name, (char *) litfile); - text_len -= (fdl_len + sizeof(fdl_len)); + strcpy(preserved_name, + (char *) litfile); + text_len -= (fdl_len + + sizeof(fdl_len)); #endif /* VMS */ } else { - fprintf(pgpout,"\n\007Unrecognised local binary type %s\n",org_sys); + fprintf(pgpout, + "\n\007Unrecognised local binary type %s\n",org_sys); return -1; } } else { /* Discard file creation timestamp for now */ fread (&dummystamp, 1, sizeof(dummystamp), f); } - start_text = ftell(f); /* mark position of text for later */ + start_text = ftell(f); /* mark position of + text for later */ } /* packet is CTB_LITERAL_TYPE */ } @@ -1475,8 +1578,11 @@ int check_signaturefile(char *infile, ch /* Get and validate public key from a key file: */ if (getpublickey(0, keyfile, &fp, NULL, keyID, (byte *)&dummystamp, userid, n, e) < 0) - { /* Can't get public key. Complain and process file copy anyway. */ - fprintf(pgpout,LANG("\nWARNING: Can't find the right public key-- can't check signature integrity.\n")); + { /* Can't get public key. Complain and + process file copy anyway. */ + fprintf(pgpout, + LANG("\nWARNING: Can't find the right public key-- can't check signature \ +integrity.\n")); goto outsig; } /* Can't find public key */ @@ -1497,19 +1603,24 @@ Can't check signature integrity.\n"), pg goto outsig; /* Output data anyway */ } if (count == -5) { /* RSAREF returned malformed */ - fputs(LANG("\a\nMalformed or obsolete signature. Can't check signature integrity.\n"), + fputs( +LANG("\a\nMalformed or obsolete signature. Can't check signature \ +integrity.\n"), pgpout); goto outsig; } if (count == -3) { /* Key too big */ - fputs(LANG("\a\nSigning key is too large. RSA keys may be no longer than 1024 bits,\n\ -due to limitations imposed by software provided by RSADSI.\n\ + fputs( +LANG("\a\nSigning key is too large. RSA keys may be no longer than 1024 \ +bits,\ndue to limitations imposed by software provided by RSADSI.\n\ Can't check signature integrity.\n"), pgpout); goto outsig; } if (count < 0) { /* Catch-all */ - fprintf(pgpout,LANG("\n\007Error: RSA-decrypted block is corrupted.\n\ -This may be caused either by corrupted data or by using the wrong RSA key.\n")); + fprintf(pgpout, +LANG("\n\007Error: RSA-decrypted block is corrupted.\n\ +This may be caused either by corrupted data or by using the wrong RSA key.\n\ +")); goto outsig; /* Output data anyway */ } @@ -1519,19 +1630,24 @@ This may be caused either by corrupted d if (outbuf[outbufoffset] != mdlow2[0] || outbuf[outbufoffset+1] != mdlow2[1]) { - fprintf(pgpout,LANG("\n\007Error: RSA-decrypted block is corrupted.\n\ -This may be caused either by corrupted data or by using the wrong RSA key.\n")); + fprintf(pgpout, + LANG("\n\007Error: RSA-decrypted block is corrupted.\n\ +This may be caused either by corrupted data or by using the wrong RSA key.\n\ +")); goto outsig; /* Output data anyway */ } /* Reposition file to where that plaintext begins... */ fseek(f,start_text,SEEK_SET); /* reposition file from last ftell */ - MDfile0_len(&MD,f,text_len);/* compute a message digest from rest of file */ + MDfile0_len(&MD,f,text_len); /* compute a message digest from + rest of file */ - MD_addbuffer (&MD, mdextras, mdlensave, digest); /* Finish message digest */ + MD_addbuffer (&MD, mdextras, mdlensave, digest); /* Finish message + digest */ - convert_byteorder(timestamp,4); /* convert timestamp from external form */ + convert_byteorder(timestamp,4); /* convert timestamp from external + form */ PascalToC((char *)userid); /* for display */ /* now compare computed MD with claimed MD */ @@ -1548,38 +1664,49 @@ This may be caused either by corrupted d a canonical text packet, but it was in canonical text form when the signature was created, so by re-canonicalizing it we can check the signature. */ - if (class == SM_SIGNATURE_BYTE && separate_signature && is_text_file(outfile)) - { /* Reposition file to where the plaintext begins and canonicalize it */ + if (class == SM_SIGNATURE_BYTE && separate_signature + && is_text_file(outfile)) + { /* Reposition file to where the plaintext begins + and canonicalize it */ rewind( f ); tempFileName = tempfile( TMP_WIPE | TMP_TMPDIR ); if (verbose) - fprintf(stderr, "signature checking failed, trying in canonical mode\n"); - if( ( tempFile = fopen( tempFileName, FOPWPBIN ) ) != NULL ) - { /* We've opened a temporary work file, copy the text to it + fprintf(stderr, + "signature checking failed, trying in canonical mode\n"); + if( ( tempFile = fopen( tempFileName, FOPWPBIN ) ) + != NULL ) + { /* We've opened a temporary work file, + copy the text to it with canonicalization */ copyfile_to_canon( f, tempFile, -1L ); - /* Move back to the start of the file and recalculate the MD */ + /* Move back to the start of the file + and recalculate the MD */ rewind( tempFile ); - MDfile0_len( &MD, tempFile, -1L ); - MD_addbuffer( &MD, mdextras, mdlensave, digest ); + MDfile0_len(&MD, tempFile, -1L ); + MD_addbuffer(&MD, mdextras, mdlensave, + digest); /* Clean up behind us */ fclose( tempFile ); rmtemp( tempFileName ); - /* Check if the signature is OK this time round */ + /* Check if the signature is OK this time + round */ /* Assume MSB external byte ordering */ - if(equal_buffers(digest, outbuf+outbufoffset, 16)) + if(equal_buffers(digest, outbuf+outbufoffset, + 16)) goto goodsig; } } #endif /* !CANONICAL_TEXT */ - fprintf(pgpout,LANG("\007\nWARNING: Bad signature, doesn't match file contents!\007\n")); + fprintf(pgpout, +LANG("\007\nWARNING: Bad signature, doesn't match file contents!\007\n")); fprintf(pgpout,LANG("\nBad signature from user \"%s\".\n"), LOCAL_CHARSET((char *)userid)); - fprintf(pgpout,LANG("Signature made %s\n"),ctdate((word32 *)timestamp)); + fprintf(pgpout, +LANG("Signature made %s\n"),ctdate((word32 *)timestamp)); if (moreflag && !batchmode) { /* more will scroll the message off the screen */ fprintf(pgpout, LANG("\nPress ENTER to continue...")); @@ -1593,7 +1720,8 @@ goodsig: signature_checked = TRUE; /* set flag for batch processing */ fprintf(pgpout,LANG("\nGood signature from user \"%s\".\n"), LOCAL_CHARSET((char *)userid)); - fprintf(pgpout,LANG("Signature made %s\n"),ctdate((word32 *)timestamp)); + fprintf(pgpout, +LANG("Signature made %s\n"),ctdate((word32 *)timestamp)); warnsig: /* warn only, don't ask if user wants to use the key */ @@ -1606,18 +1734,22 @@ outsig: if (separate_signature) { if (!quietmode) - fprintf(pgpout,LANG("\nSignature and text are separate. No output file produced. ")); + fprintf(pgpout, +LANG("\nSignature and text are separate. No output file produced. ")); } else { /* signature precedes plaintext in file... */ /* produce a plaintext output file from signature file */ /* open file g for write, in binary or text mode...*/ if (lit_mode==MODE_LOCAL) { #ifdef VMS - if (status = fdl_copyfile2bin( f, g, text_len)) { /* Copy ok? */ + if (status = fdl_copyfile2bin( f, g, text_len)) { + /* Copy ok? */ if (status > 0) - fprintf(stderr,"\n...copying to literal file\n"); + fprintf(stderr, + "\n...copying to literal file\n"); else - perror("\nError copying from work file"); + perror( + "\nError copying from work file"); fdl_close(g); goto err1; } @@ -1629,7 +1761,8 @@ outsig: else g = fopen(outfile, FOPWTXT); if (g == NULL) { - fprintf(pgpout,LANG("\n\007Can't create plaintext file '%s'\n"),outfile); + fprintf(pgpout, +LANG("\n\007Can't create plaintext file '%s'\n"),outfile); goto err1; } CONVERSION = (lit_mode==MODE_TEXT)?EXT_CONV:NO_CONV; @@ -1650,24 +1783,28 @@ outsig: strcpy (sigfile, outfile); force_extension(sigfile,SIG_EXTENSION); if (!force_flag && file_exists(sigfile)) { - fprintf(pgpout,LANG("\n\007Signature file '%s' already exists. Overwrite (y/N)? "), + fprintf(pgpout, +LANG("\n\007Signature file '%s' already exists. Overwrite (y/N)? "), sigfile); if (!getyesno('n')) goto err1; } if ((g = fopen(sigfile,FOPWBIN)) == NULL) { - fprintf(pgpout,LANG("\n\007Can't create signature file '%s'\n"),sigfile); + fprintf(pgpout, +LANG("\n\007Can't create signature file '%s'\n"),sigfile); goto err1; } fseek (f,0L,SEEK_SET); - copyfile (f,g,(unsigned long)(cert_length+ctb_llength(ctb)+1)); + copyfile (f,g,(unsigned long)(cert_length + +ctb_llength(ctb)+1)); if (write_error(g)) { fclose(g); goto err1; } fclose(g); if (!quietmode) - fprintf(pgpout,LANG("\nWriting signature certificate to '%s'\n"),sigfile); + fprintf(pgpout, +LANG("\nWriting signature certificate to '%s'\n"),sigfile); } } @@ -1676,15 +1813,19 @@ outsig: fclose(f); if (separate_signature) return 0; /* normal return, no nested info */ - if (is_ctb(ctb2) && (is_ctb_type(ctb2,CTB_LITERAL_TYPE) || fixedLiteral)) - /* we already stripped away the CTB_LITERAL */ + if (is_ctb(ctb2) && (is_ctb_type(ctb2,CTB_LITERAL_TYPE) + || fixedLiteral)) + /* we already stripped away the CTB_LITERAL */ return 0; /* normal return, no nested info */ - /* Otherwise, it's best to assume a nested CTB */ - return 1; /* nested information return */ + /* Otherwise, it's best to assume a + nested CTB */ + return 1; /* nested information return */ badcert: /* Bad packet. Complain. */ - fprintf(pgpout,LANG("\n\007Error: Badly-formed or corrupted signature certificate.\n")); - fprintf(pgpout,LANG("File \"%s\" does not have a properly-formed signature.\n"),infile); + fprintf(pgpout, +LANG("\n\007Error: Badly-formed or corrupted signature certificate.\n")); + fprintf(pgpout, +LANG("File \"%s\" does not have a properly-formed signature.\n"),infile); /* Now just drop through to error exit... */ err1: @@ -1695,10 +1836,6 @@ err1: } /* check_signaturefile */ - -int check_key_sig(FILE *fkey, long fpkey, int keypktlen, char *keyuserid, - FILE *fsig, long fpsig, char *keyfile, char *siguserid, byte *xtimestamp, - byte *sigclass) /* * Check signature of key in file fkey at position fpkey, using signature * in file fsig and position fpsig. keyfile tells the file to use to @@ -1715,6 +1852,9 @@ int check_key_sig(FILE *fkey, long fpkey * -10 Malformed packet * -20 BAD SIGNATURE */ +int check_key_sig(FILE *fkey, long fpkey, int keypktlen, char *keyuserid, + FILE *fsig, long fpsig, char *keyfile, char *siguserid, + byte *xtimestamp, byte *sigclass) { byte ctb; /* Cipher Type Bytes */ long fp; @@ -1730,7 +1870,7 @@ int check_key_sig(FILE *fkey, long fpkey byte digest[16]; byte *mdextras; word32 tstamp; - byte *timestamp = (byte *) &tstamp; /* key certificate timestamp */ + byte *timestamp = (byte *) &tstamp; /* key certificate timestamp */ byte version; byte mdlen; /* length of material to be added to MD calculation */ byte class; @@ -1741,7 +1881,7 @@ int check_key_sig(FILE *fkey, long fpkey set_precision(MAX_UNIT_PRECISION); /* safest opening assumption */ - /******************** Read header CTB and length field ******************/ + /******************** Read header CTB and length field ******************/ fseek(fsig, fpsig, SEEK_SET); fread(&ctb,1,1,fsig); /* read certificate CTB byte */ @@ -1769,7 +1909,8 @@ int check_key_sig(FILE *fkey, long fpkey if (version_error(mdlen, 5)) return -8; - mdextras = certificate; /* pointer to extra material for MD calculation */ + mdextras = certificate; /* pointer to extra material for MD + calculation */ *sigclass = class = *certificate++; if (class != K0_SIGNATURE_BYTE && class != K1_SIGNATURE_BYTE && @@ -1807,7 +1948,8 @@ int check_key_sig(FILE *fkey, long fpkey xtimestamp, (unsigned char *)siguserid, n, e) < 0) return -2; - if (mpi2reg((unitptr)inbuf,certificate) == -1) /* get signed message digest */ + if (mpi2reg((unitptr)inbuf,certificate) == -1) /* get signed message + digest */ return -10; certificate += countbytes((unitptr)inbuf)+2; @@ -1822,7 +1964,8 @@ int check_key_sig(FILE *fkey, long fpkey return count; if (count != sizeof(digest)) - return -9; /* Bad RSA decrypt. Corruption, or wrong key. */ + return -9; /* Bad RSA decrypt. Corruption, + or wrong key. */ /* outbuf should contain message digest packet */ /*==================================================================*/ @@ -1830,7 +1973,8 @@ int check_key_sig(FILE *fkey, long fpkey /* Assume MSB external byte ordering */ if (outbuf[0] != mdlow2[0] || outbuf[1] != mdlow2[1]) - return -9; /* Bad RSA decrypt. Corruption, or wrong key. */ + return -9; /* Bad RSA decrypt. Corruption, + or wrong key. */ /* Position file to where that plaintext begins... */ fseek(fkey,fpkey,SEEK_SET); @@ -1839,27 +1983,29 @@ int check_key_sig(FILE *fkey, long fpkey MDfile0_len(&MD,fkey,keypktlen); /* Add data from user id */ if (class != KC_SIGNATURE_BYTE) - MD5Update(&MD, (unsigned char *) keyuserid+1, (int)(unsigned char)keyuserid[0]); + MD5Update(&MD, (unsigned char *) keyuserid+1, + (int)(unsigned char)keyuserid[0]); /* Add time and class data */ - MD_addbuffer (&MD, mdextras, mdlen, digest); /* Finish message digest */ + MD_addbuffer (&MD, mdextras, mdlen, digest); /* Finish message + digest */ /* now compare computed MD with claimed MD */ /* Assume MSB external byte ordering */ if (!equal_buffers(digest, outbuf, 16)) return -20; /* BAD SIGNATURE */ - convert_byteorder(timestamp,4); /* convert timestamp from external form */ - memcpy (xtimestamp, timestamp, 4); /* Return signature timestamp */ + convert_byteorder(timestamp,4); /* convert timestamp from external + form */ + memcpy (xtimestamp, timestamp, 4); /* Return signature timestamp */ return 0; /* normal return */ badcert: /* Bad packet. Complain. */ - fprintf(pgpout,LANG("\n\007Error: Badly-formed or corrupted signature certificate.\n")); + fprintf(pgpout, +LANG("\n\007Error: Badly-formed or corrupted signature certificate.\n")); return -10; } /* check_key_sig */ - - /*======================================================================*/ static int squish_and_idea_file(byte *ideakey, FILE *f, FILE *g, boolean attempt_compression) @@ -1884,20 +2030,24 @@ static int squish_and_idea_file(byte *id t = f; /* skip compression attempt */ else /* attempt compression-- get a tempfile */ if ((tempf = tempfile(TMP_TMPDIR|TMP_WIPE)) == NULL || - (t = fopen(tempf, FOPWPBIN)) == NULL) /* error: no tempfile */ + (t = fopen(tempf, FOPWPBIN)) == NULL) + /* error: no tempfile */ t = f; /* skip compression attempt */ else /* attempt compression */ { extern int zipup( FILE *, FILE * ); - if (verbose) fprintf(pgpout,"\nCompressing [%s] ", plainfile); + if (verbose) fprintf(pgpout, +"\nCompressing [%s] ", plainfile); /* We don't put a length field on CTB_COMPRESSED yet */ - putc(CTB_COMPRESSED, t); /* write CTB_COMPRESSED */ - /* No CTB packet length specified means indefinite length. */ - putc(ZIP2_ALGORITHM_BYTE, t); /* write ZIP algorithm byte */ + putc(CTB_COMPRESSED, t); /* write CTB_COMPRESSED */ + /* No CTB packet length specified + means indefinite length. */ + putc(ZIP2_ALGORITHM_BYTE, t); /* write ZIP algorithm + byte */ /* Compression the file */ zipup( f, t); @@ -1936,7 +2086,6 @@ static int squish_and_idea_file(byte *id } /* squish_and_idea_file */ - int squish_file(char *infile, char *outfile) { FILE *f, *g; @@ -1954,7 +2103,8 @@ int squish_file(char *infile, char *outf /* open file g for write, in binary (not text) mode...*/ if ((g = fopen( outfile, FOPWBIN )) == NULL) { - fprintf(pgpout,LANG("\n\007Can't create compressed file '%s'\n"), outfile ); + fprintf(pgpout, +LANG("\n\007Can't create compressed file '%s'\n"), outfile ); fclose(f); return -1; } @@ -1992,18 +2142,21 @@ int idea_encryptfile(char *infile, char struct hashedpw *hpw; if (verbose) - fprintf(pgpout,"idea_encryptfile: infile = '%s', outfile = '%s'\n", + fprintf(pgpout, +"idea_encryptfile: infile = '%s', outfile = '%s'\n", infile,outfile); /* open file f for read, in binary (not text) mode...*/ if ((f = fopen( infile, FOPRBIN )) == NULL) { - fprintf(pgpout,LANG("\n\007Can't open plaintext file '%s'\n"), infile ); + fprintf(pgpout, +LANG("\n\007Can't open plaintext file '%s'\n"), infile ); return -1; } /* open file g for write, in binary (not text) mode...*/ if ((g = fopen( outfile, FOPWBIN )) == NULL) { - fprintf(pgpout,LANG("\n\007Can't create ciphertext file '%s'\n"), outfile ); + fprintf(pgpout, +LANG("\n\007Can't create ciphertext file '%s'\n"), outfile ); fclose(f); return -1; } @@ -2017,8 +2170,10 @@ int idea_encryptfile(char *infile, char free(hpw); } else { if (!quietmode) - fprintf(pgpout,LANG("\nYou need a pass phrase to encrypt the file. ")); - if (batchmode || GetHashedPassPhrase((char *)ideakey,NOECHO2) <= 0) + fprintf(pgpout, +LANG("\nYou need a pass phrase to encrypt the file. ")); + if (batchmode + || GetHashedPassPhrase((char *)ideakey,NOECHO2) <= 0) { fclose(f); fclose(g); @@ -2033,7 +2188,8 @@ int idea_encryptfile(char *infile, char make_random_ideakey(ideakey, 16); if (!quietmode) { - fprintf(pgpout,LANG("Just a moment...")); /* this may take a while */ + fprintf(pgpout, +LANG("Just a moment...")); /* this may take a while */ fflush(pgpout); } @@ -2053,7 +2209,6 @@ int idea_encryptfile(char *infile, char } /* idea_encryptfile */ - /*======================================================================*/ static byte (*keyID_list)[KEYFRAGSIZE] = NULL; @@ -2099,14 +2254,16 @@ int encryptfile(char **mcguffins, char * /* open file f for read, in binary (not text) mode...*/ if ((f = fopen( infile, FOPRBIN )) == NULL) { - fprintf(pgpout,LANG("\n\007Can't open plaintext file '%s'\n"), infile ); + fprintf(pgpout, +LANG("\n\007Can't open plaintext file '%s'\n"), infile ); return -1; } /* open file g for write, in binary (not text) mode...*/ if ((g = fopen( outfile, FOPWBIN )) == NULL) { - fprintf(pgpout,LANG("\n\007Can't create ciphertext file '%s'\n"), outfile ); + fprintf(pgpout, +LANG("\n\007Can't create ciphertext file '%s'\n"), outfile ); fclose(f); return -1; } @@ -2134,11 +2291,13 @@ int encryptfile(char **mcguffins, char * struct MD5Context MD; MD5Init(&MD); - MDfile0_len(&MD, f, 4096); /* Ignore errors - what could be done? */ + MDfile0_len(&MD, f, 4096); /* Ignore errors - what could be + done? */ MD5Final(md5buf, &MD); already_have_md5 = 1; - fseek(f, 0, SEEK_SET); /* Get back to the beginning for encryption */ + fseek(f, 0, SEEK_SET); /* Get back to the beginning for + encryption */ } ckp_length = make_random_ideakey(ideakey, 0); @@ -2219,7 +2378,6 @@ int encryptfile(char **mcguffins, char * return 0; } /* encryptfile */ - static int encryptkeyintofile(FILE *g, char *mcguffin, byte *keybuf, char *keyfile, int ckp_length, int keys_used) { @@ -2228,7 +2386,8 @@ encryptkeyintofile(FILE *g, char *mcguff byte keyID[KEYFRAGSIZE]; byte inbuf[MAX_BYTE_PRECISION]; byte outbuf[MAX_BYTE_PRECISION]; - word32 tstamp; byte *timestamp = (byte *) &tstamp; /* key certificate timestamp */ + word32 tstamp; byte *timestamp = (byte *) &tstamp; /* key certificate + timestamp */ byte userid[256]; long fp; int blocksize; @@ -2247,10 +2406,12 @@ encryptkeyintofile(FILE *g, char *mcguff * for a keyfile if its not in the default. */ - if (getpublickey((quietmode?0:GPK_SHOW)|GPK_NORVK, keyfile, &fp, NULL, NULL, + if (getpublickey((quietmode?0:GPK_SHOW)|GPK_NORVK, + keyfile, &fp, NULL, NULL, timestamp, userid, n, e) < 0) { - fprintf(pgpout, LANG("\n\007Cannot find the public key matching userid '%s'\n\ + fprintf(pgpout, +LANG("\n\007Cannot find the public key matching userid '%s'\n\ This user will not be able to decrypt this message.\n"), LOCAL_CHARSET(mcguffin)); continue; @@ -2264,7 +2425,8 @@ This user will not be able to decrypt th } if (keyp < keyID_list + keys_used) { - /* This key was already specified. Quietly ignore it. */ + /* This key was already specified. + Quietly ignore it. */ continue; } @@ -2289,7 +2451,8 @@ This user will not be able to decrypt th /* size of a plaintext block */ if (blocksize < 31) { - fprintf(pgpout,"\n\007Error: RSA key length must be at least 256 bits.\n"); + fprintf(pgpout, +"\n\007Error: RSA key length must be at least 256 bits.\n"); fprintf(pgpout, "Skipping userid %s\n", mcguffin); continue; } @@ -2303,17 +2466,22 @@ This user will not be able to decrypt th fprintf(pgpout, "%02X ", keybuf[i]); fprintf(pgpout, "\n"); #endif - i = rsa_public_encrypt((unitptr)outbuf, keybuf, ckp_length, e, n); + i = rsa_public_encrypt((unitptr)outbuf, keybuf, + ckp_length, e, n); if (i < 0) { if (i == -4) { - fprintf(pgpout,"\n\007Error: RSA key length must be at least 256 bits.\n"); + fprintf(pgpout, +"\n\007Error: RSA key length must be at least 256 bits.\n"); } else if (i == -3) { - fputs(LANG("\a\nError: key is too large. RSA keys may be no longer than 1024 bits,\n\ -due to limitations imposed by software provided by RSADSI.\n"), pgpout); + fputs( +LANG("\a\nError: key is too large. RSA keys may be no longer than 1024 \ +bits,\ndue to limitations imposed by software provided by RSADSI.\n"), pgpout); } else { - fprintf(pgpout, "\a\nUnexpected error %d encrypting\n", i); + fprintf(pgpout, +"\a\nUnexpected error %d encrypting\n", i); } - fprintf(pgpout, LANG("Skipping userid %s\n"), mcguffin); + fprintf(pgpout, +LANG("Skipping userid %s\n"), mcguffin); continue; } @@ -2349,11 +2517,12 @@ due to limitations imposed by software p } /* encryptkeyintofile */ /*======================================================================*/ -int make_literal(char *infile, char *outfile, char lit_mode, char *literalfile) + /* * Prepend a CTB_LITERAL prefix to a file. Convert to canonical form if * lit_mode is MODE_TEXT. */ +int make_literal(char *infile, char *outfile, char lit_mode, char *literalfile) { char lfile[MAX_PATH]; FILE *f; @@ -2368,7 +2537,8 @@ int make_literal(char *infile, char *out word32 dummystamp = 0; if (verbose) - fprintf(pgpout,"make_literal: infile = %s, outfile = %s, mode = '%c', literalfile = '%s'\n", + fprintf(pgpout, +"make_literal: infile = %s, outfile = %s, mode = '%c', literalfile = '%s'\n", infile,outfile,lit_mode,literalfile); /* open file f for read, in binary or text mode...*/ @@ -2376,7 +2546,8 @@ int make_literal(char *infile, char *out #ifdef VMS if (lit_mode == MODE_LOCAL) { if (!(fdl_generate(infile, &fdl, &fdl_len ) & 01)) { - fprintf(pgpout,LANG("\n\007Can't open input plaintext file '%s'\n"),infile); + fprintf(pgpout, +LANG("\n\007Can't open input plaintext file '%s'\n"),infile); return -1; } } @@ -2386,14 +2557,16 @@ int make_literal(char *infile, char *out else f = fopen(infile, FOPRBIN); if (f == NULL) { - fprintf(pgpout,LANG("\n\007Can't open input plaintext file '%s'\n"),infile); + fprintf(pgpout, +LANG("\n\007Can't open input plaintext file '%s'\n"),infile); return -1; } flen = fsize(f); /* open file g for write, in binary (not text) mode... */ if ((g = fopen( outfile,FOPWBIN )) == NULL) { - fprintf(pgpout, LANG("\n\007Can't create plaintext file '%s'\n"), outfile ); + fprintf(pgpout, +LANG("\n\007Can't create plaintext file '%s'\n"), outfile ); goto err1; } @@ -2417,7 +2590,8 @@ int make_literal(char *infile, char *out write_ctb_len (g, LIT_TYPE, LENGTH_FIELD, FALSE); #ifdef VMS else if (lit_mode == MODE_LOCAL) - write_ctb_len (g, CTB_LITERAL2_TYPE, flen + fdl_len + sizeof(fdl_len) + 6, TRUE); + write_ctb_len (g, CTB_LITERAL2_TYPE, flen + + fdl_len + sizeof(fdl_len) + 6, TRUE); #endif /* VMS */ else /* Will put in size field later for text mode */ write_ctb_len (g, LIT_TYPE, 0L, TRUE); @@ -2445,7 +2619,8 @@ int make_literal(char *infile, char *out if ((lit_mode == MODE_BINARY) || (lit_mode == MODE_LOCAL)) { if (copyfile( f, g, -1L )) { - fprintf(pgpout,"\n\007Unable to append to literal plaintext file"); + fprintf(pgpout, +"\n\007Unable to append to literal plaintext file"); perror("\n"); fclose(g); goto err1; @@ -2474,10 +2649,8 @@ err1: #undef LENGTH_FIELD #undef LIT_TYPE - /*======================================================================*/ -int strip_literal(char *infile, char *outfile, char *preserved_name, - char *lit_mode) + /* * Strip off literal prefix from infile, copying to outfile. * Get lit_mode and literalfile info from @@ -2487,6 +2660,8 @@ int strip_literal(char *infile, char *ou * If lit_mode is MODE_TEXT, convert from canonical form as we * copy the data. */ +int strip_literal(char *infile, char *outfile, char *preserved_name, + char *lit_mode) { byte ctb; /* Cipher Type Byte */ FILE *f; @@ -2510,7 +2685,8 @@ int strip_literal(char *infile, char *ou /* open file f for read, in binary (not text) mode...*/ if ((f = fopen(infile,FOPRBIN)) == NULL) { - fprintf(pgpout,LANG("\n\007Can't open input plaintext file '%s'\n"),infile); + fprintf(pgpout, +LANG("\n\007Can't open input plaintext file '%s'\n"),infile); return -1; } @@ -2520,7 +2696,8 @@ int strip_literal(char *infile, char *ou is_ctb_type(ctb,CTB_LITERAL2_TYPE))) { /* debug message in English only -- something got corrupted */ - fprintf(pgpout,"\n\007'%s' is not a literal plaintext file.\n",infile); + fprintf(pgpout, +"\n\007'%s' is not a literal plaintext file.\n",infile); fclose(f); return -1; } @@ -2543,7 +2720,8 @@ int strip_literal(char *infile, char *ou litfile[0] = 0; fread (litfile,1,1,f); if (is_ctb_type(ctb, CTB_LITERAL2_TYPE)) { - /* subtract header length: namelength + lengthbyte + modebyte + stamp */ + /* subtract header length: namelength + + lengthbyte + modebyte + stamp */ LITlength -= litfile[0] + 2 + sizeof(dummystamp); } /* Use litfile if it's writeable and he didn't say an outfile */ @@ -2558,7 +2736,8 @@ int strip_literal(char *infile, char *ou if (litfile[0]) { PascalToC( (char *)litfile ); if (verbose) - fprintf(pgpout, LANG("Original plaintext file name was: '%s'\n"), litfile); + fprintf(pgpout, +LANG("Original plaintext file name was: '%s'\n"), litfile); if (preserved_name) strcpy(preserved_name, (char *) litfile); } @@ -2571,12 +2750,15 @@ int strip_literal(char *infile, char *ou #endif if (LOCAL_TEST) { #ifdef VMS - remove(outfile); /* Prevent litter, we recreate the file with correct chars. */ + remove(outfile); /* Prevent litter, we recreate + the file with correct chars. */ fread(&fdl_len, 2, 1, f); fdl = (char *) malloc(fdl_len); fread(fdl, 1, fdl_len, f); - if ((g = fdl_create( fdl, fdl_len, outfile, (char *) litfile)) == NULL) { - fprintf(pgpout,"\n\007Unable to create file %s\n", outfile); + if ((g = fdl_create( fdl, fdl_len, outfile, + (char *) litfile)) == NULL) { + fprintf(pgpout, +"\n\007Unable to create file %s\n", outfile); return -1; } free(fdl); @@ -2585,7 +2767,8 @@ int strip_literal(char *infile, char *ou LITlength -= (fdl_len + sizeof(fdl_len)); #endif /* VMS */ } else { - fprintf(pgpout,"\n\007Unrecognised local binary type %s\n",org_sys); + fprintf(pgpout, +"\n\007Unrecognised local binary type %s\n",org_sys); return -1; } } else { @@ -2595,9 +2778,11 @@ int strip_literal(char *infile, char *ou if (*lit_mode==MODE_LOCAL) { #ifdef VMS - if (status = fdl_copyfile2bin( f, g, LITlength)) { /* Copy ok? */ + if (status = fdl_copyfile2bin( f, g, LITlength)) { + /* Copy ok? */ if (status > 0) - fprintf(stderr,"\n...copying to literal file\n"); + fprintf(stderr, +"\n...copying to literal file\n"); else perror("\nError copying from work file"); fdl_close(g); @@ -2611,7 +2796,8 @@ int strip_literal(char *infile, char *ou else g = fopen(outfile, FOPWBIN); if (g == NULL) { - fprintf(pgpout, LANG("\n\007Can't create plaintext file '%s'\n"), outfile ); + fprintf(pgpout, +LANG("\n\007Can't create plaintext file '%s'\n"), outfile ); goto err1; } /* copy rest of literal plaintext file */ @@ -2637,10 +2823,8 @@ err1: } /* strip_literal */ - /*======================================================================*/ - int decryptfile(char *infile, char *outfile) { byte ctb; /* Cipher Type Byte */ @@ -2648,12 +2832,15 @@ int decryptfile(char *infile, char *outf FILE *f; FILE *g; int count = 0, status, thiskey, gotkey, end_of_pkes; - unit n[MAX_UNIT_PRECISION], e[MAX_UNIT_PRECISION], d[MAX_UNIT_PRECISION]; - unit p[MAX_UNIT_PRECISION], q[MAX_UNIT_PRECISION], u[MAX_UNIT_PRECISION]; + unit n[MAX_UNIT_PRECISION], e[MAX_UNIT_PRECISION]; + unit d[MAX_UNIT_PRECISION]; + unit p[MAX_UNIT_PRECISION], q[MAX_UNIT_PRECISION]; + unit u[MAX_UNIT_PRECISION]; byte inbuf[MAX_BYTE_PRECISION]; byte outbuf[MAX_BYTE_PRECISION]; byte keyID[KEYFRAGSIZE]; - word32 tstamp; byte *timestamp = (byte *) &tstamp; /* key certificate timestamp */ + word32 tstamp; byte *timestamp = (byte *) &tstamp; /* key certificate + timestamp */ byte userid[256]; word32 flen; word32 fpos = 0; @@ -2671,7 +2858,8 @@ int decryptfile(char *infile, char *outf /* open file f for read, in binary (not text) mode...*/ if ((f = fopen(infile,FOPRBIN)) == NULL) { - fprintf(pgpout,LANG("\n\007Can't open ciphertext file '%s'\n"),infile); + fprintf(pgpout, +LANG("\n\007Can't open ciphertext file '%s'\n"),infile); return -1; } @@ -2697,7 +2885,8 @@ int decryptfile(char *infile, char *outf fread(&ctb,1,1,f); /* read Cipher Type Byte */ if (!is_ctb(ctb)) { - fprintf(pgpout,LANG("\n\007'%s' is not a cipher file.\n"),infile); + fprintf(pgpout, +LANG("\n\007'%s' is not a cipher file.\n"),infile); fclose(f); return -1; } @@ -2776,15 +2965,20 @@ int decryptfile(char *infile, char *outf e, d, p, q, u, n); if (count < 0) { if (count == -3) { - fputs(LANG("\a\nError: key is too large. RSA keys may be no longer than 1024 bits,\n\ -due to limitations imposed by software provided by RSADSI.\n"), pgpout); + fputs( +LANG("\a\nError: key is too large. RSA keys may be no longer than 1024 bits\ +,\ndue to limitations imposed by software provided by RSADSI.\n"), pgpout); } else if (count == -9 || count == -7) { - fprintf(pgpout, LANG("\n\007Error: RSA-decrypted block is corrupted.\n\ -This may be caused either by corrupted data or by using the wrong RSA key.\n")); + fprintf(pgpout, +LANG("\n\007Error: RSA-decrypted block is corrupted.\n\ +This may be caused either by corrupted data or by using the wrong RSA key.\n\ +")); } else if (count == -5) { - fprintf(pgpout, LANG("\n\007Error: RSA block is possibly malformed. Old format, maybe?\n")); + fprintf(pgpout, +LANG("\n\007Error: RSA block is possibly malformed. Old format, maybe?\n")); } else { - fprintf(pgpout, "\a\nUnexpected error %d decrypting\n", count); + fprintf(pgpout, +"\a\nUnexpected error %d decrypting\n", count); } fclose(f); return count; @@ -2808,11 +3002,13 @@ This may be caused either by corrupted d if (gotkey) /* verbose flag */ fprintf(pgpout,"\nRecipients:\n"); else - fprintf(pgpout,LANG("\nThis message can only be read by:\n")); + fprintf(pgpout, +LANG("\nThis message can only be read by:\n")); for (nkey = nkeys; nkey; nkey = nkey->next) { if ((user = user_from_keyID(nkey->keyID)) == NULL) - fprintf(pgpout, " keyID: %s\n", keyIDstring(nkey->keyID)); + fprintf(pgpout, +" keyID: %s\n", keyIDstring(nkey->keyID)); else fprintf(pgpout, " %s\n", LOCAL_CHARSET(user)); } @@ -2833,7 +3029,8 @@ This may be caused either by corrupted d set_precision(realprecision); /* reset the precision */ } else { /* No secret key, exit gracefully (NOT!) */ - fprintf(pgpout, LANG("\n\007You do not have the secret key needed to decrypt this file.\n")); + fprintf(pgpout, +LANG("\n\007You do not have the secret key needed to decrypt this file.\n")); fclose(f); return -1; } @@ -2850,8 +3047,10 @@ This may be caused either by corrupted d /* Assume MSB external byte ordering */ chksum = fetch_word16(outbuf+1+count); if (chksum != checksum(outbuf+1, count)) { - fprintf(pgpout,LANG("\n\007Error: RSA-decrypted block is corrupted.\n\ -This may be caused either by corrupted data or by using the wrong RSA key.\n")); + fprintf(pgpout, +LANG("\n\007Error: RSA-decrypted block is corrupted.\n\ +This may be caused either by corrupted data or by using the wrong RSA key.\n\ +")); fclose(f); return -1; } @@ -2862,7 +3061,8 @@ This may be caused either by corrupted d /* open file g for write, in binary (not text) mode... */ if ((g = fopen( outfile, FOPWBIN )) == NULL) { - fprintf(pgpout, LANG("\n\007Can't create plaintext file '%s'\n"), outfile ); + fprintf(pgpout, +LANG("\n\007Can't create plaintext file '%s'\n"), outfile ); goto err1; } @@ -2879,7 +3079,8 @@ This may be caused either by corrupted d /* Assume MSB external byte ordering */ status = idea_file( outbuf+1, DECRYPT_IT, f, g, flen ); if (status < 0) { - fprintf(pgpout,LANG("\n\007Error: Decrypted plaintext is corrupted.\n")); + fprintf(pgpout, +LANG("\n\007Error: Decrypted plaintext is corrupted.\n")); } if (!quietmode) fputc('.',pgpout); /* show progress */ @@ -2898,7 +3099,8 @@ This may be caused either by corrupted d mp_burn(u); /* burn sensitive data on stack */ if (status < 0) /* if idea_file failed, then error return */ return status; - return 1; /* always indicate output file has nested stuff in it. */ + return 1; /* always indicate output file has + nested stuff in it. */ err1: fclose(f); @@ -2912,8 +3114,6 @@ err1: } /* decryptfile */ - - int idea_decryptfile(char *infile, char *outfile) { byte ctb; /* Cipher Type Byte */ @@ -2930,13 +3130,15 @@ int idea_decryptfile(char *infile, char /* open file f for read, in binary (not text) mode...*/ if ((f = fopen(infile,FOPRBIN)) == NULL) { - fprintf(pgpout,LANG("\n\007Can't open ciphertext file '%s'\n"),infile); + fprintf(pgpout, +LANG("\n\007Can't open ciphertext file '%s'\n"),infile); return -1; } /* open file g for write, in binary (not text) mode... */ if ((g = fopen( outfile, FOPWBIN )) == NULL) { - fprintf(pgpout, LANG("\n\007Can't create plaintext file '%s'\n"), outfile ); + fprintf(pgpout, +LANG("\n\007Can't create plaintext file '%s'\n"), outfile ); goto err1; } @@ -2946,7 +3148,8 @@ int idea_decryptfile(char *infile, char do /* while pass phrase is bad */ { - fread(&ctb,1,1,f); /* read Cipher Type Byte, should be CTB_CKE */ + fread(&ctb,1,1,f); /* read Cipher Type Byte, + should be CTB_CKE */ if (!is_ctb(ctb) || !is_ctb_type(ctb,CTB_CKE_TYPE)) { /* Should never get here. */ @@ -2961,8 +3164,11 @@ int idea_decryptfile(char *infile, char /* first try environment passwords */ memcpy(ideakey, hpw->hash, sizeof(ideakey)); } else { - fprintf(pgpout,LANG("\nYou need a pass phrase to decrypt this file. ")); - if (batchmode || GetHashedPassPhrase((char *)ideakey,NOECHO1) <= 0) + fprintf(pgpout, +LANG("\nYou need a pass phrase to decrypt this file. ")); + if (batchmode + || GetHashedPassPhrase((char *)ideakey,NOECHO1) + <= 0) { fclose(f); fclose(g); @@ -2971,7 +3177,8 @@ int idea_decryptfile(char *infile, char } if (!quietmode) { - fprintf(pgpout,LANG("Just a moment...")); /* this may take a while */ + fprintf(pgpout,LANG("Just a moment...")); + /* this may take a while */ fflush(pgpout); } @@ -2991,7 +3198,8 @@ int idea_decryptfile(char *infile, char hpw = *hpwp; } else { ++retries; - fprintf(pgpout,LANG("\n\007Error: Bad pass phrase.\n")); + fprintf(pgpout, +LANG("\n\007Error: Bad pass phrase.\n")); } rewind(f); @@ -3016,7 +3224,8 @@ int idea_decryptfile(char *infile, char } if (!quietmode) fprintf(pgpout,LANG("Pass phrase appears good. ")); - return 1; /* always indicate output file has nested stuff in it. */ + return 1; /* always indicate output file has + nested stuff in it. */ err1: fclose(f); @@ -3024,8 +3233,6 @@ err1: } /* idea_decryptfile */ - - int decompress_file(char *infile, char *outfile) { byte ctb; @@ -3037,7 +3244,8 @@ int decompress_file(char *infile, char * /* open file f for read, in binary (not text) mode...*/ if ((f = fopen(infile,FOPRBIN)) == NULL) { - fprintf(pgpout,LANG("\n\007Can't open compressed file '%s'\n"),infile); + fprintf(pgpout, +LANG("\n\007Can't open compressed file '%s'\n"),infile); return -1; } @@ -3051,24 +3259,28 @@ int decompress_file(char *infile, char * getpastlength(ctb, f); /* read packet length */ /* The packet length is ignored. Assume it's huge. */ - fread(&ctb,1,1,f); /* read and skip over compression algorithm byte */ + fread(&ctb,1,1,f); /* read and skip over compression + algorithm byte */ if (ctb != ZIP2_ALGORITHM_BYTE) { /* We only know how to uncompress deflate-compressed data. We may hit imploded or Lharc'ed data but treat it as an error just the same */ - fprintf(pgpout,LANG("\007\nUnrecognized compression algorithm.\n\ + fprintf(pgpout, +LANG("\007\nUnrecognized compression algorithm.\n\ This may require a newer version of PGP.\n")); goto err1; /* Abandon ship! */ } /* open file g for write, in binary (not text) mode... */ if ((g = fopen( outfile, FOPWBIN )) == NULL) { - fprintf(pgpout, LANG("\n\007Can't create decompressed file '%s'\n"), outfile ); + fprintf(pgpout, +LANG("\n\007Can't create decompressed file '%s'\n"), outfile ); goto err1; } if (unzip( f, g )) { - fprintf(pgpout,LANG("\n\007Decompression error. Probable corrupted input.\n")); + fprintf(pgpout, +LANG("\n\007Decompression error. Probable corrupted input.\n")); goto err2; } @@ -3082,7 +3294,8 @@ This may require a newer version of PGP. fclose(g); fclose(f); - return 1; /* always indicate output file has nested stuff in it. */ + return 1; /* always indicate output file + has nested stuff in it. */ err2: fclose(g); @@ -3091,4 +3304,3 @@ err1: return -1; /* error return */ } /* decompress_file */ -