Initial import from FreeBSD RELENG_4:
[dragonfly.git] / lib / libmd / mddriver.c
1 /* MDDRIVER.C - test driver for MD2, MD4 and MD5
2  * $FreeBSD: src/lib/libmd/mddriver.c,v 1.6 1999/08/28 00:05:07 peter Exp $
3  */
4
5 /* Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All
6    rights reserved.
7
8    RSA Data Security, Inc. makes no representations concerning either
9    the merchantability of this software or the suitability of this
10    software for any particular purpose. It is provided "as is"
11    without express or implied warranty of any kind.
12
13    These notices must be retained in any copies of any part of this
14    documentation and/or software.
15  */
16
17 /* The following makes MD default to MD5 if it has not already been
18      defined with C compiler flags.
19  */
20 #ifndef MD
21 #define MD 5
22 #endif
23
24 #include <sys/types.h>
25
26 #include <stdio.h>
27 #include <time.h>
28 #include <string.h>
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  */
44 static void MDString (string)
45 char *string;
46 {
47   char buf[33];
48
49   printf ("MD%d (\"%s\") = %s\n", 
50         MD, string, MDData(string,strlen(string),buf));
51 }
52
53 /* Digests a reference suite of strings and prints the results.
54  */
55 main()
56 {
57   printf ("MD%d test suite:\n", MD);
58
59   MDString ("");
60   MDString ("a");
61   MDString ("abc");
62   MDString ("message digest");
63   MDString ("abcdefghijklmnopqrstuvwxyz");
64   MDString
65     ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
66   MDString
67     ("1234567890123456789012345678901234567890\
68 1234567890123456789012345678901234567890");
69   return 0;
70 }