Sun, 16 Jun 2013 03:46:10 +0530
Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
|
34566
e0f887dee077
Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents:
34561
diff
changeset
|
1 | /* purple |
| 10684 | 2 | * |
| 15884 | 3 | * Purple is the legal property of its developers, whose names are too numerous |
| 10684 | 4 | * to list here. Please refer to the COPYRIGHT file distributed with this |
| 5 | * source distribution. | |
| 6 | * | |
| 7 | * This program is free software; you can redistribute it and/or modify | |
| 8 | * it under the terms of the GNU General Public License as published by | |
| 9 | * the Free Software Foundation; either version 2 of the License, or | |
| 10 | * (at your option) any later version. | |
| 11 | * | |
| 12 | * This program is distributed in the hope that it will be useful, | |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 | * GNU General Public License for more details. | |
| 16 | * | |
| 17 | * You should have received a copy of the GNU General Public License | |
| 18 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19832
diff
changeset
|
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 10684 | 20 | */ |
| 21 | #include "internal.h" | |
| 22 | #include "cipher.h" | |
|
34558
2e1dc888240d
Refactored the libpurple core to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34535
diff
changeset
|
23 | #include "debug.h" |
| 10684 | 24 | |
| 25 | /****************************************************************************** | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
26 | * Object Stuff |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
27 | *****************************************************************************/ |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
28 | static void |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
29 | purple_cipher_class_init(PurpleCipherClass *klass) { |
|
34534
9aa25874424b
Initialized methods of PurpleCipher to NULL
Ankit Vani <a@nevitus.org>
parents:
34533
diff
changeset
|
30 | klass->reset = NULL; |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
31 | klass->reset_state = NULL; |
|
34534
9aa25874424b
Initialized methods of PurpleCipher to NULL
Ankit Vani <a@nevitus.org>
parents:
34533
diff
changeset
|
32 | klass->set_iv = NULL; |
|
9aa25874424b
Initialized methods of PurpleCipher to NULL
Ankit Vani <a@nevitus.org>
parents:
34533
diff
changeset
|
33 | klass->append = NULL; |
|
9aa25874424b
Initialized methods of PurpleCipher to NULL
Ankit Vani <a@nevitus.org>
parents:
34533
diff
changeset
|
34 | klass->digest = NULL; |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
35 | klass->get_digest_size = NULL; |
|
34534
9aa25874424b
Initialized methods of PurpleCipher to NULL
Ankit Vani <a@nevitus.org>
parents:
34533
diff
changeset
|
36 | klass->encrypt = NULL; |
|
9aa25874424b
Initialized methods of PurpleCipher to NULL
Ankit Vani <a@nevitus.org>
parents:
34533
diff
changeset
|
37 | klass->decrypt = NULL; |
|
9aa25874424b
Initialized methods of PurpleCipher to NULL
Ankit Vani <a@nevitus.org>
parents:
34533
diff
changeset
|
38 | klass->set_salt = NULL; |
|
9aa25874424b
Initialized methods of PurpleCipher to NULL
Ankit Vani <a@nevitus.org>
parents:
34533
diff
changeset
|
39 | klass->set_key = NULL; |
|
9aa25874424b
Initialized methods of PurpleCipher to NULL
Ankit Vani <a@nevitus.org>
parents:
34533
diff
changeset
|
40 | klass->get_key_size = NULL; |
|
9aa25874424b
Initialized methods of PurpleCipher to NULL
Ankit Vani <a@nevitus.org>
parents:
34533
diff
changeset
|
41 | klass->set_batch_mode = NULL; |
|
9aa25874424b
Initialized methods of PurpleCipher to NULL
Ankit Vani <a@nevitus.org>
parents:
34533
diff
changeset
|
42 | klass->get_batch_mode = NULL; |
|
9aa25874424b
Initialized methods of PurpleCipher to NULL
Ankit Vani <a@nevitus.org>
parents:
34533
diff
changeset
|
43 | klass->get_block_size = NULL; |
|
9aa25874424b
Initialized methods of PurpleCipher to NULL
Ankit Vani <a@nevitus.org>
parents:
34533
diff
changeset
|
44 | klass->get_name = NULL; |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
45 | } |
| 10684 | 46 | |
| 47 | /****************************************************************************** | |
| 15884 | 48 | * PurpleCipher API |
| 10684 | 49 | *****************************************************************************/ |
| 50 | const gchar * | |
| 15884 | 51 | purple_cipher_get_name(PurpleCipher *cipher) { |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
52 | PurpleCipherClass *klass = NULL; |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
53 | |
| 10684 | 54 | g_return_val_if_fail(cipher, NULL); |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
55 | g_return_val_if_fail(PURPLE_IS_CIPHER(cipher), NULL); |
| 10684 | 56 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
57 | klass = PURPLE_CIPHER_GET_CLASS(cipher); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
58 | g_return_val_if_fail(klass->get_name, NULL); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
59 | |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
60 | return klass->get_name(cipher); |
| 10684 | 61 | } |
| 62 | ||
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
63 | GType |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
64 | purple_cipher_get_type(void) { |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
65 | static GType type = 0; |
| 10684 | 66 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
67 | if(type == 0) { |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
68 | static const GTypeInfo info = { |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
69 | sizeof(PurpleCipherClass), |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
70 | NULL, |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
71 | NULL, |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
72 | (GClassInitFunc)purple_cipher_class_init, |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
73 | NULL, |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
74 | NULL, |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
75 | sizeof(PurpleCipher), |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
76 | 0, |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
77 | NULL, |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
78 | NULL |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
79 | }; |
| 10684 | 80 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
81 | type = g_type_register_static(G_TYPE_OBJECT, |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
82 | "PurpleCipher", |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
83 | &info, G_TYPE_FLAG_ABSTRACT); |
| 10684 | 84 | } |
| 85 | ||
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
86 | return type; |
| 10684 | 87 | } |
| 88 | ||
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
89 | GType |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
90 | purple_cipher_batch_mode_get_type(void) { |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
91 | static GType type = 0; |
| 10684 | 92 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
93 | if(type == 0) { |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
94 | static const GEnumValue values[] = { |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
95 | { PURPLE_CIPHER_BATCH_MODE_ECB, "ECB", "ECB" }, |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
96 | { PURPLE_CIPHER_BATCH_MODE_CBC, "CBC", "CBC" }, |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
97 | { 0, NULL, NULL }, |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
98 | }; |
| 10684 | 99 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
100 | type = g_enum_register_static("PurpleCipherBatchMode", values); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
101 | } |
| 10684 | 102 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
103 | return type; |
| 10684 | 104 | } |
| 105 | ||
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
106 | /** |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
107 | * purple_cipher_reset: |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
108 | * @cipher: The cipher to reset |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
109 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
110 | * Resets a cipher to it's default value |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
111 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
112 | * @note If you have set an IV you will have to set it after resetting |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
113 | */ |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
114 | void |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
115 | purple_cipher_reset(PurpleCipher *cipher) { |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
116 | PurpleCipherClass *klass = NULL; |
| 10684 | 117 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
118 | g_return_if_fail(PURPLE_IS_CIPHER(cipher)); |
| 10684 | 119 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
120 | klass = PURPLE_CIPHER_GET_CLASS(cipher); |
| 10684 | 121 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
122 | if(klass && klass->reset) |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
123 | klass->reset(cipher); |
|
34560
d4caeb911491
Added a debug warning if a cipher's reset method was called and it isn't implemented
Ankit Vani <a@nevitus.org>
parents:
34558
diff
changeset
|
124 | else |
|
d4caeb911491
Added a debug warning if a cipher's reset method was called and it isn't implemented
Ankit Vani <a@nevitus.org>
parents:
34558
diff
changeset
|
125 | purple_debug_warning("cipher", "the %s cipher does not implement the " |
|
d4caeb911491
Added a debug warning if a cipher's reset method was called and it isn't implemented
Ankit Vani <a@nevitus.org>
parents:
34558
diff
changeset
|
126 | "reset method\n", |
|
d4caeb911491
Added a debug warning if a cipher's reset method was called and it isn't implemented
Ankit Vani <a@nevitus.org>
parents:
34558
diff
changeset
|
127 | klass->get_name ? klass->get_name(cipher) : ""); |
| 10684 | 128 | } |
| 129 | ||
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
130 | /** |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
131 | * Resets a cipher state to it's default value, but doesn't touch stateless |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
132 | * configuration. |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
133 | * |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
134 | * That means, IV and digest context will be wiped out, but keys, ops or salt |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
135 | * will remain untouched. |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
136 | */ |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
137 | void |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
138 | purple_cipher_reset_state(PurpleCipher *cipher) { |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
139 | PurpleCipherClass *klass = NULL; |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
140 | |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
141 | g_return_if_fail(PURPLE_IS_CIPHER(cipher)); |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
142 | |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
143 | klass = PURPLE_CIPHER_GET_CLASS(cipher); |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
144 | |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
145 | if(klass && klass->reset_state) |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
146 | klass->reset_state(cipher); |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
147 | else |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
148 | purple_debug_warning("cipher", "the %s cipher does not implement the " |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
149 | "reset_state method\n", |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
150 | klass->get_name ? klass->get_name(cipher) : ""); |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
151 | } |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
152 | |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
153 | /** |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
154 | * purple_cipher_set_iv: |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
155 | * @cipher: The cipher to set the IV to |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
156 | * @iv: The initialization vector to set |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
157 | * @len: The len of the IV |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
158 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
159 | * @note This should only be called right after a cipher is created or reset |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
160 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
161 | * Sets the initialization vector for a cipher |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
162 | */ |
| 10684 | 163 | void |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
164 | purple_cipher_set_iv(PurpleCipher *cipher, guchar *iv, size_t len) |
| 10684 | 165 | { |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
166 | PurpleCipherClass *klass = NULL; |
| 10684 | 167 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
168 | g_return_if_fail(PURPLE_IS_CIPHER(cipher)); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
169 | g_return_if_fail(iv); |
| 10684 | 170 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
171 | klass = PURPLE_CIPHER_GET_CLASS(cipher); |
| 10684 | 172 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
173 | if(klass && klass->set_iv) |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
174 | klass->set_iv(cipher, iv, len); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
175 | else |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
176 | purple_debug_warning("cipher", "the %s cipher does not implement the " |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
177 | "set_iv method\n", |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
178 | klass->get_name ? klass->get_name(cipher) : ""); |
| 10684 | 179 | } |
| 180 | ||
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
181 | /** |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
182 | * purple_cipher_append: |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
183 | * @cipher: The cipher to append data to |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
184 | * @data: The data to append |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
185 | * @len: The length of the data |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
186 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
187 | * Appends data to the cipher |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
188 | */ |
| 10684 | 189 | void |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
190 | purple_cipher_append(PurpleCipher *cipher, const guchar *data, |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
191 | size_t len) |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
192 | { |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
193 | PurpleCipherClass *klass = NULL; |
|
33913
9effc94565d8
ciphers cleanup: add reset state callback
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33912
diff
changeset
|
194 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
195 | g_return_if_fail(PURPLE_IS_CIPHER(cipher)); |
|
33913
9effc94565d8
ciphers cleanup: add reset state callback
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33912
diff
changeset
|
196 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
197 | klass = PURPLE_CIPHER_GET_CLASS(cipher); |
| 10684 | 198 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
199 | if(klass && klass->append) |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
200 | klass->append(cipher, data, len); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
201 | else |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
202 | purple_debug_warning("cipher", "the %s cipher does not implement the " |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
203 | "append method\n", |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
204 | klass->get_name ? klass->get_name(cipher) : ""); |
| 10684 | 205 | } |
| 206 | ||
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
207 | /** |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
208 | * purple_cipher_digest: |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
209 | * @cipher: The cipher to digest |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
210 | * @in_len: The length of the buffer |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
211 | * @digest: The return buffer for the digest |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
212 | * @out_len: The length of the returned value |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
213 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
214 | * Digests a cipher |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
215 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
216 | * Return Value: TRUE if the digest was successful, FALSE otherwise. |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
217 | */ |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
218 | gboolean |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
219 | purple_cipher_digest(PurpleCipher *cipher, guchar digest[], size_t len) |
| 10684 | 220 | { |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
221 | PurpleCipherClass *klass = NULL; |
| 10684 | 222 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
223 | g_return_val_if_fail(PURPLE_IS_CIPHER(cipher), FALSE); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
224 | |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
225 | klass = PURPLE_CIPHER_GET_CLASS(cipher); |
| 10684 | 226 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
227 | if(klass && klass->digest) |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
228 | return klass->digest(cipher, digest, len); |
| 10684 | 229 | else |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
230 | purple_debug_warning("cipher", "the %s cipher does not implement the " |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
231 | "digest method\n", |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
232 | klass->get_name ? klass->get_name(cipher) : ""); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
233 | |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
234 | return FALSE; |
| 10684 | 235 | } |
| 236 | ||
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
237 | /** |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
238 | * purple_cipher_digest_to_str: |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
239 | * @cipher: The cipher to get a digest from |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
240 | * @in_len: The length of the buffer |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
241 | * @digest_s: The return buffer for the string digest |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
242 | * @out_len: The length of the returned value |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
243 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
244 | * Converts a guchar digest into a hex string |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
245 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
246 | * Return Value: TRUE if the digest was successful, FALSE otherwise. |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
247 | */ |
| 10684 | 248 | gboolean |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
249 | purple_cipher_digest_to_str(PurpleCipher *cipher, gchar digest_s[], size_t len) |
| 10684 | 250 | { |
| 10687 | 251 | /* 8k is a bit excessive, will tweak later. */ |
|
11183
be87fe695c93
[gaim-migrate @ 13295]
Mark Doliner <markdoliner@pidgin.im>
parents:
11143
diff
changeset
|
252 | guchar digest[BUF_LEN * 4]; |
| 10684 | 253 | gint n = 0; |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
254 | size_t digest_size; |
| 10684 | 255 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
256 | g_return_val_if_fail(cipher, FALSE); |
| 10684 | 257 | g_return_val_if_fail(digest_s, FALSE); |
| 258 | ||
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
259 | digest_size = purple_cipher_get_digest_size(cipher); |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
260 | |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
261 | g_return_val_if_fail(digest_size <= BUF_LEN * 4, FALSE); |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
262 | |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
263 | if(!purple_cipher_digest(cipher, digest, sizeof(digest))) |
| 10684 | 264 | return FALSE; |
| 265 | ||
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
266 | /* Every digest byte occupies 2 chars + the NUL at the end. */ |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
267 | g_return_val_if_fail(digest_size * 2 + 1 <= len, FALSE); |
| 10684 | 268 | |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
269 | for(n = 0; n < digest_size; n++) |
| 10684 | 270 | sprintf(digest_s + (n * 2), "%02x", digest[n]); |
| 271 | ||
| 272 | digest_s[n * 2] = '\0'; | |
| 273 | ||
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
274 | return TRUE; |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
275 | } |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
276 | |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
277 | size_t |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
278 | purple_cipher_get_digest_size(PurpleCipher *cipher) |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
279 | { |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
280 | PurpleCipherClass *klass = NULL; |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
281 | |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
282 | g_return_val_if_fail(PURPLE_IS_CIPHER(cipher), FALSE); |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
283 | |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
284 | klass = PURPLE_CIPHER_GET_CLASS(cipher); |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
285 | |
|
34558
2e1dc888240d
Refactored the libpurple core to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34535
diff
changeset
|
286 | if(klass && klass->get_digest_size) |
|
2e1dc888240d
Refactored the libpurple core to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34535
diff
changeset
|
287 | return klass->get_digest_size(cipher); |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
288 | else |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
289 | purple_debug_warning("cipher", "the %s cipher does not implement the " |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
290 | "get_digest_size method\n", |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
291 | klass->get_name ? klass->get_name(cipher) : ""); |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
292 | |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
293 | return FALSE; |
|
33909
773899cbd05a
ciphers cleanup: salt and digest lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33908
diff
changeset
|
294 | } |
|
773899cbd05a
ciphers cleanup: salt and digest lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33908
diff
changeset
|
295 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
296 | /** |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
297 | * purple_cipher_encrypt: |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
298 | * @cipher: The cipher |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
299 | * @data: The data to encrypt |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
300 | * @len: The length of the data |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
301 | * @output: The output buffer |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
302 | * @outlen: The len of data that was outputed |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
303 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
304 | * Encrypts data using the cipher |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
305 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
306 | * Return Value: A cipher specific status code |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
307 | */ |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
308 | ssize_t |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
309 | purple_cipher_encrypt(PurpleCipher *cipher, const guchar input[], |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
310 | size_t in_len, guchar output[], size_t out_size) |
|
33909
773899cbd05a
ciphers cleanup: salt and digest lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33908
diff
changeset
|
311 | { |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
312 | PurpleCipherClass *klass = NULL; |
| 10684 | 313 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
314 | g_return_val_if_fail(PURPLE_IS_CIPHER(cipher), -1); |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
315 | g_return_val_if_fail(input != NULL, -1); |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
316 | g_return_val_if_fail(output != NULL, -1); |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
317 | g_return_val_if_fail(out_size >= in_len, -1); |
| 10684 | 318 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
319 | klass = PURPLE_CIPHER_GET_CLASS(cipher); |
| 10684 | 320 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
321 | if(klass && klass->encrypt) |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
322 | return klass->encrypt(cipher, input, in_len, output, out_size); |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
323 | else |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
324 | purple_debug_warning("cipher", "the %s cipher does not implement the " |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
325 | "encrypt method\n", |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
326 | klass->get_name ? klass->get_name(cipher) : ""); |
| 10684 | 327 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
328 | return -1; |
| 10684 | 329 | } |
| 330 | ||
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
331 | /** |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
332 | * purple_cipher_decrypt: |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
333 | * @cipher: The cipher |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
334 | * @data: The data to encrypt |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
335 | * @len: The length of the returned value |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
336 | * @output: The output buffer |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
337 | * @outlen: The len of data that was outputed |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
338 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
339 | * Decrypts data using the cipher |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
340 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
341 | * Return Value: A cipher specific status code |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
342 | */ |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
343 | ssize_t |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
344 | purple_cipher_decrypt(PurpleCipher *cipher, const guchar input[], |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
345 | size_t in_len, guchar output[], size_t out_size) |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
346 | { |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
347 | PurpleCipherClass *klass = NULL; |
| 10684 | 348 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
349 | g_return_val_if_fail(PURPLE_IS_CIPHER(cipher), -1); |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
350 | g_return_val_if_fail(input != NULL, -1); |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
351 | g_return_val_if_fail(output != NULL, -1); |
| 10684 | 352 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
353 | klass = PURPLE_CIPHER_GET_CLASS(cipher); |
| 10684 | 354 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
355 | if(klass && klass->decrypt) |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
356 | return klass->decrypt(cipher, input, in_len, output, out_size); |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
357 | else |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
358 | purple_debug_warning("cipher", "the %s cipher does not implement the " |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
359 | "decrypt method\n", |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
360 | klass->get_name ? klass->get_name(cipher) : ""); |
| 10684 | 361 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
362 | return -1; |
| 10684 | 363 | } |
| 364 | ||
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
365 | /** |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
366 | * purple_cipher_set_salt: |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
367 | * @cipher: The cipher whose salt to set |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
368 | * @salt: The salt |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
369 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
370 | * Sets the salt on a cipher |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
371 | */ |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
372 | void |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
373 | purple_cipher_set_salt(PurpleCipher *cipher, const guchar *salt, size_t len) { |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
374 | PurpleCipherClass *klass = NULL; |
|
33910
5749f2724b12
ciphers cleanup: get key size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
375 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
376 | g_return_if_fail(PURPLE_IS_CIPHER(cipher)); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
377 | |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
378 | klass = PURPLE_CIPHER_GET_CLASS(cipher); |
|
33910
5749f2724b12
ciphers cleanup: get key size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
379 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
380 | if(klass && klass->set_salt) |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
381 | klass->set_salt(cipher, salt, len); |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
382 | else |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
383 | purple_debug_warning("cipher", "the %s cipher does not implement the " |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
384 | "set_salt method\n", |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
385 | klass->get_name ? klass->get_name(cipher) : ""); |
|
33910
5749f2724b12
ciphers cleanup: get key size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
386 | } |
|
5749f2724b12
ciphers cleanup: get key size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
387 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
388 | /** |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
389 | * purple_cipher_set_key: |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
390 | * @cipher: The cipher whose key to set |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
391 | * @key: The key |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
392 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
393 | * Sets the key on a cipher |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
394 | */ |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
395 | void |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
396 | purple_cipher_set_key(PurpleCipher *cipher, const guchar *key, size_t len) { |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
397 | PurpleCipherClass *klass = NULL; |
|
22025
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
398 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
399 | g_return_if_fail(PURPLE_IS_CIPHER(cipher)); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
400 | |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
401 | klass = PURPLE_CIPHER_GET_CLASS(cipher); |
|
22025
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
402 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
403 | if(klass && klass->set_key) |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
404 | klass->set_key(cipher, key, len); |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
405 | else |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
406 | purple_debug_warning("cipher", "the %s cipher does not implement the " |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
407 | "set_key method\n", |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
408 | klass->get_name ? klass->get_name(cipher) : ""); |
| 10684 | 409 | } |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
410 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
411 | /** |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
412 | * purple_cipher_get_key_size: |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
413 | * @cipher: The cipher whose key size to get |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
414 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
415 | * Gets the key size for a cipher |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
416 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
417 | * Return Value: The size of the key |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
418 | */ |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
419 | size_t |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
420 | purple_cipher_get_key_size(PurpleCipher *cipher) { |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
421 | PurpleCipherClass *klass = NULL; |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
422 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
423 | g_return_val_if_fail(PURPLE_IS_CIPHER(cipher), -1); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
424 | |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
425 | klass = PURPLE_CIPHER_GET_CLASS(cipher); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
426 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
427 | if(klass && klass->get_key_size) |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
428 | return klass->get_key_size(cipher); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
429 | else |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
430 | purple_debug_warning("cipher", "the %s cipher does not implement the " |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
431 | "get_key_size method\n", |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
432 | klass->get_name ? klass->get_name(cipher) : ""); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
433 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
434 | return -1; |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
435 | } |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
436 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
437 | /** |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
438 | * purple_cipher_set_batch_mode: |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
439 | * @cipher: The cipher whose batch mode to set |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
440 | * @mode: The batch mode under which the cipher should operate |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
441 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
442 | * Sets the batch mode of a cipher |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
443 | */ |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
444 | void |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
445 | purple_cipher_set_batch_mode(PurpleCipher *cipher, |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
446 | PurpleCipherBatchMode mode) |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
447 | { |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
448 | PurpleCipherClass *klass = NULL; |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
449 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
450 | g_return_if_fail(PURPLE_IS_CIPHER(cipher)); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
451 | |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
452 | klass = PURPLE_CIPHER_GET_CLASS(cipher); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
453 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
454 | if(klass && klass->set_batch_mode) |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
455 | klass->set_batch_mode(cipher, mode); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
456 | else |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
457 | purple_debug_warning("cipher", "the %s cipher does not implement the " |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
458 | "set_batch_mode method\n", |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
459 | klass->get_name ? klass->get_name(cipher) : ""); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
460 | } |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
461 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
462 | /** |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
463 | * purple_cipher_get_batch_mode: |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
464 | * @cipher: The cipher whose batch mode to get |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
465 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
466 | * Gets the batch mode of a cipher |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
467 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
468 | * Return Value: The batch mode under which the cipher is operating |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
469 | */ |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
470 | PurpleCipherBatchMode |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
471 | purple_cipher_get_batch_mode(PurpleCipher *cipher) |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
472 | { |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
473 | PurpleCipherClass *klass = NULL; |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
474 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
475 | g_return_val_if_fail(PURPLE_IS_CIPHER(cipher), -1); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
476 | |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
477 | klass = PURPLE_CIPHER_GET_CLASS(cipher); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
478 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
479 | if(klass && klass->get_batch_mode) |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
480 | return klass->get_batch_mode(cipher); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
481 | else |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
482 | purple_debug_warning("cipher", "the %s cipher does not implement the " |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
483 | "get_batch_mode method\n", |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
484 | klass->get_name ? klass->get_name(cipher) : ""); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
485 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
486 | return -1; |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
487 | } |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
488 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
489 | /** |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
490 | * purple_cipher_get_block_size: |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
491 | * @cipher: The cipher whose block size to get |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
492 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
493 | * Gets the block size of a cipher |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
494 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
495 | * Return Value: The block size of the cipher |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
496 | */ |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
497 | size_t |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
498 | purple_cipher_get_block_size(PurpleCipher *cipher) |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
499 | { |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
500 | PurpleCipherClass *klass = NULL; |
|
12389
7196ba664097
[gaim-migrate @ 14695]
Richard Laager <rlaager@pidgin.im>
parents:
12388
diff
changeset
|
501 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
502 | g_return_val_if_fail(PURPLE_IS_CIPHER(cipher), -1); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
503 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
504 | klass = PURPLE_CIPHER_GET_CLASS(cipher); |
|
12389
7196ba664097
[gaim-migrate @ 14695]
Richard Laager <rlaager@pidgin.im>
parents:
12388
diff
changeset
|
505 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
506 | if(klass && klass->get_block_size) |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
507 | return klass->get_block_size(cipher); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
508 | else |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
509 | purple_debug_warning("cipher", "the %s cipher does not implement the " |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
510 | "get_block_size method\n", |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
511 | klass->get_name ? klass->get_name(cipher) : ""); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
512 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
513 | return -1; |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
514 | } |