Sat, 15 Jun 2013 20:41:52 +0530
Refactored the libpurple core to use the GObject-based PurpleCipher
| 10684 | 1 | /* |
| 15884 | 2 | * purple |
| 10684 | 3 | * |
| 15884 | 4 | * Purple is the legal property of its developers, whose names are too numerous |
| 10684 | 5 | * to list here. Please refer to the COPYRIGHT file distributed with this |
| 6 | * source distribution. | |
| 7 | * | |
|
11335
8e8d266179bb
[gaim-migrate @ 13548]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11333
diff
changeset
|
8 | * Original des taken from gpg |
|
8e8d266179bb
[gaim-migrate @ 13548]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11333
diff
changeset
|
9 | * |
|
8e8d266179bb
[gaim-migrate @ 13548]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11333
diff
changeset
|
10 | * des.c - DES and Triple-DES encryption/decryption Algorithm |
|
8e8d266179bb
[gaim-migrate @ 13548]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11333
diff
changeset
|
11 | * Copyright (C) 1998 Free Software Foundation, Inc. |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13760
diff
changeset
|
12 | * |
|
11335
8e8d266179bb
[gaim-migrate @ 13548]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11333
diff
changeset
|
13 | * Please see below for more legal information! |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13760
diff
changeset
|
14 | * |
|
11335
8e8d266179bb
[gaim-migrate @ 13548]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11333
diff
changeset
|
15 | * According to the definition of DES in FIPS PUB 46-2 from December 1993. |
|
8e8d266179bb
[gaim-migrate @ 13548]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11333
diff
changeset
|
16 | * For a description of triple encryption, see: |
|
8e8d266179bb
[gaim-migrate @ 13548]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11333
diff
changeset
|
17 | * Bruce Schneier: Applied Cryptography. Second Edition. |
|
8e8d266179bb
[gaim-migrate @ 13548]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11333
diff
changeset
|
18 | * John Wiley & Sons, 1996. ISBN 0-471-12845-7. Pages 358 ff. |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13760
diff
changeset
|
19 | * |
|
11335
8e8d266179bb
[gaim-migrate @ 13548]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11333
diff
changeset
|
20 | * This file is part of GnuPG. |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13760
diff
changeset
|
21 | * |
| 10684 | 22 | * This program is free software; you can redistribute it and/or modify |
| 23 | * it under the terms of the GNU General Public License as published by | |
| 24 | * the Free Software Foundation; either version 2 of the License, or | |
| 25 | * (at your option) any later version. | |
| 26 | * | |
| 27 | * This program is distributed in the hope that it will be useful, | |
| 28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 30 | * GNU General Public License for more details. | |
| 31 | * | |
| 32 | * You should have received a copy of the GNU General Public License | |
| 33 | * 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
|
34 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 10684 | 35 | */ |
| 36 | #include "internal.h" | |
| 37 | #include "cipher.h" | |
|
34558
2e1dc888240d
Refactored the libpurple core to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34535
diff
changeset
|
38 | #include "debug.h" |
| 10684 | 39 | |
| 40 | /****************************************************************************** | |
| 41 | * Globals | |
| 42 | *****************************************************************************/ | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
43 | static GObjectClass *parent_class = NULL; |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
44 | |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
45 | /****************************************************************************** |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
46 | * Object Stuff |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
47 | *****************************************************************************/ |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
48 | static void |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
49 | purple_cipher_finalize(GObject *obj) { |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
50 | purple_cipher_reset(PURPLE_CIPHER(obj)); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
51 | |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
52 | G_OBJECT_CLASS(parent_class)->finalize(obj); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
53 | } |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
54 | |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
55 | static void |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
56 | purple_cipher_class_init(PurpleCipherClass *klass) { |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
57 | GObjectClass *obj_class = G_OBJECT_CLASS(klass); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
58 | |
|
34534
9aa25874424b
Initialized methods of PurpleCipher to NULL
Ankit Vani <a@nevitus.org>
parents:
34533
diff
changeset
|
59 | klass->reset = NULL; |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
60 | klass->reset_state = NULL; |
|
34534
9aa25874424b
Initialized methods of PurpleCipher to NULL
Ankit Vani <a@nevitus.org>
parents:
34533
diff
changeset
|
61 | klass->set_iv = NULL; |
|
9aa25874424b
Initialized methods of PurpleCipher to NULL
Ankit Vani <a@nevitus.org>
parents:
34533
diff
changeset
|
62 | klass->append = NULL; |
|
9aa25874424b
Initialized methods of PurpleCipher to NULL
Ankit Vani <a@nevitus.org>
parents:
34533
diff
changeset
|
63 | klass->digest = NULL; |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
64 | klass->get_digest_size = NULL; |
|
34534
9aa25874424b
Initialized methods of PurpleCipher to NULL
Ankit Vani <a@nevitus.org>
parents:
34533
diff
changeset
|
65 | klass->encrypt = NULL; |
|
9aa25874424b
Initialized methods of PurpleCipher to NULL
Ankit Vani <a@nevitus.org>
parents:
34533
diff
changeset
|
66 | klass->decrypt = NULL; |
|
9aa25874424b
Initialized methods of PurpleCipher to NULL
Ankit Vani <a@nevitus.org>
parents:
34533
diff
changeset
|
67 | klass->set_salt = NULL; |
|
9aa25874424b
Initialized methods of PurpleCipher to NULL
Ankit Vani <a@nevitus.org>
parents:
34533
diff
changeset
|
68 | klass->get_salt_size = NULL; |
|
9aa25874424b
Initialized methods of PurpleCipher to NULL
Ankit Vani <a@nevitus.org>
parents:
34533
diff
changeset
|
69 | klass->set_key = NULL; |
|
9aa25874424b
Initialized methods of PurpleCipher to NULL
Ankit Vani <a@nevitus.org>
parents:
34533
diff
changeset
|
70 | klass->get_key_size = NULL; |
|
9aa25874424b
Initialized methods of PurpleCipher to NULL
Ankit Vani <a@nevitus.org>
parents:
34533
diff
changeset
|
71 | klass->set_batch_mode = NULL; |
|
9aa25874424b
Initialized methods of PurpleCipher to NULL
Ankit Vani <a@nevitus.org>
parents:
34533
diff
changeset
|
72 | klass->get_batch_mode = NULL; |
|
9aa25874424b
Initialized methods of PurpleCipher to NULL
Ankit Vani <a@nevitus.org>
parents:
34533
diff
changeset
|
73 | klass->get_block_size = NULL; |
|
9aa25874424b
Initialized methods of PurpleCipher to NULL
Ankit Vani <a@nevitus.org>
parents:
34533
diff
changeset
|
74 | klass->get_name = NULL; |
|
9aa25874424b
Initialized methods of PurpleCipher to NULL
Ankit Vani <a@nevitus.org>
parents:
34533
diff
changeset
|
75 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
76 | parent_class = g_type_class_peek_parent(klass); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
77 | |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
78 | obj_class->finalize = purple_cipher_finalize; |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
79 | } |
| 10684 | 80 | |
| 81 | /****************************************************************************** | |
| 15884 | 82 | * PurpleCipher API |
| 10684 | 83 | *****************************************************************************/ |
| 84 | const gchar * | |
| 15884 | 85 | purple_cipher_get_name(PurpleCipher *cipher) { |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
86 | PurpleCipherClass *klass = NULL; |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
87 | |
| 10684 | 88 | g_return_val_if_fail(cipher, NULL); |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
89 | g_return_val_if_fail(PURPLE_IS_CIPHER(cipher), NULL); |
| 10684 | 90 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
91 | klass = PURPLE_CIPHER_GET_CLASS(cipher); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
92 | g_return_val_if_fail(klass->get_name, NULL); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
93 | |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
94 | return klass->get_name(cipher); |
| 10684 | 95 | } |
| 96 | ||
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
97 | GType |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
98 | purple_cipher_get_type(void) { |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
99 | static GType type = 0; |
| 10684 | 100 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
101 | if(type == 0) { |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
102 | static const GTypeInfo info = { |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
103 | sizeof(PurpleCipherClass), |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
104 | NULL, |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
105 | NULL, |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
106 | (GClassInitFunc)purple_cipher_class_init, |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
107 | NULL, |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
108 | NULL, |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
109 | sizeof(PurpleCipher), |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
110 | 0, |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
111 | NULL, |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
112 | NULL |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
113 | }; |
| 10684 | 114 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
115 | type = g_type_register_static(G_TYPE_OBJECT, |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
116 | "PurpleCipher", |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
117 | &info, G_TYPE_FLAG_ABSTRACT); |
| 10684 | 118 | } |
| 119 | ||
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
120 | return type; |
| 10684 | 121 | } |
| 122 | ||
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
123 | GType |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
124 | purple_cipher_batch_mode_get_type(void) { |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
125 | static GType type = 0; |
| 10684 | 126 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
127 | if(type == 0) { |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
128 | static const GEnumValue values[] = { |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
129 | { PURPLE_CIPHER_BATCH_MODE_ECB, "ECB", "ECB" }, |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
130 | { PURPLE_CIPHER_BATCH_MODE_CBC, "CBC", "CBC" }, |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
131 | { 0, NULL, NULL }, |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
132 | }; |
| 10684 | 133 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
134 | type = g_enum_register_static("PurpleCipherBatchMode", values); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
135 | } |
| 10684 | 136 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
137 | return type; |
| 10684 | 138 | } |
| 139 | ||
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
140 | /** |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
141 | * purple_cipher_reset: |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
142 | * @cipher: The cipher to reset |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
143 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
144 | * Resets a cipher to it's default value |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
145 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
146 | * @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
|
147 | */ |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
148 | void |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
149 | purple_cipher_reset(PurpleCipher *cipher) { |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
150 | PurpleCipherClass *klass = NULL; |
| 10684 | 151 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
152 | g_return_if_fail(PURPLE_IS_CIPHER(cipher)); |
| 10684 | 153 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
154 | klass = PURPLE_CIPHER_GET_CLASS(cipher); |
| 10684 | 155 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
156 | if(klass && klass->reset) |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
157 | klass->reset(cipher); |
| 10684 | 158 | } |
| 159 | ||
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
160 | /** |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
161 | * 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
|
162 | * configuration. |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
163 | * |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
164 | * 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
|
165 | * will remain untouched. |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
166 | */ |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
167 | void |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
168 | 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
|
169 | PurpleCipherClass *klass = NULL; |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
170 | |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
171 | 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
|
172 | |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
173 | 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
|
174 | |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
175 | if(klass && klass->reset_state) |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
176 | klass->reset_state(cipher); |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
177 | else |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
178 | 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
|
179 | "reset_state method\n", |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
180 | 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
|
181 | } |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
182 | |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
183 | /** |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
184 | * purple_cipher_set_iv: |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
185 | * @cipher: The cipher to set the IV to |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
186 | * @iv: The initialization vector to set |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
187 | * @len: The len of the IV |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
188 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
189 | * @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
|
190 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
191 | * Sets the initialization vector for a cipher |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
192 | */ |
| 10684 | 193 | void |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
194 | purple_cipher_set_iv(PurpleCipher *cipher, guchar *iv, size_t len) |
| 10684 | 195 | { |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
196 | PurpleCipherClass *klass = NULL; |
| 10684 | 197 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
198 | g_return_if_fail(PURPLE_IS_CIPHER(cipher)); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
199 | g_return_if_fail(iv); |
| 10684 | 200 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
201 | klass = PURPLE_CIPHER_GET_CLASS(cipher); |
| 10684 | 202 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
203 | if(klass && klass->set_iv) |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
204 | klass->set_iv(cipher, iv, len); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
205 | else |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
206 | 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
|
207 | "set_iv method\n", |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
208 | klass->get_name ? klass->get_name(cipher) : ""); |
| 10684 | 209 | } |
| 210 | ||
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
211 | /** |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
212 | * purple_cipher_append: |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
213 | * @cipher: The cipher to append data to |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
214 | * @data: The data to append |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
215 | * @len: The length of the data |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
216 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
217 | * Appends data to the cipher |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
218 | */ |
| 10684 | 219 | void |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
220 | purple_cipher_append(PurpleCipher *cipher, const guchar *data, |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
221 | size_t len) |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
222 | { |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
223 | PurpleCipherClass *klass = NULL; |
|
33913
9effc94565d8
ciphers cleanup: add reset state callback
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33912
diff
changeset
|
224 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
225 | 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
|
226 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
227 | klass = PURPLE_CIPHER_GET_CLASS(cipher); |
| 10684 | 228 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
229 | if(klass && klass->append) |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
230 | klass->append(cipher, data, len); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
231 | else |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
232 | 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
|
233 | "append method\n", |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
234 | klass->get_name ? klass->get_name(cipher) : ""); |
| 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: |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
239 | * @cipher: The cipher to digest |
|
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: The return buffer for the 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 | * Digests a cipher |
|
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 | */ |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
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(PurpleCipher *cipher, guchar digest[], size_t len) |
| 10684 | 250 | { |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
251 | PurpleCipherClass *klass = NULL; |
| 10684 | 252 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
253 | g_return_val_if_fail(PURPLE_IS_CIPHER(cipher), FALSE); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
254 | |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
255 | klass = PURPLE_CIPHER_GET_CLASS(cipher); |
| 10684 | 256 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
257 | if(klass && klass->digest) |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
258 | return klass->digest(cipher, digest, len); |
| 10684 | 259 | else |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
260 | 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
|
261 | "digest method\n", |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
262 | klass->get_name ? klass->get_name(cipher) : ""); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
263 | |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
264 | return FALSE; |
| 10684 | 265 | } |
| 266 | ||
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
267 | /** |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
268 | * purple_cipher_digest_to_str: |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
269 | * @cipher: The cipher to get a digest from |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
270 | * @in_len: The length of the buffer |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
271 | * @digest_s: The return buffer for the string digest |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
272 | * @out_len: The length of the returned value |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
273 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
274 | * Converts a guchar digest into a hex string |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
275 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
276 | * Return Value: TRUE if the digest was successful, FALSE otherwise. |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
277 | */ |
| 10684 | 278 | gboolean |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
279 | purple_cipher_digest_to_str(PurpleCipher *cipher, gchar digest_s[], size_t len) |
| 10684 | 280 | { |
| 10687 | 281 | /* 8k is a bit excessive, will tweak later. */ |
|
11183
be87fe695c93
[gaim-migrate @ 13295]
Mark Doliner <markdoliner@pidgin.im>
parents:
11143
diff
changeset
|
282 | guchar digest[BUF_LEN * 4]; |
| 10684 | 283 | gint n = 0; |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
284 | size_t digest_size; |
| 10684 | 285 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
286 | g_return_val_if_fail(cipher, FALSE); |
| 10684 | 287 | g_return_val_if_fail(digest_s, FALSE); |
| 288 | ||
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
289 | 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
|
290 | |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
291 | 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
|
292 | |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
293 | if(!purple_cipher_digest(cipher, digest, sizeof(digest))) |
| 10684 | 294 | return FALSE; |
| 295 | ||
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
296 | /* 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
|
297 | g_return_val_if_fail(digest_size * 2 + 1 <= len, FALSE); |
| 10684 | 298 | |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
299 | for(n = 0; n < digest_size; n++) |
| 10684 | 300 | sprintf(digest_s + (n * 2), "%02x", digest[n]); |
| 301 | ||
| 302 | digest_s[n * 2] = '\0'; | |
| 303 | ||
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
304 | return TRUE; |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
305 | } |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
306 | |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
307 | size_t |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
308 | 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
|
309 | { |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
310 | PurpleCipherClass *klass = NULL; |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
311 | |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
312 | 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
|
313 | |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
314 | 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
|
315 | |
|
34558
2e1dc888240d
Refactored the libpurple core to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents:
34535
diff
changeset
|
316 | 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
|
317 | 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
|
318 | else |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
319 | 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
|
320 | "get_digest_size method\n", |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
321 | 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
|
322 | |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
323 | return FALSE; |
|
33909
773899cbd05a
ciphers cleanup: salt and digest lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33908
diff
changeset
|
324 | } |
|
773899cbd05a
ciphers cleanup: salt and digest lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33908
diff
changeset
|
325 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
326 | /** |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
327 | * purple_cipher_encrypt: |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
328 | * @cipher: The cipher |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
329 | * @data: The data to encrypt |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
330 | * @len: The length of the data |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
331 | * @output: The output buffer |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
332 | * @outlen: The len of data that was outputed |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
333 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
334 | * Encrypts data using the cipher |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
335 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
336 | * Return Value: A cipher specific status code |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
337 | */ |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
338 | ssize_t |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
339 | 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
|
340 | 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
|
341 | { |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
342 | PurpleCipherClass *klass = NULL; |
| 10684 | 343 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
344 | 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
|
345 | 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
|
346 | 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
|
347 | g_return_val_if_fail(out_size >= in_len, -1); |
| 10684 | 348 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
349 | klass = PURPLE_CIPHER_GET_CLASS(cipher); |
| 10684 | 350 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
351 | if(klass && klass->encrypt) |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
352 | 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
|
353 | else |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
354 | 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
|
355 | "encrypt method\n", |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
356 | klass->get_name ? klass->get_name(cipher) : ""); |
| 10684 | 357 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
358 | return -1; |
| 10684 | 359 | } |
| 360 | ||
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
361 | /** |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
362 | * purple_cipher_decrypt: |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
363 | * @cipher: The cipher |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
364 | * @data: The data to encrypt |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
365 | * @len: The length of the returned value |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
366 | * @output: The output buffer |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
367 | * @outlen: The len of data that was outputed |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
368 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
369 | * Decrypts data using the cipher |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
370 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
371 | * Return Value: A cipher specific status code |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
372 | */ |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
373 | ssize_t |
|
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
374 | 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
|
375 | 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
|
376 | { |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
377 | PurpleCipherClass *klass = NULL; |
| 10684 | 378 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
379 | 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
|
380 | 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
|
381 | g_return_val_if_fail(output != NULL, -1); |
| 10684 | 382 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
383 | klass = PURPLE_CIPHER_GET_CLASS(cipher); |
| 10684 | 384 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
385 | if(klass && klass->decrypt) |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
386 | 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
|
387 | else |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
388 | 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
|
389 | "decrypt method\n", |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
390 | klass->get_name ? klass->get_name(cipher) : ""); |
| 10684 | 391 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
392 | return -1; |
| 10684 | 393 | } |
| 394 | ||
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
395 | /** |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
396 | * purple_cipher_set_salt: |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
397 | * @cipher: The cipher whose salt to set |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
398 | * @salt: The salt |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
399 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
400 | * Sets the salt on a cipher |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
401 | */ |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
402 | void |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
403 | 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
|
404 | PurpleCipherClass *klass = NULL; |
|
33910
5749f2724b12
ciphers cleanup: get key size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
405 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
406 | g_return_if_fail(PURPLE_IS_CIPHER(cipher)); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
407 | |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
408 | klass = PURPLE_CIPHER_GET_CLASS(cipher); |
|
33910
5749f2724b12
ciphers cleanup: get key size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
409 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
410 | 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
|
411 | klass->set_salt(cipher, salt, len); |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
412 | else |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
413 | 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
|
414 | "set_salt method\n", |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
415 | klass->get_name ? klass->get_name(cipher) : ""); |
|
33910
5749f2724b12
ciphers cleanup: get key size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
416 | } |
|
5749f2724b12
ciphers cleanup: get key size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
417 | |
|
34533
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 | * purple_cipher_get_salt_size: |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
420 | * @cipher: The cipher whose salt size to get |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
421 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
422 | * Gets the size of the salt if the cipher supports it |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
423 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
424 | * Return Value: The size of the salt |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
425 | */ |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
426 | size_t |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
427 | purple_cipher_get_salt_size(PurpleCipher *cipher) { |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
428 | PurpleCipherClass *klass = NULL; |
|
22024
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
429 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
430 | g_return_val_if_fail(PURPLE_IS_CIPHER(cipher), -1); |
|
22024
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
431 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
432 | klass = PURPLE_CIPHER_GET_CLASS(cipher); |
|
22024
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
433 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
434 | if(klass && klass->get_salt_size) |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
435 | return klass->get_salt_size(cipher); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
436 | else |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
437 | 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
|
438 | "get_salt_size method\n", |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
439 | klass->get_name ? klass->get_name(cipher) : ""); |
|
22024
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
440 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
441 | return -1; |
|
22024
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
442 | } |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
443 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
444 | /** |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
445 | * purple_cipher_set_key: |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
446 | * @cipher: The cipher whose key to set |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
447 | * @key: The key |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
448 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
449 | * Sets the key on a cipher |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
450 | */ |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
451 | void |
|
34535
f8fd1c60c22a
Merged PurpleCipher structure with the one in default branch
Ankit Vani <a@nevitus.org>
parents:
34534
diff
changeset
|
452 | 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
|
453 | PurpleCipherClass *klass = NULL; |
|
22025
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
454 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
455 | g_return_if_fail(PURPLE_IS_CIPHER(cipher)); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
456 | |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
457 | 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
|
458 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
459 | 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
|
460 | klass->set_key(cipher, key, len); |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
461 | else |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
462 | 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
|
463 | "set_key method\n", |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
464 | klass->get_name ? klass->get_name(cipher) : ""); |
| 10684 | 465 | } |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
466 | |
|
34533
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 | * purple_cipher_get_key_size: |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
469 | * @cipher: The cipher whose key size to get |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
470 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
471 | * Gets the key size for a cipher |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
472 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
473 | * Return Value: The size of the key |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
474 | */ |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
475 | size_t |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
476 | purple_cipher_get_key_size(PurpleCipher *cipher) { |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
477 | PurpleCipherClass *klass = NULL; |
|
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 | g_return_val_if_fail(PURPLE_IS_CIPHER(cipher), -1); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
480 | |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
481 | klass = PURPLE_CIPHER_GET_CLASS(cipher); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
482 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
483 | if(klass && klass->get_key_size) |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
484 | return klass->get_key_size(cipher); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
485 | else |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
486 | 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
|
487 | "get_key_size method\n", |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
488 | klass->get_name ? klass->get_name(cipher) : ""); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
489 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
490 | return -1; |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
491 | } |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
492 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
493 | /** |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
494 | * purple_cipher_set_batch_mode: |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
495 | * @cipher: The cipher whose batch mode to set |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
496 | * @mode: The batch mode under which the cipher should operate |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
497 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
498 | * Sets the batch mode of a 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 | void |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
501 | purple_cipher_set_batch_mode(PurpleCipher *cipher, |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
502 | PurpleCipherBatchMode mode) |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
503 | { |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
504 | PurpleCipherClass *klass = NULL; |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
505 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
506 | g_return_if_fail(PURPLE_IS_CIPHER(cipher)); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
507 | |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
508 | klass = PURPLE_CIPHER_GET_CLASS(cipher); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
509 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
510 | if(klass && klass->set_batch_mode) |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
511 | klass->set_batch_mode(cipher, mode); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
512 | else |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
513 | 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
|
514 | "set_batch_mode method\n", |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
515 | klass->get_name ? klass->get_name(cipher) : ""); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
516 | } |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
517 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
518 | /** |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
519 | * purple_cipher_get_batch_mode: |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
520 | * @cipher: The cipher whose batch mode to get |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
521 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
522 | * Gets the batch mode of a cipher |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
523 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
524 | * 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
|
525 | */ |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
526 | PurpleCipherBatchMode |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
527 | purple_cipher_get_batch_mode(PurpleCipher *cipher) |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
528 | { |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
529 | PurpleCipherClass *klass = NULL; |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
530 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
531 | g_return_val_if_fail(PURPLE_IS_CIPHER(cipher), -1); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
532 | |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
533 | klass = PURPLE_CIPHER_GET_CLASS(cipher); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
534 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
535 | if(klass && klass->get_batch_mode) |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
536 | return klass->get_batch_mode(cipher); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
537 | else |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
538 | 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
|
539 | "get_batch_mode method\n", |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
540 | klass->get_name ? klass->get_name(cipher) : ""); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
541 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
542 | return -1; |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
543 | } |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
544 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
545 | /** |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
546 | * purple_cipher_get_block_size: |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
547 | * @cipher: The cipher whose block size to get |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
548 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
549 | * Gets the block size of a cipher |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
550 | * |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
551 | * Return Value: The block size of the cipher |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
552 | */ |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
553 | size_t |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
554 | purple_cipher_get_block_size(PurpleCipher *cipher) |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
555 | { |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
556 | PurpleCipherClass *klass = NULL; |
|
12389
7196ba664097
[gaim-migrate @ 14695]
Richard Laager <rlaager@pidgin.im>
parents:
12388
diff
changeset
|
557 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
558 | g_return_val_if_fail(PURPLE_IS_CIPHER(cipher), -1); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
559 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
560 | klass = PURPLE_CIPHER_GET_CLASS(cipher); |
|
12389
7196ba664097
[gaim-migrate @ 14695]
Richard Laager <rlaager@pidgin.im>
parents:
12388
diff
changeset
|
561 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
562 | if(klass && klass->get_block_size) |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
563 | return klass->get_block_size(cipher); |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
564 | else |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
565 | 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
|
566 | "get_block_size method\n", |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
567 | klass->get_name ? klass->get_name(cipher) : ""); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
568 | |
|
34533
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
569 | return -1; |
|
74b179b1e8ef
GObjectify the PurpleCipher structure
Ankit Vani <a@nevitus.org>
parents:
34182
diff
changeset
|
570 | } |