libpurple/ciphers/rc4cipher.c

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

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

Removed 'get_name' from PurpleCipher

31425
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * purple
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 *
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 * Purple is the legal property of its developers, whose names are too numerous
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * source distribution.
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 *
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * (at your option) any later version.
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 *
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * GNU General Public License for more details.
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 *
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 */
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34551
diff changeset
22 #include "rc4cipher.h"
33911
a924aacd5a37 ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33910
diff changeset
23
34536
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
24 /*******************************************************************************
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
25 * Structs
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
26 ******************************************************************************/
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
27 #define PURPLE_RC4_CIPHER_GET_PRIVATE(obj) \
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
28 (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_RC4_CIPHER, PurpleRC4CipherPrivate))
31425
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29
34536
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
30 typedef struct {
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
31 guchar state[256];
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
32 guchar x;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
33 guchar y;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
34 gint key_len;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
35 } PurpleRC4CipherPrivate;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
36
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
37 /******************************************************************************
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
38 * Enums
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
39 *****************************************************************************/
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
40 enum {
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
41 PROP_ZERO,
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
42 PROP_KEY_LEN,
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
43 PROP_KEY,
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
44 PROP_LAST,
31425
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45 };
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46
34536
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
47 /******************************************************************************
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
48 * Globals
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
49 *****************************************************************************/
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
50 static GObjectClass *parent_class = NULL;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
51
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
52 /******************************************************************************
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
53 * Cipher Stuff
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
54 *****************************************************************************/
31425
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55 static void
34536
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
56 purple_rc4_cipher_reset(PurpleCipher *cipher) {
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
57 PurpleRC4Cipher *rc4_cipher = PURPLE_RC4_CIPHER(cipher);
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
58 PurpleRC4CipherPrivate *priv = PURPLE_RC4_CIPHER_GET_PRIVATE(rc4_cipher);
31425
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 guint i;
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
61 for(i = 0; i < 256; i++)
34536
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
62 priv->state[i] = i;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
63 priv->x = 0;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
64 priv->y = 0;
31425
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66 /* default is 5 bytes (40bit key) */
34536
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
67 priv->key_len = 5;
31425
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68 }
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
70 static void
34536
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
71 purple_rc4_cipher_set_key(PurpleCipher *cipher, const guchar *key, size_t len) {
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
72 PurpleRC4Cipher *rc4_cipher = PURPLE_RC4_CIPHER(cipher);
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
73 PurpleRC4CipherPrivate *priv = PURPLE_RC4_CIPHER_GET_PRIVATE(rc4_cipher);
31425
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74 guchar *state;
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75 guchar temp_swap;
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76 guchar x, y;
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
77 guint i;
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
78
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
79 x = 0;
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
80 y = 0;
34536
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
81 state = &priv->state[0];
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
82 priv->key_len = len;
31425
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
83 for(i = 0; i < 256; i++)
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
84 {
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
85 y = (key[x] + state[i] + y) % 256;
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
86 temp_swap = state[i];
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
87 state[i] = state[y];
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
88 state[y] = temp_swap;
33908
78b42fd69e02 ciphers cleanup: passing keys with length by default
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33881
diff changeset
89 x = (x + 1) % len;
31425
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
90 }
34536
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
91
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
92 g_object_notify(G_OBJECT(rc4_cipher), "key");
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
93 }
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
94
33911
a924aacd5a37 ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33910
diff changeset
95 static ssize_t
34536
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
96 purple_rc4_cipher_encrypt(PurpleCipher *cipher, const guchar input[], size_t in_len,
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
97 guchar output[], size_t out_size)
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
98 {
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
99 PurpleRC4Cipher *rc4_cipher = PURPLE_RC4_CIPHER(cipher);
31425
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
100 guchar temp_swap;
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
101 guchar x, y, z;
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
102 guchar *state;
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
103 guint i;
34536
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
104 PurpleRC4CipherPrivate *priv = PURPLE_RC4_CIPHER_GET_PRIVATE(rc4_cipher);
31425
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
105
34536
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
106 x = priv->x;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
107 y = priv->y;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
108 state = &priv->state[0];
31425
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
109
33911
a924aacd5a37 ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33910
diff changeset
110 for(i = 0; i < in_len; i++)
31425
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
111 {
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
112 x = (x + 1) % 256;
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
113 y = (state[x] + y) % 256;
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
114 temp_swap = state[x];
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
115 state[x] = state[y];
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
116 state[y] = temp_swap;
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
117 z = state[x] + (state[y]) % 256;
33911
a924aacd5a37 ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33910
diff changeset
118 output[i] = input[i] ^ state[z];
31425
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
119 }
34536
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
120 priv->x = x;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
121 priv->y = y;
31425
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
122
33911
a924aacd5a37 ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33910
diff changeset
123 return in_len;
31425
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
124 }
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
125
34536
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
126 /******************************************************************************
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
127 * Object Stuff
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
128 *****************************************************************************/
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
129 static void
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
130 purple_rc4_cipher_set_property(GObject *obj, guint param_id,
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
131 const GValue *value, GParamSpec *pspec)
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
132 {
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
133 PurpleCipher *cipher = PURPLE_CIPHER(obj);
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
134 PurpleRC4Cipher *rc4_cipher = PURPLE_RC4_CIPHER(obj);
31425
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
135
34536
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
136 switch(param_id) {
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
137 case PROP_KEY_LEN:
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
138 purple_rc4_cipher_set_key_len(rc4_cipher, g_value_get_int(value));
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
139 break;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
140 case PROP_KEY:
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
141 {
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
142 guchar *key = (guchar *)g_value_get_string(value);
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
143 purple_rc4_cipher_set_key(cipher, key, strlen((gchar *) key));
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
144 }
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
145 break;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
146 default:
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
147 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
148 break;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
149 }
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
150 }
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
151
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
152 static void
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
153 purple_rc4_cipher_get_property(GObject *obj, guint param_id, GValue *value,
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
154 GParamSpec *pspec)
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
155 {
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
156 PurpleRC4Cipher *rc4_cipher = PURPLE_RC4_CIPHER(obj);
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
157
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
158 switch(param_id) {
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
159 case PROP_KEY_LEN:
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
160 g_value_set_int(value,
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
161 purple_rc4_cipher_get_key_len(rc4_cipher));
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
162 break;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
163 default:
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
164 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
165 break;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
166 }
31425
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
167 }
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
168
34536
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
169 static void
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
170 purple_rc4_cipher_class_init(PurpleRC4CipherClass *klass) {
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
171 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
172 PurpleCipherClass *cipher_class = PURPLE_CIPHER_CLASS(klass);
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
173 GParamSpec *pspec = NULL;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
174
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
175 parent_class = g_type_class_peek_parent(klass);
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
176
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
177 obj_class->set_property = purple_rc4_cipher_set_property;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
178 obj_class->get_property = purple_rc4_cipher_get_property;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
179
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
180 cipher_class->reset = purple_rc4_cipher_reset;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
181 cipher_class->encrypt = purple_rc4_cipher_encrypt;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
182 cipher_class->set_key = purple_rc4_cipher_set_key;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
183
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
184 pspec = g_param_spec_int("key_len", "key_len", "key_len",
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
185 G_MININT, G_MAXINT, 0,
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
186 G_PARAM_READWRITE);
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
187 g_object_class_install_property(obj_class, PROP_KEY_LEN, pspec);
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
188
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
189 pspec = g_param_spec_string("key", "key", "key", NULL,
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
190 G_PARAM_WRITABLE);
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
191 g_object_class_install_property(obj_class, PROP_KEY, pspec);
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
192
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
193 g_type_class_add_private(klass, sizeof(PurpleRC4CipherPrivate));
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
194 }
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
195
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
196 static void
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
197 purple_rc4_cipher_init(PurpleCipher *cipher) {
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
198 purple_rc4_cipher_reset(cipher);
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
199 }
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
200
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
201 /******************************************************************************
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
202 * API
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
203 *****************************************************************************/
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
204 GType
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
205 purple_rc4_cipher_get_gtype(void) {
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
206 static GType type = 0;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
207
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
208 if(type == 0) {
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
209 static const GTypeInfo info = {
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
210 sizeof(PurpleRC4CipherClass),
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
211 NULL,
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
212 NULL,
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
213 (GClassInitFunc)purple_rc4_cipher_class_init,
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
214 NULL,
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
215 NULL,
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
216 sizeof(PurpleRC4Cipher),
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
217 0,
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
218 (GInstanceInitFunc)purple_rc4_cipher_init,
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
219 NULL,
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
220 };
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
221
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
222 type = g_type_register_static(PURPLE_TYPE_CIPHER,
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
223 "PurpleRC4Cipher",
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
224 &info, 0);
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
225 }
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
226
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
227 return type;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
228 }
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
229
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
230 PurpleCipher *
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
231 purple_rc4_cipher_new(void) {
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
232 return g_object_new(PURPLE_TYPE_RC4_CIPHER, NULL);
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
233 }
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
234
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
235 void
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
236 purple_rc4_cipher_set_key_len(PurpleRC4Cipher *rc4_cipher,
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
237 gint key_len)
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
238 {
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
239 PurpleRC4CipherPrivate *priv;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
240
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
241 g_return_if_fail(PURPLE_IS_RC4_CIPHER(rc4_cipher));
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
242
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
243 priv = PURPLE_RC4_CIPHER_GET_PRIVATE(rc4_cipher);
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
244 priv->key_len = key_len;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
245
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
246 g_object_notify(G_OBJECT(rc4_cipher), "key_len");
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
247 }
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
248
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
249 gint
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
250 purple_rc4_cipher_get_key_len(PurpleRC4Cipher *rc4_cipher)
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
251 {
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
252 PurpleRC4CipherPrivate *priv;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
253
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
254 g_return_val_if_fail(PURPLE_IS_RC4_CIPHER(rc4_cipher), 0);
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
255
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
256 priv = PURPLE_RC4_CIPHER_GET_PRIVATE(rc4_cipher);
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
257
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
258 return priv->key_len;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
259 }

mercurial