Sat, 08 Feb 2014 00:57:28 +0100
Fix some clang static analysis warnings
| 34178 | 1 | /* |
| 2 | * purple | |
| 3 | * | |
| 4 | * Purple is the legal property of its developers, whose names are too numerous | |
| 5 | * to list here. Please refer to the COPYRIGHT file distributed with this | |
| 6 | * source distribution. | |
| 7 | * | |
| 8 | * This program is free software; you can redistribute it and/or modify | |
| 9 | * it under the terms of the GNU General Public License as published by | |
| 10 | * the Free Software Foundation; either version 2 of the License, or | |
| 11 | * (at your option) any later version. | |
| 12 | * | |
| 13 | * This program is distributed in the hope that it will be useful, | |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | * GNU General Public License for more details. | |
| 17 | * | |
| 18 | * You should have received a copy of the GNU General Public License | |
| 19 | * along with this program; if not, write to the Free Software | |
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA | |
| 21 | * | |
| 22 | * Written by Tomek Wasilczyk <tomkiewicz@cpw.pidgin.im> | |
| 23 | */ | |
|
35026
fde23518e1e5
Moved PurpleHash to cipher.[ch]
Ankit Vani <a@nevitus.org>
parents:
35020
diff
changeset
|
24 | #include "internal.h" |
|
35077
0a120b204362
ciphers: use g_object_notify_by_pspec instead of g_object_notify
Ankit Vani <a@nevitus.org>
parents:
35065
diff
changeset
|
25 | #include "glibcompat.h" |
|
0a120b204362
ciphers: use g_object_notify_by_pspec instead of g_object_notify
Ankit Vani <a@nevitus.org>
parents:
35065
diff
changeset
|
26 | |
|
34566
e0f887dee077
Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents:
34561
diff
changeset
|
27 | #include "pbkdf2cipher.h" |
|
e0f887dee077
Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents:
34561
diff
changeset
|
28 | #include "hmaccipher.h" |
| 34178 | 29 | #include "debug.h" |
| 30 | ||
| 31 | /* 1024bit */ | |
| 32 | #define PBKDF2_HASH_MAX_LEN 128 | |
| 33 | ||
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
34 | /****************************************************************************** |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
35 | * Structs |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
36 | *****************************************************************************/ |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
37 | #define PURPLE_PBKDF2_CIPHER_GET_PRIVATE(obj) \ |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
38 | (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_PBKDF2_CIPHER, PurplePBKDF2CipherPrivate)) |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
39 | |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
40 | typedef struct { |
|
34566
e0f887dee077
Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents:
34561
diff
changeset
|
41 | PurpleHash *hash; |
| 34178 | 42 | guint iter_count; |
| 43 | size_t out_len; | |
| 44 | ||
| 45 | guchar *salt; | |
| 46 | size_t salt_len; | |
| 47 | guchar *passphrase; | |
| 48 | size_t passphrase_len; | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
49 | } PurplePBKDF2CipherPrivate; |
| 34178 | 50 | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
51 | /****************************************************************************** |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
52 | * Enums |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
53 | *****************************************************************************/ |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
54 | enum { |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
55 | PROP_NONE, |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
56 | PROP_HASH, |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
57 | PROP_ITER_COUNT, |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
58 | PROP_OUT_LEN, |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
59 | PROP_LAST, |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
60 | }; |
| 34178 | 61 | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
62 | /******************************************************************************* |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
63 | * Globals |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
64 | ******************************************************************************/ |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
65 | static GObjectClass *parent_class = NULL; |
|
35077
0a120b204362
ciphers: use g_object_notify_by_pspec instead of g_object_notify
Ankit Vani <a@nevitus.org>
parents:
35065
diff
changeset
|
66 | static GParamSpec *properties[PROP_LAST]; |
| 34178 | 67 | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
68 | /******************************************************************************* |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
69 | * Helpers |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
70 | ******************************************************************************/ |
| 34178 | 71 | static void |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
72 | purple_pbkdf2_cipher_set_hash(PurpleCipher *cipher, |
|
34567
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34566
diff
changeset
|
73 | PurpleHash *hash) |
| 34178 | 74 | { |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
75 | PurplePBKDF2CipherPrivate *priv = PURPLE_PBKDF2_CIPHER_GET_PRIVATE(cipher); |
| 34178 | 76 | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
77 | priv->hash = g_object_ref(G_OBJECT(hash)); |
|
35065
2fe1b3f20c3c
Added a few missing G_PARAM_STATIC_STRINGS and g_object_notify
Ankit Vani <a@nevitus.org>
parents:
35062
diff
changeset
|
78 | |
|
35077
0a120b204362
ciphers: use g_object_notify_by_pspec instead of g_object_notify
Ankit Vani <a@nevitus.org>
parents:
35065
diff
changeset
|
79 | g_object_notify_by_pspec(G_OBJECT(cipher), properties[PROP_HASH]); |
| 34178 | 80 | } |
| 81 | ||
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
82 | /****************************************************************************** |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
83 | * Cipher Stuff |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
84 | *****************************************************************************/ |
| 34178 | 85 | static void |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
86 | purple_pbkdf2_cipher_reset(PurpleCipher *cipher) |
| 34178 | 87 | { |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
88 | PurplePBKDF2CipherPrivate *priv = PURPLE_PBKDF2_CIPHER_GET_PRIVATE(cipher); |
| 34178 | 89 | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
90 | g_return_if_fail(priv != NULL); |
| 34178 | 91 | |
|
34566
e0f887dee077
Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents:
34561
diff
changeset
|
92 | if(PURPLE_IS_HASH(priv->hash)) |
|
e0f887dee077
Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents:
34561
diff
changeset
|
93 | purple_hash_reset(priv->hash); |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
94 | priv->iter_count = 1; |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
95 | priv->out_len = 256; |
| 34178 | 96 | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
97 | purple_cipher_reset_state(cipher); |
| 34178 | 98 | } |
| 99 | ||
| 100 | static void | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
101 | purple_pbkdf2_cipher_reset_state(PurpleCipher *cipher) |
| 34178 | 102 | { |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
103 | PurplePBKDF2CipherPrivate *priv = PURPLE_PBKDF2_CIPHER_GET_PRIVATE(cipher); |
| 34178 | 104 | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
105 | g_return_if_fail(priv != NULL); |
| 34178 | 106 | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
107 | purple_cipher_set_salt(cipher, NULL, 0); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
108 | purple_cipher_set_key(cipher, NULL, 0); |
| 34178 | 109 | } |
| 110 | ||
| 111 | static size_t | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
112 | purple_pbkdf2_cipher_get_digest_size(PurpleCipher *cipher) |
| 34178 | 113 | { |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
114 | PurplePBKDF2CipherPrivate *priv = PURPLE_PBKDF2_CIPHER_GET_PRIVATE(cipher); |
| 34178 | 115 | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
116 | g_return_val_if_fail(priv != NULL, 0); |
| 34178 | 117 | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
118 | return priv->out_len; |
| 34178 | 119 | } |
| 120 | ||
| 121 | static void | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
122 | purple_pbkdf2_cipher_set_salt(PurpleCipher *cipher, const guchar *salt, size_t len) |
| 34178 | 123 | { |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
124 | PurplePBKDF2CipherPrivate *priv = PURPLE_PBKDF2_CIPHER_GET_PRIVATE(cipher); |
| 34178 | 125 | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
126 | g_return_if_fail(priv != NULL); |
| 34178 | 127 | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
128 | g_free(priv->salt); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
129 | priv->salt = NULL; |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
130 | priv->salt_len = 0; |
| 34178 | 131 | |
| 132 | if (len == 0) | |
| 133 | return; | |
| 134 | g_return_if_fail(salt != NULL); | |
| 135 | ||
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
136 | priv->salt = g_memdup(salt, len); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
137 | priv->salt_len = len; |
| 34178 | 138 | } |
| 139 | ||
| 140 | static void | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
141 | purple_pbkdf2_cipher_set_key(PurpleCipher *cipher, const guchar *key, |
| 34178 | 142 | size_t len) |
| 143 | { | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
144 | PurplePBKDF2CipherPrivate *priv = PURPLE_PBKDF2_CIPHER_GET_PRIVATE(cipher); |
| 34178 | 145 | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
146 | g_return_if_fail(priv != NULL); |
| 34178 | 147 | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
148 | if (priv->passphrase != NULL) { |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
149 | memset(priv->passphrase, 0, priv->passphrase_len); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
150 | g_free(priv->passphrase); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
151 | priv->passphrase = NULL; |
| 34178 | 152 | } |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
153 | priv->passphrase_len = 0; |
| 34178 | 154 | |
| 155 | if (len == 0) | |
| 156 | return; | |
| 157 | g_return_if_fail(key != NULL); | |
| 158 | ||
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
159 | priv->passphrase = g_memdup(key, len); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
160 | priv->passphrase_len = len; |
| 34178 | 161 | } |
| 162 | ||
| 163 | /* inspired by gnutls 3.1.10, pbkdf2-sha1.c */ | |
| 164 | static gboolean | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
165 | purple_pbkdf2_cipher_digest(PurpleCipher *cipher, guchar digest[], size_t len) |
| 34178 | 166 | { |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
167 | PurplePBKDF2CipherPrivate *priv = PURPLE_PBKDF2_CIPHER_GET_PRIVATE(cipher); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
168 | |
| 34178 | 169 | guchar halfkey[PBKDF2_HASH_MAX_LEN], halfkey_hash[PBKDF2_HASH_MAX_LEN]; |
| 170 | guint halfkey_len, halfkey_count, halfkey_pad, halfkey_no; | |
| 171 | guchar *salt_ext; | |
| 172 | size_t salt_ext_len; | |
| 173 | guint iter_no; | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
174 | PurpleCipher *hash; |
| 34178 | 175 | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
176 | g_return_val_if_fail(priv != NULL, FALSE); |
| 34178 | 177 | g_return_val_if_fail(digest != NULL, FALSE); |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
178 | g_return_val_if_fail(len >= priv->out_len, FALSE); |
| 34178 | 179 | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
180 | g_return_val_if_fail(priv->hash != NULL, FALSE); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
181 | g_return_val_if_fail(priv->iter_count > 0, FALSE); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
182 | g_return_val_if_fail(priv->passphrase != NULL || |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
183 | priv->passphrase_len == 0, FALSE); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
184 | g_return_val_if_fail(priv->salt != NULL || priv->salt_len == 0, |
| 34178 | 185 | FALSE); |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
186 | g_return_val_if_fail(priv->out_len > 0, FALSE); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
187 | g_return_val_if_fail(priv->out_len < 0xFFFFFFFFU, FALSE); |
| 34178 | 188 | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
189 | salt_ext_len = priv->salt_len + 4; |
| 34178 | 190 | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
191 | hash = purple_hmac_cipher_new(priv->hash); |
| 34178 | 192 | if (hash == NULL) { |
| 193 | purple_debug_error("pbkdf2", "Couldn't create new hmac " | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
194 | "cipher\n"); |
| 34178 | 195 | return FALSE; |
| 196 | } | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
197 | purple_cipher_set_key(hash, (const guchar*)priv->passphrase, |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
198 | priv->passphrase_len); |
| 34178 | 199 | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
200 | halfkey_len = purple_cipher_get_digest_size(hash); |
| 34178 | 201 | if (halfkey_len <= 0 || halfkey_len > PBKDF2_HASH_MAX_LEN) { |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
202 | purple_debug_error("pbkdf2", "Unsupported hash function. " |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
203 | "(digest size: %d)\n", halfkey_len); |
| 34178 | 204 | return FALSE; |
| 205 | } | |
| 206 | ||
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
207 | halfkey_count = ((priv->out_len - 1) / halfkey_len) + 1; |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
208 | halfkey_pad = priv->out_len - (halfkey_count - 1) * halfkey_len; |
| 34178 | 209 | |
| 210 | salt_ext = g_new(guchar, salt_ext_len); | |
|
35382
1b75f8a4129c
Fix some clang static analysis warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35084
diff
changeset
|
211 | if (priv->salt_len > 0) |
|
1b75f8a4129c
Fix some clang static analysis warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35084
diff
changeset
|
212 | memcpy(salt_ext, priv->salt, priv->salt_len); |
| 34178 | 213 | |
| 214 | for (halfkey_no = 1; halfkey_no <= halfkey_count; halfkey_no++) { | |
| 215 | memset(halfkey, 0, halfkey_len); | |
| 216 | ||
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
217 | for (iter_no = 1; iter_no <= priv->iter_count; iter_no++) { |
|
34304
faf0414a8b51
Fix most of libpurple warnings about -Wsign-compare
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
34178
diff
changeset
|
218 | guint i; |
| 34178 | 219 | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
220 | purple_cipher_reset_state(hash); |
| 34178 | 221 | |
| 222 | if (iter_no == 1) { | |
| 223 | salt_ext[salt_ext_len - 4] = | |
| 224 | (halfkey_no & 0xff000000) >> 24; | |
| 225 | salt_ext[salt_ext_len - 3] = | |
| 226 | (halfkey_no & 0x00ff0000) >> 16; | |
| 227 | salt_ext[salt_ext_len - 2] = | |
| 228 | (halfkey_no & 0x0000ff00) >> 8; | |
| 229 | salt_ext[salt_ext_len - 1] = | |
| 230 | (halfkey_no & 0x000000ff) >> 0; | |
| 231 | ||
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
232 | purple_cipher_append(hash, salt_ext, |
| 34178 | 233 | salt_ext_len); |
| 234 | } | |
| 235 | else | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
236 | purple_cipher_append(hash, halfkey_hash, |
| 34178 | 237 | halfkey_len); |
| 238 | ||
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
239 | if (!purple_cipher_digest(hash, halfkey_hash, |
| 34178 | 240 | halfkey_len)) { |
| 241 | purple_debug_error("pbkdf2", | |
| 242 | "Couldn't retrieve a digest\n"); | |
| 243 | g_free(salt_ext); | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
244 | g_object_unref(hash); |
| 34178 | 245 | return FALSE; |
| 246 | } | |
| 247 | ||
| 248 | for (i = 0; i < halfkey_len; i++) | |
| 249 | halfkey[i] ^= halfkey_hash[i]; | |
| 250 | } | |
| 251 | ||
| 252 | memcpy(digest + (halfkey_no - 1) * halfkey_len, halfkey, | |
| 253 | (halfkey_no == halfkey_count) ? halfkey_pad : | |
| 254 | halfkey_len); | |
| 255 | } | |
| 256 | ||
| 257 | g_free(salt_ext); | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
258 | g_object_unref(hash); |
| 34178 | 259 | |
| 260 | return TRUE; | |
| 261 | } | |
| 262 | ||
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
263 | /****************************************************************************** |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
264 | * Object Stuff |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
265 | *****************************************************************************/ |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
266 | static void |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
267 | purple_pbkdf2_cipher_get_property(GObject *obj, guint param_id, GValue *value, |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
268 | GParamSpec *pspec) |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
269 | { |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
270 | PurplePBKDF2Cipher *cipher = PURPLE_PBKDF2_CIPHER(obj); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
271 | PurplePBKDF2CipherPrivate *priv = PURPLE_PBKDF2_CIPHER_GET_PRIVATE(cipher); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
272 | |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
273 | switch(param_id) { |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
274 | case PROP_HASH: |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
275 | g_value_set_object(value, purple_pbkdf2_cipher_get_hash(cipher)); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
276 | break; |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
277 | case PROP_ITER_COUNT: |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
278 | g_value_set_uint(value, priv->iter_count); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
279 | break; |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
280 | case PROP_OUT_LEN: |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
281 | g_value_set_uint(value, priv->out_len); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
282 | break; |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
283 | default: |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
284 | G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
285 | break; |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
286 | } |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
287 | } |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
288 | |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
289 | static void |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
290 | purple_pbkdf2_cipher_set_property(GObject *obj, guint param_id, |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
291 | const GValue *value, GParamSpec *pspec) |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
292 | { |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
293 | PurpleCipher *cipher = PURPLE_CIPHER(obj); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
294 | PurplePBKDF2CipherPrivate *priv = PURPLE_PBKDF2_CIPHER_GET_PRIVATE(cipher); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
295 | |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
296 | switch(param_id) { |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
297 | case PROP_HASH: |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
298 | purple_pbkdf2_cipher_set_hash(cipher, g_value_get_object(value)); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
299 | break; |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
300 | case PROP_ITER_COUNT: |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
301 | priv->iter_count = GPOINTER_TO_UINT(value); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
302 | break; |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
303 | case PROP_OUT_LEN: |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
304 | priv->out_len = GPOINTER_TO_UINT(value); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
305 | break; |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
306 | default: |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
307 | G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
308 | break; |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
309 | } |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
310 | } |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
311 | |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
312 | static void |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
313 | purple_pbkdf2_cipher_finalize(GObject *obj) |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
314 | { |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
315 | PurpleCipher *cipher = PURPLE_CIPHER(obj); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
316 | PurplePBKDF2CipherPrivate *priv = PURPLE_PBKDF2_CIPHER_GET_PRIVATE(cipher); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
317 | |
|
34561
dfeaa5c9c33a
Removed finalize from PurpleCipher, and fixed appropriate finalize methods for ciphers that need it
Ankit Vani <a@nevitus.org>
parents:
34549
diff
changeset
|
318 | purple_pbkdf2_cipher_reset(cipher); |
|
dfeaa5c9c33a
Removed finalize from PurpleCipher, and fixed appropriate finalize methods for ciphers that need it
Ankit Vani <a@nevitus.org>
parents:
34549
diff
changeset
|
319 | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
320 | if (priv->hash != NULL) |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
321 | g_object_unref(priv->hash); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
322 | |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
323 | parent_class->finalize(obj); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
324 | } |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
325 | |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
326 | static void |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
327 | purple_pbkdf2_cipher_class_init(PurplePBKDF2CipherClass *klass) { |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
328 | GObjectClass *obj_class = G_OBJECT_CLASS(klass); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
329 | PurpleCipherClass *cipher_class = PURPLE_CIPHER_CLASS(klass); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
330 | |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
331 | parent_class = g_type_class_peek_parent(klass); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
332 | |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
333 | obj_class->finalize = purple_pbkdf2_cipher_finalize; |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
334 | obj_class->get_property = purple_pbkdf2_cipher_get_property; |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
335 | obj_class->set_property = purple_pbkdf2_cipher_set_property; |
| 34178 | 336 | |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
337 | cipher_class->reset = purple_pbkdf2_cipher_reset; |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
338 | cipher_class->reset_state = purple_pbkdf2_cipher_reset_state; |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
339 | cipher_class->digest = purple_pbkdf2_cipher_digest; |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
340 | cipher_class->get_digest_size = purple_pbkdf2_cipher_get_digest_size; |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
341 | cipher_class->set_salt = purple_pbkdf2_cipher_set_salt; |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
342 | cipher_class->set_key = purple_pbkdf2_cipher_set_key; |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
343 | |
|
35084
07cd7f1767c7
ciphers: use g_object_class_install_properties instead of repeated g_object_class_install_property
Ankit Vani <a@nevitus.org>
parents:
35077
diff
changeset
|
344 | g_type_class_add_private(klass, sizeof(PurplePBKDF2CipherPrivate)); |
|
07cd7f1767c7
ciphers: use g_object_class_install_properties instead of repeated g_object_class_install_property
Ankit Vani <a@nevitus.org>
parents:
35077
diff
changeset
|
345 | |
|
35077
0a120b204362
ciphers: use g_object_notify_by_pspec instead of g_object_notify
Ankit Vani <a@nevitus.org>
parents:
35065
diff
changeset
|
346 | properties[PROP_HASH] = g_param_spec_object("hash", "hash", "hash", |
|
0a120b204362
ciphers: use g_object_notify_by_pspec instead of g_object_notify
Ankit Vani <a@nevitus.org>
parents:
35065
diff
changeset
|
347 | PURPLE_TYPE_HASH, |
|
35062
2aee8634c912
ciphers: Use G_PARAM_STATIC_STRINGS and ensure g_object_notify is always called
Ankit Vani <a@nevitus.org>
parents:
35026
diff
changeset
|
348 | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | |
|
2aee8634c912
ciphers: Use G_PARAM_STATIC_STRINGS and ensure g_object_notify is always called
Ankit Vani <a@nevitus.org>
parents:
35026
diff
changeset
|
349 | G_PARAM_STATIC_STRINGS); |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
350 | |
|
35077
0a120b204362
ciphers: use g_object_notify_by_pspec instead of g_object_notify
Ankit Vani <a@nevitus.org>
parents:
35065
diff
changeset
|
351 | properties[PROP_ITER_COUNT] = g_param_spec_uint("iter-count", "iter-count", |
|
0a120b204362
ciphers: use g_object_notify_by_pspec instead of g_object_notify
Ankit Vani <a@nevitus.org>
parents:
35065
diff
changeset
|
352 | "iter-count", 0, |
|
35062
2aee8634c912
ciphers: Use G_PARAM_STATIC_STRINGS and ensure g_object_notify is always called
Ankit Vani <a@nevitus.org>
parents:
35026
diff
changeset
|
353 | G_MAXUINT, 0, G_PARAM_READWRITE | |
|
2aee8634c912
ciphers: Use G_PARAM_STATIC_STRINGS and ensure g_object_notify is always called
Ankit Vani <a@nevitus.org>
parents:
35026
diff
changeset
|
354 | G_PARAM_STATIC_STRINGS); |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
355 | |
|
35077
0a120b204362
ciphers: use g_object_notify_by_pspec instead of g_object_notify
Ankit Vani <a@nevitus.org>
parents:
35065
diff
changeset
|
356 | properties[PROP_OUT_LEN] = g_param_spec_uint("out-len", "out-len", |
|
0a120b204362
ciphers: use g_object_notify_by_pspec instead of g_object_notify
Ankit Vani <a@nevitus.org>
parents:
35065
diff
changeset
|
357 | "out-len", 0, |
|
35062
2aee8634c912
ciphers: Use G_PARAM_STATIC_STRINGS and ensure g_object_notify is always called
Ankit Vani <a@nevitus.org>
parents:
35026
diff
changeset
|
358 | G_MAXUINT, 0, G_PARAM_READWRITE | |
|
2aee8634c912
ciphers: Use G_PARAM_STATIC_STRINGS and ensure g_object_notify is always called
Ankit Vani <a@nevitus.org>
parents:
35026
diff
changeset
|
359 | G_PARAM_STATIC_STRINGS); |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
360 | |
|
35084
07cd7f1767c7
ciphers: use g_object_class_install_properties instead of repeated g_object_class_install_property
Ankit Vani <a@nevitus.org>
parents:
35077
diff
changeset
|
361 | g_object_class_install_properties(obj_class, PROP_LAST, properties); |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
362 | } |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
363 | |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
364 | static void |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
365 | purple_pbkdf2_cipher_init(PurpleCipher *cipher) |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
366 | { |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
367 | purple_cipher_reset(cipher); |
| 34178 | 368 | } |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
369 | |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
370 | /****************************************************************************** |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
371 | * API |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
372 | *****************************************************************************/ |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
373 | GType |
|
35020
0ab63ada3cf2
Changed *_get_gtype to *_get_type for ciphers and hashes so gtk-doc can find them
Ankit Vani <a@nevitus.org>
parents:
35014
diff
changeset
|
374 | purple_pbkdf2_cipher_get_type(void) { |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
375 | static GType type = 0; |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
376 | |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
377 | if(type == 0) { |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
378 | static const GTypeInfo info = { |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
379 | sizeof(PurplePBKDF2CipherClass), |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
380 | NULL, |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
381 | NULL, |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
382 | (GClassInitFunc)purple_pbkdf2_cipher_class_init, |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
383 | NULL, |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
384 | NULL, |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
385 | sizeof(PurplePBKDF2Cipher), |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
386 | 0, |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
387 | (GInstanceInitFunc)purple_pbkdf2_cipher_init, |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
388 | NULL |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
389 | }; |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
390 | |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
391 | type = g_type_register_static(PURPLE_TYPE_CIPHER, |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
392 | "PurplePBKDF2Cipher", |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
393 | &info, 0); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
394 | } |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
395 | |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
396 | return type; |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
397 | } |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
398 | |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
399 | PurpleCipher * |
|
34566
e0f887dee077
Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents:
34561
diff
changeset
|
400 | purple_pbkdf2_cipher_new(PurpleHash *hash) { |
|
e0f887dee077
Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents:
34561
diff
changeset
|
401 | g_return_val_if_fail(PURPLE_IS_HASH(hash), NULL); |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
402 | |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
403 | return g_object_new(PURPLE_TYPE_PBKDF2_CIPHER, |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
404 | "hash", hash, |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
405 | NULL); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
406 | } |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
407 | |
|
34566
e0f887dee077
Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents:
34561
diff
changeset
|
408 | PurpleHash * |
|
34543
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
409 | purple_pbkdf2_cipher_get_hash(const PurplePBKDF2Cipher *cipher) { |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
410 | PurplePBKDF2CipherPrivate *priv = NULL; |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
411 | |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
412 | g_return_val_if_fail(PURPLE_IS_PBKDF2_CIPHER(cipher), NULL); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
413 | |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
414 | priv = PURPLE_PBKDF2_CIPHER_GET_PRIVATE(cipher); |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
415 | |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
416 | if(priv && priv->hash) |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
417 | return priv->hash; |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
418 | |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
419 | return NULL; |
|
5d7a7966a23c
GObjectified PBKDF2 cipher as PurplePBKDF2Cipher
Ankit Vani <a@nevitus.org>
parents:
34178
diff
changeset
|
420 | } |