md5.c (32074) | md5.c (32086) |
---|---|
1/* | 1/* |
2 * $Id: md5.c,v 1.10 1997/02/22 14:32:37 peter Exp $ | 2 * $Id: md5.c,v 1.11 1997/12/29 03:40:37 steve Exp $ |
3 * 4 * Derived from: 5 */ 6 7/* 8 * MDDRIVER.C - test driver for MD2, MD4 and MD5 9 */ 10 --- 41 unchanged lines hidden (view full) --- 52 filename - digests file 53 (none) - digests standard input 54 */ 55int 56main(argc, argv) 57 int argc; 58 char *argv[]; 59{ | 3 * 4 * Derived from: 5 */ 6 7/* 8 * MDDRIVER.C - test driver for MD2, MD4 and MD5 9 */ 10 --- 41 unchanged lines hidden (view full) --- 52 filename - digests file 53 (none) - digests standard input 54 */ 55int 56main(argc, argv) 57 int argc; 58 char *argv[]; 59{ |
60 int i; | 60 int ch; |
61 char *p; 62 char buf[33]; 63 64 if (argc > 1) { | 61 char *p; 62 char buf[33]; 63 64 if (argc > 1) { |
65 while ((i = getopt(argc, argv, "ps:tx")) != EOF) { 66 switch (i) { | 65 while ((ch = getopt(argc, argv, "ps:tx")) != -1) { 66 switch (ch) { |
67 case 'p': 68 MDFilter(1); 69 break; 70 case 's': 71 MDString(optarg); 72 break; 73 case 't': 74 MDTimeTrial(); --- 72 unchanged lines hidden (view full) --- 147 (long) TEST_BLOCK_LEN * (long) TEST_BLOCK_COUNT / ((endTime - startTime) != 0 ? (endTime - startTime) : 1)); 148} 149/* 150 * Digests a reference suite of strings and prints the results. 151 */ 152static void 153MDTestSuite() 154{ | 67 case 'p': 68 MDFilter(1); 69 break; 70 case 's': 71 MDString(optarg); 72 break; 73 case 't': 74 MDTimeTrial(); --- 72 unchanged lines hidden (view full) --- 147 (long) TEST_BLOCK_LEN * (long) TEST_BLOCK_COUNT / ((endTime - startTime) != 0 ? (endTime - startTime) : 1)); 148} 149/* 150 * Digests a reference suite of strings and prints the results. 151 */ 152static void 153MDTestSuite() 154{ |
155 |
|
155 printf("MD5 test suite:\n"); 156 157 MDString(""); 158 MDString("a"); 159 MDString("abc"); 160 MDString("message digest"); 161 MDString("abcdefghijklmnopqrstuvwxyz"); 162 MDString 163 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); 164 MDString 165 ("1234567890123456789012345678901234567890\ 1661234567890123456789012345678901234567890"); 167} 168 169/* 170 * Digests the standard input and prints the result. 171 */ 172static void | 156 printf("MD5 test suite:\n"); 157 158 MDString(""); 159 MDString("a"); 160 MDString("abc"); 161 MDString("message digest"); 162 MDString("abcdefghijklmnopqrstuvwxyz"); 163 MDString 164 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); 165 MDString 166 ("1234567890123456789012345678901234567890\ 1671234567890123456789012345678901234567890"); 168} 169 170/* 171 * Digests the standard input and prints the result. 172 */ 173static void |
173MDFilter(int pipe) | 174MDFilter(pipe) 175 int pipe; |
174{ 175 MD5_CTX context; 176 int len; 177 unsigned char buffer[BUFSIZ]; 178 char buf[33]; 179 180 MD5Init(&context); 181 while ((len = fread(buffer, 1, BUFSIZ, stdin))) { 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 | 176{ 177 MD5_CTX context; 178 int len; 179 unsigned char buffer[BUFSIZ]; 180 char buf[33]; 181 182 MD5Init(&context); 183 while ((len = fread(buffer, 1, BUFSIZ, stdin))) { 184 if(pipe && (len != fwrite(buffer, 1, len, stdout))) { 185 perror("stdout"); 186 exit(1); 187 } 188 MD5Update(&context, buffer, len); 189 } 190 printf("%s\n", MD5End(&context,buf)); 191} 192 |
191/* 192 * Displays a usage summary. 193 */ | |
194static void | 193static void |
195usage(void) | 194usage() |
196{ | 195{ |
197 (void)fprintf(stderr, 198 "usage: md5 [-ptx] [-s string] [file ...]\n"); | 196 197 fprintf(stderr, "usage: md5 [-ptx] [-s string] [files ...]\n"); |
199 exit(1); 200} | 198 exit(1); 199} |