Annotation of pgp/src/mdfile.c, revision 1.1.1.6

1.1.1.6 ! root        1: /*     mdfile.c  - Message Digest routines for PGP.
        !             2:        PGP: Pretty Good(tm) Privacy - public key cryptography for the masses.
        !             3: 
        !             4:        (c) Copyright 1990-1994 by Philip Zimmermann.  All rights reserved.
        !             5:        The author assumes no liability for damages resulting from the use
        !             6:        of this software, even if the damage results from defects in this
        !             7:        software.  No warranty is expressed or implied.
        !             8: 
        !             9:        Note that while most PGP source modules bear Philip Zimmermann's
        !            10:        copyright notice, many of them have been revised or entirely written
        !            11:        by contributors who frequently failed to put their names in their
        !            12:        code.  Code that has been incorporated into PGP from other authors
        !            13:        was either originally published in the public domain or is used with
        !            14:        permission from the various authors.
        !            15: 
        !            16:        PGP is available for free to the public under certain restrictions.
        !            17:        See the PGP User's Guide (included in the release package) for
        !            18:        important information about licensing, patent restrictions on
        !            19:        certain algorithms, trademarks, copyrights, and export controls.
        !            20: */
        !            21: 
        !            22: #include <stdio.h>
        !            23: #include "mpilib.h"
        !            24: #include "mdfile.h"
        !            25: #include "fileio.h"
        !            26: #include "language.h"
        !            27: #include "pgp.h"
        !            28: 
        !            29: /* Begin MD5 routines */
        !            30: 
        !            31: /* Note - the routines in this module, except for MD_addbuffer,
        !            32:  * do not "finish" the MD5 calculation.  MD_addbuffer finishes the
        !            33:  * calculation in each case, usually to append the timestamp and class info.
        !            34:  */
        !            35: 
        !            36: /* Computes the message digest for a file from current position for
        !            37:    longcount bytes.
        !            38:    Uses the RSA Data Security Inc. MD5 Message Digest Algorithm */
        !            39: int MDfile0_len(struct MD5Context *mdContext, FILE *f, word32 longcount)
        !            40: {
        !            41:        int bytecount;
        !            42:        unsigned char buffer[1024];
        !            43: 
        !            44:        MD5Init(mdContext);
        !            45:        /* Process 1024 bytes at a time... */
        !            46:        do {
        !            47:                if (longcount < (word32) 1024)
        !            48:                        bytecount = (int)longcount;
        !            49:                else
        !            50:                        bytecount = 1024;
        !            51:                bytecount = fread(buffer, 1, bytecount, f);
        !            52:                if (bytecount>0) {
        !            53:                        MD5Update(mdContext, buffer, bytecount);
        !            54:                        longcount -= bytecount;
        !            55:                }
        !            56:                /* if text block was short, exit loop */
        !            57:        } while (bytecount==1024);
        !            58:        return 0;
        !            59: }      /* MDfile0_len */
        !            60: 
        !            61: 
        !            62: /* Computes the message digest for a file from current position to EOF.
        !            63:    Uses the RSA Data Security Inc. MD5 Message Digest Algorithm */
        !            64: 
        !            65: static int MDfile0(struct MD5Context *mdContext,FILE *inFile)
        !            66: {
        !            67:        int bytes;
        !            68:        unsigned char buffer[1024];
        !            69: 
        !            70:        MD5Init(mdContext);
        !            71:        while ((bytes = fread(buffer,1,1024,inFile)) != 0)
        !            72:                MD5Update(mdContext,buffer,bytes);
        !            73:        return 0;
        !            74: }
        !            75: 
        !            76: /* Computes the message digest for a specified file */
        !            77: 
        !            78: int MDfile(struct MD5Context *mdContext,char *filename)
        !            79: {
        !            80:        FILE *inFile;
        !            81:        inFile = fopen(filename,FOPRBIN);
        !            82: 
        !            83:        if (inFile == NULL) {
        !            84:                fprintf(pgpout,LANG("\n\007Can't open file '%s'\n"),filename);
        !            85:                return -1;
        !            86:        }
        !            87:        MDfile0(mdContext,inFile);
        !            88:        fclose (inFile);
        !            89:        return 0;
        !            90: }
        !            91: 
        !            92: /* Add a buffer's worth of data to the MD5 computation.  If a digest
        !            93:  * pointer is supplied, complete the computation and write the digest.
        !            94:  */
        !            95: void MD_addbuffer (struct MD5Context *mdContext, byte *buf, int buflen,
        !            96:         byte digest[16])
        !            97: {
        !            98:        MD5Update(mdContext,buf,buflen);
        !            99:        if (digest) {
        !           100:                MD5Final(digest, mdContext);
        !           101:                burn(*mdContext);       /* Paranoia */
        !           102:        }
        !           103: }
        !           104: 
        !           105: /* End MD5 routines */

unix.superglobalmegacorp.com

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