Sun, 16 Oct 2011 03:03:39 +0000
Remove free_memory argument from D-Bus list functions. It's already
always set to FALSE in the auto-generated code.
Fixes #1747.
|
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 | */ |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
22 | #include <cipher.h> |
|
31434
d9b76cfd8500
rc4.c and sha1.c needs to include libpurple/util.h as well
Gary Kramlich <grim@reaperworld.com>
parents:
31429
diff
changeset
|
23 | #include <util.h> |
|
31425
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
24 | |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
25 | struct RC4Context { |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
26 | guchar state[256]; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
27 | guchar x; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
28 | guchar y; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
29 | gint key_len; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
30 | }; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
31 | |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
32 | static void |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
33 | rc4_init(PurpleCipherContext *context, void *extra) { |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
34 | struct RC4Context *rc4_ctx; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
35 | rc4_ctx = g_new0(struct RC4Context, 1); |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
36 | purple_cipher_context_set_data(context, rc4_ctx); |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
37 | purple_cipher_context_reset(context, extra); |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
38 | } |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
39 | |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
40 | |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
41 | static void |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
42 | rc4_reset(PurpleCipherContext *context, void *extra) { |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
43 | struct RC4Context *rc4_ctx; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
44 | guint i; |
|
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 | rc4_ctx = purple_cipher_context_get_data(context); |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
47 | |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
48 | g_return_if_fail(rc4_ctx); |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
49 | |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
50 | for(i = 0; i < 256; i++) |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
51 | rc4_ctx->state[i] = i; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
52 | rc4_ctx->x = 0; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
53 | rc4_ctx->y = 0; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
54 | |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
55 | /* default is 5 bytes (40bit key) */ |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
56 | rc4_ctx->key_len = 5; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
57 | |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
58 | } |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
59 | |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
60 | static void |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
61 | rc4_uninit(PurpleCipherContext *context) { |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
62 | struct RC4Context *rc4_ctx; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
63 | |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
64 | rc4_ctx = purple_cipher_context_get_data(context); |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
65 | memset(rc4_ctx, 0, sizeof(*rc4_ctx)); |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
66 | |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
67 | g_free(rc4_ctx); |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
68 | rc4_ctx = NULL; |
|
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 | |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
71 | |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
72 | |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
73 | static void |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
74 | rc4_set_key (PurpleCipherContext *context, const guchar * key) { |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
75 | struct RC4Context *ctx; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
76 | guchar *state; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
77 | guchar temp_swap; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
78 | guchar x, y; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
79 | guint i; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
80 | |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
81 | ctx = purple_cipher_context_get_data(context); |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
82 | |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
83 | x = 0; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
84 | y = 0; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
85 | state = &ctx->state[0]; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
86 | for(i = 0; i < 256; i++) |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
87 | { |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
88 | y = (key[x] + state[i] + y) % 256; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
89 | temp_swap = state[i]; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
90 | state[i] = state[y]; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
91 | state[y] = temp_swap; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
92 | x = (x + 1) % ctx->key_len; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
93 | } |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
94 | } |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
95 | |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
96 | static void |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
97 | rc4_set_opt(PurpleCipherContext *context, const gchar *name, void *value) { |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
98 | struct RC4Context *ctx; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
99 | |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
100 | ctx = purple_cipher_context_get_data(context); |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
101 | |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
102 | if(purple_strequal(name, "key_len")) { |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
103 | ctx->key_len = GPOINTER_TO_INT(value); |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
104 | } |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
105 | } |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
106 | |
|
31429
e88f769a8e05
fixed some indentation issues that were missed earlier in rc4.c
Gary Kramlich <grim@reaperworld.com>
parents:
31428
diff
changeset
|
107 | static size_t |
|
31425
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
108 | rc4_get_key_size (PurpleCipherContext *context) |
|
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 | struct RC4Context *ctx; |
|
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 | g_return_val_if_fail(context, -1); |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
113 | |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
114 | ctx = purple_cipher_context_get_data(context); |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
115 | |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
116 | g_return_val_if_fail(ctx, -1); |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
117 | |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
118 | return ctx->key_len; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
119 | } |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
120 | |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
121 | static void * |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
122 | rc4_get_opt(PurpleCipherContext *context, const gchar *name) { |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
123 | struct RC4Context *ctx; |
|
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 | ctx = purple_cipher_context_get_data(context); |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
126 | |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
127 | if(purple_strequal(name, "key_len")) { |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
128 | return GINT_TO_POINTER(ctx->key_len); |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
129 | } |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
130 | |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
131 | return NULL; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
132 | } |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
133 | |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
134 | static gint |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
135 | rc4_encrypt(PurpleCipherContext *context, const guchar data[], |
|
31429
e88f769a8e05
fixed some indentation issues that were missed earlier in rc4.c
Gary Kramlich <grim@reaperworld.com>
parents:
31428
diff
changeset
|
136 | size_t len, guchar output[], size_t *outlen) { |
|
31425
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
137 | struct RC4Context *ctx; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
138 | guchar temp_swap; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
139 | guchar x, y, z; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
140 | guchar *state; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
141 | guint i; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
142 | |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
143 | ctx = purple_cipher_context_get_data(context); |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
144 | |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
145 | x = ctx->x; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
146 | y = ctx->y; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
147 | state = &ctx->state[0]; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
148 | |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
149 | for(i = 0; i < len; i++) |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
150 | { |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
151 | x = (x + 1) % 256; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
152 | y = (state[x] + y) % 256; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
153 | temp_swap = state[x]; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
154 | state[x] = state[y]; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
155 | state[y] = temp_swap; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
156 | z = state[x] + (state[y]) % 256; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
157 | output[i] = data[i] ^ state[z]; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
158 | } |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
159 | ctx->x = x; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
160 | ctx->y = y; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
161 | if(outlen) |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
162 | *outlen = len; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
163 | |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
164 | return 0; |
|
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 | |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
167 | static PurpleCipherOps RC4Ops = { |
|
31553
45a14a4b0a87
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31434
diff
changeset
|
168 | rc4_set_opt, /* Set Option */ |
|
45a14a4b0a87
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31434
diff
changeset
|
169 | rc4_get_opt, /* Get Option */ |
|
45a14a4b0a87
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31434
diff
changeset
|
170 | rc4_init, /* init */ |
|
45a14a4b0a87
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31434
diff
changeset
|
171 | rc4_reset, /* reset */ |
|
45a14a4b0a87
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31434
diff
changeset
|
172 | rc4_uninit, /* uninit */ |
|
45a14a4b0a87
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31434
diff
changeset
|
173 | NULL, /* set iv */ |
|
45a14a4b0a87
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31434
diff
changeset
|
174 | NULL, /* append */ |
|
45a14a4b0a87
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31434
diff
changeset
|
175 | NULL, /* digest */ |
|
45a14a4b0a87
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31434
diff
changeset
|
176 | rc4_encrypt, /* encrypt */ |
|
45a14a4b0a87
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31434
diff
changeset
|
177 | NULL, /* decrypt */ |
|
45a14a4b0a87
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31434
diff
changeset
|
178 | NULL, /* set salt */ |
|
45a14a4b0a87
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31434
diff
changeset
|
179 | NULL, /* get salt size */ |
|
45a14a4b0a87
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31434
diff
changeset
|
180 | rc4_set_key, /* set key */ |
|
45a14a4b0a87
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31434
diff
changeset
|
181 | rc4_get_key_size, /* get key size */ |
|
45a14a4b0a87
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31434
diff
changeset
|
182 | NULL, /* set batch mode */ |
|
45a14a4b0a87
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31434
diff
changeset
|
183 | NULL, /* get batch mode */ |
|
45a14a4b0a87
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31434
diff
changeset
|
184 | NULL, /* get block size */ |
|
45a14a4b0a87
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31434
diff
changeset
|
185 | NULL /* set key with len */ |
|
31425
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
186 | }; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
187 | |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
188 | PurpleCipherOps * |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
189 | purple_rc4_cipher_get_ops(void) { |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
190 | return &RC4Ops; |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
191 | } |
|
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
192 |