md5.c (22990) | md5.c (32074) |
---|---|
1/* | 1/* |
2 * $Id$ | 2 * $Id: md5.c,v 1.10 1997/02/22 14:32:37 peter Exp $ |
3 * 4 * Derived from: 5 */ 6 7/* 8 * MDDRIVER.C - test driver for MD2, MD4 and MD5 9 */ 10 --- 11 unchanged lines hidden (view full) --- 22 */ 23 24#include <sys/types.h> 25#include <md5.h> 26 27#include <stdio.h> 28#include <string.h> 29#include <time.h> | 3 * 4 * Derived from: 5 */ 6 7/* 8 * MDDRIVER.C - test driver for MD2, MD4 and MD5 9 */ 10 --- 11 unchanged lines hidden (view full) --- 22 */ 23 24#include <sys/types.h> 25#include <md5.h> 26 27#include <stdio.h> 28#include <string.h> 29#include <time.h> |
30#include <unistd.h> |
|
30 31#include "global.h" 32 33/* 34 * Length of test block, number of test blocks. 35 */ 36#define TEST_BLOCK_LEN 1000 37#define TEST_BLOCK_COUNT 1000 38 39static void MDString PROTO_LIST((char *)); 40static void MDTimeTrial PROTO_LIST((void)); 41static void MDTestSuite PROTO_LIST((void)); 42static void MDFilter PROTO_LIST((int)); | 31 32#include "global.h" 33 34/* 35 * Length of test block, number of test blocks. 36 */ 37#define TEST_BLOCK_LEN 1000 38#define TEST_BLOCK_COUNT 1000 39 40static void MDString PROTO_LIST((char *)); 41static void MDTimeTrial PROTO_LIST((void)); 42static void MDTestSuite PROTO_LIST((void)); 43static void MDFilter PROTO_LIST((int)); |
44static void usage PROTO_LIST((void)); |
|
43 44/* Main driver. 45 46Arguments (may be any combination): 47 -sstring - digests string 48 -t - runs time trial 49 -x - runs test script 50 filename - digests file 51 (none) - digests standard input 52 */ 53int 54main(argc, argv) 55 int argc; 56 char *argv[]; 57{ 58 int i; 59 char *p; 60 char buf[33]; 61 | 45 46/* Main driver. 47 48Arguments (may be any combination): 49 -sstring - digests string 50 -t - runs time trial 51 -x - runs test script 52 filename - digests file 53 (none) - digests standard input 54 */ 55int 56main(argc, argv) 57 int argc; 58 char *argv[]; 59{ 60 int i; 61 char *p; 62 char buf[33]; 63 |
62 if (argc > 1) 63 for (i = 1; i < argc; i++) 64 if (argv[i][0] == '-' && argv[i][1] == 's') 65 MDString(argv[i] + 2); 66 else if (strcmp(argv[i], "-t") == 0) 67 MDTimeTrial(); 68 else if (strcmp(argv[i], "-p") == 0) | 64 if (argc > 1) { 65 while ((i = getopt(argc, argv, "ps:tx")) != EOF) { 66 switch (i) { 67 case 'p': |
69 MDFilter(1); | 68 MDFilter(1); |
70 else if (strcmp(argv[i], "-x") == 0) | 69 break; 70 case 's': 71 MDString(optarg); 72 break; 73 case 't': 74 MDTimeTrial(); 75 break; 76 case 'x': |
71 MDTestSuite(); | 77 MDTestSuite(); |
72 else { 73 p = MD5File(argv[i],buf); 74 if (!p) 75 perror(argv[i]); 76 else 77 printf("MD5 (%s) = %s\n", argv[i], p); | 78 break; 79 default: 80 usage(); |
78 } | 81 } |
79 else | 82 } 83 while (optind < argc) { 84 p = MD5File(argv[optind], buf); 85 if (!p) 86 perror(argv[optind]); 87 else 88 printf("MD5 (%s) = %s\n", argv[optind], p); 89 optind++; 90 } 91 } else |
80 MDFilter(0); 81 82 return (0); 83} 84/* 85 * Digests a string and prints the result. 86 */ 87static void --- 69 unchanged lines hidden (view full) --- 157/* 158 * Digests the standard input and prints the result. 159 */ 160static void 161MDFilter(int pipe) 162{ 163 MD5_CTX context; 164 int len; | 92 MDFilter(0); 93 94 return (0); 95} 96/* 97 * Digests a string and prints the result. 98 */ 99static void --- 69 unchanged lines hidden (view full) --- 169/* 170 * Digests the standard input and prints the result. 171 */ 172static void 173MDFilter(int pipe) 174{ 175 MD5_CTX context; 176 int len; |
165 unsigned char buffer[BUFSIZ], digest[16]; | 177 unsigned char buffer[BUFSIZ]; |
166 char buf[33]; 167 168 MD5Init(&context); | 178 char buf[33]; 179 180 MD5Init(&context); |
169 while (len = fread(buffer, 1, BUFSIZ, stdin)) { | 181 while ((len = fread(buffer, 1, BUFSIZ, stdin))) { |
170 if(pipe && (len != fwrite(buffer, 1, len, stdout))) { 171 perror("stdout"); 172 exit(1); 173 } 174 MD5Update(&context, buffer, len); 175 } 176 printf("%s\n", MD5End(&context,buf)); 177} | 182 if(pipe && (len != fwrite(buffer, 1, len, stdout))) { 183 perror("stdout"); 184 exit(1); 185 } 186 MD5Update(&context, buffer, len); 187 } 188 printf("%s\n", MD5End(&context,buf)); 189} |
190 191/* 192 * Displays a usage summary. 193 */ 194static void 195usage(void) 196{ 197 (void)fprintf(stderr, 198 "usage: md5 [-ptx] [-s string] [file ...]\n"); 199 exit(1); 200} |
|