cipher.h

Go to the documentation of this file.
00001 
00006 /* purple
00007  *
00008  * Purple is the legal property of its developers, whose names are too numerous
00009  * to list here.  Please refer to the COPYRIGHT file distributed with this
00010  * source distribution.
00011  *
00012  * This program is free software; you can redistribute it and/or modify
00013  * it under the terms of the GNU General Public License as published by
00014  * the Free Software Foundation; either version 2 of the License, or
00015  * (at your option) any later version.
00016  *
00017  * This program is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  * GNU General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU General Public License
00023  * along with this program; if not, write to the Free Software
00024  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
00025  *
00026  * @see @ref cipher-signals
00027  */
00028 #ifndef PURPLE_CIPHER_H
00029 #define PURPLE_CIPHER_H
00030 
00031 #include <glib.h>
00032 
00033 #define PURPLE_CIPHER(obj)          ((PurpleCipher *)(obj))         
00034 #define PURPLE_CIPHER_OPS(obj)      ((PurpleCipherOps *)(obj))      
00035 #define PURPLE_CIPHER_CONTEXT(obj)  ((PurpleCipherContext *)(obj))  
00037 typedef struct _PurpleCipher            PurpleCipher;           
00038 typedef struct _PurpleCipherOps     PurpleCipherOps;        
00039 typedef struct _PurpleCipherContext PurpleCipherContext;    
00045 typedef enum _PurpleCipherCaps {
00046     PURPLE_CIPHER_CAPS_SET_OPT          = 1 << 1,       
00047     PURPLE_CIPHER_CAPS_GET_OPT          = 1 << 2,       
00048     PURPLE_CIPHER_CAPS_INIT             = 1 << 3,       
00049     PURPLE_CIPHER_CAPS_RESET                = 1 << 4,       
00050     PURPLE_CIPHER_CAPS_UNINIT               = 1 << 5,       
00051     PURPLE_CIPHER_CAPS_SET_IV               = 1 << 6,       
00052     PURPLE_CIPHER_CAPS_APPEND               = 1 << 7,       
00053     PURPLE_CIPHER_CAPS_DIGEST               = 1 << 8,       
00054     PURPLE_CIPHER_CAPS_ENCRYPT          = 1 << 9,       
00055     PURPLE_CIPHER_CAPS_DECRYPT          = 1 << 10,      
00056     PURPLE_CIPHER_CAPS_SET_SALT         = 1 << 11,      
00057     PURPLE_CIPHER_CAPS_GET_SALT_SIZE        = 1 << 12,      
00058     PURPLE_CIPHER_CAPS_SET_KEY          = 1 << 13,      
00059     PURPLE_CIPHER_CAPS_GET_KEY_SIZE     = 1 << 14,      
00060     PURPLE_CIPHER_CAPS_UNKNOWN          = 1 << 16       
00061 } PurpleCipherCaps;
00062 
00066 struct _PurpleCipherOps {
00068     void (*set_option)(PurpleCipherContext *context, const gchar *name, void *value);
00069 
00071     void *(*get_option)(PurpleCipherContext *context, const gchar *name);
00072 
00074     void (*init)(PurpleCipherContext *context, void *extra);
00075 
00077     void (*reset)(PurpleCipherContext *context, void *extra);
00078 
00080     void (*uninit)(PurpleCipherContext *context);
00081 
00083     void (*set_iv)(PurpleCipherContext *context, guchar *iv, size_t len);
00084 
00086     void (*append)(PurpleCipherContext *context, const guchar *data, size_t len);
00087 
00089     gboolean (*digest)(PurpleCipherContext *context, size_t in_len, guchar digest[], size_t *out_len);
00090 
00092     int (*encrypt)(PurpleCipherContext *context, const guchar data[], size_t len, guchar output[], size_t *outlen);
00093 
00095     int (*decrypt)(PurpleCipherContext *context, const guchar data[], size_t len, guchar output[], size_t *outlen);
00096 
00098     void (*set_salt)(PurpleCipherContext *context, guchar *salt);
00099 
00101     size_t (*get_salt_size)(PurpleCipherContext *context);
00102 
00104     void (*set_key)(PurpleCipherContext *context, const guchar *key);
00105 
00107     size_t (*get_key_size)(PurpleCipherContext *context);
00108 
00109     void (*_purple_reserved1)(void);
00110     void (*_purple_reserved2)(void);
00111     void (*_purple_reserved3)(void);
00112     void (*_purple_reserved4)(void);
00113 };
00114 
00115 #ifdef __cplusplus
00116 extern "C" {
00117 #endif /* __cplusplus */
00118 
00119 /*****************************************************************************/
00121 /*****************************************************************************/
00131 const gchar *purple_cipher_get_name(PurpleCipher *cipher);
00132 
00140 guint purple_cipher_get_capabilities(PurpleCipher *cipher);
00141 
00154 gboolean purple_cipher_digest_region(const gchar *name, const guchar *data, size_t data_len, size_t in_len, guchar digest[], size_t *out_len);
00155 
00157 /******************************************************************************/
00159 /******************************************************************************/
00169 PurpleCipher *purple_ciphers_find_cipher(const gchar *name);
00170 
00179 PurpleCipher *purple_ciphers_register_cipher(const gchar *name, PurpleCipherOps *ops);
00180 
00188 gboolean purple_ciphers_unregister_cipher(PurpleCipher *cipher);
00189 
00196 GList *purple_ciphers_get_ciphers(void);
00197 
00199 /******************************************************************************/
00201 /******************************************************************************/
00209 gpointer purple_ciphers_get_handle(void);
00210 
00214 void purple_ciphers_init(void);
00215 
00219 void purple_ciphers_uninit(void);
00220 
00222 /******************************************************************************/
00224 /******************************************************************************/
00234 void purple_cipher_context_set_option(PurpleCipherContext *context, const gchar *name, gpointer value);
00235 
00243 gpointer purple_cipher_context_get_option(PurpleCipherContext *context, const gchar *name);
00244 
00253 PurpleCipherContext *purple_cipher_context_new(PurpleCipher *cipher, void *extra);
00254 
00263 PurpleCipherContext *purple_cipher_context_new_by_name(const gchar *name, void *extra);
00264 
00272 void purple_cipher_context_reset(PurpleCipherContext *context, gpointer extra);
00273 
00279 void purple_cipher_context_destroy(PurpleCipherContext *context);
00280 
00289 void purple_cipher_context_set_iv(PurpleCipherContext *context, guchar *iv, size_t len);
00290 
00298 void purple_cipher_context_append(PurpleCipherContext *context, const guchar *data, size_t len);
00299 
00308 gboolean purple_cipher_context_digest(PurpleCipherContext *context, size_t in_len, guchar digest[], size_t *out_len);
00309 
00318 gboolean purple_cipher_context_digest_to_str(PurpleCipherContext *context, size_t in_len, gchar digest_s[], size_t *out_len);
00319 
00331 gint purple_cipher_context_encrypt(PurpleCipherContext *context, const guchar data[], size_t len, guchar output[], size_t *outlen);
00332 
00344 gint purple_cipher_context_decrypt(PurpleCipherContext *context, const guchar data[], size_t len, guchar output[], size_t *outlen);
00345 
00352 void purple_cipher_context_set_salt(PurpleCipherContext *context, guchar *salt);
00353 
00361 size_t purple_cipher_context_get_salt_size(PurpleCipherContext *context);
00362 
00369 void purple_cipher_context_set_key(PurpleCipherContext *context, const guchar *key);
00370 
00378 size_t purple_cipher_context_get_key_size(PurpleCipherContext *context);
00379 
00386 void purple_cipher_context_set_data(PurpleCipherContext *context, gpointer data);
00387 
00395 gpointer purple_cipher_context_get_data(PurpleCipherContext *context);
00396 
00398 /*****************************************************************************/
00400 /*****************************************************************************/
00417 gchar *purple_cipher_http_digest_calculate_session_key(
00418         const gchar *algorithm, const gchar *username,
00419         const gchar *realm, const gchar *password,
00420         const gchar *nonce, const gchar *client_nonce);
00421 
00438 gchar *purple_cipher_http_digest_calculate_response(
00439         const gchar *algorithm, const gchar *method,
00440         const gchar *digest_uri, const gchar *qop,
00441         const gchar *entity, const gchar *nonce,
00442         const gchar *nonce_count, const gchar *client_nonce,
00443         const gchar *session_key);
00444 
00447 #ifdef __cplusplus
00448 }
00449 #endif /* __cplusplus */
00450 
00451 #endif /* PURPLE_CIPHER_H */