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