libpurple/ciphers/hmaccipher.c

Sun, 28 May 2017 13:26:27 +0300

author
Arkadiy Illarionov <qarkai@gmail.com>
date
Sun, 28 May 2017 13:26:27 +0300
changeset 38886
c1fb4e53da4e
parent 37426
6fd4989b77e4
permissions
-rw-r--r--

Merged pidgin/main into default

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 */
35026
fde23518e1e5 Moved PurpleHash to cipher.[ch]
Ankit Vani <a@nevitus.org>
parents: 35020
diff changeset
22 #include "internal.h"
35077
0a120b204362 ciphers: use g_object_notify_by_pspec instead of g_object_notify
Ankit Vani <a@nevitus.org>
parents: 35065
diff changeset
23 #include "glibcompat.h"
0a120b204362 ciphers: use g_object_notify_by_pspec instead of g_object_notify
Ankit Vani <a@nevitus.org>
parents: 35065
diff changeset
24
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
25 #include "hmaccipher.h"
33911
a924aacd5a37 ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33910
diff changeset
26
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
27 #include <string.h>
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 /*******************************************************************************
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
30 * Structs
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
31 ******************************************************************************/
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
32 #define PURPLE_HMAC_CIPHER_GET_PRIVATE(obj) \
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
33 (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
34
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
35 typedef struct {
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
36 PurpleHash *hash;
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
37 guchar *ipad;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
38 guchar *opad;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
39 } PurpleHMACCipherPrivate;
31433
74874b2d24f9 hmac.c needs to include libpurple/util.h
Gary Kramlich <grim@reaperworld.com>
parents: 31428
diff changeset
40
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
41 /******************************************************************************
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
42 * Enums
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
43 *****************************************************************************/
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
44 enum {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
45 PROP_NONE,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
46 PROP_HASH,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
47 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
48 };
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
49
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
50 /*******************************************************************************
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
51 * Globals
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 static GObjectClass *parent_class = NULL;
35077
0a120b204362 ciphers: use g_object_notify_by_pspec instead of g_object_notify
Ankit Vani <a@nevitus.org>
parents: 35065
diff changeset
54 static GParamSpec *properties[PROP_LAST];
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
55
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
56 /*******************************************************************************
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
57 * Helpers
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
58 ******************************************************************************/
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
59 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
60 purple_hmac_cipher_set_hash(PurpleCipher *cipher,
34567
ea5103f66b0e Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents: 34566
diff changeset
61 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
62 {
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
63 PurpleHMACCipherPrivate *priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
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 priv->hash = g_object_ref(G_OBJECT(hash));
35065
2fe1b3f20c3c Added a few missing G_PARAM_STATIC_STRINGS and g_object_notify
Ankit Vani <a@nevitus.org>
parents: 35062
diff changeset
66
35077
0a120b204362 ciphers: use g_object_notify_by_pspec instead of g_object_notify
Ankit Vani <a@nevitus.org>
parents: 35065
diff changeset
67 g_object_notify_by_pspec(G_OBJECT(cipher), properties[PROP_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
68 }
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
69
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
70 /*******************************************************************************
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
71 * Cipher Stuff
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
72 ******************************************************************************/
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
73 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
74 purple_hmac_cipher_reset(PurpleCipher *cipher) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
75 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
76
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
77 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
78 purple_hash_reset(priv->hash);
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
79
37426
6fd4989b77e4 The last of the NULL-checks before free()
Michael McConville <mmcco@mykolab.com>
parents: 35084
diff changeset
80 g_free(priv->ipad);
6fd4989b77e4 The last of the NULL-checks before free()
Michael McConville <mmcco@mykolab.com>
parents: 35084
diff changeset
81 priv->ipad = NULL;
6fd4989b77e4 The last of the NULL-checks before free()
Michael McConville <mmcco@mykolab.com>
parents: 35084
diff changeset
82 g_free(priv->opad);
6fd4989b77e4 The last of the NULL-checks before free()
Michael McConville <mmcco@mykolab.com>
parents: 35084
diff changeset
83 priv->opad = NULL;
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
84 }
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
85
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
86 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
87 purple_hmac_cipher_reset_state(PurpleCipher *cipher) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
88 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
89
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
90 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
91 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
92 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
93 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
94 }
33913
9effc94565d8 ciphers cleanup: add reset state callback
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33911
diff changeset
95 }
9effc94565d8 ciphers cleanup: add reset state callback
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33911
diff changeset
96
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
97 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
98 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
99 PurpleHMACCipherPrivate *priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
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 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
102
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
103 purple_hash_append(priv->hash, d, l);
34541
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
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
106 static gboolean
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
107 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
108 {
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
109 PurpleHMACCipherPrivate *priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
110 guchar *digest = NULL;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
111 size_t hash_len, block_size;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
112 gboolean result = FALSE;
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 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
115
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
116 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
117 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
118
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
119 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
120 digest = g_malloc(hash_len);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
121
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
122 /* 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
123 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
124 purple_hash_reset(priv->hash);
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
125
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
126 if(!result) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
127 g_free(digest);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
128
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
129 return FALSE;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
130 }
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
131
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
132 /* 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
133 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
134 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
135
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
136 /* 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
137 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
138
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
139 /* cleanup */
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
140 g_free(digest);
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 return result;
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
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
145 static size_t
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
146 purple_hmac_cipher_get_digest_size(PurpleCipher *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 PurpleHMACCipherPrivate *priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
149
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
150 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
151
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
152 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
153 }
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
154
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
155 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
156 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
157 size_t key_len)
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
158 {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
159 PurpleHMACCipherPrivate *priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
34891
3882234d2097 Fixed variable name
Ankit Vani <a@nevitus.org>
parents: 34889
diff changeset
160 gsize block_size, i;
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
161 guchar *full_key;
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_return_if_fail(priv->hash);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
164
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
165 g_free(priv->ipad);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
166 g_free(priv->opad);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
167
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
168 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
169 priv->ipad = g_malloc(block_size);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
170 priv->opad = g_malloc(block_size);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
171
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
172 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
173 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
174 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
175
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
176 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
177 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
178 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
179 } else {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
180 full_key = g_memdup(key, key_len);
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
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
183 if (key_len < block_size) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
184 full_key = g_realloc(full_key, block_size);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
185 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
186 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
187
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
188 for(i = 0; i < block_size; i++) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
189 priv->ipad[i] = 0x36 ^ full_key[i];
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
190 priv->opad[i] = 0x5c ^ full_key[i];
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
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
193 g_free(full_key);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
194
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
195 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
196 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
197 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
198
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
199 static size_t
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
200 purple_hmac_cipher_get_block_size(PurpleCipher *cipher)
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 PurpleHMACCipherPrivate *priv = NULL;
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 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
205
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
206 priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
207
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
208 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
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 /******************************************************************************
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
212 * Object Stuff
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
213 *****************************************************************************/
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
214 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
215 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
216 const GValue *value,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
217 GParamSpec *pspec)
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 PurpleCipher *cipher = PURPLE_CIPHER(obj);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
220
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
221 switch(param_id) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
222 case PROP_HASH:
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
223 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
224 break;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
225 default:
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
226 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
227 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
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 }
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
230
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
231 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
232 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
233 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
234 {
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
235 PurpleHMACCipher *cipher = PURPLE_HMAC_CIPHER(obj);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
236
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
237 switch(param_id) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
238 case PROP_HASH:
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
239 g_value_set_object(value,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
240 purple_hmac_cipher_get_hash(cipher));
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
241 break;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
242 default:
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
243 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
244 break;
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
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
248 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
249 purple_hmac_cipher_finalize(GObject *obj) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
250 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
251 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
252
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
253 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
254
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
255 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
256 g_object_unref(priv->hash);
34541
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 parent_class->finalize(obj);
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
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
261 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
262 purple_hmac_cipher_class_init(PurpleHMACCipherClass *klass) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
263 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
264 PurpleCipherClass *cipher_class = PURPLE_CIPHER_CLASS(klass);
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
35077
0a120b204362 ciphers: use g_object_notify_by_pspec instead of g_object_notify
Ankit Vani <a@nevitus.org>
parents: 35065
diff changeset
282 properties[PROP_HASH] = g_param_spec_object("hash", "hash", "hash",
0a120b204362 ciphers: use g_object_notify_by_pspec instead of g_object_notify
Ankit Vani <a@nevitus.org>
parents: 35065
diff changeset
283 PURPLE_TYPE_HASH,
35062
2aee8634c912 ciphers: Use G_PARAM_STATIC_STRINGS and ensure g_object_notify is always called
Ankit Vani <a@nevitus.org>
parents: 35026
diff changeset
284 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
2aee8634c912 ciphers: Use G_PARAM_STATIC_STRINGS and ensure g_object_notify is always called
Ankit Vani <a@nevitus.org>
parents: 35026
diff changeset
285 G_PARAM_STATIC_STRINGS);
35084
07cd7f1767c7 ciphers: use g_object_class_install_properties instead of repeated g_object_class_install_property
Ankit Vani <a@nevitus.org>
parents: 35077
diff changeset
286
07cd7f1767c7 ciphers: use g_object_class_install_properties instead of repeated g_object_class_install_property
Ankit Vani <a@nevitus.org>
parents: 35077
diff changeset
287 g_object_class_install_properties(obj_class, PROP_LAST, properties);
34541
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
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
290 /******************************************************************************
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
291 * PurpleHMACCipher API
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 GType
35020
0ab63ada3cf2 Changed *_get_gtype to *_get_type for ciphers and hashes so gtk-doc can find them
Ankit Vani <a@nevitus.org>
parents: 35014
diff changeset
294 purple_hmac_cipher_get_type(void) {
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
295 static GType type = 0;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
296
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
297 if(type == 0) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
298 static const GTypeInfo info = {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
299 sizeof(PurpleHMACCipherClass),
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 (GClassInitFunc)purple_hmac_cipher_class_init,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
303 NULL,
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 sizeof(PurpleHMACCipher),
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
306 0,
34548
18cc6efb5194 Added reset at every cipher's initialization
Ankit Vani <a@nevitus.org>
parents: 34547
diff changeset
307 (GInstanceInitFunc)purple_cipher_reset,
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
308 NULL,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
309 };
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
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
311 type = g_type_register_static(PURPLE_TYPE_CIPHER,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
312 "PurpleHMACCipher",
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
313 &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
314 }
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
315
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
316 return type;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
317 }
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 PurpleCipher *
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
320 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
321 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
322
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
323 return g_object_new(PURPLE_TYPE_HMAC_CIPHER,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
324 "hash", hash,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
325 NULL);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
326 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
327
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
328 PurpleHash *
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
329 purple_hmac_cipher_get_hash(const PurpleHMACCipher *cipher) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
330 PurpleHMACCipherPrivate *priv = NULL;
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 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
333
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
334 priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
335
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
336 if(priv && priv->hash)
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
337 return priv->hash;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
338
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
339 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
340 }
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
341

mercurial