libpurple/ciphers/rc4cipher.c

Sat, 12 Oct 2013 20:46:23 +0530

author
Ankit Vani <a@nevitus.org>
date
Sat, 12 Oct 2013 20:46:23 +0530
branch
soc.2013.gobjectification
changeset 35020
0ab63ada3cf2
parent 35014
21864c2f543f
child 35026
fde23518e1e5
permissions
-rw-r--r--

Changed *_get_gtype to *_get_type for ciphers and hashes so gtk-doc can find them

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
33911
a924aacd5a37 ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33910
diff changeset
93 static ssize_t
34536
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
94 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
95 guchar output[], size_t out_size)
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
96 {
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
97 PurpleRC4Cipher *rc4_cipher = PURPLE_RC4_CIPHER(cipher);
31425
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
98 guchar temp_swap;
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
99 guchar x, y, z;
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
100 guchar *state;
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
101 guint i;
34536
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
102 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
103
34536
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
104 x = priv->x;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
105 y = priv->y;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
106 state = &priv->state[0];
31425
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
107
33911
a924aacd5a37 ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33910
diff changeset
108 for(i = 0; i < in_len; i++)
31425
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
109 {
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
110 x = (x + 1) % 256;
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
111 y = (state[x] + y) % 256;
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
112 temp_swap = state[x];
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
113 state[x] = state[y];
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
114 state[y] = temp_swap;
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
115 z = state[x] + (state[y]) % 256;
33911
a924aacd5a37 ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33910
diff changeset
116 output[i] = input[i] ^ state[z];
31425
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
117 }
34536
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
118 priv->x = x;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
119 priv->y = y;
31425
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
120
33911
a924aacd5a37 ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33910
diff changeset
121 return in_len;
31425
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
122 }
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
123
34536
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
124 /******************************************************************************
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
125 * Object Stuff
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 static void
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
128 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
129 const GValue *value, GParamSpec *pspec)
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
130 {
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
131 PurpleCipher *cipher = PURPLE_CIPHER(obj);
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
132 PurpleRC4Cipher *rc4_cipher = PURPLE_RC4_CIPHER(obj);
31425
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
133
34536
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
134 switch(param_id) {
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
135 case PROP_KEY_LEN:
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
136 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
137 break;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
138 case PROP_KEY:
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
139 {
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
140 guchar *key = (guchar *)g_value_get_string(value);
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
141 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
142 }
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
143 break;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
144 default:
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
145 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
146 break;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
147 }
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
148 }
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 static void
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
151 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
152 GParamSpec *pspec)
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
153 {
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
154 PurpleRC4Cipher *rc4_cipher = PURPLE_RC4_CIPHER(obj);
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 switch(param_id) {
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
157 case PROP_KEY_LEN:
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
158 g_value_set_int(value,
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
159 purple_rc4_cipher_get_key_len(rc4_cipher));
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
160 break;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
161 default:
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
162 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
163 break;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
164 }
31425
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
165 }
e8113737ec1a Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
166
34536
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
167 static void
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
168 purple_rc4_cipher_class_init(PurpleRC4CipherClass *klass) {
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
169 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
170 PurpleCipherClass *cipher_class = PURPLE_CIPHER_CLASS(klass);
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
171 GParamSpec *pspec = NULL;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
172
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
173 parent_class = g_type_class_peek_parent(klass);
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 obj_class->set_property = purple_rc4_cipher_set_property;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
176 obj_class->get_property = purple_rc4_cipher_get_property;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
177
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
178 cipher_class->reset = purple_rc4_cipher_reset;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
179 cipher_class->encrypt = purple_rc4_cipher_encrypt;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
180 cipher_class->set_key = purple_rc4_cipher_set_key;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
181
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
182 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
183 G_MININT, G_MAXINT, 0,
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
184 G_PARAM_READWRITE);
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
185 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
186
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
187 pspec = g_param_spec_string("key", "key", "key", NULL,
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
188 G_PARAM_WRITABLE);
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
189 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
190
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
191 g_type_class_add_private(klass, sizeof(PurpleRC4CipherPrivate));
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
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
194 static void
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
195 purple_rc4_cipher_init(PurpleCipher *cipher) {
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
196 purple_rc4_cipher_reset(cipher);
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
197 }
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
198
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 * API
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 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
203 purple_rc4_cipher_get_type(void) {
34536
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
204 static GType type = 0;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
205
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
206 if(type == 0) {
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
207 static const GTypeInfo info = {
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
208 sizeof(PurpleRC4CipherClass),
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
209 NULL,
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
210 NULL,
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
211 (GClassInitFunc)purple_rc4_cipher_class_init,
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 NULL,
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
214 sizeof(PurpleRC4Cipher),
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
215 0,
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
216 (GInstanceInitFunc)purple_rc4_cipher_init,
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
217 NULL,
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
218 };
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
219
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
220 type = g_type_register_static(PURPLE_TYPE_CIPHER,
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
221 "PurpleRC4Cipher",
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
222 &info, 0);
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
223 }
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
224
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
225 return type;
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
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
228 PurpleCipher *
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
229 purple_rc4_cipher_new(void) {
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
230 return g_object_new(PURPLE_TYPE_RC4_CIPHER, NULL);
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
231 }
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
232
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
233 void
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
234 purple_rc4_cipher_set_key_len(PurpleRC4Cipher *rc4_cipher,
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
235 gint key_len)
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
236 {
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
237 PurpleRC4CipherPrivate *priv;
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 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
240
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
241 priv = PURPLE_RC4_CIPHER_GET_PRIVATE(rc4_cipher);
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
242 priv->key_len = key_len;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
243 }
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
244
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
245 gint
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
246 purple_rc4_cipher_get_key_len(PurpleRC4Cipher *rc4_cipher)
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 PurpleRC4CipherPrivate *priv;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
249
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
250 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
251
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
252 priv = PURPLE_RC4_CIPHER_GET_PRIVATE(rc4_cipher);
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 return priv->key_len;
38cc893bae51 GObjectify RC4 cipher as PurpleRC4Cipher
Ankit Vani <a@nevitus.org>
parents: 33914
diff changeset
255 }

mercurial