libpurple/ciphers/hmaccipher.c

Fri, 11 Oct 2013 15:34:15 +0530

author
Ankit Vani <a@nevitus.org>
date
Fri, 11 Oct 2013 15:34:15 +0530
branch
soc.2013.gobjectification
changeset 35014
21864c2f543f
parent 34965
9abd15d6da07
child 35020
0ab63ada3cf2
permissions
-rw-r--r--

Removed g_object_notify calls from ciphers and hashes

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));
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
62 }
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
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
64 /*******************************************************************************
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
65 * Cipher Stuff
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
66 ******************************************************************************/
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
67 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
68 purple_hmac_cipher_reset(PurpleCipher *cipher) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
69 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
70
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
71 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
72 purple_hash_reset(priv->hash);
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
73
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
74 if(priv->ipad) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
75 g_free(priv->ipad);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
76 priv->ipad = NULL;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
77 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
78 if(priv->opad) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
79 g_free(priv->opad);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
80 priv->opad = NULL;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
81 }
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
82 }
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
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
84 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
85 purple_hmac_cipher_reset_state(PurpleCipher *cipher) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
86 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
87
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
88 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
89 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
90 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
91 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
92 }
33913
9effc94565d8 ciphers cleanup: add reset state callback
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33911
diff changeset
93 }
9effc94565d8 ciphers cleanup: add reset state callback
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33911
diff changeset
94
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
95 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
96 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
97 PurpleHMACCipherPrivate *priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
98
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
99 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
100
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
101 purple_hash_append(priv->hash, d, l);
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
102 }
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 static gboolean
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
105 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
106 {
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
107 PurpleHMACCipherPrivate *priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
108 guchar *digest = NULL;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
109 size_t hash_len, block_size;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
110 gboolean result = FALSE;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
111
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
112 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
113
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
114 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
115 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
116
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
117 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
118 digest = g_malloc(hash_len);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
119
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
120 /* 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
121 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
122 purple_hash_reset(priv->hash);
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
123
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
124 if(!result) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
125 g_free(digest);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
126
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
127 return FALSE;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
128 }
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
129
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
130 /* 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
131 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
132 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
133
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
134 /* 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
135 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
136
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
137 /* cleanup */
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
138 g_free(digest);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
139
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
140 return result;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
141 }
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 static size_t
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
144 purple_hmac_cipher_get_digest_size(PurpleCipher *cipher)
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
145 {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
146 PurpleHMACCipherPrivate *priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
147
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
148 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
149
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
150 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
151 }
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
152
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
153 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
154 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
155 size_t key_len)
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
156 {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
157 PurpleHMACCipherPrivate *priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
34891
3882234d2097 Fixed variable name
Ankit Vani <a@nevitus.org>
parents: 34889
diff changeset
158 gsize block_size, i;
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
159 guchar *full_key;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
160
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
161 g_return_if_fail(priv->hash);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
162
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
163 g_free(priv->ipad);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
164 g_free(priv->opad);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
165
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
166 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
167 priv->ipad = g_malloc(block_size);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
168 priv->opad = g_malloc(block_size);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
169
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
170 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
171 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
172 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
173
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
174 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
175 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
176 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
177 } else {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
178 full_key = g_memdup(key, key_len);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
179 }
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 if (key_len < block_size) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
182 full_key = g_realloc(full_key, block_size);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
183 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
184 }
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 for(i = 0; i < block_size; i++) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
187 priv->ipad[i] = 0x36 ^ full_key[i];
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
188 priv->opad[i] = 0x5c ^ full_key[i];
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
189 }
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 g_free(full_key);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
192
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
193 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
194 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
195 }
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 static size_t
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
198 purple_hmac_cipher_get_block_size(PurpleCipher *cipher)
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
199 {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
200 PurpleHMACCipherPrivate *priv = NULL;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
201
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
202 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
203
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
204 priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
205
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
206 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
207 }
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 /******************************************************************************
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
210 * Object Stuff
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
211 *****************************************************************************/
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
212 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
213 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
214 const GValue *value,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
215 GParamSpec *pspec)
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 PurpleCipher *cipher = PURPLE_CIPHER(obj);
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 switch(param_id) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
220 case PROP_HASH:
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
221 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
222 break;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
223 default:
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
224 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
225 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
226 }
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
227 }
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
228
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
229 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
230 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
231 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
232 {
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
233 PurpleHMACCipher *cipher = PURPLE_HMAC_CIPHER(obj);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
234
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
235 switch(param_id) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
236 case PROP_HASH:
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
237 g_value_set_object(value,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
238 purple_hmac_cipher_get_hash(cipher));
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
239 break;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
240 default:
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
241 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
242 break;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
243 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
244 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
245
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
246 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
247 purple_hmac_cipher_finalize(GObject *obj) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
248 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
249 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
250
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
251 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
252
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
253 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
254 g_object_unref(priv->hash);
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
255
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
256 parent_class->finalize(obj);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
257 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
258
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
259 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
260 purple_hmac_cipher_class_init(PurpleHMACCipherClass *klass) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
261 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
262 PurpleCipherClass *cipher_class = PURPLE_CIPHER_CLASS(klass);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
263 GParamSpec *pspec;
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 parent_class = g_type_class_peek_parent(klass);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
266
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
267 g_type_class_add_private(klass, sizeof(PurpleHMACCipherPrivate));
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
268
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
269 obj_class->finalize = purple_hmac_cipher_finalize;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
270 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
271 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
272
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
273 cipher_class->reset = purple_hmac_cipher_reset;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
274 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
275 cipher_class->append = purple_hmac_cipher_append;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
276 cipher_class->digest = purple_hmac_cipher_digest;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
277 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
278 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
279 cipher_class->get_block_size = purple_hmac_cipher_get_block_size;
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
280
34567
ea5103f66b0e Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents: 34566
diff changeset
281 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
282 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
283 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
284 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
285
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
286 /******************************************************************************
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
287 * PurpleHMACCipher API
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
288 *****************************************************************************/
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
289 GType
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
290 purple_hmac_cipher_get_gtype(void) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
291 static GType type = 0;
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 if(type == 0) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
294 static const GTypeInfo info = {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
295 sizeof(PurpleHMACCipherClass),
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
296 NULL,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
297 NULL,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
298 (GClassInitFunc)purple_hmac_cipher_class_init,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
299 NULL,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
300 NULL,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
301 sizeof(PurpleHMACCipher),
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
302 0,
34548
18cc6efb5194 Added reset at every cipher's initialization
Ankit Vani <a@nevitus.org>
parents: 34547
diff changeset
303 (GInstanceInitFunc)purple_cipher_reset,
34541
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 };
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
306
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
307 type = g_type_register_static(PURPLE_TYPE_CIPHER,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
308 "PurpleHMACCipher",
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
309 &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
310 }
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
311
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
312 return type;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
313 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
314
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
315 PurpleCipher *
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
316 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
317 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
318
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
319 return g_object_new(PURPLE_TYPE_HMAC_CIPHER,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
320 "hash", hash,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
321 NULL);
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
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
324 PurpleHash *
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
325 purple_hmac_cipher_get_hash(const PurpleHMACCipher *cipher) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
326 PurpleHMACCipherPrivate *priv = NULL;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
327
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
328 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
329
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
330 priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
331
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
332 if(priv && priv->hash)
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
333 return priv->hash;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
334
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
335 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
336 }
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
337

mercurial