--- pgp/src/mdfile.c 2018/04/24 16:39:05 1.1.1.3 +++ pgp/src/mdfile.c 2018/04/24 16:42:02 1.1.1.6 @@ -1,21 +1,22 @@ /* mdfile.c - Message Digest routines for PGP. PGP: Pretty Good(tm) Privacy - public key cryptography for the masses. - (c) Copyright 1990-1992 by Philip Zimmermann. All rights reserved. + (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. - All the source code Philip Zimmermann wrote for PGP is available for - free under the "Copyleft" General Public License from the Free - Software Foundation. A copy of that license agreement is included in - the source release package of PGP. Code developed by others for PGP - is also freely available. Other code that has been incorporated into - PGP from other sources was either originally published in the public - domain or was used with permission from the various authors. See the - PGP User's Guide for more complete information about licensing, - patent restrictions on certain algorithms, trademarks, copyrights, - and export controls. + 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. */ #include @@ -35,66 +36,70 @@ /* Computes the message digest for a file from current position for longcount bytes. Uses the RSA Data Security Inc. MD5 Message Digest Algorithm */ -int MDfile0_len(MD5_CTX *mdContext, FILE *f, word32 longcount) -{ int bytecount; +int MDfile0_len(struct MD5Context *mdContext, FILE *f, word32 longcount) +{ + int bytecount; unsigned char buffer[1024]; MD5Init(mdContext); /* Process 1024 bytes at a time... */ - do - { + do { if (longcount < (word32) 1024) bytecount = (int)longcount; else bytecount = 1024; bytecount = fread(buffer, 1, bytecount, f); - if (bytecount>0) - { MD5Update(mdContext, buffer, bytecount); + if (bytecount>0) { + MD5Update(mdContext, buffer, bytecount); longcount -= bytecount; } /* if text block was short, exit loop */ } while (bytecount==1024); - return(0); + return 0; } /* MDfile0_len */ /* Computes the message digest for a file from current position to EOF. Uses the RSA Data Security Inc. MD5 Message Digest Algorithm */ -static int MDfile0(MD5_CTX *mdContext,FILE *inFile) -{ int bytes; +static int MDfile0(struct MD5Context *mdContext,FILE *inFile) +{ + int bytes; unsigned char buffer[1024]; MD5Init(mdContext); while ((bytes = fread(buffer,1,1024,inFile)) != 0) MD5Update(mdContext,buffer,bytes); - return(0); + return 0; } /* Computes the message digest for a specified file */ -int MDfile(MD5_CTX *mdContext,char *filename) +int MDfile(struct MD5Context *mdContext,char *filename) { FILE *inFile; inFile = fopen(filename,FOPRBIN); - if (inFile == NULL) - { fprintf(pgpout,PSTR("\n\007Can't open file '%s'\n"),filename); - return(-1); + if (inFile == NULL) { + fprintf(pgpout,LANG("\n\007Can't open file '%s'\n"),filename); + return -1; } MDfile0(mdContext,inFile); fclose (inFile); - return(0); + return 0; } -/* Finish the MD5 calculation with an extra buffer implicitly appended - * to the data. +/* Add a buffer's worth of data to the MD5 computation. If a digest + * pointer is supplied, complete the computation and write the digest. */ -void MD_addbuffer (MD5_CTX *mdContext, byte *buf, int buflen, boolean finish) +void MD_addbuffer (struct MD5Context *mdContext, byte *buf, int buflen, + byte digest[16]) { MD5Update(mdContext,buf,buflen); - if (finish) - MD5Final(mdContext); + if (digest) { + MD5Final(digest, mdContext); + burn(*mdContext); /* Paranoia */ + } } /* End MD5 routines */