Mercurial > pidgin
comparison plugins/ciphertest.c @ 10684:72a5babfa8b4
[gaim-migrate @ 12231]
the cipher api that grim has been working on for ages is finally done!! big
congrats and thanks to him!!
lots of modified files in this commit. it builds here.
moved the md5 files to src/protocols/oscar so that it continues to depend
on nothing in gaim. everything else uses the new centralized cipher api.
I'm not sure if src/md5.* needs to be removed or not, so I left it there.
someone let me know or do it directly.
someone check if these need to be added to potfiles.in
and let there be much rejoicing!
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Fri, 11 Mar 2005 13:05:31 +0000 |
parents | |
children | b256ce6b85b8 |
comparison
equal
deleted
inserted
replaced
10683:e11f3e1599d4 | 10684:72a5babfa8b4 |
---|---|
1 /* | |
2 * A plugin to test the ciphers that ship with gaim | |
3 * | |
4 * Copyright (C) 2004, Gary Kramlich <amc_grim@users.sf.net> | |
5 * | |
6 * This program is free software; you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation; either version 2 of the | |
9 * License, or (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, but | |
12 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
19 * 02111-1307, USA. | |
20 */ | |
21 | |
22 #ifdef HAVE_CONFIG_H | |
23 #include <config.h> | |
24 #endif | |
25 | |
26 #ifndef GAIM_PLUGINS | |
27 #define GAIM_PLUGINS | |
28 #endif | |
29 | |
30 #include "internal.h" | |
31 | |
32 #include <glib.h> | |
33 #include <string.h> | |
34 | |
35 #include "cipher.h" | |
36 #include "debug.h" | |
37 #include "plugin.h" | |
38 #include "version.h" | |
39 | |
40 struct test { | |
41 const guint8 *question; | |
42 const guint8 *answer; | |
43 }; | |
44 | |
45 /************************************************************************** | |
46 * MD5 Stuff | |
47 **************************************************************************/ | |
48 struct test md5_tests[8] = { | |
49 { "", "d41d8cd98f00b204e9800998ecf8427e"}, | |
50 { "a", "0cc175b9c0f1b6a831c399e269772661"}, | |
51 { "abc", "900150983cd24fb0d6963f7d28e17f72"}, | |
52 { "message digest", "f96b697d7cb7938d525a2f31aaf161d0"}, | |
53 { "abcdefghijklmnopqrstuvwxyz", "c3fcd3d76192e4007dfb496cca67e13b"}, | |
54 { "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
55 "abcdefghijklmnopqrstuvwxyz" | |
56 "0123456789", "d174ab98d277d9f5a5611c2c9f419d9f"}, | |
57 {"123456789012345678901234567" | |
58 "890123456789012345678901234" | |
59 "56789012345678901234567890", "57edf4a22be3c955ac49da2e2107b67a"}, | |
60 { NULL, NULL } | |
61 }; | |
62 | |
63 static void | |
64 cipher_test_md5() { | |
65 GaimCipher *cipher; | |
66 GaimCipherContext *context; | |
67 gchar digest[32]; | |
68 gint i = 0; | |
69 | |
70 cipher = gaim_ciphers_find_cipher("md5"); | |
71 if(!cipher) { | |
72 gaim_debug_info("cipher-test", | |
73 "could not find md5 cipher, not testing\n"); | |
74 return; | |
75 } | |
76 | |
77 gaim_debug_info("cipher-test", "Running md5 tests\n"); | |
78 | |
79 context = gaim_cipher_context_new(cipher, NULL); | |
80 | |
81 while(md5_tests[i].answer) { | |
82 gaim_debug_info("cipher-test", "Test %02d:\n", i); | |
83 gaim_debug_info("cipher-test", "Testing '%s'\n", md5_tests[i].question); | |
84 | |
85 gaim_cipher_context_append(context, md5_tests[i].question, | |
86 strlen(md5_tests[i].question)); | |
87 | |
88 gaim_cipher_context_digest_to_str(context, NULL, digest); | |
89 | |
90 gaim_debug_info("cipher-test", "\tGot: %s\n", digest); | |
91 gaim_debug_info("cipher-test", "\tWanted: %s\n", md5_tests[i].answer); | |
92 | |
93 gaim_cipher_context_reset(context, NULL); | |
94 i++; | |
95 } | |
96 | |
97 gaim_cipher_context_destroy(context); | |
98 | |
99 gaim_debug_info("cipher-test", "md5 tests completed\n\n"); | |
100 } | |
101 | |
102 /************************************************************************** | |
103 * SHA-1 stuff | |
104 **************************************************************************/ | |
105 struct test sha1_tests[5] = { | |
106 {"a", "86f7e437faa5a7fce15d1ddcb9eaeaea377667b8"}, | |
107 {"abc", "a9993e364706816aba3e25717850c26c9cd0d89d"} , | |
108 {"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", "84983e441c3bd26ebaae4aa1f95129e5e54670f1"} , | |
109 {NULL, "34aa973cd4c4daa4f61eeb2bdbad27316534016f"}, | |
110 {NULL, NULL} | |
111 }; | |
112 | |
113 static void | |
114 cipher_test_sha1() { | |
115 GaimCipher *cipher; | |
116 GaimCipherContext *context; | |
117 gchar digest[40]; | |
118 gint i = 0; | |
119 | |
120 cipher = gaim_ciphers_find_cipher("sha1"); | |
121 if(!cipher) { | |
122 gaim_debug_info("cipher-test", | |
123 "could not find sha1 cipher, not testing\n"); | |
124 return; | |
125 } | |
126 | |
127 gaim_debug_info("cipher-test", "Running sha1 tests\n"); | |
128 | |
129 context = gaim_cipher_context_new(cipher, NULL); | |
130 | |
131 while(sha1_tests[i].answer) { | |
132 gaim_debug_info("cipher-test", "Test %02d:\n", i); | |
133 gaim_debug_info("cipher-test", "Testing '%s'\n", | |
134 (sha1_tests[i].question != NULL) ? | |
135 sha1_tests[i].question : "'a'x1000, 1000 times"); | |
136 | |
137 if(sha1_tests[i].question) { | |
138 gaim_cipher_context_append(context, sha1_tests[i].question, | |
139 strlen(sha1_tests[i].question)); | |
140 } else { | |
141 gint j; | |
142 guint8 buff[1000]; | |
143 | |
144 memset(buff, 'a', 1000); | |
145 | |
146 for(j = 0; j < 1000; j++) | |
147 gaim_cipher_context_append(context, buff, 1000); | |
148 } | |
149 | |
150 gaim_cipher_context_digest_to_str(context, NULL, digest); | |
151 | |
152 gaim_debug_info("cipher-test", "\tGot: %s\n", digest); | |
153 gaim_debug_info("cipher-test", "\tWanted: %s\n", sha1_tests[i].answer); | |
154 | |
155 gaim_cipher_context_reset(context, NULL); | |
156 i++; | |
157 } | |
158 | |
159 gaim_cipher_context_destroy(context); | |
160 | |
161 gaim_debug_info("cipher-test", "sha1 tests completed\n\n"); | |
162 } | |
163 /************************************************************************** | |
164 * Plugin stuff | |
165 **************************************************************************/ | |
166 static gboolean | |
167 plugin_load(GaimPlugin *plugin) { | |
168 cipher_test_md5(); | |
169 cipher_test_sha1(); | |
170 | |
171 return TRUE; | |
172 } | |
173 | |
174 static GaimPluginInfo info = | |
175 { | |
176 GAIM_PLUGIN_MAGIC, | |
177 GAIM_MAJOR_VERSION, | |
178 GAIM_MINOR_VERSION, | |
179 GAIM_PLUGIN_STANDARD, /**< type */ | |
180 NULL, /**< ui_requirement */ | |
181 0, /**< flags */ | |
182 NULL, /**< dependencies */ | |
183 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
184 | |
185 "core-cipher-test", /**< id */ | |
186 N_("Cipher Test"), /**< name */ | |
187 VERSION, /**< version */ | |
188 /** summary */ | |
189 N_("Tests the ciphers that ship with gaim."), | |
190 /** description */ | |
191 N_("Tests the ciphers that ship with gaim."), | |
192 "Gary Kramlich <amc_grim@users.sf.net>", /**< author */ | |
193 GAIM_WEBSITE, /**< homepage */ | |
194 | |
195 plugin_load, /**< load */ | |
196 NULL, /**< unload */ | |
197 NULL, /**< destroy */ | |
198 | |
199 NULL, /**< ui_info */ | |
200 NULL, /**< extra_info */ | |
201 NULL, | |
202 NULL | |
203 }; | |
204 | |
205 static void | |
206 init_plugin(GaimPlugin *plugin) { | |
207 } | |
208 | |
209 GAIM_INIT_PLUGIN(ciper_test, init_plugin, info) |