libpurple/ciphers/hmaccipher.c

Sat, 29 Jun 2013 22:10:18 +0530

author
Ankit Vani <a@nevitus.org>
date
Sat, 29 Jun 2013 22:10:18 +0530
branch
soc.2013.gobjectification
changeset 34678
40a30f74a7b8
parent 34572
d5f3707d4032
child 34889
4ea2da14cd0e
permissions
-rw-r--r--

Removed purple_conversation_[gs]et_data(). Used g_object_[gs]et_data() instead.
Removed data from PurpleConversationPrivate.

31423
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * purple
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 *
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 * Purple is the legal property of its developers, whose names are too numerous
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * source distribution.
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 *
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * (at your option) any later version.
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 *
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * GNU General Public License for more details.
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 *
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 */
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
22 #include "hmaccipher.h"
33911
a924aacd5a37 ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33910
diff changeset
23
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
24 #include <string.h>
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
25
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
26 /*******************************************************************************
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
27 * Structs
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
28 ******************************************************************************/
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
29 #define PURPLE_HMAC_CIPHER_GET_PRIVATE(obj) \
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
30 (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_HMAC_CIPHER, PurpleHMACCipherPrivate))
31423
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
32 typedef struct {
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
33 PurpleHash *hash;
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
34 guchar *ipad;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
35 guchar *opad;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
36 } PurpleHMACCipherPrivate;
31433
74874b2d24f9 hmac.c needs to include libpurple/util.h
Gary Kramlich <grim@reaperworld.com>
parents: 31428
diff changeset
37
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
38 /******************************************************************************
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
39 * Enums
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
40 *****************************************************************************/
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
41 enum {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
42 PROP_NONE,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
43 PROP_HASH,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
44 PROP_LAST,
31423
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45 };
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
47 /*******************************************************************************
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
48 * Globals
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
49 ******************************************************************************/
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
50 static GObjectClass *parent_class = NULL;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
51
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
52 /*******************************************************************************
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
53 * Helpers
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
54 ******************************************************************************/
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
55 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
56 purple_hmac_cipher_set_hash(PurpleCipher *cipher,
34567
ea5103f66b0e Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents: 34566
diff changeset
57 PurpleHash *hash)
31423
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58 {
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
59 PurpleHMACCipherPrivate *priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
60
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
61 priv->hash = g_object_ref(G_OBJECT(hash));
34549
7ac9ea3e16e0 Added g_object_notify for property changes
Ankit Vani <a@nevitus.org>
parents: 34548
diff changeset
62 g_object_notify(G_OBJECT(cipher), "hash");
31423
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63 }
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
65 /*******************************************************************************
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
66 * Cipher Stuff
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
67 ******************************************************************************/
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
68 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
69 purple_hmac_cipher_reset(PurpleCipher *cipher) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
70 PurpleHMACCipherPrivate *priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
31423
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
71
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
72 if(PURPLE_IS_HASH(priv->hash))
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
73 purple_hash_reset(priv->hash);
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
74
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
75 if(priv->ipad) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
76 g_free(priv->ipad);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
77 priv->ipad = NULL;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
78 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
79 if(priv->opad) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
80 g_free(priv->opad);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
81 priv->opad = NULL;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
82 }
31423
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
83 }
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
84
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
85 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
86 purple_hmac_cipher_reset_state(PurpleCipher *cipher) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
87 PurpleHMACCipherPrivate *priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
33913
9effc94565d8 ciphers cleanup: add reset state callback
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33911
diff changeset
88
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
89 if(PURPLE_IS_HASH(priv->hash)) {
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
90 purple_hash_reset_state(priv->hash);
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
91 purple_hash_append(priv->hash, priv->ipad,
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
92 purple_hash_get_block_size(priv->hash));
33916
822d515c34c9 ciphers cleanup: hmac - correctly set up after resetting state
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33914
diff changeset
93 }
33913
9effc94565d8 ciphers cleanup: add reset state callback
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33911
diff changeset
94 }
9effc94565d8 ciphers cleanup: add reset state callback
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33911
diff changeset
95
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
96 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
97 purple_hmac_cipher_append(PurpleCipher *cipher, const guchar *d, size_t l) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
98 PurpleHMACCipherPrivate *priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
99
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
100 g_return_if_fail(PURPLE_IS_HASH(priv->hash));
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
101
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
102 purple_hash_append(priv->hash, d, l);
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
103 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
104
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
105 static gboolean
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
106 purple_hmac_cipher_digest(PurpleCipher *cipher, guchar *out, size_t len)
31423
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
107 {
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
108 PurpleHMACCipherPrivate *priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
109 guchar *digest = NULL;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
110 size_t hash_len, block_size;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
111 gboolean result = FALSE;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
112
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
113 g_return_val_if_fail(PURPLE_IS_HASH(priv->hash), FALSE);
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
114
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
115 hash_len = purple_hash_get_digest_size(priv->hash);
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
116 g_return_val_if_fail(hash_len > 0, FALSE);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
117
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
118 block_size = purple_hash_get_block_size(priv->hash);
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
119 digest = g_malloc(hash_len);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
120
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
121 /* get the digest of the data */
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
122 result = purple_hash_digest(priv->hash, digest, hash_len);
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
123 purple_hash_reset(priv->hash);
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
124
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
125 if(!result) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
126 g_free(digest);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
127
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
128 return FALSE;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
129 }
31423
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
130
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
131 /* now append the opad and the digest from above */
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
132 purple_hash_append(priv->hash, priv->opad, block_size);
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
133 purple_hash_append(priv->hash, digest, hash_len);
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
134
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
135 /* do our last digest */
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
136 result = purple_hash_digest(priv->hash, out, len);
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
137
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
138 /* cleanup */
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
139 g_free(digest);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
140
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
141 return result;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
142 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
143
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
144 static size_t
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
145 purple_hmac_cipher_get_digest_size(PurpleCipher *cipher)
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
146 {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
147 PurpleHMACCipherPrivate *priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
148
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
149 g_return_val_if_fail(priv->hash != NULL, 0);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
150
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
151 return purple_hash_get_digest_size(priv->hash);
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
152 }
31423
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
153
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
154 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
155 purple_hmac_cipher_set_key(PurpleCipher *cipher, const guchar *key,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
156 size_t key_len)
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
157 {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
158 PurpleHMACCipherPrivate *priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
159 gint block_size, i;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
160 guchar *full_key;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
161
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
162 g_return_if_fail(priv->hash);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
163
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
164 g_free(priv->ipad);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
165 g_free(priv->opad);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
166
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
167 block_size = purple_hash_get_block_size(priv->hash);
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
168 priv->ipad = g_malloc(block_size);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
169 priv->opad = g_malloc(block_size);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
170
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
171 if (key_len > block_size) {
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
172 purple_hash_reset(priv->hash);
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
173 purple_hash_append(priv->hash, key, key_len);
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
174
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
175 key_len = purple_hash_get_digest_size(priv->hash);
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
176 full_key = g_malloc(key_len);
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
177 purple_hash_digest(priv->hash, full_key, key_len);
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
178 } else {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
179 full_key = g_memdup(key, key_len);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
180 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
181
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
182 if (key_len < block_size) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
183 full_key = g_realloc(full_key, block_size);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
184 memset(full_key + key_len, 0, block_size - key_len);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
185 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
186
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
187 for(i = 0; i < block_size; i++) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
188 priv->ipad[i] = 0x36 ^ full_key[i];
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
189 priv->opad[i] = 0x5c ^ full_key[i];
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
190 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
191
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
192 g_free(full_key);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
193
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
194 purple_hash_reset(priv->hash);
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
195 purple_hash_append(priv->hash, priv->ipad, block_size);
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
196 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
197
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
198 static size_t
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
199 purple_hmac_cipher_get_block_size(PurpleCipher *cipher)
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
200 {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
201 PurpleHMACCipherPrivate *priv = NULL;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
202
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
203 g_return_val_if_fail(PURPLE_IS_HMAC_CIPHER(cipher), 0);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
204
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
205 priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
206
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
207 return purple_hash_get_block_size(priv->hash);
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
208 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
209
34547
45b72366ddde Added get_name method to all PurpleCiphers
Ankit Vani <a@nevitus.org>
parents: 34542
diff changeset
210 static const gchar*
45b72366ddde Added get_name method to all PurpleCiphers
Ankit Vani <a@nevitus.org>
parents: 34542
diff changeset
211 purple_hmac_cipher_get_name(PurpleCipher *cipher)
45b72366ddde Added get_name method to all PurpleCiphers
Ankit Vani <a@nevitus.org>
parents: 34542
diff changeset
212 {
45b72366ddde Added get_name method to all PurpleCiphers
Ankit Vani <a@nevitus.org>
parents: 34542
diff changeset
213 return "hmac";
45b72366ddde Added get_name method to all PurpleCiphers
Ankit Vani <a@nevitus.org>
parents: 34542
diff changeset
214 }
45b72366ddde Added get_name method to all PurpleCiphers
Ankit Vani <a@nevitus.org>
parents: 34542
diff changeset
215
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
216 /******************************************************************************
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
217 * Object Stuff
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
218 *****************************************************************************/
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
219 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
220 purple_hmac_cipher_set_property(GObject *obj, guint param_id,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
221 const GValue *value,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
222 GParamSpec *pspec)
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
223 {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
224 PurpleCipher *cipher = PURPLE_CIPHER(obj);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
225
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
226 switch(param_id) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
227 case PROP_HASH:
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
228 purple_hmac_cipher_set_hash(cipher, g_value_get_object(value));
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
229 break;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
230 default:
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
231 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
232 break;
31423
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
233 }
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
234 }
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
235
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
236 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
237 purple_hmac_cipher_get_property(GObject *obj, guint param_id, GValue *value,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
238 GParamSpec *pspec)
31423
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
239 {
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
240 PurpleHMACCipher *cipher = PURPLE_HMAC_CIPHER(obj);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
241
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
242 switch(param_id) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
243 case PROP_HASH:
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
244 g_value_set_object(value,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
245 purple_hmac_cipher_get_hash(cipher));
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
246 break;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
247 default:
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
248 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
249 break;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
250 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
251 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
252
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
253 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
254 purple_hmac_cipher_finalize(GObject *obj) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
255 PurpleCipher *cipher = PURPLE_CIPHER(obj);
34542
1d3e542445c3 Unref the hash function when finalizing PurpleHMACCipher. reset is called by PurpleCipher's finalize.
Ankit Vani <a@nevitus.org>
parents: 34541
diff changeset
256 PurpleHMACCipherPrivate *priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
257
34561
dfeaa5c9c33a Removed finalize from PurpleCipher, and fixed appropriate finalize methods for ciphers that need it
Ankit Vani <a@nevitus.org>
parents: 34549
diff changeset
258 purple_hmac_cipher_reset(cipher);
dfeaa5c9c33a Removed finalize from PurpleCipher, and fixed appropriate finalize methods for ciphers that need it
Ankit Vani <a@nevitus.org>
parents: 34549
diff changeset
259
34542
1d3e542445c3 Unref the hash function when finalizing PurpleHMACCipher. reset is called by PurpleCipher's finalize.
Ankit Vani <a@nevitus.org>
parents: 34541
diff changeset
260 if (priv->hash != NULL)
1d3e542445c3 Unref the hash function when finalizing PurpleHMACCipher. reset is called by PurpleCipher's finalize.
Ankit Vani <a@nevitus.org>
parents: 34541
diff changeset
261 g_object_unref(priv->hash);
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
262
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
263 parent_class->finalize(obj);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
264 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
265
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
266 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
267 purple_hmac_cipher_class_init(PurpleHMACCipherClass *klass) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
268 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
269 PurpleCipherClass *cipher_class = PURPLE_CIPHER_CLASS(klass);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
270 GParamSpec *pspec;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
271
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
272 parent_class = g_type_class_peek_parent(klass);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
273
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
274 g_type_class_add_private(klass, sizeof(PurpleHMACCipherPrivate));
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
275
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
276 obj_class->finalize = purple_hmac_cipher_finalize;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
277 obj_class->get_property = purple_hmac_cipher_get_property;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
278 obj_class->set_property = purple_hmac_cipher_set_property;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
279
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
280 cipher_class->reset = purple_hmac_cipher_reset;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
281 cipher_class->reset_state = purple_hmac_cipher_reset_state;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
282 cipher_class->append = purple_hmac_cipher_append;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
283 cipher_class->digest = purple_hmac_cipher_digest;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
284 cipher_class->get_digest_size = purple_hmac_cipher_get_digest_size;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
285 cipher_class->set_key = purple_hmac_cipher_set_key;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
286 cipher_class->get_block_size = purple_hmac_cipher_get_block_size;
34547
45b72366ddde Added get_name method to all PurpleCiphers
Ankit Vani <a@nevitus.org>
parents: 34542
diff changeset
287 cipher_class->get_name = purple_hmac_cipher_get_name;
31423
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
288
34567
ea5103f66b0e Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents: 34566
diff changeset
289 pspec = g_param_spec_object("hash", "hash", "hash", PURPLE_TYPE_HASH,
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
290 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
291 g_object_class_install_property(obj_class, PROP_HASH, pspec);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
292 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
293
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
294 /******************************************************************************
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
295 * PurpleHMACCipher API
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
296 *****************************************************************************/
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
297 GType
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
298 purple_hmac_cipher_get_gtype(void) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
299 static GType type = 0;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
300
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
301 if(type == 0) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
302 static const GTypeInfo info = {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
303 sizeof(PurpleHMACCipherClass),
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
304 NULL,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
305 NULL,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
306 (GClassInitFunc)purple_hmac_cipher_class_init,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
307 NULL,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
308 NULL,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
309 sizeof(PurpleHMACCipher),
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
310 0,
34548
18cc6efb5194 Added reset at every cipher's initialization
Ankit Vani <a@nevitus.org>
parents: 34547
diff changeset
311 (GInstanceInitFunc)purple_cipher_reset,
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
312 NULL,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
313 };
31423
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
314
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
315 type = g_type_register_static(PURPLE_TYPE_CIPHER,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
316 "PurpleHMACCipher",
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
317 &info, 0);
31423
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
318 }
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
319
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
320 return type;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
321 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
322
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
323 PurpleCipher *
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
324 purple_hmac_cipher_new(PurpleHash *hash) {
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
325 g_return_val_if_fail(PURPLE_IS_HASH(hash), NULL);
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
326
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
327 return g_object_new(PURPLE_TYPE_HMAC_CIPHER,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
328 "hash", hash,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
329 NULL);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
330 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
331
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
332 PurpleHash *
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
333 purple_hmac_cipher_get_hash(const PurpleHMACCipher *cipher) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
334 PurpleHMACCipherPrivate *priv = NULL;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
335
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
336 g_return_val_if_fail(PURPLE_IS_HMAC_CIPHER(cipher), NULL);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
337
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
338 priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
339
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
340 if(priv && priv->hash)
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
341 return priv->hash;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
342
31423
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
343 return NULL;
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
344 }
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
345

mercurial