1 /* MDDRIVER.C - test driver for MD2, MD4 and MD5 */ 2 3 /* Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All rights 4 * reserved. 5 * 6 * RSA Data Security, Inc. makes no representations concerning either the 7 * merchantability of this software or the suitability of this software for 8 * any particular purpose. It is provided "as is" without express or implied 9 * warranty of any kind. 10 * 11 * These notices must be retained in any copies of any part of this 12 * documentation and/or software. */ 13 14 #include <sys/cdefs.h> 15 #include <sys/types.h> 16 17 #include <stdio.h> 18 #include <time.h> 19 #include <string.h> 20 21 /* The following makes MD default to MD5 if it has not already been defined 22 * with C compiler flags. */ 23 #ifndef MD 24 #define MD 5 25 #endif 26 27 #if MD == 2 28 #include "md2.h" 29 #define MDData MD2Data 30 #endif 31 #if MD == 4 32 #include "md4.h" 33 #define MDData MD4Data 34 #endif 35 #if MD == 5 36 #include "md5.h" 37 #define MDData MD5Data 38 #endif 39 40 /* Digests a string and prints the result. */ 41 static void 42 MDString(char *string) 43 { 44 char buf[33]; 45 46 printf("MD%d (\"%s\") = %s\n", 47 MD, string, MDData(string, strlen(string), buf)); 48 } 49 50 /* Digests a reference suite of strings and prints the results. */ 51 int 52 main(void) 53 { 54 printf("MD%d test suite:\n", MD); 55 56 MDString(""); 57 MDString("a"); 58 MDString("abc"); 59 MDString("message digest"); 60 MDString("abcdefghijklmnopqrstuvwxyz"); 61 MDString("ABCDEFGHIJKLMNOPQRSTUVWXYZ" 62 "abcdefghijklmnopqrstuvwxyz0123456789"); 63 MDString("1234567890123456789012345678901234567890" 64 "1234567890123456789012345678901234567890"); 65 66 return 0; 67 } 68