cipher.h
Go to the documentation of this file.
00001 
00007 /* purple
00008  *
00009  * Purple is the legal property of its developers, whose names are too numerous
00010  * to list here.  Please refer to the COPYRIGHT file distributed with this
00011  * source distribution.
00012  *
00013  * This program is free software; you can redistribute it and/or modify
00014  * it under the terms of the GNU General Public License as published by
00015  * the Free Software Foundation; either version 2 of the License, or
00016  * (at your option) any later version.
00017  *
00018  * This program is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License
00024  * along with this program; if not, write to the Free Software
00025  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
00026  */
00027 #ifndef PURPLE_CIPHER_H
00028 #define PURPLE_CIPHER_H
00029 
00030 #include <glib.h>
00031 #include <string.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;    
00044 typedef enum _PurpleCipherBatchMode {
00045     PURPLE_CIPHER_BATCH_MODE_ECB,
00046     PURPLE_CIPHER_BATCH_MODE_CBC
00047 } PurpleCipherBatchMode;
00048 
00052 typedef enum _PurpleCipherCaps {
00053     PURPLE_CIPHER_CAPS_SET_OPT          = 1 << 1,   
00054     PURPLE_CIPHER_CAPS_GET_OPT          = 1 << 2,   
00055     PURPLE_CIPHER_CAPS_INIT             = 1 << 3,   
00056     PURPLE_CIPHER_CAPS_RESET            = 1 << 4,   
00057     PURPLE_CIPHER_CAPS_UNINIT           = 1 << 5,   
00058     PURPLE_CIPHER_CAPS_SET_IV           = 1 << 6,   
00059     PURPLE_CIPHER_CAPS_APPEND           = 1 << 7,   
00060     PURPLE_CIPHER_CAPS_DIGEST           = 1 << 8,   
00061     PURPLE_CIPHER_CAPS_ENCRYPT          = 1 << 9,   
00062     PURPLE_CIPHER_CAPS_DECRYPT          = 1 << 10,  
00063     PURPLE_CIPHER_CAPS_SET_SALT         = 1 << 11,  
00064     PURPLE_CIPHER_CAPS_GET_SALT_SIZE    = 1 << 12,  
00065     PURPLE_CIPHER_CAPS_SET_KEY          = 1 << 13,  
00066     PURPLE_CIPHER_CAPS_GET_KEY_SIZE     = 1 << 14,  
00067     PURPLE_CIPHER_CAPS_SET_BATCH_MODE   = 1 << 15,  
00068     PURPLE_CIPHER_CAPS_GET_BATCH_MODE   = 1 << 16,  
00069     PURPLE_CIPHER_CAPS_GET_BLOCK_SIZE   = 1 << 17,  
00070     PURPLE_CIPHER_CAPS_SET_KEY_WITH_LEN = 1 << 18,  
00071     PURPLE_CIPHER_CAPS_UNKNOWN          = 1 << 19   
00072 } PurpleCipherCaps;
00073 
00077 struct _PurpleCipherOps {
00079     void (*set_option)(PurpleCipherContext *context, const gchar *name, void *value);
00080 
00082     void *(*get_option)(PurpleCipherContext *context, const gchar *name);
00083 
00085     void (*init)(PurpleCipherContext *context, void *extra);
00086 
00088     void (*reset)(PurpleCipherContext *context, void *extra);
00089 
00091     void (*uninit)(PurpleCipherContext *context);
00092 
00094     void (*set_iv)(PurpleCipherContext *context, guchar *iv, size_t len);
00095 
00097     void (*append)(PurpleCipherContext *context, const guchar *data, size_t len);
00098 
00100     gboolean (*digest)(PurpleCipherContext *context, size_t in_len, guchar digest[], size_t *out_len);
00101 
00103     int (*encrypt)(PurpleCipherContext *context, const guchar data[], size_t len, guchar output[], size_t *outlen);
00104 
00106     int (*decrypt)(PurpleCipherContext *context, const guchar data[], size_t len, guchar output[], size_t *outlen);
00107 
00109     void (*set_salt)(PurpleCipherContext *context, guchar *salt);
00110 
00112     size_t (*get_salt_size)(PurpleCipherContext *context);
00113 
00115     void (*set_key)(PurpleCipherContext *context, const guchar *key);
00116 
00118     size_t (*get_key_size)(PurpleCipherContext *context);
00119 
00121     void (*set_batch_mode)(PurpleCipherContext *context, PurpleCipherBatchMode mode);
00122 
00124     PurpleCipherBatchMode (*get_batch_mode)(PurpleCipherContext *context);
00125 
00127     size_t (*get_block_size)(PurpleCipherContext *context);
00128 
00130     void (*set_key_with_len)(PurpleCipherContext *context, const guchar *key, size_t len);
00131 };
00132 
00133 G_BEGIN_DECLS
00134 
00135 /*****************************************************************************/
00137 /*****************************************************************************/
00147 const gchar *purple_cipher_get_name(PurpleCipher *cipher);
00148 
00156 guint purple_cipher_get_capabilities(PurpleCipher *cipher);
00157 
00170 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);
00171 
00173 /******************************************************************************/
00175 /******************************************************************************/
00185 PurpleCipher *purple_ciphers_find_cipher(const gchar *name);
00186 
00195 PurpleCipher *purple_ciphers_register_cipher(const gchar *name, PurpleCipherOps *ops);
00196 
00204 gboolean purple_ciphers_unregister_cipher(PurpleCipher *cipher);
00205 
00212 GList *purple_ciphers_get_ciphers(void);
00213 
00215 /******************************************************************************/
00217 /******************************************************************************/
00225 gpointer purple_ciphers_get_handle(void);
00226 
00230 void purple_ciphers_init(void);
00231 
00235 void purple_ciphers_uninit(void);
00236 
00238 /******************************************************************************/
00240 /******************************************************************************/
00250 void purple_cipher_context_set_option(PurpleCipherContext *context, const gchar *name, gpointer value);
00251 
00259 gpointer purple_cipher_context_get_option(PurpleCipherContext *context, const gchar *name);
00260 
00269 PurpleCipherContext *purple_cipher_context_new(PurpleCipher *cipher, void *extra);
00270 
00279 PurpleCipherContext *purple_cipher_context_new_by_name(const gchar *name, void *extra);
00280 
00288 void purple_cipher_context_reset(PurpleCipherContext *context, gpointer extra);
00289 
00295 void purple_cipher_context_destroy(PurpleCipherContext *context);
00296 
00305 void purple_cipher_context_set_iv(PurpleCipherContext *context, guchar *iv, size_t len);
00306 
00314 void purple_cipher_context_append(PurpleCipherContext *context, const guchar *data, size_t len);
00315 
00324 gboolean purple_cipher_context_digest(PurpleCipherContext *context, size_t in_len, guchar digest[], size_t *out_len);
00325 
00334 gboolean purple_cipher_context_digest_to_str(PurpleCipherContext *context, size_t in_len, gchar digest_s[], size_t *out_len);
00335 
00347 gint purple_cipher_context_encrypt(PurpleCipherContext *context, const guchar data[], size_t len, guchar output[], size_t *outlen);
00348 
00360 gint purple_cipher_context_decrypt(PurpleCipherContext *context, const guchar data[], size_t len, guchar output[], size_t *outlen);
00361 
00368 void purple_cipher_context_set_salt(PurpleCipherContext *context, guchar *salt);
00369 
00377 size_t purple_cipher_context_get_salt_size(PurpleCipherContext *context);
00378 
00385 void purple_cipher_context_set_key(PurpleCipherContext *context, const guchar *key);
00386 
00394 size_t purple_cipher_context_get_key_size(PurpleCipherContext *context);
00395 
00403 void purple_cipher_context_set_batch_mode(PurpleCipherContext *context, PurpleCipherBatchMode mode);
00404 
00412 PurpleCipherBatchMode purple_cipher_context_get_batch_mode(PurpleCipherContext *context);
00413 
00421 size_t purple_cipher_context_get_block_size(PurpleCipherContext *context);
00422 
00431 void purple_cipher_context_set_key_with_len(PurpleCipherContext *context, const guchar *key, size_t len);
00432 
00439 void purple_cipher_context_set_data(PurpleCipherContext *context, gpointer data);
00440 
00448 gpointer purple_cipher_context_get_data(PurpleCipherContext *context);
00449 
00451 /*****************************************************************************/
00453 /*****************************************************************************/
00470 gchar *purple_cipher_http_digest_calculate_session_key(
00471         const gchar *algorithm, const gchar *username,
00472         const gchar *realm, const gchar *password,
00473         const gchar *nonce, const gchar *client_nonce);
00474 
00491 gchar *purple_cipher_http_digest_calculate_response(
00492         const gchar *algorithm, const gchar *method,
00493         const gchar *digest_uri, const gchar *qop,
00494         const gchar *entity, const gchar *nonce,
00495         const gchar *nonce_count, const gchar *client_nonce,
00496         const gchar *session_key);
00497 
00500 G_END_DECLS
00501 
00502 #endif /* PURPLE_CIPHER_H */