libpurple/ciphers/hmaccipher.c

Thu, 03 Apr 2014 16:02:37 +0200

author
Tomasz Wasilczyk <twasilczyk@pidgin.im>
date
Thu, 03 Apr 2014 16:02:37 +0200
changeset 35686
cae91a875b23
parent 35084
07cd7f1767c7
child 37426
6fd4989b77e4
permissions
-rw-r--r--

Merge release-2.x.y

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
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
80 if(priv->ipad) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
81 g_free(priv->ipad);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
82 priv->ipad = NULL;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
83 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
84 if(priv->opad) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
85 g_free(priv->opad);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
86 priv->opad = NULL;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
87 }
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
88 }
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
89
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
90 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
91 purple_hmac_cipher_reset_state(PurpleCipher *cipher) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
92 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
93
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
94 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
95 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
96 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
97 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
98 }
33913
9effc94565d8 ciphers cleanup: add reset state callback
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33911
diff changeset
99 }
9effc94565d8 ciphers cleanup: add reset state callback
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33911
diff changeset
100
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
101 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
102 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
103 PurpleHMACCipherPrivate *priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
104
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
105 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
106
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
107 purple_hash_append(priv->hash, d, l);
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
108 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
109
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
110 static gboolean
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
111 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
112 {
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
113 PurpleHMACCipherPrivate *priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
114 guchar *digest = NULL;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
115 size_t hash_len, block_size;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
116 gboolean result = 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 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
119
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
120 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
121 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
122
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
123 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
124 digest = g_malloc(hash_len);
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 /* 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
127 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
128 purple_hash_reset(priv->hash);
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
129
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
130 if(!result) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
131 g_free(digest);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
132
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
133 return FALSE;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
134 }
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
135
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
136 /* 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
137 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
138 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
139
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
140 /* 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
141 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
142
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
143 /* cleanup */
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
144 g_free(digest);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
145
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
146 return result;
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
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
149 static size_t
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
150 purple_hmac_cipher_get_digest_size(PurpleCipher *cipher)
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
151 {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
152 PurpleHMACCipherPrivate *priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
153
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
154 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
155
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
156 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
157 }
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
158
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
159 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
160 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
161 size_t key_len)
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 PurpleHMACCipherPrivate *priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
34891
3882234d2097 Fixed variable name
Ankit Vani <a@nevitus.org>
parents: 34889
diff changeset
164 gsize block_size, i;
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
165 guchar *full_key;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
166
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
167 g_return_if_fail(priv->hash);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
168
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
169 g_free(priv->ipad);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
170 g_free(priv->opad);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
171
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
172 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
173 priv->ipad = g_malloc(block_size);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
174 priv->opad = g_malloc(block_size);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
175
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
176 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
177 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
178 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
179
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
180 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
181 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
182 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
183 } else {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
184 full_key = g_memdup(key, 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 if (key_len < block_size) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
188 full_key = g_realloc(full_key, block_size);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
189 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
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 for(i = 0; i < block_size; i++) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
193 priv->ipad[i] = 0x36 ^ full_key[i];
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
194 priv->opad[i] = 0x5c ^ full_key[i];
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
195 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
196
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
197 g_free(full_key);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
198
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
199 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
200 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
201 }
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 static size_t
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
204 purple_hmac_cipher_get_block_size(PurpleCipher *cipher)
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 PurpleHMACCipherPrivate *priv = NULL;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
207
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
208 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
209
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
210 priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
211
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
212 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
213 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
214
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
215 /******************************************************************************
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
216 * Object Stuff
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 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
219 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
220 const GValue *value,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
221 GParamSpec *pspec)
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
222 {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
223 PurpleCipher *cipher = PURPLE_CIPHER(obj);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
224
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
225 switch(param_id) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
226 case PROP_HASH:
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
227 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
228 break;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
229 default:
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
230 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
231 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
232 }
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
233 }
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
234
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
235 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
236 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
237 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
238 {
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
239 PurpleHMACCipher *cipher = PURPLE_HMAC_CIPHER(obj);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
240
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
241 switch(param_id) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
242 case PROP_HASH:
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
243 g_value_set_object(value,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
244 purple_hmac_cipher_get_hash(cipher));
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
245 break;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
246 default:
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
247 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
248 break;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
249 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
250 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
251
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
252 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
253 purple_hmac_cipher_finalize(GObject *obj) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
254 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
255 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
256
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
257 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
258
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
259 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
260 g_object_unref(priv->hash);
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
261
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
262 parent_class->finalize(obj);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
263 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
264
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
265 static void
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
266 purple_hmac_cipher_class_init(PurpleHMACCipherClass *klass) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
267 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
268 PurpleCipherClass *cipher_class = PURPLE_CIPHER_CLASS(klass);
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 parent_class = g_type_class_peek_parent(klass);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
271
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
272 g_type_class_add_private(klass, sizeof(PurpleHMACCipherPrivate));
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 obj_class->finalize = purple_hmac_cipher_finalize;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
275 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
276 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
277
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
278 cipher_class->reset = purple_hmac_cipher_reset;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
279 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
280 cipher_class->append = purple_hmac_cipher_append;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
281 cipher_class->digest = purple_hmac_cipher_digest;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
282 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
283 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
284 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
285
35077
0a120b204362 ciphers: use g_object_notify_by_pspec instead of g_object_notify
Ankit Vani <a@nevitus.org>
parents: 35065
diff changeset
286 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
287 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
288 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
289 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
290
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
291 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
292 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
293
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
294 /******************************************************************************
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
295 * PurpleHMACCipher API
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
296 *****************************************************************************/
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
297 GType
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
298 purple_hmac_cipher_get_type(void) {
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
299 static GType type = 0;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
300
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
301 if(type == 0) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
302 static const GTypeInfo info = {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
303 sizeof(PurpleHMACCipherClass),
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
304 NULL,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
305 NULL,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
306 (GClassInitFunc)purple_hmac_cipher_class_init,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
307 NULL,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
308 NULL,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
309 sizeof(PurpleHMACCipher),
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
310 0,
34548
18cc6efb5194 Added reset at every cipher's initialization
Ankit Vani <a@nevitus.org>
parents: 34547
diff changeset
311 (GInstanceInitFunc)purple_cipher_reset,
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
312 NULL,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
313 };
31423
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
314
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
315 type = g_type_register_static(PURPLE_TYPE_CIPHER,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
316 "PurpleHMACCipher",
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
317 &info, 0);
31423
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
318 }
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
319
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
320 return type;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
321 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
322
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
323 PurpleCipher *
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
324 purple_hmac_cipher_new(PurpleHash *hash) {
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
325 g_return_val_if_fail(PURPLE_IS_HASH(hash), NULL);
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
326
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
327 return g_object_new(PURPLE_TYPE_HMAC_CIPHER,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
328 "hash", hash,
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
329 NULL);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
330 }
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
331
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34561
diff changeset
332 PurpleHash *
34541
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
333 purple_hmac_cipher_get_hash(const PurpleHMACCipher *cipher) {
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
334 PurpleHMACCipherPrivate *priv = NULL;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
335
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
336 g_return_val_if_fail(PURPLE_IS_HMAC_CIPHER(cipher), NULL);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
337
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
338 priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
339
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
340 if(priv && priv->hash)
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
341 return priv->hash;
9a96150a0365 GObjectified the HMAC cipher as PurpleHMACCipher
Ankit Vani <a@nevitus.org>
parents: 33916
diff changeset
342
31423
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
343 return NULL;
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
344 }
8483c092dbc4 Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
345

mercurial