1218893Sdim/* crypto/md4/md4test.c */
2193326Sed/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3193326Sed * All rights reserved.
4193326Sed *
5193326Sed * This package is an SSL implementation written
6193326Sed * by Eric Young (eay@cryptsoft.com).
7193326Sed * The implementation was written so as to conform with Netscapes SSL.
8193326Sed *
9193326Sed * This library is free for commercial and non-commercial use as long as
10193326Sed * the following conditions are aheared to.  The following conditions
11193326Sed * apply to all code found in this distribution, be it the RC4, RSA,
12193326Sed * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
13193326Sed * included with this distribution is covered by the same copyright terms
14193326Sed * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15193326Sed *
16193326Sed * Copyright remains Eric Young's, and as such any Copyright notices in
17193326Sed * the code are not to be removed.
18193326Sed * If this package is used in a product, Eric Young should be given attribution
19193326Sed * as the author of the parts of the library used.
20193326Sed * This can be in the form of a textual message at program startup or
21218893Sdim * in documentation (online or textual) provided with the package.
22193326Sed *
23252723Sdim * Redistribution and use in source and binary forms, with or without
24218893Sdim * modification, are permitted provided that the following conditions
25218893Sdim * are met:
26252723Sdim * 1. Redistributions of source code must retain the copyright
27198092Srdivacky *    notice, this list of conditions and the following disclaimer.
28218893Sdim * 2. Redistributions in binary form must reproduce the above copyright
29198092Srdivacky *    notice, this list of conditions and the following disclaimer in the
30198092Srdivacky *    documentation and/or other materials provided with the distribution.
31198092Srdivacky * 3. All advertising materials mentioning features or use of this software
32218893Sdim *    must display the following acknowledgement:
33218893Sdim *    "This product includes cryptographic software written by
34218893Sdim *     Eric Young (eay@cryptsoft.com)"
35218893Sdim *    The word 'cryptographic' can be left out if the rouines from the library
36218893Sdim *    being used are not cryptographic related :-).
37218893Sdim * 4. If you include any Windows specific code (or a derivative thereof) from
38218893Sdim *    the apps directory (application code) you must include an acknowledgement:
39245431Sdim *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40245431Sdim *
41218893Sdim * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42245431Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43252723Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44252723Sdim * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45252723Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46193326Sed * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47193326Sed * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48193326Sed * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49193326Sed * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50193326Sed * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51193326Sed * SUCH DAMAGE.
52193326Sed *
53193326Sed * The licence and distribution terms for any publically available version or
54193326Sed * derivative of this code cannot be changed.  i.e. this code cannot simply be
55218893Sdim * copied and put under another distribution licence
56218893Sdim * [including the GNU Public Licence.]
57218893Sdim */
58218893Sdim
59218893Sdim#include <stdio.h>
60218893Sdim#include <string.h>
61218893Sdim#include <stdlib.h>
62218893Sdim
63218893Sdim#include "../e_os.h"
64218893Sdim
65218893Sdim#ifdef OPENSSL_NO_MD4
66193326Sedint main(int argc, char *argv[])
67193326Sed{
68263509Sdim    printf("No MD4 support\n");
69193326Sed    return(0);
70193326Sed}
71218893Sdim#else
72218893Sdim#include <openssl/evp.h>
73218893Sdim#include <openssl/md4.h>
74263509Sdim
75263509Sdimstatic char *test[]={
76193326Sed	"",
77193326Sed	"a",
78218893Sdim	"abc",
79193326Sed	"message digest",
80193326Sed	"abcdefghijklmnopqrstuvwxyz",
81193326Sed	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
82193326Sed	"12345678901234567890123456789012345678901234567890123456789012345678901234567890",
83193326Sed	NULL,
84193326Sed	};
85193326Sed
86218893Sdimstatic char *ret[]={
87218893Sdim"31d6cfe0d16ae931b73c59d7e0c089c0",
88218893Sdim"bde52cb31de33e46245e05fbdbd6fb24",
89263509Sdim"a448017aaf21d8525fc10ae87aa6729d",
90263509Sdim"d9130a8164549fe818874806e1c7014b",
91263509Sdim"d79e1c308aa5bbcdeea8ed63df412da9",
92263509Sdim"043f8582f241db351ce627e153e7f0e4",
93193326Sed"e33b4ddc9c38f2199c3e7b164fcc0536",
94193326Sed};
95218893Sdim
96245431Sdimstatic char *pt(unsigned char *md);
97245431Sdimint main(int argc, char *argv[])
98193326Sed	{
99193326Sed	int i,err=0;
100193326Sed	char **P,**R;
101193326Sed	char *p;
102193326Sed	unsigned char md[MD4_DIGEST_LENGTH];
103193326Sed
104218893Sdim	P=test;
105218893Sdim	R=ret;
106218893Sdim	i=1;
107218893Sdim	while (*P != NULL)
108218893Sdim		{
109193326Sed		EVP_Digest(&(P[0][0]),strlen((char *)*P),md,NULL,EVP_md4(), NULL);
110193326Sed		p=pt(md);
111193326Sed		if (strcmp(p,(char *)*R) != 0)
112193326Sed			{
113193326Sed			printf("error calculating MD4 on '%s'\n",*P);
114218893Sdim			printf("got %s instead of %s\n",p,*R);
115218893Sdim			err++;
116218893Sdim			}
117218893Sdim		else
118218893Sdim			printf("test %d ok\n",i);
119218893Sdim		i++;
120193326Sed		R++;
121193326Sed		P++;
122218893Sdim		}
123218893Sdim	EXIT(err);
124198398Srdivacky	return(0);
125198398Srdivacky	}
126198398Srdivacky
127198398Srdivackystatic char *pt(unsigned char *md)
128198398Srdivacky	{
129198398Srdivacky	int i;
130198398Srdivacky	static char buf[80];
131218893Sdim
132198398Srdivacky	for (i=0; i<MD4_DIGEST_LENGTH; i++)
133198398Srdivacky		sprintf(&(buf[i*2]),"%02x",md[i]);
134198398Srdivacky	return(buf);
135198398Srdivacky	}
136198398Srdivacky#endif
137198398Srdivacky