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 __FBSDID("$FreeBSD$");
16
17 #include <sys/types.h>
18
19 #include <stdio.h>
20 #include <time.h>
21 #include <string.h>
22
23 /* The following makes MD default to MD5 if it has not already been defined
24 * with C compiler flags. */
25 #ifndef MD
26 #define MD 5
27 #endif
28
29 #if MD == 2
30 #include "md2.h"
31 #define MDData MD2Data
32 #endif
33 #if MD == 4
34 #include "md4.h"
35 #define MDData MD4Data
36 #endif
37 #if MD == 5
38 #include "md5.h"
39 #define MDData MD5Data
40 #endif
41
42 /* Digests a string and prints the result. */
43 static void
MDString(char * string)44 MDString(char *string)
45 {
46 char buf[33];
47
48 printf("MD%d (\"%s\") = %s\n",
49 MD, string, MDData(string, strlen(string), buf));
50 }
51
52 /* Digests a reference suite of strings and prints the results. */
53 int
main(void)54 main(void)
55 {
56 printf("MD%d test suite:\n", MD);
57
58 MDString("");
59 MDString("a");
60 MDString("abc");
61 MDString("message digest");
62 MDString("abcdefghijklmnopqrstuvwxyz");
63 MDString("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
64 "abcdefghijklmnopqrstuvwxyz0123456789");
65 MDString("1234567890123456789012345678901234567890"
66 "1234567890123456789012345678901234567890");
67
68 return 0;
69 }
70