Thu, 24 Oct 2013 03:37:02 +0530
Merged default branch
| 10684 | 1 | /* |
| 15884 | 2 | * A plugin to test the ciphers that ship with purple |
| 10684 | 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 | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
16786
diff
changeset
|
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
16786
diff
changeset
|
19 | * 02111-1301, USA. |
| 10684 | 20 | */ |
| 21 | ||
| 22 | #ifdef HAVE_CONFIG_H | |
| 23 | #include <config.h> | |
| 24 | #endif | |
| 25 | ||
| 15884 | 26 | #ifndef PURPLE_PLUGINS |
| 27 | #define PURPLE_PLUGINS | |
| 10684 | 28 | #endif |
| 29 | ||
| 30 | #include "internal.h" | |
| 31 | ||
| 32 | #include <glib.h> | |
| 33 | #include <string.h> | |
| 34 | ||
| 35 | #include "debug.h" | |
| 36 | #include "plugin.h" | |
| 37 | #include "version.h" | |
|
34554
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
38 | #include "util.h" |
|
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
39 | |
|
34567
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34554
diff
changeset
|
40 | #include "ciphers/aescipher.h" |
|
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34554
diff
changeset
|
41 | #include "ciphers/md5hash.h" |
|
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34554
diff
changeset
|
42 | #include "ciphers/pbkdf2cipher.h" |
|
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34554
diff
changeset
|
43 | #include "ciphers/sha1hash.h" |
|
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34554
diff
changeset
|
44 | #include "ciphers/sha256hash.h" |
| 10684 | 45 | |
| 46 | struct test { | |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
47 | const gchar *question; |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
48 | const gchar *answer; |
| 10684 | 49 | }; |
| 50 | ||
| 51 | /************************************************************************** | |
| 52 | * MD5 Stuff | |
| 53 | **************************************************************************/ | |
| 54 | struct test md5_tests[8] = { | |
| 55 | { "", "d41d8cd98f00b204e9800998ecf8427e"}, | |
| 56 | { "a", "0cc175b9c0f1b6a831c399e269772661"}, | |
| 57 | { "abc", "900150983cd24fb0d6963f7d28e17f72"}, | |
| 58 | { "message digest", "f96b697d7cb7938d525a2f31aaf161d0"}, | |
| 59 | { "abcdefghijklmnopqrstuvwxyz", "c3fcd3d76192e4007dfb496cca67e13b"}, | |
| 60 | { "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
| 61 | "abcdefghijklmnopqrstuvwxyz" | |
| 62 | "0123456789", "d174ab98d277d9f5a5611c2c9f419d9f"}, | |
| 63 | {"123456789012345678901234567" | |
| 64 | "890123456789012345678901234" | |
| 65 | "56789012345678901234567890", "57edf4a22be3c955ac49da2e2107b67a"}, | |
| 66 | { NULL, NULL } | |
| 67 | }; | |
| 68 | ||
| 69 | static void | |
|
22104
56970903b8e9
Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@pidgin.im>
parents:
20288
diff
changeset
|
70 | cipher_test_md5(void) { |
|
34567
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34554
diff
changeset
|
71 | PurpleHash *hash; |
|
12388
3a25d96abdaf
[gaim-migrate @ 14694]
Richard Laager <rlaager@pidgin.im>
parents:
12387
diff
changeset
|
72 | gchar digest[33]; |
| 10687 | 73 | gboolean ret; |
| 10684 | 74 | gint i = 0; |
| 75 | ||
|
34567
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34554
diff
changeset
|
76 | hash = purple_md5_hash_new(); |
|
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34554
diff
changeset
|
77 | if(!hash) { |
| 15884 | 78 | purple_debug_info("cipher-test", |
| 10684 | 79 | "could not find md5 cipher, not testing\n"); |
| 80 | return; | |
| 81 | } | |
| 82 | ||
| 15884 | 83 | purple_debug_info("cipher-test", "Running md5 tests\n"); |
| 10684 | 84 | |
| 85 | while(md5_tests[i].answer) { | |
| 15884 | 86 | purple_debug_info("cipher-test", "Test %02d:\n", i); |
| 87 | purple_debug_info("cipher-test", "Testing '%s'\n", md5_tests[i].question); | |
| 10684 | 88 | |
|
34567
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34554
diff
changeset
|
89 | purple_hash_append(hash, (guchar *)md5_tests[i].question, |
| 10684 | 90 | strlen(md5_tests[i].question)); |
| 91 | ||
|
34567
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34554
diff
changeset
|
92 | ret = purple_hash_digest_to_str(hash, digest, sizeof(digest)); |
| 10684 | 93 | |
| 10687 | 94 | if(!ret) { |
| 15884 | 95 | purple_debug_info("cipher-test", "failed\n"); |
| 10687 | 96 | } else { |
| 15884 | 97 | purple_debug_info("cipher-test", "\tGot: %s\n", digest); |
| 98 | purple_debug_info("cipher-test", "\tWanted: %s\n", | |
| 10687 | 99 | md5_tests[i].answer); |
| 100 | } | |
| 10684 | 101 | |
|
34567
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34554
diff
changeset
|
102 | purple_hash_reset(hash); |
| 10684 | 103 | i++; |
| 104 | } | |
| 105 | ||
|
34567
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34554
diff
changeset
|
106 | g_object_unref(hash); |
| 10684 | 107 | |
| 15884 | 108 | purple_debug_info("cipher-test", "md5 tests completed\n\n"); |
| 10684 | 109 | } |
| 110 | ||
| 111 | /************************************************************************** | |
| 112 | * SHA-1 stuff | |
| 113 | **************************************************************************/ | |
| 114 | struct test sha1_tests[5] = { | |
| 115 | {"a", "86f7e437faa5a7fce15d1ddcb9eaeaea377667b8"}, | |
| 116 | {"abc", "a9993e364706816aba3e25717850c26c9cd0d89d"} , | |
| 117 | {"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", "84983e441c3bd26ebaae4aa1f95129e5e54670f1"} , | |
|
22104
56970903b8e9
Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@pidgin.im>
parents:
20288
diff
changeset
|
118 | {NULL, "34aa973cd4c4daa4f61eeb2bdbad27316534016f"}, |
| 10684 | 119 | {NULL, NULL} |
| 120 | }; | |
| 121 | ||
| 122 | static void | |
|
22104
56970903b8e9
Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@pidgin.im>
parents:
20288
diff
changeset
|
123 | cipher_test_sha1(void) { |
|
34567
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34554
diff
changeset
|
124 | PurpleHash *hash; |
|
12388
3a25d96abdaf
[gaim-migrate @ 14694]
Richard Laager <rlaager@pidgin.im>
parents:
12387
diff
changeset
|
125 | gchar digest[41]; |
| 10684 | 126 | gint i = 0; |
| 10687 | 127 | gboolean ret; |
| 10684 | 128 | |
|
34567
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34554
diff
changeset
|
129 | hash = purple_sha1_hash_new(); |
|
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34554
diff
changeset
|
130 | if(!hash) { |
| 15884 | 131 | purple_debug_info("cipher-test", |
| 10684 | 132 | "could not find sha1 cipher, not testing\n"); |
| 133 | return; | |
| 134 | } | |
| 135 | ||
| 15884 | 136 | purple_debug_info("cipher-test", "Running sha1 tests\n"); |
| 10684 | 137 | |
| 138 | while(sha1_tests[i].answer) { | |
| 15884 | 139 | purple_debug_info("cipher-test", "Test %02d:\n", i); |
| 140 | purple_debug_info("cipher-test", "Testing '%s'\n", | |
| 10684 | 141 | (sha1_tests[i].question != NULL) ? |
| 142 | sha1_tests[i].question : "'a'x1000, 1000 times"); | |
| 143 | ||
| 144 | if(sha1_tests[i].question) { | |
|
34567
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34554
diff
changeset
|
145 | purple_hash_append(hash, (guchar *)sha1_tests[i].question, |
| 10684 | 146 | strlen(sha1_tests[i].question)); |
| 147 | } else { | |
| 148 | gint j; | |
|
11183
be87fe695c93
[gaim-migrate @ 13295]
Mark Doliner <markdoliner@pidgin.im>
parents:
11033
diff
changeset
|
149 | guchar buff[1000]; |
| 10684 | 150 | |
| 151 | memset(buff, 'a', 1000); | |
| 152 | ||
| 153 | for(j = 0; j < 1000; j++) | |
|
34567
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34554
diff
changeset
|
154 | purple_hash_append(hash, buff, 1000); |
| 10684 | 155 | } |
| 156 | ||
|
34567
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34554
diff
changeset
|
157 | ret = purple_hash_digest_to_str(hash, digest, sizeof(digest)); |
| 10684 | 158 | |
| 10687 | 159 | if(!ret) { |
| 15884 | 160 | purple_debug_info("cipher-test", "failed\n"); |
| 10687 | 161 | } else { |
| 15884 | 162 | purple_debug_info("cipher-test", "\tGot: %s\n", digest); |
| 163 | purple_debug_info("cipher-test", "\tWanted: %s\n", | |
| 10687 | 164 | sha1_tests[i].answer); |
| 165 | } | |
| 10684 | 166 | |
|
34567
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34554
diff
changeset
|
167 | purple_hash_reset(hash); |
| 10684 | 168 | i++; |
| 169 | } | |
| 170 | ||
|
34567
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34554
diff
changeset
|
171 | g_object_unref(hash); |
| 10684 | 172 | |
| 15884 | 173 | purple_debug_info("cipher-test", "sha1 tests completed\n\n"); |
| 10684 | 174 | } |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
175 | |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
176 | static void |
|
22104
56970903b8e9
Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@pidgin.im>
parents:
20288
diff
changeset
|
177 | cipher_test_digest(void) |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
178 | { |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
179 | const gchar *nonce = "dcd98b7102dd2f0e8b11d0f600bfb0c093"; |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
180 | const gchar *client_nonce = "0a4f113b"; |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
181 | const gchar *username = "Mufasa"; |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
182 | const gchar *realm = "testrealm@host.com"; |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
183 | const gchar *password = "Circle Of Life"; |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
184 | const gchar *algorithm = "md5"; |
|
12389
7196ba664097
[gaim-migrate @ 14695]
Richard Laager <rlaager@pidgin.im>
parents:
12388
diff
changeset
|
185 | const gchar *nonce_count = "00000001"; |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
186 | const gchar *method = "GET"; |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
187 | const gchar *qop = "auth"; |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
188 | const gchar *digest_uri = "/dir/index.html"; |
|
12389
7196ba664097
[gaim-migrate @ 14695]
Richard Laager <rlaager@pidgin.im>
parents:
12388
diff
changeset
|
189 | const gchar *entity = NULL; |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
190 | |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
191 | gchar *session_key; |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
192 | |
| 15884 | 193 | purple_debug_info("cipher-test", "Running HTTP Digest tests\n"); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
194 | |
|
34554
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
195 | session_key = purple_http_digest_calculate_session_key( |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
196 | algorithm, username, realm, password, |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
197 | nonce, client_nonce); |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
198 | |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
199 | if (session_key == NULL) |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
200 | { |
| 15884 | 201 | purple_debug_info("cipher-test", |
| 202 | "purple_cipher_http_digest_calculate_session_key failed.\n"); | |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
203 | } |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
204 | else |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
205 | { |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
206 | gchar *response; |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
207 | |
| 15884 | 208 | purple_debug_info("cipher-test", "\tsession_key: Got: %s\n", session_key); |
| 209 | purple_debug_info("cipher-test", "\tsession_key: Wanted: %s\n", "939e7578ed9e3c518a452acee763bce9"); | |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
210 | |
|
34554
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
211 | response = purple_http_digest_calculate_response( |
|
12389
7196ba664097
[gaim-migrate @ 14695]
Richard Laager <rlaager@pidgin.im>
parents:
12388
diff
changeset
|
212 | algorithm, method, digest_uri, qop, entity, |
|
7196ba664097
[gaim-migrate @ 14695]
Richard Laager <rlaager@pidgin.im>
parents:
12388
diff
changeset
|
213 | nonce, nonce_count, client_nonce, session_key); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
214 | |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
215 | g_free(session_key); |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
216 | |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
217 | if (response == NULL) |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
218 | { |
| 15884 | 219 | purple_debug_info("cipher-test", |
| 220 | "purple_cipher_http_digest_calculate_session_key failed.\n"); | |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
221 | } |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
222 | else |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
223 | { |
| 15884 | 224 | purple_debug_info("cipher-test", "\tresponse: Got: %s\n", response); |
| 225 | purple_debug_info("cipher-test", "\tresponse: Wanted: %s\n", "6629fae49393a05397450978507c4ef1"); | |
|
12387
913d216b13b2
[gaim-migrate @ 14693]
Richard Laager <rlaager@pidgin.im>
parents:
12382
diff
changeset
|
226 | g_free(response); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
227 | } |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
228 | } |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
229 | |
| 15884 | 230 | purple_debug_info("cipher-test", "HTTP Digest tests completed\n\n"); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
231 | } |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
232 | |
| 10684 | 233 | /************************************************************************** |
|
34178
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
234 | * PBKDF2 stuff |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
235 | **************************************************************************/ |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
236 | |
| 34182 | 237 | #ifdef HAVE_NSS |
| 238 | # include <nss.h> | |
| 239 | # include <secmod.h> | |
| 240 | # include <pk11func.h> | |
| 241 | # include <prerror.h> | |
| 242 | # include <secerr.h> | |
| 243 | #endif | |
|
34178
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
244 | |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
245 | typedef struct { |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
246 | const gchar *hash; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
247 | const guint iter_count; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
248 | const gchar *passphrase; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
249 | const gchar *salt; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
250 | const guint out_len; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
251 | const gchar *answer; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
252 | } pbkdf2_test; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
253 | |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
254 | pbkdf2_test pbkdf2_tests[] = { |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
255 | { "sha256", 1, "password", "salt", 32, "120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17b"}, |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
256 | { "sha1", 1, "password", "salt", 32, "0c60c80f961f0e71f3a9b524af6012062fe037a6e0f0eb94fe8fc46bdc637164"}, |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
257 | { "sha1", 1000, "ala ma kota", "", 16, "924dba137b5bcf6d0de84998f3d8e1f9"}, |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
258 | { "sha1", 1, "", "", 32, "1e437a1c79d75be61e91141dae20affc4892cc99abcc3fe753887bccc8920176"}, |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
259 | { "sha256", 100, "some password", "and salt", 1, "c7"}, |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
260 | { "sha1", 10000, "pretty long password W Szczebrzeszynie chrzaszcz brzmi w trzcinie i Szczebrzeszyn z tego slynie", "Grzegorz Brzeczyszczykiewicz", 32, "8cb0cb164f2554733ae02f5751b0e84a88fb385446e85a3991bdcdf1ea11795c"}, |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
261 | { NULL, 0, NULL, NULL, 0, NULL} |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
262 | }; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
263 | |
| 34182 | 264 | #ifdef HAVE_NSS |
| 265 | ||
|
34178
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
266 | static gchar* |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
267 | cipher_pbkdf2_nss_sha1(const gchar *passphrase, const gchar *salt, |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
268 | guint iter_count, guint out_len) |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
269 | { |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
270 | PK11SlotInfo *slot; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
271 | SECAlgorithmID *algorithm = NULL; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
272 | PK11SymKey *symkey = NULL; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
273 | const SECItem *symkey_data = NULL; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
274 | SECItem salt_item, passphrase_item; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
275 | guchar *passphrase_buff, *salt_buff; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
276 | gchar *ret; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
277 | |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
278 | g_return_val_if_fail(passphrase != NULL, NULL); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
279 | g_return_val_if_fail(iter_count > 0, NULL); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
280 | g_return_val_if_fail(out_len > 0, NULL); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
281 | |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
282 | NSS_NoDB_Init(NULL); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
283 | |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
284 | slot = PK11_GetBestSlot(PK11_AlgtagToMechanism(SEC_OID_PKCS5_PBKDF2), |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
285 | NULL); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
286 | if (slot == NULL) { |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
287 | purple_debug_error("cipher-test", "NSS: couldn't get slot: " |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
288 | "%d\n", PR_GetError()); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
289 | return NULL; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
290 | } |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
291 | |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
292 | salt_buff = (guchar*)g_strdup(salt ? salt : ""); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
293 | salt_item.type = siBuffer; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
294 | salt_item.data = salt_buff; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
295 | salt_item.len = salt ? strlen(salt) : 0; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
296 | |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
297 | algorithm = PK11_CreatePBEV2AlgorithmID(SEC_OID_PKCS5_PBKDF2, |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
298 | SEC_OID_AES_256_CBC, SEC_OID_HMAC_SHA1, out_len, iter_count, |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
299 | &salt_item); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
300 | if (algorithm == NULL) { |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
301 | purple_debug_error("cipher-test", "NSS: couldn't create " |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
302 | "algorithm ID: %d\n", PR_GetError()); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
303 | PK11_FreeSlot(slot); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
304 | g_free(salt_buff); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
305 | return NULL; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
306 | } |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
307 | |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
308 | passphrase_buff = (guchar*)g_strdup(passphrase); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
309 | passphrase_item.type = siBuffer; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
310 | passphrase_item.data = passphrase_buff; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
311 | passphrase_item.len = strlen(passphrase); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
312 | |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
313 | symkey = PK11_PBEKeyGen(slot, algorithm, &passphrase_item, PR_FALSE, |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
314 | NULL); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
315 | if (symkey == NULL) { |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
316 | purple_debug_error("cipher-test", "NSS: Couldn't generate key: " |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
317 | "%d\n", PR_GetError()); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
318 | SECOID_DestroyAlgorithmID(algorithm, PR_TRUE); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
319 | PK11_FreeSlot(slot); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
320 | g_free(passphrase_buff); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
321 | g_free(salt_buff); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
322 | return NULL; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
323 | } |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
324 | |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
325 | if (PK11_ExtractKeyValue(symkey) == SECSuccess) |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
326 | symkey_data = PK11_GetKeyData(symkey); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
327 | |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
328 | if (symkey_data == NULL || symkey_data->data == NULL) { |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
329 | purple_debug_error("cipher-test", "NSS: Couldn't extract key " |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
330 | "value: %d\n", PR_GetError()); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
331 | PK11_FreeSymKey(symkey); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
332 | SECOID_DestroyAlgorithmID(algorithm, PR_TRUE); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
333 | PK11_FreeSlot(slot); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
334 | g_free(passphrase_buff); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
335 | g_free(salt_buff); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
336 | return NULL; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
337 | } |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
338 | |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
339 | if (symkey_data->len != out_len) { |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
340 | purple_debug_error("cipher-test", "NSS: Invalid key length: %d " |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
341 | "(should be %d)\n", symkey_data->len, out_len); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
342 | PK11_FreeSymKey(symkey); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
343 | SECOID_DestroyAlgorithmID(algorithm, PR_TRUE); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
344 | PK11_FreeSlot(slot); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
345 | g_free(passphrase_buff); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
346 | g_free(salt_buff); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
347 | return NULL; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
348 | } |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
349 | |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
350 | ret = purple_base16_encode(symkey_data->data, symkey_data->len); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
351 | |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
352 | PK11_FreeSymKey(symkey); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
353 | SECOID_DestroyAlgorithmID(algorithm, PR_TRUE); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
354 | PK11_FreeSlot(slot); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
355 | g_free(passphrase_buff); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
356 | g_free(salt_buff); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
357 | return ret; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
358 | } |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
359 | |
| 34182 | 360 | #endif /* HAVE_NSS */ |
| 361 | ||
|
34178
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
362 | static void |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
363 | cipher_test_pbkdf2(void) |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
364 | { |
|
34567
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34554
diff
changeset
|
365 | PurpleCipher *cipher; |
|
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34554
diff
changeset
|
366 | PurpleHash *hash; |
|
34178
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
367 | int i = 0; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
368 | gboolean fail = FALSE; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
369 | |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
370 | purple_debug_info("cipher-test", "Running PBKDF2 tests\n"); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
371 | |
| 34182 | 372 | while (!fail && pbkdf2_tests[i].answer) { |
|
34178
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
373 | pbkdf2_test *test = &pbkdf2_tests[i]; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
374 | gchar digest[2 * 32 + 1 + 10]; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
375 | gchar *digest_nss = NULL; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
376 | gboolean ret, skip_nss = FALSE; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
377 | |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
378 | i++; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
379 | |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
380 | purple_debug_info("cipher-test", "Test %02d:\n", i); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
381 | purple_debug_info("cipher-test", |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
382 | "\tTesting '%s' with salt:'%s' hash:%s iter_count:%d \n", |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
383 | test->passphrase, test->salt, test->hash, |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
384 | test->iter_count); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
385 | |
|
34554
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
386 | if (!strcmp(test->hash, "sha1")) |
|
34567
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34554
diff
changeset
|
387 | hash = purple_sha1_hash_new(); |
|
34554
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
388 | else if (!strcmp(test->hash, "sha256")) |
|
34567
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34554
diff
changeset
|
389 | hash = purple_sha256_hash_new(); |
|
34554
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
390 | else |
|
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
391 | hash = NULL; |
|
34178
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
392 | |
|
34554
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
393 | cipher = purple_pbkdf2_cipher_new(hash); |
|
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
394 | |
|
34569
8fdccc60cfde
Replace g_object_set_property with g_object_set where we aren't passing a GValue*
Ankit Vani <a@nevitus.org>
parents:
34568
diff
changeset
|
395 | g_object_set(G_OBJECT(cipher), "iter_count", GUINT_TO_POINTER(test->iter_count), NULL); |
|
8fdccc60cfde
Replace g_object_set_property with g_object_set where we aren't passing a GValue*
Ankit Vani <a@nevitus.org>
parents:
34568
diff
changeset
|
396 | g_object_set(G_OBJECT(cipher), "out_len", GUINT_TO_POINTER(test->out_len), NULL); |
|
34554
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
397 | purple_cipher_set_salt(cipher, (const guchar*)test->salt, test->salt ? strlen(test->salt): 0); |
|
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
398 | purple_cipher_set_key(cipher, (const guchar*)test->passphrase, strlen(test->passphrase)); |
|
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
399 | |
|
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
400 | ret = purple_cipher_digest_to_str(cipher, digest, sizeof(digest)); |
|
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
401 | purple_cipher_reset(cipher); |
|
34178
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
402 | |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
403 | if (!ret) { |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
404 | purple_debug_info("cipher-test", "\tfailed\n"); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
405 | fail = TRUE; |
|
34554
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
406 | g_object_unref(cipher); |
|
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
407 | g_object_unref(hash); |
|
34178
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
408 | continue; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
409 | } |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
410 | |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
411 | if (g_strcmp0(test->hash, "sha1") != 0) |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
412 | skip_nss = TRUE; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
413 | if (test->out_len != 16 && test->out_len != 32) |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
414 | skip_nss = TRUE; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
415 | |
| 34182 | 416 | #ifdef HAVE_NSS |
|
34178
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
417 | if (!skip_nss) { |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
418 | digest_nss = cipher_pbkdf2_nss_sha1(test->passphrase, |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
419 | test->salt, test->iter_count, test->out_len); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
420 | } |
| 34182 | 421 | #else |
| 422 | skip_nss = TRUE; | |
| 423 | #endif | |
|
34178
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
424 | |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
425 | if (!ret) { |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
426 | purple_debug_info("cipher-test", "\tnss test failed\n"); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
427 | fail = TRUE; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
428 | } |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
429 | |
| 34182 | 430 | purple_debug_info("cipher-test", "\tGot: %s\n", digest); |
| 431 | if (digest_nss) | |
| 432 | purple_debug_info("cipher-test", "\tGot from NSS: %s\n", digest_nss); | |
| 433 | purple_debug_info("cipher-test", "\tWanted: %s\n", test->answer); | |
| 434 | ||
|
34178
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
435 | if (g_strcmp0(digest, test->answer) == 0 && |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
436 | (skip_nss || g_strcmp0(digest, digest_nss) == 0)) { |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
437 | purple_debug_info("cipher-test", "\tTest OK\n"); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
438 | } |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
439 | else { |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
440 | purple_debug_info("cipher-test", "\twrong answer\n"); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
441 | fail = TRUE; |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
442 | } |
|
34554
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
443 | |
|
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
444 | g_object_unref(cipher); |
|
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
445 | g_object_unref(hash); |
|
34178
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
446 | } |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
447 | |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
448 | if (fail) |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
449 | purple_debug_info("cipher-test", "PBKDF2 tests FAILED\n\n"); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
450 | else |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
451 | purple_debug_info("cipher-test", "PBKDF2 tests completed successfully\n\n"); |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
452 | } |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
453 | |
|
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
454 | /************************************************************************** |
| 34182 | 455 | * AES stuff |
| 456 | **************************************************************************/ | |
| 457 | ||
| 458 | typedef struct { | |
| 459 | const gchar *iv; | |
| 460 | const gchar *key; | |
| 461 | const gchar *plaintext; | |
| 462 | const gchar *cipher; | |
| 463 | } aes_test; | |
| 464 | ||
| 465 | aes_test aes_tests[] = { | |
| 466 | { NULL, "000102030405060708090a0b0c0d0e0f", "plaintext", "152e5b950e5f28fafadee9e96fcc59c9" }, | |
| 467 | { NULL, "000102030405060708090a0b0c0d0e0f", NULL, "954f64f2e4e86e9eee82d20216684899" }, | |
| 468 | { "01010101010101010101010101010101", "000102030405060708090a0b0c0d0e0f", NULL, "35d14e6d3e3a279cf01e343e34e7ded3" }, | |
| 469 | { "01010101010101010101010101010101", "000102030405060708090a0b0c0d0e0f", "plaintext", "19d1996e8c098cf3c94bba5dcf5bc57e" }, | |
| 470 | { "01010101010101010101010101010101", "000102030405060708090a0b0c0d0e0f1011121314151617", "plaintext", "e8fba0deae94f63fe72ae9b8ef128aed" }, | |
| 471 | { "01010101010101010101010101010101", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", "plaintext", "e2dc50f6c60b33ac3b5953b6503cb684" }, | |
| 472 | { "01010101010101010101010101010101", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", "W Szczebrzeszynie chrzaszcz brzmi w trzcinie i Szczebrzeszyn z tego slynie", "8fcc068964e3505f0c2fac61c24592e5c8a9582d3a3264217cf605e9fd1cb056e679e159c4ac3110e8ce6c76c6630d42658c566ba3750c0e6da385b3a9baaa8b3a735b4c1ecaacf58037c8c281e523d2" }, | |
| 473 | { NULL, NULL, NULL, NULL } | |
| 474 | }; | |
| 475 | ||
| 476 | static void | |
| 477 | cipher_test_aes(void) | |
| 478 | { | |
|
34554
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
479 | PurpleCipher *cipher; |
| 34182 | 480 | int i = 0; |
| 481 | gboolean fail = FALSE; | |
| 482 | ||
| 483 | purple_debug_info("cipher-test", "Running AES tests\n"); | |
| 484 | ||
|
34554
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
485 | cipher = purple_aes_cipher_new(); |
|
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
486 | if (cipher == NULL) { |
| 34182 | 487 | purple_debug_error("cipher-test", "AES cipher not found\n"); |
| 488 | fail = TRUE; | |
| 489 | } | |
| 490 | ||
| 491 | while (!fail && aes_tests[i].cipher) { | |
| 492 | aes_test *test = &aes_tests[i]; | |
| 493 | gsize key_size; | |
| 494 | guchar *key; | |
|
34554
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
495 | guchar cipher_s[1024], decipher_s[1024]; |
| 34182 | 496 | ssize_t cipher_len, decipher_len; |
| 497 | gchar *cipher_b16, *deciphered; | |
| 498 | ||
| 499 | purple_debug_info("cipher-test", "Test %02d:\n", i); | |
|
34275
a6ddc53d1c84
Fix minor printf format warning.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
34182
diff
changeset
|
500 | purple_debug_info("cipher-test", "\tTesting '%s' (%" G_GSIZE_FORMAT "bit) \n", |
| 34182 | 501 | test->plaintext ? test->plaintext : "(null)", |
| 502 | strlen(test->key) * 8 / 2); | |
| 503 | ||
| 504 | i++; | |
| 505 | ||
|
34554
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
506 | purple_cipher_reset(cipher); |
| 34182 | 507 | |
| 508 | if (test->iv) { | |
| 509 | gsize iv_size; | |
| 510 | guchar *iv = purple_base16_decode(test->iv, &iv_size); | |
| 511 | g_assert(iv != NULL); | |
|
34554
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
512 | purple_cipher_set_iv(cipher, iv, iv_size); |
| 34182 | 513 | g_free(iv); |
| 514 | } | |
| 515 | ||
| 516 | key = purple_base16_decode(test->key, &key_size); | |
| 517 | g_assert(key != NULL); | |
|
34554
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
518 | purple_cipher_set_key(cipher, key, key_size); |
| 34182 | 519 | g_free(key); |
| 520 | ||
|
34554
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
521 | if (purple_cipher_get_key_size(cipher) != key_size) { |
| 34182 | 522 | purple_debug_info("cipher-test", "\tinvalid key size\n"); |
| 523 | fail = TRUE; | |
| 524 | continue; | |
| 525 | } | |
| 526 | ||
|
34554
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
527 | cipher_len = purple_cipher_encrypt(cipher, |
| 34182 | 528 | (const guchar*)(test->plaintext ? test->plaintext : ""), |
| 529 | test->plaintext ? (strlen(test->plaintext) + 1) : 0, | |
|
34554
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
530 | cipher_s, sizeof(cipher_s)); |
| 34182 | 531 | if (cipher_len < 0) { |
| 532 | purple_debug_info("cipher-test", "\tencryption failed\n"); | |
| 533 | fail = TRUE; | |
| 534 | continue; | |
| 535 | } | |
| 536 | ||
|
34554
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
537 | cipher_b16 = purple_base16_encode(cipher_s, cipher_len); |
| 34182 | 538 | |
| 539 | purple_debug_info("cipher-test", "\tGot: %s\n", cipher_b16); | |
| 540 | purple_debug_info("cipher-test", "\tWanted: %s\n", test->cipher); | |
| 541 | ||
| 542 | if (g_strcmp0(cipher_b16, test->cipher) != 0) { | |
| 543 | purple_debug_info("cipher-test", | |
| 544 | "\tencrypted data doesn't match\n"); | |
| 545 | g_free(cipher_b16); | |
| 546 | fail = TRUE; | |
| 547 | continue; | |
| 548 | } | |
| 549 | g_free(cipher_b16); | |
| 550 | ||
|
34554
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
551 | decipher_len = purple_cipher_decrypt(cipher, |
|
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
552 | cipher_s, cipher_len, decipher_s, sizeof(decipher_s)); |
| 34182 | 553 | if (decipher_len < 0) { |
| 554 | purple_debug_info("cipher-test", "\tdecryption failed\n"); | |
| 555 | fail = TRUE; | |
| 556 | continue; | |
| 557 | } | |
| 558 | ||
|
34554
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
559 | deciphered = (decipher_len > 0) ? (gchar*)decipher_s : NULL; |
| 34182 | 560 | |
| 561 | if (g_strcmp0(deciphered, test->plaintext) != 0) { | |
| 562 | purple_debug_info("cipher-test", | |
| 563 | "\tdecrypted data doesn't match\n"); | |
| 564 | fail = TRUE; | |
| 565 | continue; | |
| 566 | } | |
| 567 | ||
| 568 | purple_debug_info("cipher-test", "\tTest OK\n"); | |
| 569 | } | |
| 570 | ||
|
34554
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
571 | if (cipher != NULL) |
|
9c9febf0807f
Refactored libpurple/plugins to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
572 | g_object_unref(cipher); |
| 34182 | 573 | |
| 574 | if (fail) | |
| 575 | purple_debug_info("cipher-test", "AES tests FAILED\n\n"); | |
| 576 | else | |
| 577 | purple_debug_info("cipher-test", "AES tests completed successfully\n\n"); | |
| 578 | } | |
| 579 | ||
| 580 | /************************************************************************** | |
| 10684 | 581 | * Plugin stuff |
| 582 | **************************************************************************/ | |
| 583 | static gboolean | |
| 15884 | 584 | plugin_load(PurplePlugin *plugin) { |
| 10684 | 585 | cipher_test_md5(); |
| 586 | cipher_test_sha1(); | |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
587 | cipher_test_digest(); |
|
34178
4712cf749699
PBKDF2 support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
588 | cipher_test_pbkdf2(); |
| 34182 | 589 | cipher_test_aes(); |
| 10684 | 590 | |
| 591 | return TRUE; | |
| 592 | } | |
| 593 | ||
| 11033 | 594 | static gboolean |
| 15884 | 595 | plugin_unload(PurplePlugin *plugin) { |
| 11033 | 596 | return TRUE; |
| 597 | } | |
| 598 | ||
| 15884 | 599 | static PurplePluginInfo info = |
| 10684 | 600 | { |
| 15884 | 601 | PURPLE_PLUGIN_MAGIC, |
| 602 | PURPLE_MAJOR_VERSION, | |
| 603 | PURPLE_MINOR_VERSION, | |
| 604 | PURPLE_PLUGIN_STANDARD, /**< type */ | |
| 10684 | 605 | NULL, /**< ui_requirement */ |
| 606 | 0, /**< flags */ | |
| 607 | NULL, /**< dependencies */ | |
| 15884 | 608 | PURPLE_PRIORITY_DEFAULT, /**< priority */ |
| 10684 | 609 | |
| 610 | "core-cipher-test", /**< id */ | |
| 611 | N_("Cipher Test"), /**< name */ | |
|
20288
5ca925a094e2
applied changes from 03b709ec2a153e7e82719df0ba4635108bb1d3c6
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
612 | DISPLAY_VERSION, /**< version */ |
| 10684 | 613 | /** summary */ |
|
15498
2ee3112b6f24
This should be the last of the string changes
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
614 | N_("Tests the ciphers that ship with libpurple."), |
| 10684 | 615 | /** description */ |
|
15498
2ee3112b6f24
This should be the last of the string changes
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
616 | N_("Tests the ciphers that ship with libpurple."), |
| 10684 | 617 | "Gary Kramlich <amc_grim@users.sf.net>", /**< author */ |
| 15884 | 618 | PURPLE_WEBSITE, /**< homepage */ |
| 10684 | 619 | |
| 620 | plugin_load, /**< load */ | |
| 11033 | 621 | plugin_unload, /**< unload */ |
| 10684 | 622 | NULL, /**< destroy */ |
| 623 | ||
| 624 | NULL, /**< ui_info */ | |
| 625 | NULL, /**< extra_info */ | |
| 626 | NULL, | |
|
16786
65c04c7e5c8a
Add padding to structs as necessary to silence compiler warnings
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
627 | NULL, |
|
65c04c7e5c8a
Add padding to structs as necessary to silence compiler warnings
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
628 | /* padding */ |
|
65c04c7e5c8a
Add padding to structs as necessary to silence compiler warnings
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
629 | NULL, |
|
65c04c7e5c8a
Add padding to structs as necessary to silence compiler warnings
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
630 | NULL, |
|
65c04c7e5c8a
Add padding to structs as necessary to silence compiler warnings
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
631 | NULL, |
| 10684 | 632 | NULL |
| 633 | }; | |
| 634 | ||
| 635 | static void | |
| 15884 | 636 | init_plugin(PurplePlugin *plugin) { |
| 10684 | 637 | } |
| 638 | ||
| 15884 | 639 | PURPLE_INIT_PLUGIN(cipher_test, init_plugin, info) |