Mercurial > pidgin.yaz
comparison src/cipher.h @ 10684:72a5babfa8b4
[gaim-migrate @ 12231]
the cipher api that grim has been working on for ages is finally done!! big
congrats and thanks to him!!
lots of modified files in this commit. it builds here.
moved the md5 files to src/protocols/oscar so that it continues to depend
on nothing in gaim. everything else uses the new centralized cipher api.
I'm not sure if src/md5.* needs to be removed or not, so I left it there.
someone let me know or do it directly.
someone check if these need to be added to potfiles.in
and let there be much rejoicing!
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Fri, 11 Mar 2005 13:05:31 +0000 |
parents | |
children | b256ce6b85b8 |
comparison
equal
deleted
inserted
replaced
10683:e11f3e1599d4 | 10684:72a5babfa8b4 |
---|---|
1 /** | |
2 * @file cipher.h Gaim Cipher API | |
3 * @ingroup core | |
4 * | |
5 * gaim | |
6 * | |
7 * Gaim is the legal property of its developers, whose names are too numerous | |
8 * to list here. Please refer to the COPYRIGHT file distributed with this | |
9 * source distribution. | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 */ | |
25 #ifndef GAIM_CIPHER_H | |
26 #define GAIM_CIPHER_H | |
27 | |
28 #include <glib.h> | |
29 | |
30 #define GAIM_CIPHER(obj) ((GaimCipher *)(obj)) /**< GaimCipher typecast helper */ | |
31 #define GAIM_CIPHER_OPS(obj) ((GaimCipherOps *)(obj)) /**< GaimCipherInfo typecase helper */ | |
32 #define GAIM_CIPHER_CONTEXT(obj) ((GaimCipherContext *)(obj)) /**< GaimCipherContext typecast helper */ | |
33 | |
34 typedef struct _GaimCipher GaimCipher; /**< A handle to a GaimCipher */ | |
35 typedef struct _GaimCipherOps GaimCipherOps; /**< Ops for a GaimCipher */ | |
36 typedef struct _GaimCipherContext GaimCipherContext; /**< A context for a GaimCipher */ | |
37 | |
38 | |
39 /** | |
40 * The operation flags for a cipher | |
41 */ | |
42 typedef enum _GaimCipherCaps { | |
43 GAIM_CIPHER_CAPS_SET_OPT = 1 << 1, /**< Set option flag */ | |
44 GAIM_CIPHER_CAPS_GET_OPT = 1 << 2, /**< Get option flag */ | |
45 GAIM_CIPHER_CAPS_INIT = 1 << 3, /**< Init flag */ | |
46 GAIM_CIPHER_CAPS_RESET = 1 << 4, /**< Reset flag */ | |
47 GAIM_CIPHER_CAPS_UNINIT = 1 << 5, /**< Uninit flag */ | |
48 GAIM_CIPHER_CAPS_SET_IV = 1 << 6, /**< Set IV flag */ | |
49 GAIM_CIPHER_CAPS_APPEND = 1 << 7, /**< Append flag */ | |
50 GAIM_CIPHER_CAPS_DIGEST = 1 << 8, /**< Digest flag */ | |
51 GAIM_CIPHER_CAPS_ENCRYPT = 1 << 9, /**< Encrypt flag */ | |
52 GAIM_CIPHER_CAPS_DECRYPT = 1 << 10, /**< Decrypt flag */ | |
53 GAIM_CIPHER_CAPS_SET_SALT = 1 << 11, /**< Set salt flag */ | |
54 GAIM_CIPHER_CAPS_GET_SALT_SIZE = 1 << 12, /**< Get salt size flag */ | |
55 GAIM_CIPHER_CAPS_SET_KEY = 1 << 13, /**< Set key flag */ | |
56 GAIM_CIPHER_CAPS_GET_KEY_SIZE = 1 << 14, /**< Get key size flag */ | |
57 GAIM_CIPHER_CAPS_UNKNOWN = 1 << 16 /**< Unknown */ | |
58 } GaimCipherCaps; | |
59 | |
60 /** | |
61 * The operations of a cipher. Every cipher must implement one of these. | |
62 */ | |
63 struct _GaimCipherOps { | |
64 /** The set option function */ | |
65 void (*set_option)(GaimCipherContext *context, const gchar *name, void *value); | |
66 | |
67 /** The get option function */ | |
68 void *(*get_option)(GaimCipherContext *context, const gchar *name); | |
69 | |
70 /** The init function */ | |
71 void (*init)(GaimCipherContext *context, void *extra); | |
72 | |
73 /** The reset function */ | |
74 void (*reset)(GaimCipherContext *context, void *extra); | |
75 | |
76 /** The uninit function */ | |
77 void (*uninit)(GaimCipherContext *context); | |
78 | |
79 /** The set initialization vector function */ | |
80 void (*set_iv)(GaimCipherContext *context, guint8 *iv, size_t len); | |
81 | |
82 /** The append data function */ | |
83 void (*append)(GaimCipherContext *context, const guint8 *data, size_t len); | |
84 | |
85 /** The digest function */ | |
86 gboolean (*digest)(GaimCipherContext *context, size_t *len, guint8 digest[]); | |
87 | |
88 /** The encrypt function */ | |
89 int (*encrypt)(GaimCipherContext *context, const guint8 data[], size_t len, guint8 output[], size_t *outlen); | |
90 | |
91 /** The decrypt function */ | |
92 int (*decrypt)(GaimCipherContext *context, const guint8 data[], size_t len, guint8 output[], size_t *outlen); | |
93 | |
94 /** The set salt function */ | |
95 void (*set_salt)(GaimCipherContext *context, guint8 *salt); | |
96 | |
97 /** The get salt size function */ | |
98 size_t (*get_salt_size)(GaimCipherContext *context); | |
99 | |
100 /** The set key function */ | |
101 void (*set_key)(GaimCipherContext *context, guint8 *key); | |
102 | |
103 /** The get key size function */ | |
104 size_t (*get_key_size)(GaimCipherContext *context); | |
105 }; | |
106 | |
107 #ifdef __cplusplus | |
108 extern "C" { | |
109 #endif /* __cplusplus */ | |
110 | |
111 /*****************************************************************************/ | |
112 /** @name GaimCipher API */ | |
113 /*****************************************************************************/ | |
114 /*@{*/ | |
115 | |
116 /** | |
117 * Gets a cipher's name | |
118 * | |
119 * @param cipher The cipher handle | |
120 * | |
121 * @return The cipher's name | |
122 */ | |
123 const gchar *gaim_cipher_get_name(GaimCipher *cipher); | |
124 | |
125 /** | |
126 * Gets a cipher's capabilities | |
127 * | |
128 * @param cipher The cipher handle | |
129 * | |
130 * @return The cipher's info | |
131 */ | |
132 guint gaim_cipher_get_capabilities(GaimCipher *cipher); | |
133 | |
134 /** | |
135 * Gets a digest from a cipher | |
136 * | |
137 * @param name The cipher's name | |
138 * @param data The data to hash | |
139 * @param data_len The length of the data | |
140 * @param digest The returned digest | |
141 * @param digest_len The returned digest's length | |
142 */ | |
143 void gaim_cipher_digest_region(const gchar *name, const guint8 *data, size_t data_len, guint8 digest[], size_t *digest_len); | |
144 | |
145 /*@}*/ | |
146 /******************************************************************************/ | |
147 /** @name GaimCiphers API */ | |
148 /******************************************************************************/ | |
149 /*@{*/ | |
150 | |
151 /** | |
152 * Finds a cipher by it's name | |
153 * | |
154 * @param name The name of the cipher to find | |
155 * | |
156 * @return The cipher handle or @c NULL | |
157 */ | |
158 GaimCipher *gaim_ciphers_find_cipher(const gchar *name); | |
159 | |
160 /** | |
161 * Registers a cipher as a usable cipher | |
162 * | |
163 * @param name The name of the new cipher | |
164 * @param ops The cipher ops to register | |
165 * | |
166 * @return The handle to the new cipher or @c NULL if it failed | |
167 */ | |
168 GaimCipher *gaim_ciphers_register_cipher(const gchar *name, GaimCipherOps *ops); | |
169 | |
170 /** | |
171 * Unregisters a cipher | |
172 * | |
173 * @param cipher The cipher handle to unregister | |
174 * | |
175 * @return Whether or not the cipher was successfully unloaded | |
176 */ | |
177 gboolean gaim_ciphers_unregister_cipher(GaimCipher *cipher); | |
178 | |
179 /** | |
180 * Gets the list of ciphers | |
181 * | |
182 * @return The list of available ciphers | |
183 * @note This list should not be modified, it is owned by the cipher core | |
184 */ | |
185 GList *gaim_ciphers_get_ciphers(); | |
186 | |
187 /*@}*/ | |
188 /******************************************************************************/ | |
189 /** @name GaimCipher Subsystem API */ | |
190 /******************************************************************************/ | |
191 /*@{*/ | |
192 | |
193 /** | |
194 * Gets the handle to the cipher subsystem | |
195 * | |
196 * @return The handle to the cipher subsystem | |
197 */ | |
198 gpointer gaim_ciphers_get_handle(); | |
199 | |
200 /** | |
201 * Initializes the cipher core | |
202 */ | |
203 void gaim_ciphers_init(); | |
204 | |
205 /** | |
206 * Uninitializes the cipher core | |
207 */ | |
208 void gaim_ciphers_uninit(); | |
209 | |
210 /*@}*/ | |
211 /******************************************************************************/ | |
212 /** @name GaimCipherContext API */ | |
213 /******************************************************************************/ | |
214 /*@{*/ | |
215 | |
216 /** | |
217 * Sets the value an option on a cipher context | |
218 * | |
219 * @param context The cipher context | |
220 * @param name The name of the option | |
221 * @param value The value to set | |
222 */ | |
223 void gaim_cipher_context_set_option(GaimCipherContext *context, const gchar *name, gpointer value); | |
224 | |
225 /** | |
226 * Gets the vale of an option on a cipher context | |
227 * | |
228 * @param context The cipher context | |
229 * @param name The name of the option | |
230 * @return The value of the option | |
231 */ | |
232 gpointer gaim_cipher_context_get_option(GaimCipherContext *context, const gchar *name); | |
233 | |
234 /** | |
235 * Creates a new cipher context and initializes it | |
236 * | |
237 * @param cipher The cipher to use | |
238 * @param extra Extra data for the specific cipher | |
239 * | |
240 * @return The new cipher context | |
241 */ | |
242 GaimCipherContext *gaim_cipher_context_new(GaimCipher *cipher, void *extra); | |
243 | |
244 /** | |
245 * Creates a new cipher context by the cipher name and initializes it | |
246 * | |
247 * @param name The cipher's name | |
248 * @param extra Extra data for the specific cipher | |
249 * | |
250 * @return The new cipher context | |
251 */ | |
252 GaimCipherContext *gaim_cipher_context_new_by_name(const gchar *name, void *extra); | |
253 | |
254 /** | |
255 * Resets a cipher context to it's default value | |
256 * @note If you have set an IV you will have to set it after resetting | |
257 * | |
258 * @param context The context to reset | |
259 * @param extra Extra data for the specific cipher | |
260 */ | |
261 void gaim_cipher_context_reset(GaimCipherContext *context, gpointer extra); | |
262 | |
263 /** | |
264 * Destorys a cipher context and deinitializes it | |
265 * | |
266 * @param context The cipher context to destory | |
267 */ | |
268 void gaim_cipher_context_destroy(GaimCipherContext *context); | |
269 | |
270 /** | |
271 * Sets the initialization vector for a context | |
272 * @note This should only be called right after a cipher context is created or reset | |
273 * | |
274 * @param context The context to set the IV to | |
275 * @param iv The initialization vector to set | |
276 * @param len The len of the IV | |
277 */ | |
278 void gaim_cipher_context_set_iv(GaimCipherContext *context, guint8 *iv, size_t len); | |
279 | |
280 /** | |
281 * Appends data to the context | |
282 * | |
283 * @param context The context to append data to | |
284 * @param data The data to append | |
285 * @param len The length of the data | |
286 */ | |
287 void gaim_cipher_context_append(GaimCipherContext *context, const guint8 *data, size_t len); | |
288 | |
289 /** | |
290 * Digests a context | |
291 * | |
292 * @param context The context to digest | |
293 * @param len The length of the returned value | |
294 * @param digest The return buffer for the digest | |
295 */ | |
296 gboolean gaim_cipher_context_digest(GaimCipherContext *context, size_t *len, guint8 digest[]); | |
297 | |
298 /** | |
299 * Converts a guint8 digest into a hex string | |
300 * | |
301 * @param context The context to get a digest from | |
302 * @param len The length of the returned value | |
303 * @param digest_s The return buffer for the string digest | |
304 */ | |
305 gboolean gaim_cipher_context_digest_to_str(GaimCipherContext *context, size_t *len, gchar digest_s[]); | |
306 | |
307 /** | |
308 * Encrypts data using the context | |
309 * | |
310 * @param context The context | |
311 * @param data The data to encrypt | |
312 * @param len The length of the data | |
313 * @param output The output buffer | |
314 * @param outlen The len of data that was outputed | |
315 * | |
316 * @return A cipher specific status code | |
317 */ | |
318 gint gaim_cipher_context_encrypt(GaimCipherContext *context, const guint8 data[], size_t len, guint8 output[], size_t *outlen); | |
319 | |
320 /** | |
321 * Decrypts data using the context | |
322 * | |
323 * @param context The context | |
324 * @param data The data to encrypt | |
325 * @param len The length of the returned value | |
326 * @param output The output buffer | |
327 * @param outlen The len of data that was outputed | |
328 * | |
329 * @return A cipher specific status code | |
330 */ | |
331 gint gaim_cipher_context_decrypt(GaimCipherContext *context, const guint8 data[], size_t len, guint8 output[], size_t *outlen); | |
332 | |
333 /** | |
334 * Sets the salt on a context | |
335 * | |
336 * @param context The context who's salt to set | |
337 * @param salt The salt | |
338 */ | |
339 void gaim_cipher_context_set_salt(GaimCipherContext *context, guint8 *salt); | |
340 | |
341 /** | |
342 * Gets the size of the salt if the cipher supports it | |
343 * | |
344 * @param context The context who's salt size to get | |
345 * | |
346 * @return The size of the salt | |
347 */ | |
348 size_t gaim_cipher_context_get_salt_size(GaimCipherContext *context); | |
349 | |
350 /** | |
351 * Sets the key on a context | |
352 * | |
353 * @param context The context who's key to set | |
354 * @param key The key | |
355 */ | |
356 void gaim_cipher_context_set_key(GaimCipherContext *context, guint8 *key); | |
357 | |
358 /** | |
359 * Gets the key size for a context | |
360 * | |
361 * @param context The context who's key size to get | |
362 * | |
363 * @return The size of the key | |
364 */ | |
365 size_t gaim_cipher_context_get_key_size(GaimCipherContext *context); | |
366 | |
367 /** | |
368 * Sets the cipher data for a context | |
369 * | |
370 * @param context The context who's cipher data to set | |
371 * @param data The cipher data to set | |
372 */ | |
373 void gaim_cipher_context_set_data(GaimCipherContext *context, gpointer data); | |
374 | |
375 /** | |
376 * Gets the cipher data for a context | |
377 * | |
378 * @param context The context who's cipher data to get | |
379 * | |
380 * @return The cipher data | |
381 */ | |
382 gpointer gaim_cipher_context_get_data(GaimCipherContext *context); | |
383 | |
384 /*@}*/ | |
385 | |
386 #ifdef __cplusplus | |
387 } | |
388 #endif /* __cplusplus */ | |
389 | |
390 #endif /* GAIM_CIPHER_H */ |