1220496Smarkm/* MDDRIVER.C - test driver for MD2, MD4 and MD5 */
21802Sphk
3220496Smarkm/* Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All rights
4220496Smarkm * reserved.
5220496Smarkm *
6220496Smarkm * RSA Data Security, Inc. makes no representations concerning either the
7220496Smarkm * merchantability of this software or the suitability of this software for
8220496Smarkm * any particular purpose. It is provided "as is" without express or implied
9220496Smarkm * warranty of any kind.
10220496Smarkm *
11220496Smarkm * These notices must be retained in any copies of any part of this
12220496Smarkm * documentation and/or software. */
13220496Smarkm
1484211Sdillon#include <sys/cdefs.h>
1584211Sdillon__FBSDID("$FreeBSD$");
1684211Sdillon
17220496Smarkm#include <sys/types.h>
181802Sphk
19220496Smarkm#include <stdio.h>
20220496Smarkm#include <time.h>
21220496Smarkm#include <string.h>
221802Sphk
23220496Smarkm/* The following makes MD default to MD5 if it has not already been defined
24220496Smarkm * with C compiler flags. */
251802Sphk#ifndef MD
2628688Sjoerg#define MD 5
271802Sphk#endif
281802Sphk
291802Sphk#if MD == 2
301802Sphk#include "md2.h"
311802Sphk#define MDData MD2Data
321802Sphk#endif
331802Sphk#if MD == 4
341802Sphk#include "md4.h"
351802Sphk#define MDData MD4Data
361802Sphk#endif
371802Sphk#if MD == 5
381802Sphk#include "md5.h"
391802Sphk#define MDData MD5Data
401802Sphk#endif
411802Sphk
42220496Smarkm/* Digests a string and prints the result. */
43220496Smarkmstatic void
44220496SmarkmMDString(char *string)
451802Sphk{
46220496Smarkm	char buf[33];
471802Sphk
48220496Smarkm	printf("MD%d (\"%s\") = %s\n",
49220496Smarkm	       MD, string, MDData(string, strlen(string), buf));
501802Sphk}
511802Sphk
52220496Smarkm/* Digests a reference suite of strings and prints the results. */
53220496Smarkmint
54220496Smarkmmain(void)
551802Sphk{
56220496Smarkm	printf("MD%d test suite:\n", MD);
571802Sphk
58220496Smarkm	MDString("");
59220496Smarkm	MDString("a");
60220496Smarkm	MDString("abc");
61220496Smarkm	MDString("message digest");
62220496Smarkm	MDString("abcdefghijklmnopqrstuvwxyz");
63220496Smarkm	MDString("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
64220496Smarkm		"abcdefghijklmnopqrstuvwxyz0123456789");
65220496Smarkm	MDString("1234567890123456789012345678901234567890"
66220496Smarkm		"1234567890123456789012345678901234567890");
67220496Smarkm
68220496Smarkm	return 0;
691802Sphk}
70