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.
22 #include "apr_xlate.h"
23 #include "apr_general.h"
34 "\xa5\x25\x8a\x89\x11\xb2\x9d\x1f\x81\x75\x96\x3b\x60\x94\x49\xc0"},
35 {"01234567890aBcDeFASDFGHJKLPOIUYTR"
36 "POIUYTREWQZXCVBN LLLLLLLLLLLLLLL",
37 "\xd4\x1a\x06\x2c\xc5\xfd\x6f\x24\x67\x68\x56\x7c\x40\x8a\xd5\x69"},
38 {"111111118888888888888888*******%%%%%%%%%%#####"
39 "142134u8097289720432098409289nkjlfkjlmn,m.. ",
40 "\xb6\xea\x5b\xe8\xca\x45\x8a\x33\xf0\xf1\x84\x6f\xf9\x65\xa8\xe1"},
41 {"01234567890aBcDeFASDFGHJKLPOIUYTR"
42 "POIUYTREWQZXCVBN LLLLLLLLLLLLLLL"
43 "01234567890aBcDeFASDFGHJKLPOIUYTR"
44 "POIUYTREWQZXCVBN LLLLLLLLLLLLLLL"
46 "\xd1\xa1\xc0\x97\x8a\x60\xbb\xfb\x2a\x25\x46\x9d\xa5\xae\xd0\xb0"}
49 static int num_sums = sizeof(md5sums) / sizeof(md5sums[0]);
52 static void test_md5sum(abts_case *tc, void *data)
54 apr_md5_ctx_t context;
55 unsigned char digest[APR_MD5_DIGESTSIZE];
56 const void *string = md5sums[count].string;
57 const void *sum = md5sums[count].digest;
58 unsigned int len = strlen(string);
60 ABTS_ASSERT(tc, "apr_md5_init", (apr_md5_init(&context) == 0));
61 ABTS_ASSERT(tc, "apr_md5_update",
62 (apr_md5_update(&context, string, len) == 0));
63 ABTS_ASSERT(tc, "apr_md5_final", (apr_md5_final(digest, &context)
65 ABTS_ASSERT(tc, "check for correct md5 digest",
66 (memcmp(digest, sum, APR_MD5_DIGESTSIZE) == 0));
69 static void test_md5sum_unaligned(abts_case *tc, void *data)
71 apr_md5_ctx_t context;
72 const char *string = "abcdefghijklmnopqrstuvwxyz01234"
73 "abcdefghijklmnopqrstuvwxyz01234"
74 "abcdefghijklmnopqrstuvwxyz01234"
75 "abcdefghijklmnopqrstuvwxyz01234_";
77 "\x93\x17\x22\x78\xee\x30\x82\xb3\xeb\x95\x33\xec\xea\x78\xb7\x89";
78 unsigned char digest[APR_MD5_DIGESTSIZE];
81 ABTS_ASSERT(tc, "apr_md5_init", (apr_md5_init(&context) == 0));
82 for (i = 0; i < 10; i++) {
83 ABTS_ASSERT(tc, "apr_md5_update",
84 (apr_md5_update(&context, string, strlen(string)) == 0));
87 ABTS_ASSERT(tc, "apr_md5_final", (apr_md5_final(digest, &context)
89 ABTS_ASSERT(tc, "check for correct md5 digest of unaligned data",
90 (memcmp(digest, sum, APR_MD5_DIGESTSIZE) == 0));
93 abts_suite *testmd5(abts_suite *suite)
95 suite = ADD_SUITE(suite);
97 for (count=0; count < num_sums; count++) {
98 abts_run_test(suite, test_md5sum, NULL);
100 abts_run_test(suite, test_md5sum_unaligned, NULL);