1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 /* This is derived from material copyright RSA Data Security, Inc.
17 * Their notice is reproduced below in its entirety.
19 * Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All
22 * RSA Data Security, Inc. makes no representations concerning either
23 * the merchantability of this software or the suitability of this
24 * software for any particular purpose. It is provided "as is"
25 * without express or implied warranty of any kind.
27 * These notices must be retained in any copies of any part of this
28 * documentation and/or software.
35 #include "apr_errno.h"
37 #include "apr_file_io.h"
48 * Taken from the old md4 test suite.
49 * MD4 ("") = 31d6cfe0d16ae931b73c59d7e0c089c0
50 * MD4 ("a") = bde52cb31de33e46245e05fbdbd6fb24
51 * MD4 ("abc") = a448017aaf21d8525fc10ae87aa6729d
52 * MD4 ("message digest") = d9130a8164549fe818874806e1c7014b
53 * MD4 ("abcdefghijklmnopqrstuvwxyz") = d79e1c308aa5bbcdeea8ed63df412da9
54 * MD4 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")
55 * MD4 ("12345678901234567890123456789012345678901234567890123456789012345678901234567890") = e33b4ddc9c38f2199c3e7b164fcc0536
59 "\x31\xd6\xcf\xe0\xd1\x6a\xe9\x31\xb7\x3c\x59\xd7\xe0\xc0\x89\xc0"},
61 "\xbd\xe5\x2c\xb3\x1d\xe3\x3e\x46\x24\x5e\x05\xfb\xdb\xd6\xfb\x24"},
63 "\xa4\x48\x01\x7a\xaf\x21\xd8\x52\x5f\xc1\x0a\xe8\x7a\xa6\x72\x9d"},
65 "\xd9\x13\x0a\x81\x64\x54\x9f\xe8\x18\x87\x48\x06\xe1\xc7\x01\x4b"},
66 {"abcdefghijklmnopqrstuvwxyz",
67 "\xd7\x9e\x1c\x30\x8a\xa5\xbb\xcd\xee\xa8\xed\x63\xdf\x41\x2d\xa9"},
68 {"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
69 "\x04\x3f\x85\x82\xf2\x41\xdb\x35\x1c\xe6\x27\xe1\x53\xe7\xf0\xe4"},
70 {"12345678901234567890123456789012345678901234567890123456789012345678901234567890",
71 "\xe3\x3b\x4d\xdc\x9c\x38\xf2\x19\x9c\x3e\x7b\x16\x4f\xcc\x05\x36"}
74 static int num_sums = sizeof(md4sums) / sizeof(md4sums[0]);
78 static int MDStringComp(const void *string, const void *sum)
80 apr_md4_ctx_t context;
81 unsigned char digest[APR_MD4_DIGESTSIZE];
82 unsigned int len = strlen(string);
84 apr_md4_init(&context);
85 apr_md4_update(&context, (unsigned char *)string, len);
86 apr_md4_final(digest, &context);
87 return (memcmp(digest, sum, APR_MD4_DIGESTSIZE));
92 static void test_md4sum(abts_case *tc, void *data)
94 apr_md4_ctx_t context;
95 unsigned char digest[APR_MD4_DIGESTSIZE];
96 const void *string = md4sums[count].string;
97 const void *sum = md4sums[count].md4sum;
98 unsigned int len = strlen(string);
100 ABTS_ASSERT(tc, "apr_md4_init", (apr_md4_init(&context) == 0));
101 ABTS_ASSERT(tc, "apr_md4_update",
102 (apr_md4_update(&context,
103 (unsigned char *)string, len) == 0));
105 ABTS_ASSERT(tc, "apr_md4_final", (apr_md4_final(digest, &context) ==0));
106 ABTS_ASSERT(tc, "check for correct md4 digest",
107 (memcmp(digest, sum, APR_MD4_DIGESTSIZE) == 0));
110 abts_suite *testmd4(abts_suite *suite)
112 suite = ADD_SUITE(suite);
114 for (count=0; count < num_sums; count++) {
115 abts_run_test(suite, test_md4sum, NULL);