Sun, 20 Oct 2013 18:19:05 +0530
Fixed warnings
| 34182 | 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 | */ | |
| 24 | ||
|
35026
fde23518e1e5
Moved PurpleHash to cipher.[ch]
Ankit Vani <a@nevitus.org>
parents:
35020
diff
changeset
|
25 | #include "internal.h" |
|
fde23518e1e5
Moved PurpleHash to cipher.[ch]
Ankit Vani <a@nevitus.org>
parents:
35020
diff
changeset
|
26 | |
|
34566
e0f887dee077
Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents:
34547
diff
changeset
|
27 | #include "aescipher.h" |
| 34182 | 28 | #include "debug.h" |
|
34644
368d270dc0c3
Included enums.h in AES, DES and DES3 cipher to use the PURPLE_TYPE_BATCH_MODE GType for batch_mode property
Ankit Vani <a@nevitus.org>
parents:
34566
diff
changeset
|
29 | #include "enums.h" |
| 34182 | 30 | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
31 | #include <string.h> |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
32 | |
| 34182 | 33 | #if defined(HAVE_GNUTLS) |
| 34 | # define PURPLE_AES_USE_GNUTLS 1 | |
| 35 | # include <gnutls/gnutls.h> | |
| 36 | # include <gnutls/crypto.h> | |
| 37 | #elif defined(HAVE_NSS) | |
| 38 | # define PURPLE_AES_USE_NSS 1 | |
| 39 | # include <nss.h> | |
| 40 | # include <pk11pub.h> | |
| 41 | # include <prerror.h> | |
| 42 | #else | |
| 43 | # error "No GnuTLS or NSS support" | |
| 44 | #endif | |
| 45 | ||
| 46 | /* 128bit */ | |
| 47 | #define PURPLE_AES_BLOCK_SIZE 16 | |
| 48 | ||
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
49 | /****************************************************************************** |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
50 | * Structs |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
51 | *****************************************************************************/ |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
52 | #define PURPLE_AES_CIPHER_GET_PRIVATE(obj) \ |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
53 | (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_AES_CIPHER, PurpleAESCipherPrivate)) |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
54 | |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
55 | typedef struct { |
| 34182 | 56 | guchar iv[PURPLE_AES_BLOCK_SIZE]; |
| 57 | guchar key[32]; | |
| 58 | guint key_size; | |
| 59 | gboolean failure; | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
60 | } PurpleAESCipherPrivate; |
| 34182 | 61 | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
62 | /****************************************************************************** |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
63 | * Enums |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
64 | *****************************************************************************/ |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
65 | enum { |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
66 | PROP_NONE, |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
67 | PROP_BATCH_MODE, |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
68 | PROP_IV, |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
69 | PROP_KEY, |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
70 | PROP_LAST, |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
71 | }; |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
72 | |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
73 | /****************************************************************************** |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
74 | * Cipher Stuff |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
75 | *****************************************************************************/ |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
76 | |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
77 | typedef gboolean (*purple_aes_cipher_crypt_func)( |
| 34182 | 78 | const guchar *input, guchar *output, size_t len, |
| 79 | guchar iv[PURPLE_AES_BLOCK_SIZE], guchar key[32], guint key_size); | |
| 80 | ||
| 81 | static void | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
82 | purple_aes_cipher_reset(PurpleCipher *cipher) |
| 34182 | 83 | { |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
84 | PurpleAESCipherPrivate *priv = PURPLE_AES_CIPHER_GET_PRIVATE(cipher); |
| 34182 | 85 | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
86 | g_return_if_fail(priv != NULL); |
| 34182 | 87 | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
88 | memset(priv->iv, 0, sizeof(priv->iv)); |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
89 | memset(priv->key, 0, sizeof(priv->key)); |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
90 | priv->key_size = 32; /* 256bit */ |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
91 | priv->failure = FALSE; |
| 34182 | 92 | } |
| 93 | ||
| 94 | static void | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
95 | purple_aes_cipher_set_iv(PurpleCipher *cipher, guchar *iv, size_t len) |
| 34182 | 96 | { |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
97 | PurpleAESCipherPrivate *priv = PURPLE_AES_CIPHER_GET_PRIVATE(cipher); |
| 34182 | 98 | |
| 99 | if ((len > 0 && iv == NULL) || | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
100 | (len != 0 && len != sizeof(priv->iv))) { |
| 34182 | 101 | purple_debug_error("cipher-aes", "invalid IV length\n"); |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
102 | priv->failure = TRUE; |
| 34182 | 103 | return; |
| 104 | } | |
| 105 | ||
| 106 | if (len == 0) | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
107 | memset(priv->iv, 0, sizeof(priv->iv)); |
| 34182 | 108 | else |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
109 | memcpy(priv->iv, iv, len); |
| 34182 | 110 | } |
| 111 | ||
| 112 | static void | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
113 | purple_aes_cipher_set_key(PurpleCipher *cipher, const guchar *key, size_t len) |
| 34182 | 114 | { |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
115 | PurpleAESCipherPrivate *priv = PURPLE_AES_CIPHER_GET_PRIVATE(cipher); |
| 34182 | 116 | |
| 117 | if ((len > 0 && key == NULL) || | |
| 118 | (len != 0 && len != 16 && len != 24 && len != 32)) { | |
| 119 | purple_debug_error("cipher-aes", "invalid key length\n"); | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
120 | priv->failure = TRUE; |
| 34182 | 121 | return; |
| 122 | } | |
| 123 | ||
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
124 | priv->key_size = len; |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
125 | memset(priv->key, 0, sizeof(priv->key)); |
| 34182 | 126 | if (len > 0) |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
127 | memcpy(priv->key, key, len); |
| 34182 | 128 | } |
| 129 | ||
| 130 | static guchar * | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
131 | purple_aes_cipher_pad_pkcs7(const guchar input[], size_t in_len, size_t *out_len) |
| 34182 | 132 | { |
| 133 | int padding_len, total_len; | |
| 134 | guchar *padded; | |
| 135 | ||
| 136 | g_return_val_if_fail(input != NULL, NULL); | |
| 137 | g_return_val_if_fail(out_len != NULL, NULL); | |
| 138 | ||
| 139 | padding_len = PURPLE_AES_BLOCK_SIZE - (in_len % PURPLE_AES_BLOCK_SIZE); | |
| 140 | total_len = in_len + padding_len; | |
| 141 | g_assert((total_len % PURPLE_AES_BLOCK_SIZE) == 0); | |
| 142 | ||
| 143 | padded = g_new(guchar, total_len); | |
| 144 | *out_len = total_len; | |
| 145 | ||
| 146 | memcpy(padded, input, in_len); | |
| 147 | memset(padded + in_len, padding_len, padding_len); | |
| 148 | ||
| 149 | return padded; | |
| 150 | } | |
| 151 | ||
| 152 | static ssize_t | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
153 | purple_aes_cipher_unpad_pkcs7(guchar input[], size_t in_len) |
| 34182 | 154 | { |
|
34304
faf0414a8b51
Fix most of libpurple warnings about -Wsign-compare
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
34275
diff
changeset
|
155 | guchar padding_len, i; |
| 34182 | 156 | size_t out_len; |
| 157 | ||
| 158 | g_return_val_if_fail(input != NULL, -1); | |
| 159 | g_return_val_if_fail(in_len > 0, -1); | |
| 160 | ||
| 161 | padding_len = input[in_len - 1]; | |
|
34304
faf0414a8b51
Fix most of libpurple warnings about -Wsign-compare
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
34275
diff
changeset
|
162 | if (padding_len == 0 || padding_len > PURPLE_AES_BLOCK_SIZE || |
| 34182 | 163 | padding_len > in_len) { |
| 164 | purple_debug_warning("cipher-aes", | |
|
34275
a6ddc53d1c84
Fix minor printf format warning.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
34250
diff
changeset
|
165 | "Invalid padding length: %d (total %" G_GSIZE_FORMAT ") - " |
| 34182 | 166 | "most probably, the key was invalid\n", |
| 167 | padding_len, in_len); | |
| 168 | return -1; | |
| 169 | } | |
| 170 | ||
| 171 | out_len = in_len - padding_len; | |
| 172 | for (i = 0; i < padding_len; i++) { | |
| 173 | if (input[out_len + i] != padding_len) { | |
| 174 | purple_debug_warning("cipher-aes", | |
| 175 | "Padding doesn't match at pos %d (found %02x, " | |
| 176 | "expected %02x) - " | |
| 177 | "most probably, the key was invalid\n", | |
| 178 | i, input[out_len + i], padding_len); | |
| 179 | return -1; | |
| 180 | } | |
| 181 | } | |
| 182 | ||
| 183 | memset(input + out_len, 0, padding_len); | |
| 184 | return out_len; | |
| 185 | } | |
| 186 | ||
| 187 | #ifdef PURPLE_AES_USE_GNUTLS | |
| 188 | ||
| 189 | static gnutls_cipher_hd_t | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
190 | purple_aes_cipher_gnutls_crypt_init(guchar iv[PURPLE_AES_BLOCK_SIZE], guchar key[32], |
| 34182 | 191 | guint key_size) |
| 192 | { | |
| 193 | gnutls_cipher_hd_t handle; | |
| 194 | gnutls_cipher_algorithm_t algorithm; | |
| 195 | gnutls_datum_t key_info, iv_info; | |
| 196 | int ret; | |
| 197 | ||
| 198 | if (key_size == 16) | |
| 199 | algorithm = GNUTLS_CIPHER_AES_128_CBC; | |
| 200 | else if (key_size == 24) | |
| 201 | algorithm = GNUTLS_CIPHER_AES_192_CBC; | |
| 202 | else if (key_size == 32) | |
| 203 | algorithm = GNUTLS_CIPHER_AES_256_CBC; | |
| 204 | else | |
| 205 | g_return_val_if_reached(NULL); | |
| 206 | ||
| 207 | key_info.data = key; | |
| 208 | key_info.size = key_size; | |
| 209 | ||
| 210 | iv_info.data = iv; | |
| 211 | iv_info.size = PURPLE_AES_BLOCK_SIZE; | |
| 212 | ||
| 213 | ret = gnutls_cipher_init(&handle, algorithm, &key_info, &iv_info); | |
| 214 | if (ret != 0) { | |
| 215 | purple_debug_error("cipher-aes", | |
| 216 | "gnutls_cipher_init failed: %d\n", ret); | |
| 217 | return NULL; | |
| 218 | } | |
| 219 | ||
| 220 | return handle; | |
| 221 | } | |
| 222 | ||
| 223 | static gboolean | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
224 | purple_aes_cipher_gnutls_encrypt(const guchar *input, guchar *output, size_t len, |
| 34182 | 225 | guchar iv[PURPLE_AES_BLOCK_SIZE], guchar key[32], guint key_size) |
| 226 | { | |
| 227 | gnutls_cipher_hd_t handle; | |
| 228 | int ret; | |
| 229 | ||
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
230 | handle = purple_aes_cipher_gnutls_crypt_init(iv, key, key_size); |
| 34182 | 231 | if (handle == NULL) |
| 232 | return FALSE; | |
| 233 | ||
| 34758 | 234 | ret = gnutls_cipher_encrypt2(handle, (guchar *)input, len, output, len); |
| 34182 | 235 | gnutls_cipher_deinit(handle); |
| 236 | ||
| 237 | if (ret != 0) { | |
| 238 | purple_debug_error("cipher-aes", | |
| 239 | "gnutls_cipher_encrypt2 failed: %d\n", ret); | |
| 240 | return FALSE; | |
| 241 | } | |
| 242 | ||
| 243 | return TRUE; | |
| 244 | } | |
| 245 | ||
| 246 | static gboolean | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
247 | purple_aes_cipher_gnutls_decrypt(const guchar *input, guchar *output, size_t len, |
| 34182 | 248 | guchar iv[PURPLE_AES_BLOCK_SIZE], guchar key[32], guint key_size) |
| 249 | { | |
| 250 | gnutls_cipher_hd_t handle; | |
| 251 | int ret; | |
| 252 | ||
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
253 | handle = purple_aes_cipher_gnutls_crypt_init(iv, key, key_size); |
| 34182 | 254 | if (handle == NULL) |
| 255 | return FALSE; | |
| 256 | ||
| 257 | ret = gnutls_cipher_decrypt2(handle, input, len, output, len); | |
| 258 | gnutls_cipher_deinit(handle); | |
| 259 | ||
| 260 | if (ret != 0) { | |
| 261 | purple_debug_error("cipher-aes", | |
| 262 | "gnutls_cipher_decrypt2 failed: %d\n", ret); | |
| 263 | return FALSE; | |
| 264 | } | |
| 265 | ||
| 266 | return TRUE; | |
| 267 | } | |
| 268 | ||
|
34250
1625de486023
Fix pre-processing directives to consistently only inclde code that will be used.
Daniel Atallah <datallah@pidgin.im>
parents:
34248
diff
changeset
|
269 | #elif defined(PURPLE_AES_USE_NSS) |
| 34182 | 270 | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
271 | typedef struct { |
| 34182 | 272 | PK11SlotInfo *slot; |
| 273 | PK11SymKey *sym_key; | |
| 274 | SECItem *sec_param; | |
| 275 | PK11Context *enc_context; | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
276 | } PurpleAESCipherNSSContext; |
| 34182 | 277 | |
| 278 | static void | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
279 | purple_aes_cipher_nss_cleanup(PurpleAESCipherNSSContext *context) |
| 34182 | 280 | { |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
281 | g_return_if_fail(context != NULL); |
| 34182 | 282 | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
283 | if (context->enc_context != NULL) |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
284 | PK11_DestroyContext(context->enc_context, TRUE); |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
285 | if (context->sec_param != NULL) |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
286 | SECITEM_FreeItem(context->sec_param, TRUE); |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
287 | if (context->sym_key != NULL) |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
288 | PK11_FreeSymKey(context->sym_key); |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
289 | if (context->slot != NULL) |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
290 | PK11_FreeSlot(context->slot); |
| 34182 | 291 | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
292 | memset(context, 0, sizeof(PurpleAESCipherNSSContext)); |
| 34182 | 293 | } |
| 294 | ||
| 295 | static gboolean | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
296 | purple_aes_cipher_nss_crypt(const guchar *input, guchar *output, size_t len, |
| 34182 | 297 | guchar iv[PURPLE_AES_BLOCK_SIZE], guchar key[32], guint key_size, |
| 298 | CK_ATTRIBUTE_TYPE operation) | |
| 299 | { | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
300 | PurpleAESCipherNSSContext context; |
| 34182 | 301 | CK_MECHANISM_TYPE cipher_mech = CKM_AES_CBC; |
| 302 | SECItem key_item, iv_item; | |
| 303 | SECStatus ret; | |
| 35028 | 304 | int outlen = 0; |
| 34182 | 305 | unsigned int outlen_tmp = 0; |
| 306 | ||
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
307 | memset(&context, 0, sizeof(PurpleAESCipherNSSContext)); |
| 34182 | 308 | |
| 309 | if (NSS_NoDB_Init(NULL) != SECSuccess) { | |
| 310 | purple_debug_error("cipher-aes", | |
| 311 | "NSS_NoDB_Init failed: %d\n", PR_GetError()); | |
| 312 | return FALSE; | |
| 313 | } | |
| 314 | ||
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
315 | context.slot = PK11_GetBestSlot(cipher_mech, NULL); |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
316 | if (context.slot == NULL) { |
| 34182 | 317 | purple_debug_error("cipher-aes", |
| 318 | "PK11_GetBestSlot failed: %d\n", PR_GetError()); | |
| 319 | return FALSE; | |
| 320 | } | |
| 321 | ||
| 322 | key_item.type = siBuffer; | |
| 323 | key_item.data = key; | |
| 324 | key_item.len = key_size; | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
325 | context.sym_key = PK11_ImportSymKey(context.slot, cipher_mech, |
| 34182 | 326 | PK11_OriginUnwrap, CKA_ENCRYPT, &key_item, NULL); |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
327 | if (context.sym_key == NULL) { |
| 34182 | 328 | purple_debug_error("cipher-aes", |
| 329 | "PK11_ImportSymKey failed: %d\n", PR_GetError()); | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
330 | purple_aes_cipher_nss_cleanup(&context); |
| 34182 | 331 | return FALSE; |
| 332 | } | |
| 333 | ||
| 334 | iv_item.type = siBuffer; | |
| 335 | iv_item.data = iv; | |
| 336 | iv_item.len = PURPLE_AES_BLOCK_SIZE; | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
337 | context.sec_param = PK11_ParamFromIV(cipher_mech, &iv_item); |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
338 | if (context.sec_param == NULL) { |
| 34182 | 339 | purple_debug_error("cipher-aes", |
| 340 | "PK11_ParamFromIV failed: %d\n", PR_GetError()); | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
341 | purple_aes_cipher_nss_cleanup(&context); |
| 34182 | 342 | return FALSE; |
| 343 | } | |
| 344 | ||
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
345 | context.enc_context = PK11_CreateContextBySymKey(cipher_mech, operation, |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
346 | context.sym_key, context.sec_param); |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
347 | if (context.enc_context == NULL) { |
| 34182 | 348 | purple_debug_error("cipher-aes", |
| 349 | "PK11_CreateContextBySymKey failed: %d\n", | |
| 350 | PR_GetError()); | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
351 | purple_aes_cipher_nss_cleanup(&context); |
| 34182 | 352 | return FALSE; |
| 353 | } | |
| 354 | ||
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
355 | ret = PK11_CipherOp(context.enc_context, output, &outlen, len, input, len); |
| 34182 | 356 | if (ret != SECSuccess) { |
| 357 | purple_debug_error("cipher-aes", | |
| 358 | "PK11_CipherOp failed: %d\n", PR_GetError()); | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
359 | purple_aes_cipher_nss_cleanup(&context); |
| 34182 | 360 | return FALSE; |
| 361 | } | |
| 362 | ||
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
363 | ret = PK11_DigestFinal(context.enc_context, output + outlen, &outlen_tmp, |
| 34182 | 364 | len - outlen); |
| 365 | if (ret != SECSuccess) { | |
| 366 | purple_debug_error("cipher-aes", | |
| 367 | "PK11_DigestFinal failed: %d\n", PR_GetError()); | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
368 | purple_aes_cipher_nss_cleanup(&context); |
| 34182 | 369 | return FALSE; |
| 370 | } | |
| 371 | ||
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
372 | purple_aes_cipher_nss_cleanup(&context); |
| 34182 | 373 | |
| 374 | outlen += outlen_tmp; | |
| 35029 | 375 | if (outlen != (int)len) { |
| 34182 | 376 | purple_debug_error("cipher-aes", |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
377 | "resulting length doesn't match: %d (expected: %lu)\n", |
| 34182 | 378 | outlen, len); |
| 379 | return FALSE; | |
| 380 | } | |
| 381 | ||
| 382 | return TRUE; | |
| 383 | } | |
| 384 | ||
| 385 | static gboolean | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
386 | purple_aes_cipher_nss_encrypt(const guchar *input, guchar *output, size_t len, |
| 34182 | 387 | guchar iv[PURPLE_AES_BLOCK_SIZE], guchar key[32], guint key_size) |
| 388 | { | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
389 | return purple_aes_cipher_nss_crypt(input, output, len, iv, key, key_size, |
| 34182 | 390 | CKA_ENCRYPT); |
| 391 | } | |
| 392 | ||
| 393 | static gboolean | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
394 | purple_aes_cipher_nss_decrypt(const guchar *input, guchar *output, size_t len, |
| 34182 | 395 | guchar iv[PURPLE_AES_BLOCK_SIZE], guchar key[32], guint key_size) |
| 396 | { | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
397 | return purple_aes_cipher_nss_crypt(input, output, len, iv, key, key_size, |
| 34182 | 398 | CKA_DECRYPT); |
| 399 | } | |
| 400 | ||
| 401 | #endif /* PURPLE_AES_USE_NSS */ | |
| 402 | ||
| 403 | static ssize_t | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
404 | purple_aes_cipher_encrypt(PurpleCipher *cipher, const guchar input[], |
| 34182 | 405 | size_t in_len, guchar output[], size_t out_size) |
| 406 | { | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
407 | PurpleAESCipherPrivate *priv = PURPLE_AES_CIPHER_GET_PRIVATE(cipher); |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
408 | purple_aes_cipher_crypt_func encrypt_func; |
| 34182 | 409 | guchar *input_padded; |
| 410 | size_t out_len = 0; | |
| 411 | gboolean succ; | |
| 412 | ||
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
413 | if (priv->failure) |
| 34182 | 414 | return -1; |
| 415 | ||
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
416 | input_padded = purple_aes_cipher_pad_pkcs7(input, in_len, &out_len); |
| 34182 | 417 | |
| 418 | if (out_len > out_size) { | |
| 419 | purple_debug_error("cipher-aes", "Output buffer too small\n"); | |
| 420 | memset(input_padded, 0, out_len); | |
| 421 | g_free(input_padded); | |
| 422 | return -1; | |
| 423 | } | |
| 424 | ||
| 425 | #if defined(PURPLE_AES_USE_GNUTLS) | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
426 | encrypt_func = purple_aes_cipher_gnutls_encrypt; |
| 34182 | 427 | #elif defined(PURPLE_AES_USE_NSS) |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
428 | encrypt_func = purple_aes_cipher_nss_encrypt; |
| 34182 | 429 | #else |
| 430 | # error "No matching encrypt_func" | |
| 431 | #endif | |
| 432 | ||
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
433 | succ = encrypt_func(input_padded, output, out_len, priv->iv, |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
434 | priv->key, priv->key_size); |
| 34182 | 435 | |
| 436 | memset(input_padded, 0, out_len); | |
| 437 | g_free(input_padded); | |
| 438 | ||
| 439 | if (!succ) { | |
| 440 | memset(output, 0, out_len); | |
| 441 | return -1; | |
| 442 | } | |
| 443 | ||
| 444 | return out_len; | |
| 445 | } | |
| 446 | ||
| 447 | static ssize_t | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
448 | purple_aes_cipher_decrypt(PurpleCipher *cipher, const guchar input[], |
| 34182 | 449 | size_t in_len, guchar output[], size_t out_size) |
| 450 | { | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
451 | PurpleAESCipherPrivate *priv = PURPLE_AES_CIPHER_GET_PRIVATE(cipher); |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
452 | purple_aes_cipher_crypt_func decrypt_func; |
| 34182 | 453 | gboolean succ; |
| 454 | ssize_t out_len; | |
| 455 | ||
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
456 | if (priv->failure) |
| 34182 | 457 | return -1; |
| 458 | ||
| 459 | if (in_len > out_size) { | |
| 460 | purple_debug_error("cipher-aes", "Output buffer too small\n"); | |
| 461 | return -1; | |
| 462 | } | |
| 463 | ||
| 464 | if ((in_len % PURPLE_AES_BLOCK_SIZE) != 0 || in_len == 0) { | |
| 465 | purple_debug_error("cipher-aes", "Malformed data\n"); | |
| 466 | return -1; | |
| 467 | } | |
| 468 | ||
| 469 | #if defined(PURPLE_AES_USE_GNUTLS) | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
470 | decrypt_func = purple_aes_cipher_gnutls_decrypt; |
| 34182 | 471 | #elif defined(PURPLE_AES_USE_NSS) |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
472 | decrypt_func = purple_aes_cipher_nss_decrypt; |
| 34182 | 473 | #else |
| 474 | # error "No matching encrypt_func" | |
| 475 | #endif | |
| 476 | ||
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
477 | succ = decrypt_func(input, output, in_len, priv->iv, priv->key, |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
478 | priv->key_size); |
| 34182 | 479 | |
| 480 | if (!succ) { | |
| 481 | memset(output, 0, in_len); | |
| 482 | return -1; | |
| 483 | } | |
| 484 | ||
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
485 | out_len = purple_aes_cipher_unpad_pkcs7(output, in_len); |
| 34182 | 486 | if (out_len < 0) { |
| 487 | memset(output, 0, in_len); | |
| 488 | return -1; | |
| 489 | } | |
| 490 | ||
| 491 | return out_len; | |
| 492 | } | |
| 493 | ||
| 494 | static size_t | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
495 | purple_aes_cipher_get_key_size(PurpleCipher *cipher) |
| 34182 | 496 | { |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
497 | PurpleAESCipherPrivate *priv = PURPLE_AES_CIPHER_GET_PRIVATE(cipher); |
| 34182 | 498 | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
499 | return priv->key_size; |
| 34182 | 500 | } |
| 501 | ||
| 502 | static void | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
503 | purple_aes_cipher_set_batch_mode(PurpleCipher *cipher, |
| 34182 | 504 | PurpleCipherBatchMode mode) |
| 505 | { | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
506 | PurpleAESCipherPrivate *priv = PURPLE_AES_CIPHER_GET_PRIVATE(cipher); |
| 34182 | 507 | |
|
35014
21864c2f543f
Removed g_object_notify calls from ciphers and hashes
Ankit Vani <a@nevitus.org>
parents:
34965
diff
changeset
|
508 | if (mode == PURPLE_CIPHER_BATCH_MODE_CBC) |
| 34182 | 509 | return; |
| 510 | ||
| 511 | purple_debug_error("cipher-aes", "unsupported batch mode\n"); | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
512 | priv->failure = TRUE; |
| 34182 | 513 | } |
| 514 | ||
| 515 | static PurpleCipherBatchMode | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
516 | purple_aes_cipher_get_batch_mode(PurpleCipher *cipher) |
| 34182 | 517 | { |
| 518 | return PURPLE_CIPHER_BATCH_MODE_CBC; | |
| 519 | } | |
| 520 | ||
| 521 | static size_t | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
522 | purple_aes_cipher_get_block_size(PurpleCipher *cipher) |
| 34182 | 523 | { |
| 524 | return PURPLE_AES_BLOCK_SIZE; | |
| 525 | } | |
| 526 | ||
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
527 | /****************************************************************************** |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
528 | * Object Stuff |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
529 | *****************************************************************************/ |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
530 | static void |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
531 | purple_aes_cipher_get_property(GObject *obj, guint param_id, GValue *value, |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
532 | GParamSpec *pspec) |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
533 | { |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
534 | PurpleCipher *cipher = PURPLE_CIPHER(obj); |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
535 | |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
536 | switch(param_id) { |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
537 | case PROP_BATCH_MODE: |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
538 | g_value_set_enum(value, |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
539 | purple_cipher_get_batch_mode(cipher)); |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
540 | break; |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
541 | default: |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
542 | G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
543 | break; |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
544 | } |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
545 | } |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
546 | |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
547 | static void |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
548 | purple_aes_cipher_set_property(GObject *obj, guint param_id, |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
549 | const GValue *value, GParamSpec *pspec) |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
550 | { |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
551 | PurpleCipher *cipher = PURPLE_CIPHER(obj); |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
552 | |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
553 | switch(param_id) { |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
554 | case PROP_BATCH_MODE: |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
555 | purple_cipher_set_batch_mode(cipher, |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
556 | g_value_get_enum(value)); |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
557 | break; |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
558 | case PROP_IV: |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
559 | { |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
560 | guchar *iv = (guchar *)g_value_get_string(value); |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
561 | purple_cipher_set_iv(cipher, iv, strlen((gchar*)iv)); |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
562 | } |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
563 | break; |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
564 | case PROP_KEY: |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
565 | purple_cipher_set_key(cipher, (guchar *)g_value_get_string(value), |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
566 | purple_aes_cipher_get_key_size(cipher)); |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
567 | break; |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
568 | default: |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
569 | G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
570 | break; |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
571 | } |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
572 | } |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
573 | |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
574 | static void |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
575 | purple_aes_cipher_class_init(PurpleAESCipherClass *klass) { |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
576 | GObjectClass *obj_class = G_OBJECT_CLASS(klass); |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
577 | PurpleCipherClass *cipher_class = PURPLE_CIPHER_CLASS(klass); |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
578 | GParamSpec *pspec; |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
579 | |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
580 | obj_class->get_property = purple_aes_cipher_get_property; |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
581 | obj_class->set_property = purple_aes_cipher_set_property; |
| 34182 | 582 | |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
583 | cipher_class->reset = purple_aes_cipher_reset; |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
584 | cipher_class->set_iv = purple_aes_cipher_set_iv; |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
585 | cipher_class->encrypt = purple_aes_cipher_encrypt; |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
586 | cipher_class->decrypt = purple_aes_cipher_decrypt; |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
587 | cipher_class->set_key = purple_aes_cipher_set_key; |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
588 | cipher_class->get_key_size = purple_aes_cipher_get_key_size; |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
589 | cipher_class->set_batch_mode = purple_aes_cipher_set_batch_mode; |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
590 | cipher_class->get_batch_mode = purple_aes_cipher_get_batch_mode; |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
591 | cipher_class->get_block_size = purple_aes_cipher_get_block_size; |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
592 | |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
593 | pspec = g_param_spec_enum("batch_mode", "batch_mode", "batch_mode", |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
594 | PURPLE_TYPE_CIPHER_BATCH_MODE, 0, |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
595 | G_PARAM_READWRITE); |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
596 | g_object_class_install_property(obj_class, PROP_BATCH_MODE, pspec); |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
597 | |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
598 | pspec = g_param_spec_string("iv", "iv", "iv", NULL, |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
599 | G_PARAM_WRITABLE); |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
600 | g_object_class_install_property(obj_class, PROP_IV, pspec); |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
601 | |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
602 | pspec = g_param_spec_string("key", "key", "key", NULL, |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
603 | G_PARAM_WRITABLE); |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
604 | g_object_class_install_property(obj_class, PROP_KEY, pspec); |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
605 | |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
606 | g_type_class_add_private(klass, sizeof(PurpleAESCipherPrivate)); |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
607 | } |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
608 | |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
609 | static void |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
610 | purple_aes_cipher_init(PurpleCipher *cipher) { |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
611 | purple_cipher_reset(cipher); |
| 34182 | 612 | } |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
613 | |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
614 | /****************************************************************************** |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
615 | * API |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
616 | *****************************************************************************/ |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
617 | 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
|
618 | purple_aes_cipher_get_type(void) { |
|
34546
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
619 | static GType type = 0; |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
620 | |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
621 | if(type == 0) { |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
622 | static const GTypeInfo info = { |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
623 | sizeof(PurpleAESCipherClass), |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
624 | NULL, |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
625 | NULL, |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
626 | (GClassInitFunc)purple_aes_cipher_class_init, |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
627 | NULL, |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
628 | NULL, |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
629 | sizeof(PurpleAESCipher), |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
630 | 0, |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
631 | (GInstanceInitFunc)purple_aes_cipher_init, |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
632 | NULL |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
633 | }; |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
634 | |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
635 | type = g_type_register_static(PURPLE_TYPE_CIPHER, |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
636 | "PurpleAESCipher", |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
637 | &info, 0); |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
638 | } |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
639 | |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
640 | return type; |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
641 | } |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
642 | |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
643 | PurpleCipher * |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
644 | purple_aes_cipher_new(void) { |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
645 | return g_object_new(PURPLE_TYPE_AES_CIPHER, NULL); |
|
5c2f894fe4d6
GObjectified the AES cipher as PurpleAESCipher
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
646 | } |