UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
test_md5.c
Go to the documentation of this file.
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.h"
39#include "config_unix.h"
40#include "config_win32.h"
41#include "debug.h"
42#include "memory.h"
43#include "crypto/md5.h"
44#include "test_md5.h"
45
46int test_md5(void)
47{
48 MD5CTX context;
49 unsigned char digest[16];
50 unsigned char i1[] = "";
51 unsigned char o1[] =
52 { 0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04, 0xe9, 0x80, 0x09,
53 0x98, 0xec, 0xf8, 0x42, 0x7e };
54 unsigned char i2[] = "a";
55 unsigned char o2[] =
56 { 0x0c, 0xc1, 0x75, 0xb9, 0xc0, 0xf1, 0xb6, 0xa8, 0x31, 0xc3, 0x99,
57 0xe2, 0x69, 0x77, 0x26, 0x61 };
58 unsigned char i3[] = "abc";
59 unsigned char o3[] =
60 { 0x90, 0x01, 0x50, 0x98, 0x3c, 0xd2, 0x4f, 0xb0, 0xd6, 0x96, 0x3f,
61 0x7d, 0x28, 0xe1, 0x7f, 0x72 };
62 unsigned char i4[] = "message digest";
63 unsigned char o4[] =
64 { 0xf9, 0x6b, 0x69, 0x7d, 0x7c, 0xb7, 0x93, 0x8d, 0x52, 0x5a, 0x2f,
65 0x31, 0xaa, 0xf1, 0x61, 0xd0 };
66 unsigned char i5[] = "abcdefghijklmnopqrstuvwxyz";
67 unsigned char o5[] =
68 { 0xc3, 0xfc, 0xd3, 0xd7, 0x61, 0x92, 0xe4, 0x00, 0x7d, 0xfb, 0x49,
69 0x6c, 0xca, 0x67, 0xe1, 0x3b };
70 unsigned char i6[] =
71 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
72 unsigned char o6[] =
73 { 0xd1, 0x74, 0xab, 0x98, 0xd2, 0x77, 0xd9, 0xf5, 0xa5, 0x61, 0x1c,
74 0x2c, 0x9f, 0x41, 0x9d, 0x9f };
75 unsigned char i7[] =
76 "12345678901234567890123456789012345678901234567890123456789012345678901234567890";
77 unsigned char o7[] =
78 { 0x57, 0xed, 0xf4, 0xa2, 0x2b, 0xe3, 0xc9, 0x55, 0xac, 0x49, 0xda,
79 0x2e, 0x21, 0x07, 0xb6, 0x7a };
80
81 printf
82 ("Testing MD5 .............................................................. ");
83 fflush(stdout);
84
85 MD5Init(&context);
86 MD5Update(&context, i1, strlen((char *) i1));
87 MD5Final(digest, &context);
88 if (strncmp((char *) digest, (char *) o1, 16) != 0) {
89 printf("FAIL\n");
90 return -1;
91 }
92
93 MD5Init(&context);
94 MD5Update(&context, i2, strlen((char *) i2));
95 MD5Final(digest, &context);
96 if (strncmp((char *) digest, (char *) o2, 16) != 0) {
97 printf("FAIL\n");
98 return -1;
99 }
100
101 MD5Init(&context);
102 MD5Update(&context, i3, strlen((char *) i3));
103 MD5Final(digest, &context);
104 if (strncmp((char *) digest, (char *) o3, 16) != 0) {
105 printf("FAIL\n");
106 return -1;
107 }
108
109 MD5Init(&context);
110 MD5Update(&context, i4, strlen((char *) i4));
111 MD5Final(digest, &context);
112 if (strncmp((char *) digest, (char *) o4, 16) != 0) {
113 printf("FAIL\n");
114 return -1;
115 }
116
117 MD5Init(&context);
118 MD5Update(&context, i5, strlen((char *) i5));
119 MD5Final(digest, &context);
120 if (strncmp((char *) digest, (char *) o5, 16) != 0) {
121 printf("FAIL\n");
122 return -1;
123 }
124
125 MD5Init(&context);
126 MD5Update(&context, i6, strlen((char *) i6));
127 MD5Final(digest, &context);
128 if (strncmp((char *) digest, (char *) o6, 16) != 0) {
129 printf("FAIL\n");
130 return -1;
131 }
132
133 MD5Init(&context);
134 MD5Update(&context, i7, strlen((char *) i7));
135 MD5Final(digest, &context);
136 if (strncmp((char *) digest, (char *) o7, 16) != 0) {
137 printf("FAIL\n");
138 return -1;
139 }
140 printf("Ok\n");
141 return 0;
142}
void MD5Update(MD5CTX *context, const unsigned char *input, unsigned int inputLen)
Definition md5.c:249
void MD5Final(unsigned char digest[16], MD5CTX *context)
Definition md5.c:295
void MD5Init(MD5CTX *context)
Definition md5.c:229
Definition md5.h:34
int test_md5(void)
Definition test_md5.c:46