5 #include <common/md5.h>
9 gchar
*expected_output
;
12 struct td_digest td_rfc1321_1
= { "", "d41d8cd98f00b204e9800998ecf8427e" };
13 struct td_digest td_rfc1321_2
= { "a", "0cc175b9c0f1b6a831c399e269772661" };
14 struct td_digest td_rfc1321_3
= { "abc", "900150983cd24fb0d6963f7d28e17f72" };
15 struct td_digest td_rfc1321_4
= { "message digest", "f96b697d7cb7938d525a2f31aaf161d0" };
16 struct td_digest td_rfc1321_5
= { "abcdefghijklmnopqrstuvwxyz", "c3fcd3d76192e4007dfb496cca67e13b" };
17 struct td_digest td_rfc1321_6
= { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", "d174ab98d277d9f5a5611c2c9f419d9f" };
18 struct td_digest td_rfc1321_7
= { "12345678901234567890123456789012345678901234567890123456789012345678901234567890", "57edf4a22be3c955ac49da2e2107b67a" };
25 gchar
*expected_output
;
28 struct td_hmac td_hmac_null_key
= {
33 struct td_hmac td_hmac_negative_key_length
= {
38 struct td_hmac td_hmac_null_data
= {
43 struct td_hmac td_hmac_negative_data_length
= {
49 struct td_hmac td_rfc2202_1
= {
50 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 16,
52 "9294727a3638bb1c13f48ef8158bfc9d"
54 struct td_hmac td_rfc2202_2
= {
56 "what do ya want for nothing?", 28,
57 "750c783e6ab0b503eaa86e310a5db738"
59 struct td_hmac td_rfc2202_3
= {
60 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 16,
61 "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd", 50,
62 "56be34521d144c88dbb8c733f0e8b3f6"
64 struct td_hmac td_rfc2202_4
= {
65 "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19", 25,
66 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd", 50,
67 "697eaf0aca3a3aea3a75164746ffaa79"
69 struct td_hmac td_rfc2202_5
= {
70 "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c", 16,
71 "Test With Truncation", 20,
72 "56461ef2342edc00f9bab995690efd4c"
74 struct td_hmac td_rfc2202_6
= {
75 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 80,
76 "Test Using Larger Than Block-Size Key - Hash Key First", 54,
77 "6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd"
79 struct td_hmac td_rfc2202_7
= {
80 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 80,
81 "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data", 73,
82 "6f630fad67cda0ee1fb1f562db3aa53e"
86 test_md5_hex_digest_null_input(void)
92 if (!g_test_undefined())
95 if (g_test_subprocess()) {
96 md5_hex_digest(outbuf
, NULL
);
100 g_test_trap_subprocess(NULL
, 0, 0);
101 g_test_trap_assert_failed();
102 g_test_trap_assert_stderr("*CRITICAL*md5_hex_digest: assertion*failed*");
103 g_assert_cmpint(outbuf
[0], ==, '\0');
107 test_md5_hex_digest_null_output(void)
109 if (!g_test_undefined())
112 if (g_test_subprocess()) {
113 md5_hex_digest(NULL
, "");
117 g_test_trap_subprocess(NULL
, 0, 0);
118 g_test_trap_assert_failed();
119 g_test_trap_assert_stderr("*CRITICAL*md5_hex_digest: assertion*failed*");
123 test_md5_hex_digest(gconstpointer user_data
)
126 struct td_digest
*data
= (struct td_digest
*)user_data
;
128 md5_hex_digest(outbuf
, data
->input
);
130 g_assert_cmpint(outbuf
[32], ==, '\0');
131 g_assert_cmpstr(outbuf
, ==, data
->expected_output
);
135 test_md5_hex_hmac_null_output(void)
137 if (!g_test_undefined())
140 if (g_test_subprocess()) {
141 md5_hex_hmac(NULL
, "", 0, "", 0);
145 g_test_trap_subprocess(NULL
, 0, 0);
146 g_test_trap_assert_failed();
147 g_test_trap_assert_stderr("*CRITICAL*md5_hex_hmac: assertion*failed*");
150 /* We expect all test cases using this function to fail with
151 * failed assertion */
153 test_md5_hex_hmac_fails(gconstpointer user_data
)
156 struct td_hmac
*data
= (struct td_hmac
*)user_data
;
158 if (!g_test_undefined())
161 if (g_test_subprocess()) {
163 data
->data
, data
->data_len
,
164 data
->key
, data
->key_len
);
168 g_test_trap_subprocess(NULL
, 0, 0);
169 g_test_trap_assert_failed();
170 g_test_trap_assert_stderr("*CRITICAL*md5_hex_hmac: assertion*failed*");
174 test_md5_hex_hmac(gconstpointer user_data
)
177 struct td_hmac
*data
= (struct td_hmac
*)user_data
;
180 data
->data
, data
->data_len
,
181 data
->key
, data
->key_len
);
183 g_assert_cmpint(outbuf
[32], ==, '\0');
184 g_assert_cmpstr(outbuf
, ==, data
->expected_output
);
189 main(int argc
, char *argv
[])
191 g_test_init(&argc
, &argv
, NULL
);
193 g_test_add_func("/common/md5/hex_digest/null_input",
194 test_md5_hex_digest_null_input
);
195 g_test_add_func("/common/md5/hex_digest/null_output",
196 test_md5_hex_digest_null_output
);
198 g_test_add_data_func("/common/md5/hex_digest/rfc1321_1",
200 test_md5_hex_digest
);
201 g_test_add_data_func("/common/md5/hex_digest/rfc1321_2",
203 test_md5_hex_digest
);
204 g_test_add_data_func("/common/md5/hex_digest/rfc1321_3",
206 test_md5_hex_digest
);
207 g_test_add_data_func("/common/md5/hex_digest/rfc1321_4",
209 test_md5_hex_digest
);
210 g_test_add_data_func("/common/md5/hex_digest/rfc1321_5",
212 test_md5_hex_digest
);
213 g_test_add_data_func("/common/md5/hex_digest/rfc1321_6",
215 test_md5_hex_digest
);
216 g_test_add_data_func("/common/md5/hex_digest/rfc1321_7",
218 test_md5_hex_digest
);
220 g_test_add_data_func("/common/md5/hex_hmac/null_key",
222 test_md5_hex_hmac_fails
);
223 g_test_add_data_func("/common/md5/hex_hmac/negative_key_length",
224 &td_hmac_negative_key_length
,
225 test_md5_hex_hmac_fails
);
226 g_test_add_data_func("/common/md5/hex_hmac/null_data",
228 test_md5_hex_hmac_fails
);
229 g_test_add_data_func("/common/md5/hex_hmac/negative_data_length",
230 &td_hmac_negative_data_length
,
231 test_md5_hex_hmac_fails
);
232 g_test_add_func("/common/md5/hex_hmac/null_output",
233 test_md5_hex_hmac_null_output
);
235 g_test_add_data_func("/common/md5/hex_hmac/rfc2202_1",
238 g_test_add_data_func("/common/md5/hex_hmac/rfc2202_2",
241 g_test_add_data_func("/common/md5/hex_hmac/rfc2202_3",
244 g_test_add_data_func("/common/md5/hex_hmac/rfc2202_4",
247 g_test_add_data_func("/common/md5/hex_hmac/rfc2202_5",
250 g_test_add_data_func("/common/md5/hex_hmac/rfc2202_6",
253 g_test_add_data_func("/common/md5/hex_hmac/rfc2202_7",