md5test.c revision 55714
1235633Sdim/* crypto/md5/md5test.c */
2226584Sdim/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3226584Sdim * All rights reserved.
4226584Sdim *
5226584Sdim * This package is an SSL implementation written
6226584Sdim * by Eric Young (eay@cryptsoft.com).
7226584Sdim * The implementation was written so as to conform with Netscapes SSL.
8226584Sdim *
9226584Sdim * This library is free for commercial and non-commercial use as long as
10226584Sdim * the following conditions are aheared to.  The following conditions
11226584Sdim * apply to all code found in this distribution, be it the RC4, RSA,
12226584Sdim * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
13226584Sdim * included with this distribution is covered by the same copyright terms
14226584Sdim * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15226584Sdim *
16226584Sdim * Copyright remains Eric Young's, and as such any Copyright notices in
17226584Sdim * the code are not to be removed.
18226584Sdim * If this package is used in a product, Eric Young should be given attribution
19235633Sdim * as the author of the parts of the library used.
20226584Sdim * This can be in the form of a textual message at program startup or
21226584Sdim * in documentation (online or textual) provided with the package.
22226584Sdim *
23226584Sdim * Redistribution and use in source and binary forms, with or without
24226584Sdim * modification, are permitted provided that the following conditions
25226584Sdim * are met:
26226584Sdim * 1. Redistributions of source code must retain the copyright
27226584Sdim *    notice, this list of conditions and the following disclaimer.
28226584Sdim * 2. Redistributions in binary form must reproduce the above copyright
29226584Sdim *    notice, this list of conditions and the following disclaimer in the
30226584Sdim *    documentation and/or other materials provided with the distribution.
31226584Sdim * 3. All advertising materials mentioning features or use of this software
32226584Sdim *    must display the following acknowledgement:
33226584Sdim *    "This product includes cryptographic software written by
34226584Sdim *     Eric Young (eay@cryptsoft.com)"
35226584Sdim *    The word 'cryptographic' can be left out if the rouines from the library
36226584Sdim *    being used are not cryptographic related :-).
37226584Sdim * 4. If you include any Windows specific code (or a derivative thereof) from
38226584Sdim *    the apps directory (application code) you must include an acknowledgement:
39226584Sdim *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40226584Sdim *
41226584Sdim * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42226584Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43226584Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44226584Sdim * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45226584Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46226584Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47235633Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48226584Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49226584Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50226584Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51226584Sdim * SUCH DAMAGE.
52226584Sdim *
53226584Sdim * The licence and distribution terms for any publically available version or
54226584Sdim * derivative of this code cannot be changed.  i.e. this code cannot simply be
55226584Sdim * copied and put under another distribution licence
56226584Sdim * [including the GNU Public Licence.]
57226584Sdim */
58235633Sdim
59226584Sdim#include <stdio.h>
60226584Sdim#include <string.h>
61226584Sdim#include <stdlib.h>
62226584Sdim
63226584Sdim#ifdef NO_MD5
64226584Sdimint main(int argc, char *argv[])
65226584Sdim{
66226584Sdim    printf("No MD5 support\n");
67226584Sdim    return(0);
68226584Sdim}
69226584Sdim#else
70226584Sdim#include <openssl/md5.h>
71226584Sdim
72226584Sdimchar *test[]={
73226584Sdim	"",
74226584Sdim	"a",
75226584Sdim	"abc",
76235633Sdim	"message digest",
77226584Sdim	"abcdefghijklmnopqrstuvwxyz",
78226584Sdim	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
79226584Sdim	"12345678901234567890123456789012345678901234567890123456789012345678901234567890",
80226584Sdim	NULL,
81226584Sdim	};
82226584Sdim
83226584Sdimchar *ret[]={
84226584Sdim	"d41d8cd98f00b204e9800998ecf8427e",
85226584Sdim	"0cc175b9c0f1b6a831c399e269772661",
86226584Sdim	"900150983cd24fb0d6963f7d28e17f72",
87226584Sdim	"f96b697d7cb7938d525a2f31aaf161d0",
88226584Sdim	"c3fcd3d76192e4007dfb496cca67e13b",
89226584Sdim	"d174ab98d277d9f5a5611c2c9f419d9f",
90226584Sdim	"57edf4a22be3c955ac49da2e2107b67a",
91226584Sdim	};
92226584Sdim
93226584Sdimstatic char *pt(unsigned char *md);
94226584Sdimint main(int argc, char *argv[])
95226584Sdim	{
96226584Sdim	int i,err=0;
97226584Sdim	unsigned char **P,**R;
98226584Sdim	char *p;
99226584Sdim
100226584Sdim	P=(unsigned char **)test;
101226584Sdim	R=(unsigned char **)ret;
102226584Sdim	i=1;
103226584Sdim	while (*P != NULL)
104226584Sdim		{
105226584Sdim		p=pt(MD5(&(P[0][0]),(unsigned long)strlen((char *)*P),NULL));
106226584Sdim		if (strcmp(p,(char *)*R) != 0)
107226584Sdim			{
108226584Sdim			printf("error calculating MD5 on '%s'\n",*P);
109226584Sdim			printf("got %s instead of %s\n",p,*R);
110226584Sdim			err++;
111226584Sdim			}
112226584Sdim		else
113226584Sdim			printf("test %d ok\n",i);
114226584Sdim		i++;
115226584Sdim		R++;
116226584Sdim		P++;
117226584Sdim		}
118226584Sdim	exit(err);
119226584Sdim	return(0);
120226584Sdim	}
121226584Sdim
122226584Sdimstatic char *pt(unsigned char *md)
123226584Sdim	{
124226584Sdim	int i;
125226584Sdim	static char buf[80];
126226584Sdim
127226584Sdim	for (i=0; i<MD5_DIGEST_LENGTH; i++)
128226584Sdim		sprintf(&(buf[i*2]),"%02x",md[i]);
129226584Sdim	return(buf);
130226584Sdim	}
131226584Sdim#endif
132226584Sdim