root/common/trunk/tests/test_md5.c @ 3922

Revision 3922, 4.6 KB (checked in by ucacsva, 7 years ago)

1. Removed some tagged comments from previous commits (//SV-XXX).
2. Added newer config.[sub/guess]
3. Various fixes to sync common library with that of ANL:

  • Replaced some "dnl" comments with "#" and stripped off some dnl's from the end of lines
  • Require autoconf v2.5 with AC_PREREQ(2.5)
  • Replaced LIBOBJS="$LIBOBJS inet_ntop.o" by AC_LIBOBJ([inet_ntop])
  • Find which network interface is in use (WinXP).
  • Forgotten NDEF replaced by HAVE_MSGHDR_MSGCTRL.
  • Sets event.data to s->last.active (used by AccessGrid?'s logging code).
  • Introduced rtp_get_ssrc_count() (AccessGrid? logging code).


  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*
2 * FILE:    test_md5.c
3 * AUTHORS: Colin Perkins
4 *
5 * Test vector for MD5, taken from RFC 1321
6 *
7 * Copyright (c) 2002-2004 University of Southern California
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, is permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 *    must display the following acknowledgement:
20 *      This product includes software developed by the Computer Science
21 *      Department at University College London
22 * 4. Neither the name of the University nor of the Department may be used
23 *    to endorse or promote products derived from this software without
24 *    specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 */
37
38#include "config_unix.h"
39#include "config_win32.h"
40#include "debug.h"
41#include "memory.h"
42#include "md5.h"
43#include "test_md5.h"
44
45int 
46test_md5(void)
47{
48        MD5_CTX         context;
49        unsigned char   digest[16];
50        unsigned char   i1[] = "";
51        unsigned char   o1[] = {0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04, 0xe9, 0x80, 0x09, 0x98, 0xec, 0xf8, 0x42, 0x7e};
52        unsigned char   i2[] = "a";
53        unsigned char   o2[] = {0x0c, 0xc1, 0x75, 0xb9, 0xc0, 0xf1, 0xb6, 0xa8, 0x31, 0xc3, 0x99, 0xe2, 0x69, 0x77, 0x26, 0x61};
54        unsigned char   i3[] = "abc";
55        unsigned char   o3[] = {0x90, 0x01, 0x50, 0x98, 0x3c, 0xd2, 0x4f, 0xb0, 0xd6, 0x96, 0x3f, 0x7d, 0x28, 0xe1, 0x7f, 0x72};
56        unsigned char   i4[] = "message digest";
57        unsigned char   o4[] = {0xf9, 0x6b, 0x69, 0x7d, 0x7c, 0xb7, 0x93, 0x8d, 0x52, 0x5a, 0x2f, 0x31, 0xaa, 0xf1, 0x61, 0xd0};
58        unsigned char   i5[] = "abcdefghijklmnopqrstuvwxyz";
59        unsigned char   o5[] = {0xc3, 0xfc, 0xd3, 0xd7, 0x61, 0x92, 0xe4, 0x00, 0x7d, 0xfb, 0x49, 0x6c, 0xca, 0x67, 0xe1, 0x3b};
60        unsigned char   i6[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
61        unsigned char   o6[] = {0xd1, 0x74, 0xab, 0x98, 0xd2, 0x77, 0xd9, 0xf5, 0xa5, 0x61, 0x1c, 0x2c, 0x9f, 0x41, 0x9d, 0x9f};
62        unsigned char   i7[] = "12345678901234567890123456789012345678901234567890123456789012345678901234567890";
63        unsigned char   o7[] = {0x57, 0xed, 0xf4, 0xa2, 0x2b, 0xe3, 0xc9, 0x55, 0xac, 0x49, 0xda, 0x2e, 0x21, 0x07, 0xb6, 0x7a};
64
65
66        printf("MD5.................................... "); fflush(stdout);
67
68        MD5Init(&context);
69        MD5Update(&context, i1, strlen((char *)i1));
70        MD5Final(digest, &context);
71        if (strncmp((char *)digest, (char *)o1, 16) != 0) {
72                printf("FAIL\n");
73                return 1;
74        }
75
76        MD5Init(&context);
77        MD5Update(&context, i2, strlen((char *)i2));
78        MD5Final(digest, &context);
79        if (strncmp((char *)digest, (char *)o2, 16) != 0) {
80                printf("FAIL\n");
81                return 1;
82        }
83
84        MD5Init(&context);
85        MD5Update(&context, i3, strlen((char *)i3));
86        MD5Final(digest, &context);
87        if (strncmp((char *)digest, (char *)o3, 16) != 0) {
88                printf("FAIL\n");
89                return 1;
90        }
91
92        MD5Init(&context);
93        MD5Update(&context, i4, strlen((char *)i4));
94        MD5Final(digest, &context);
95        if (strncmp((char *)digest, (char *)o4, 16) != 0) {
96                printf("FAIL\n");
97                return 1;
98        }
99
100        MD5Init(&context);
101        MD5Update(&context, i5, strlen((char *)i5));
102        MD5Final(digest, &context);
103        if (strncmp((char *)digest, (char *)o5, 16) != 0) {
104                printf("FAIL\n");
105                return 1;
106        }
107
108        MD5Init(&context);
109        MD5Update(&context, i6, strlen((char *)i6));
110        MD5Final(digest, &context);
111        if (strncmp((char *)digest, (char *)o6, 16) != 0) {
112                printf("FAIL\n");
113                return 1;
114        }
115
116        MD5Init(&context);
117        MD5Update(&context, i7, strlen((char *)i7));
118        MD5Final(digest, &context);
119        if (strncmp((char *)digest, (char *)o7, 16) != 0) {
120                printf("FAIL\n");
121                return 1;
122        }
123        printf("pass\n");
124        return 0;
125}
Note: See TracBrowser for help on using the browser.