libpurple/ciphers/hmaccipher.c

Mon, 23 Sep 2013 14:41:07 +0530

author
Ankit Vani <a@nevitus.org>
date
Mon, 23 Sep 2013 14:41:07 +0530
branch
soc.2013.gobjectification
changeset 34965
9abd15d6da07
parent 34891
3882234d2097
child 35014
21864c2f543f
permissions
-rw-r--r--

Removed 'get_name' from PurpleCipher

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);
34891
3882234d2097 Fixed variable name
Ankit Vani <a@nevitus.org>
parents: 34889
diff changeset
159 gsize block_size, i;
34541
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
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
210 /******************************************************************************
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
211 * Object Stuff
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
212 *****************************************************************************/
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
213 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
214 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
215 const GValue *value,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
216 GParamSpec *pspec)
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
217 {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
218 PurpleCipher *cipher = PURPLE_CIPHER(obj);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
219
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
220 switch(param_id) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
221 case PROP_HASH:
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
222 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
223 break;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
224 default:
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
225 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
226 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
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 }
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
229
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
230 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
231 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
232 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
233 {
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
234 PurpleHMACCipher *cipher = PURPLE_HMAC_CIPHER(obj);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
235
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
236 switch(param_id) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
237 case PROP_HASH:
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
238 g_value_set_object(value,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
239 purple_hmac_cipher_get_hash(cipher));
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
240 break;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
241 default:
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
242 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
243 break;
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
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
247 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
248 purple_hmac_cipher_finalize(GObject *obj) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
249 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
250 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
251
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
252 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
253
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
254 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
255 g_object_unref(priv->hash);
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
256
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
257 parent_class->finalize(obj);
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
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
260 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
261 purple_hmac_cipher_class_init(PurpleHMACCipherClass *klass) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
262 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
263 PurpleCipherClass *cipher_class = PURPLE_CIPHER_CLASS(klass);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
264 GParamSpec *pspec;
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 parent_class = g_type_class_peek_parent(klass);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
267
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
268 g_type_class_add_private(klass, sizeof(PurpleHMACCipherPrivate));
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
269
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
270 obj_class->finalize = purple_hmac_cipher_finalize;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
271 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
272 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
273
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
274 cipher_class->reset = purple_hmac_cipher_reset;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
275 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
276 cipher_class->append = purple_hmac_cipher_append;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
277 cipher_class->digest = purple_hmac_cipher_digest;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
278 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
279 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
280 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
281
34567
ea5103f66b0e Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents: 34566
diff changeset
282 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
283 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
284 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
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 /******************************************************************************
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
288 * PurpleHMACCipher API
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
289 *****************************************************************************/
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
290 GType
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
291 purple_hmac_cipher_get_gtype(void) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
292 static GType type = 0;
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 if(type == 0) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
295 static const GTypeInfo info = {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
296 sizeof(PurpleHMACCipherClass),
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 NULL,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
299 (GClassInitFunc)purple_hmac_cipher_class_init,
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 NULL,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
302 sizeof(PurpleHMACCipher),
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
303 0,
34548
18cc6efb5194 Added reset at every cipher's initialization
Ankit Vani <a@nevitus.org>
parents: 34547
diff changeset
304 (GInstanceInitFunc)purple_cipher_reset,
34541
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 };
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
307
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
308 type = g_type_register_static(PURPLE_TYPE_CIPHER,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
309 "PurpleHMACCipher",
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
310 &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
311 }
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
312
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
313 return type;
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
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
316 PurpleCipher *
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
317 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
318 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
319
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
320 return g_object_new(PURPLE_TYPE_HMAC_CIPHER,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
321 "hash", hash,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
322 NULL);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
323 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
324
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
325 PurpleHash *
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
326 purple_hmac_cipher_get_hash(const PurpleHMACCipher *cipher) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
327 PurpleHMACCipherPrivate *priv = NULL;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
328
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
329 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
330
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
331 priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
332
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
333 if(priv && priv->hash)
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
334 return priv->hash;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
335
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
336 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
337 }
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
338

mercurial