home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 November / PCO_1198.ISO / filesbbs / os2 / fn127os2.arj / FN127OS2.ZIP / fn127os2 / src / md5.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-25  |  3.4 KB  |  108 lines

  1. /* crypto/md/md5.c */
  2. /* Copyright (C) 1995-1996 Eric Young (eay@mincom.oz.au)
  3.  * All rights reserved.
  4.  * 
  5.  * This file is part of an SSL implementation written
  6.  * by Eric Young (eay@mincom.oz.au).
  7.  * The implementation was written so as to conform with Netscapes SSL
  8.  * specification.  This library and applications are
  9.  * FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
  10.  * as long as the following conditions are aheared to.
  11.  * 
  12.  * Copyright remains Eric Young's, and as such any Copyright notices in
  13.  * the code are not to be removed.  If this code is used in a product,
  14.  * Eric Young should be given attribution as the author of the parts used.
  15.  * This can be in the form of a textual message at program startup or
  16.  * in documentation (online or textual) provided with the package.
  17.  * 
  18.  * Redistribution and use in source and binary forms, with or without
  19.  * modification, are permitted provided that the following conditions
  20.  * are met:
  21.  * 1. Redistributions of source code must retain the copyright
  22.  *    notice, this list of conditions and the following disclaimer.
  23.  * 2. Redistributions in binary form must reproduce the above copyright
  24.  *    notice, this list of conditions and the following disclaimer in the
  25.  *    documentation and/or other materials provided with the distribution.
  26.  * 3. All advertising materials mentioning features or use of this software
  27.  *    must display the following acknowledgement:
  28.  *    This product includes software developed by Eric Young (eay@mincom.oz.au)
  29.  * 
  30.  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
  31.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  32.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  34.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  38.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  39.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  40.  * SUCH DAMAGE.
  41.  * 
  42.  * The licence and distribution terms for any publically available version or
  43.  * derivative of this code cannot be changed.  i.e. this code cannot simply be
  44.  * copied and put under another distribution licence
  45.  * [including the GNU Public Licence.]
  46.  */
  47.  
  48. #include <stdio.h>
  49. #include <stdlib.h>
  50. #include "md5_calc.h"
  51.  
  52. static void usage()
  53.     {
  54.     fprintf(stderr, "Usage: md5 [file ...]\n");
  55.     fprintf(stderr, "   or: md5 -r {range} {file ...}\n");
  56.     fprintf(stderr, "range = start[-stop|:len][,range]\n");
  57.     exit(1);
  58.     }
  59.  
  60. int main(argc, argv)
  61. int argc;
  62. char **argv;
  63.     {
  64.     int i,err=0;
  65.     FILE *IN;
  66.     char *p;
  67.     char *r = NULL;
  68.  
  69.     if (argc == 1)
  70.         {
  71.         puts(md5_calc(0, ""));
  72.         }
  73.     else if (argc > 1)
  74.         {
  75.         if (strcmp(argv[1], "/?") == 0)
  76.             usage();
  77.         if (argv[1][0] == '-')
  78.             {
  79.             if (strcmp(argv[1], "-r") != 0)
  80.                 usage();
  81.             if (argc < 4)
  82.                 usage();
  83.  
  84.             r = argv[2];
  85.             argv += 2;
  86.             argc -= 2;
  87.             }
  88.  
  89.         for (i=1; i<argc; i++)
  90.             {
  91.             IN=fopen(argv[i],"rb");
  92.             if (IN == NULL)
  93.                 {
  94.                 perror(argv[i]);
  95.                 err++;
  96.                 continue;
  97.                 }
  98.             p = md5_calc(fileno(IN), r);
  99.             if (r)
  100.                 printf("MD5(%s %s)= %s\n", argv[i], r, p);
  101.             else
  102.                 printf("MD5(%s)= %s\n", argv[i], p);
  103.             fclose(IN);
  104.             }
  105.         }
  106.     exit(err);
  107.     }
  108.