Add comment to CSTR macro in k_standard.c.
[glibc.git] / crypt / md5test-giant.c
blobd95cda64995372f9740bef2336e11a01305e77b3
1 /* Testcase for http://sourceware.org/bugzilla/show_bug.cgi?id=14090.
2 Copyright (C) 2012-2015 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>. */
18 #include <stdint.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <sys/mman.h>
24 #include "md5.h"
26 /* This test will not work with 32-bit size_t, so let it succeed
27 there. */
28 #if SIZE_MAX <= UINT32_MAX
29 static int
30 do_test (void)
32 return 0;
34 #else
36 # define CONST_2G 0x080000000
37 # define CONST_10G 0x280000000
39 /* MD5 sum values of zero-filled blocks of specified sizes. */
40 static const struct test_data_s
42 const char ref[16];
43 size_t len;
44 } test_data[] =
46 { "\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\x09\x98\xec\xf8\x42\x7e",
47 0x000000000 },
48 { "\xa9\x81\x13\x0c\xf2\xb7\xe0\x9f\x46\x86\xdc\x27\x3c\xf7\x18\x7e",
49 0x080000000 },
50 { "\xc9\xa5\xa6\x87\x8d\x97\xb4\x8c\xc9\x65\xc1\xe4\x18\x59\xf0\x34",
51 0x100000000 },
52 { "\x58\xcf\x63\x8a\x73\x3f\x91\x90\x07\xb4\x28\x7c\xf5\x39\x6d\x0c",
53 0x180000000 },
54 { "\xb7\x70\x35\x1f\xad\xae\x5a\x96\xbb\xaf\x97\x02\xed\x97\xd2\x8d",
55 0x200000000 },
56 { "\x2d\xd2\x6c\x4d\x47\x99\xeb\xd2\x9f\xa3\x1e\x48\xd4\x9e\x8e\x53",
57 0x280000000 },
60 static int
61 report (const char *id, const char *md5, size_t len, const char *ref)
63 if (memcmp (md5, ref, 16))
65 printf ("test %s with size %zd failed\n", id, len);
66 return 1;
68 return 0;
71 /* Test md5 in a single md5_process_bytes call. */
72 static int
73 test_single (void *buf, size_t len, const char *ref)
75 char sum[16];
76 struct md5_ctx ctx;
78 __md5_init_ctx (&ctx);
79 __md5_process_bytes (buf, len, &ctx);
80 __md5_finish_ctx (&ctx, sum);
82 return report ("single", sum, len, ref);
85 /* Test md5 with two md5_process_bytes calls to trigger a
86 different path in md5_process_block for sizes > 2 GB. */
87 static int
88 test_double (void *buf, size_t len, const char *ref)
90 char sum[16];
91 struct md5_ctx ctx;
93 __md5_init_ctx (&ctx);
94 if (len >= CONST_2G)
96 __md5_process_bytes (buf, CONST_2G, &ctx);
97 __md5_process_bytes (buf + CONST_2G, len - CONST_2G, &ctx);
99 else
100 __md5_process_bytes (buf, len, &ctx);
102 __md5_finish_ctx (&ctx, sum);
104 return report ("double", sum, len, ref);
108 static int
109 do_test (void)
111 void *buf;
112 unsigned int j;
113 int result = 0;
115 buf = mmap64 (0, CONST_10G, PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
116 if (buf == MAP_FAILED)
118 puts ("Could not allocate 10 GB via mmap, skipping test.");
119 return 0;
122 for (j = 0; j < sizeof (test_data) / sizeof (struct test_data_s); j++)
124 if (test_single (buf, test_data[j].len, test_data[j].ref))
125 result = 1;
126 if (test_double (buf, test_data[j].len, test_data[j].ref))
127 result = 1;
130 return result;
132 #endif
134 /* This needs on a fast machine 90s. */
135 #define TIMEOUT 480
136 #define TEST_FUNCTION do_test ()
137 #include "../test-skeleton.c"