md5.c (6562) | md5.c (6725) |
---|---|
1/* | 1/* |
2 * $Id$ | 2 * $Id: md5.c,v 1.2 1995/02/20 00:48:50 phk Exp $ |
3 * 4 * Derived from: 5 */ 6 7/* 8 * MDDRIVER.C - test driver for MD2, MD4 and MD5 9 */ 10 --- 20 unchanged lines hidden (view full) --- 31 * Length of test block, number of test blocks. 32 */ 33#define TEST_BLOCK_LEN 1000 34#define TEST_BLOCK_COUNT 1000 35 36static void MDString PROTO_LIST((char *)); 37static void MDTimeTrial PROTO_LIST((void)); 38static void MDTestSuite PROTO_LIST((void)); | 3 * 4 * Derived from: 5 */ 6 7/* 8 * MDDRIVER.C - test driver for MD2, MD4 and MD5 9 */ 10 --- 20 unchanged lines hidden (view full) --- 31 * Length of test block, number of test blocks. 32 */ 33#define TEST_BLOCK_LEN 1000 34#define TEST_BLOCK_COUNT 1000 35 36static void MDString PROTO_LIST((char *)); 37static void MDTimeTrial PROTO_LIST((void)); 38static void MDTestSuite PROTO_LIST((void)); |
39static void MDFilter PROTO_LIST((void)); | 39static void MDFilter PROTO_LIST((int)); |
40 41/* Main driver. 42 43Arguments (may be any combination): 44 -sstring - digests string 45 -t - runs time trial 46 -x - runs test script 47 filename - digests file --- 8 unchanged lines hidden (view full) --- 56 char *p; 57 58 if (argc > 1) 59 for (i = 1; i < argc; i++) 60 if (argv[i][0] == '-' && argv[i][1] == 's') 61 MDString(argv[i] + 2); 62 else if (strcmp(argv[i], "-t") == 0) 63 MDTimeTrial(); | 40 41/* Main driver. 42 43Arguments (may be any combination): 44 -sstring - digests string 45 -t - runs time trial 46 -x - runs test script 47 filename - digests file --- 8 unchanged lines hidden (view full) --- 56 char *p; 57 58 if (argc > 1) 59 for (i = 1; i < argc; i++) 60 if (argv[i][0] == '-' && argv[i][1] == 's') 61 MDString(argv[i] + 2); 62 else if (strcmp(argv[i], "-t") == 0) 63 MDTimeTrial(); |
64 else if (strcmp(argv[i], "-p") == 0) 65 MDFilter(1); |
|
64 else if (strcmp(argv[i], "-x") == 0) 65 MDTestSuite(); 66 else { 67 p = MD5File(argv[i]); 68 if (!p) 69 perror(argv[i]); 70 else 71 printf("MD5 (%s) = %s\n", argv[i], p); 72 } 73 else | 66 else if (strcmp(argv[i], "-x") == 0) 67 MDTestSuite(); 68 else { 69 p = MD5File(argv[i]); 70 if (!p) 71 perror(argv[i]); 72 else 73 printf("MD5 (%s) = %s\n", argv[i], p); 74 } 75 else |
74 MDFilter(); | 76 MDFilter(0); |
75 76 return (0); 77} 78/* 79 * Digests a string and prints the result. 80 */ 81static void 82MDString(string) --- 6 unchanged lines hidden (view full) --- 89/* 90 * Measures the time to digest TEST_BLOCK_COUNT TEST_BLOCK_LEN-byte blocks. 91 */ 92static void 93MDTimeTrial() 94{ 95 MD5_CTX context; 96 time_t endTime, startTime; | 77 78 return (0); 79} 80/* 81 * Digests a string and prints the result. 82 */ 83static void 84MDString(string) --- 6 unchanged lines hidden (view full) --- 91/* 92 * Measures the time to digest TEST_BLOCK_COUNT TEST_BLOCK_LEN-byte blocks. 93 */ 94static void 95MDTimeTrial() 96{ 97 MD5_CTX context; 98 time_t endTime, startTime; |
97 unsigned char block[TEST_BLOCK_LEN], digest[16]; | 99 unsigned char block[TEST_BLOCK_LEN]; |
98 unsigned int i; 99 char *p; 100 101 printf 102 ("MD5 time trial. Digesting %d %d-byte blocks ...", 103 TEST_BLOCK_LEN, TEST_BLOCK_COUNT); 104 105 /* Initialize block */ --- 40 unchanged lines hidden (view full) --- 146 ("1234567890123456789012345678901234567890\ 1471234567890123456789012345678901234567890"); 148} 149 150/* 151 * Digests the standard input and prints the result. 152 */ 153static void | 100 unsigned int i; 101 char *p; 102 103 printf 104 ("MD5 time trial. Digesting %d %d-byte blocks ...", 105 TEST_BLOCK_LEN, TEST_BLOCK_COUNT); 106 107 /* Initialize block */ --- 40 unchanged lines hidden (view full) --- 148 ("1234567890123456789012345678901234567890\ 1491234567890123456789012345678901234567890"); 150} 151 152/* 153 * Digests the standard input and prints the result. 154 */ 155static void |
154MDFilter() | 156MDFilter(int pipe) |
155{ 156 MD5_CTX context; 157 int len; 158 unsigned char buffer[BUFSIZ], digest[16]; 159 160 MD5Init(&context); | 157{ 158 MD5_CTX context; 159 int len; 160 unsigned char buffer[BUFSIZ], digest[16]; 161 162 MD5Init(&context); |
161 while (len = fread(buffer, 1, BUFSIZ, stdin)) | 163 while (len = fread(buffer, 1, BUFSIZ, stdin)) { 164 if(pipe && (len != fwrite(buffer, 1, len, stdout))) 165 perror(stdout); |
162 MD5Update(&context, buffer, len); | 166 MD5Update(&context, buffer, len); |
167 } |
|
163 printf("%s\n", MD5End(&context)); 164} | 168 printf("%s\n", MD5End(&context)); 169} |