Mercurial > pidgin
annotate libgaim/tests/test_cipher.c @ 15209:ffec45ff82d0
[gaim-migrate @ 17999]
Setting this namespaced attribute will tell the Google Talk servers that we can accept back a JID from the bind result that isn't necessarily related to the one we requested. This allows googlemail.com users to enter gmail.com as their server and still authenticate properly. Technically, we shouldn't need an attribute like this (this is all valid XMPP), but lesser clients might choke on this.
committer: Tailor Script <tailor@pidgin.im>
| author | Sean Egan <seanegan@gmail.com> |
|---|---|
| date | Thu, 14 Dec 2006 22:25:18 +0000 |
| parents | 7236b72de90b |
| children |
| rev | line source |
|---|---|
| 15043 | 1 #include <glib.h> |
| 2 #include <check.h> | |
| 3 #include <stdlib.h> | |
| 4 #include <string.h> | |
| 5 | |
| 6 #undef HAVE_DBUS | |
| 7 | |
| 8 #include "../cipher.h" | |
| 9 #include "../signal.h" | |
| 10 | |
| 11 /****************************************************************************** | |
| 12 * MD4 Tests | |
| 13 *****************************************************************************/ | |
| 14 #define MD4_TEST(data, digest) { \ | |
| 15 GaimCipher *cipher = NULL; \ | |
| 16 GaimCipherContext *context = NULL; \ | |
| 17 gchar cdigest[33]; \ | |
| 18 gchar *sdigest = NULL; \ | |
| 19 gboolean ret = FALSE; \ | |
| 20 \ | |
| 21 cipher = gaim_ciphers_find_cipher("md4"); \ | |
| 22 context = gaim_cipher_context_new(cipher, NULL); \ | |
| 23 gaim_cipher_context_append(context, (guchar *)(data), strlen((data))); \ | |
| 24 \ | |
| 25 ret = gaim_cipher_context_digest_to_str(context, sizeof(cdigest), cdigest, \ | |
| 26 NULL); \ | |
| 27 \ | |
| 28 fail_unless(ret == TRUE, NULL); \ | |
| 29 \ | |
| 30 fail_unless(strcmp((digest), cdigest) == 0, NULL); \ | |
| 31 \ | |
| 32 gaim_cipher_context_destroy(context); \ | |
| 33 } | |
| 34 | |
| 35 START_TEST(test_md4_empty_string) { | |
| 36 MD4_TEST("", "31d6cfe0d16ae931b73c59d7e0c089c0"); | |
| 37 } | |
| 38 END_TEST | |
| 39 | |
| 40 START_TEST(test_md4_a) { | |
| 41 MD4_TEST("a", "bde52cb31de33e46245e05fbdbd6fb24"); | |
| 42 } | |
| 43 END_TEST | |
| 44 | |
| 45 START_TEST(test_md4_abc) { | |
| 46 MD4_TEST("abc", "a448017aaf21d8525fc10ae87aa6729d"); | |
| 47 } | |
| 48 END_TEST | |
| 49 | |
| 50 START_TEST(test_md4_message_digest) { | |
| 51 MD4_TEST("message digest", "d9130a8164549fe818874806e1c7014b"); | |
| 52 } | |
| 53 END_TEST | |
| 54 | |
| 55 START_TEST(test_md4_a_to_z) { | |
| 56 MD4_TEST("abcdefghijklmnopqrstuvwxyz", | |
| 57 "d79e1c308aa5bbcdeea8ed63df412da9"); | |
| 58 } | |
| 59 END_TEST | |
| 60 | |
| 61 START_TEST(test_md4_A_to_Z_a_to_z_0_to_9) { | |
| 62 MD4_TEST("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", | |
| 63 "043f8582f241db351ce627e153e7f0e4"); | |
| 64 } | |
| 65 END_TEST | |
| 66 | |
| 67 START_TEST(test_md4_1_to_0_8_times) { | |
| 68 MD4_TEST("123456789012345678901234567890123456789012345678901234567890" | |
| 69 "12345678901234567890", | |
| 70 "e33b4ddc9c38f2199c3e7b164fcc0536"); | |
| 71 } | |
| 72 END_TEST | |
| 73 | |
| 74 | |
| 75 /****************************************************************************** | |
| 76 * MD5 Tests | |
| 77 *****************************************************************************/ | |
| 78 #define MD5_TEST(data, digest) { \ | |
| 79 GaimCipher *cipher = NULL; \ | |
| 80 GaimCipherContext *context = NULL; \ | |
| 81 gchar cdigest[33]; \ | |
| 82 gchar *sdigest = NULL; \ | |
| 83 gboolean ret = FALSE; \ | |
| 84 \ | |
| 85 cipher = gaim_ciphers_find_cipher("md5"); \ | |
| 86 context = gaim_cipher_context_new(cipher, NULL); \ | |
| 87 gaim_cipher_context_append(context, (guchar *)(data), strlen((data))); \ | |
| 88 \ | |
| 89 ret = gaim_cipher_context_digest_to_str(context, sizeof(cdigest), cdigest, \ | |
| 90 NULL); \ | |
| 91 \ | |
| 92 fail_unless(ret == TRUE, NULL); \ | |
| 93 \ | |
| 94 fail_unless(strcmp((digest), cdigest) == 0, NULL); \ | |
| 95 \ | |
| 96 gaim_cipher_context_destroy(context); \ | |
| 97 } | |
| 98 | |
| 99 START_TEST(test_md5_empty_string) { | |
| 100 MD5_TEST("", "d41d8cd98f00b204e9800998ecf8427e"); | |
| 101 } | |
| 102 END_TEST | |
| 103 | |
| 104 START_TEST(test_md5_a) { | |
| 105 MD5_TEST("a", "0cc175b9c0f1b6a831c399e269772661"); | |
| 106 } | |
| 107 END_TEST | |
| 108 | |
| 109 START_TEST(test_md5_abc) { | |
| 110 MD5_TEST("abc", "900150983cd24fb0d6963f7d28e17f72"); | |
| 111 } | |
| 112 END_TEST | |
| 113 | |
| 114 START_TEST(test_md5_message_digest) { | |
| 115 MD5_TEST("message digest", "f96b697d7cb7938d525a2f31aaf161d0"); | |
| 116 } | |
| 117 END_TEST | |
| 118 | |
| 119 START_TEST(test_md5_a_to_z) { | |
| 120 MD5_TEST("abcdefghijklmnopqrstuvwxyz", | |
| 121 "c3fcd3d76192e4007dfb496cca67e13b"); | |
| 122 } | |
| 123 END_TEST | |
| 124 | |
| 125 START_TEST(test_md5_A_to_Z_a_to_z_0_to_9) { | |
| 126 MD5_TEST("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", | |
| 127 "d174ab98d277d9f5a5611c2c9f419d9f"); | |
| 128 } | |
| 129 END_TEST | |
| 130 | |
| 131 START_TEST(test_md5_1_to_0_8_times) { | |
| 132 MD5_TEST("123456789012345678901234567890123456789012345678901234567890" | |
| 133 "12345678901234567890", | |
| 134 "57edf4a22be3c955ac49da2e2107b67a"); | |
| 135 } | |
| 136 END_TEST | |
| 137 | |
| 138 /****************************************************************************** | |
| 139 * SHA-1 Tests | |
| 140 *****************************************************************************/ | |
| 141 #define SHA1_TEST(data, digest) { \ | |
| 142 GaimCipher *cipher = NULL; \ | |
| 143 GaimCipherContext *context = NULL; \ | |
| 144 gchar cdigest[41]; \ | |
| 145 gchar *sdigest = NULL; \ | |
| 146 gboolean ret = FALSE; \ | |
| 147 \ | |
| 148 cipher = gaim_ciphers_find_cipher("sha1"); \ | |
| 149 context = gaim_cipher_context_new(cipher, NULL); \ | |
| 150 \ | |
| 151 if((data)) { \ | |
| 152 gaim_cipher_context_append(context, (guchar *)(data), strlen((data))); \ | |
| 153 } else { \ | |
| 154 gint j; \ | |
| 155 guchar buff[1000]; \ | |
| 156 \ | |
| 157 memset(buff, 'a', 1000); \ | |
| 158 \ | |
| 159 for(j = 0; j < 1000; j++) \ | |
| 160 gaim_cipher_context_append(context, buff, 1000); \ | |
| 161 } \ | |
| 162 \ | |
| 163 ret = gaim_cipher_context_digest_to_str(context, sizeof(cdigest), cdigest, \ | |
| 164 NULL); \ | |
| 165 \ | |
| 166 fail_unless(ret == TRUE, NULL); \ | |
| 167 \ | |
| 168 fail_unless(strcmp((digest), cdigest) == 0, NULL); \ | |
| 169 \ | |
| 170 gaim_cipher_context_destroy(context); \ | |
| 171 } | |
| 172 | |
| 173 START_TEST(test_sha1_a) { | |
| 174 SHA1_TEST("a", "86f7e437faa5a7fce15d1ddcb9eaeaea377667b8"); | |
| 175 } | |
| 176 END_TEST | |
| 177 | |
| 178 START_TEST(test_sha1_abc) { | |
| 179 SHA1_TEST("abc", "a9993e364706816aba3e25717850c26c9cd0d89d"); | |
| 180 } | |
| 181 END_TEST | |
| 182 | |
| 183 START_TEST(test_sha1_abcd_gibberish) { | |
| 184 SHA1_TEST("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", | |
| 185 "84983e441c3bd26ebaae4aa1f95129e5e54670f1"); | |
| 186 } | |
| 187 END_TEST | |
| 188 | |
| 189 START_TEST(test_sha1_1000_as_1000_times) { | |
| 190 SHA1_TEST(NULL, "34aa973cd4c4daa4f61eeb2bdbad27316534016f"); | |
| 191 } | |
| 192 END_TEST | |
| 193 | |
| 194 /****************************************************************************** | |
| 195 * Suite | |
| 196 *****************************************************************************/ | |
| 197 Suite * | |
| 198 cipher_suite(void) { | |
| 199 Suite *s = suite_create("Cipher Suite"); | |
| 200 TCase *tc = NULL; | |
| 201 | |
|
15044
7236b72de90b
[gaim-migrate @ 17828]
Gary Kramlich <grim@reaperworld.com>
parents:
15043
diff
changeset
|
202 /* md4 tests */ |
| 15043 | 203 tc = tcase_create("MD4"); |
| 204 tcase_add_test(tc, test_md4_empty_string); | |
| 205 tcase_add_test(tc, test_md4_a); | |
| 206 tcase_add_test(tc, test_md4_abc); | |
| 207 tcase_add_test(tc, test_md4_message_digest); | |
| 208 tcase_add_test(tc, test_md4_a_to_z); | |
| 209 tcase_add_test(tc, test_md4_A_to_Z_a_to_z_0_to_9); | |
| 210 tcase_add_test(tc, test_md4_1_to_0_8_times); | |
| 211 suite_add_tcase(s, tc); | |
| 212 | |
| 213 /* md5 tests */ | |
| 214 tc = tcase_create("MD5"); | |
| 215 tcase_add_test(tc, test_md5_empty_string); | |
| 216 tcase_add_test(tc, test_md5_a); | |
| 217 tcase_add_test(tc, test_md5_abc); | |
| 218 tcase_add_test(tc, test_md5_message_digest); | |
| 219 tcase_add_test(tc, test_md5_a_to_z); | |
| 220 tcase_add_test(tc, test_md5_A_to_Z_a_to_z_0_to_9); | |
| 221 tcase_add_test(tc, test_md5_1_to_0_8_times); | |
| 222 suite_add_tcase(s, tc); | |
| 223 | |
| 224 /* sha1 tests */ | |
| 225 tc = tcase_create("SHA1"); | |
| 226 tcase_add_test(tc, test_sha1_a); | |
| 227 tcase_add_test(tc, test_sha1_abc); | |
| 228 tcase_add_test(tc, test_sha1_abcd_gibberish); | |
| 229 tcase_add_test(tc, test_sha1_1000_as_1000_times); | |
| 230 suite_add_tcase(s, tc); | |
| 231 | |
| 232 return s; | |
| 233 } | |
| 234 | |
| 235 |
