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 
00032 #define PURPLE_CIPHER(obj)          ((PurpleCipher *)(obj))         
00033 #define PURPLE_CIPHER_OPS(obj)      ((PurpleCipherOps *)(obj))      
00034 #define PURPLE_CIPHER_CONTEXT(obj)  ((PurpleCipherContext *)(obj))  
00036 typedef struct _PurpleCipher            PurpleCipher;           
00037 typedef struct _PurpleCipherOps     PurpleCipherOps;        
00038 typedef struct _PurpleCipherContext PurpleCipherContext;    
00043 typedef enum _PurpleCipherBatchMode {
00044     PURPLE_CIPHER_BATCH_MODE_ECB,
00045     PURPLE_CIPHER_BATCH_MODE_CBC
00046 } PurpleCipherBatchMode;
00047 
00051 typedef enum _PurpleCipherCaps {
00052     PURPLE_CIPHER_CAPS_SET_OPT          = 1 << 1,   
00053     PURPLE_CIPHER_CAPS_GET_OPT          = 1 << 2,   
00054     PURPLE_CIPHER_CAPS_INIT             = 1 << 3,   
00055     PURPLE_CIPHER_CAPS_RESET            = 1 << 4,   
00056     PURPLE_CIPHER_CAPS_UNINIT           = 1 << 5,   
00057     PURPLE_CIPHER_CAPS_SET_IV           = 1 << 6,   
00058     PURPLE_CIPHER_CAPS_APPEND           = 1 << 7,   
00059     PURPLE_CIPHER_CAPS_DIGEST           = 1 << 8,   
00060     PURPLE_CIPHER_CAPS_ENCRYPT          = 1 << 9,   
00061     PURPLE_CIPHER_CAPS_DECRYPT          = 1 << 10,  
00062     PURPLE_CIPHER_CAPS_SET_SALT         = 1 << 11,  
00063     PURPLE_CIPHER_CAPS_GET_SALT_SIZE    = 1 << 12,  
00064     PURPLE_CIPHER_CAPS_SET_KEY          = 1 << 13,  
00065     PURPLE_CIPHER_CAPS_GET_KEY_SIZE     = 1 << 14,  
00066     PURPLE_CIPHER_CAPS_SET_BATCH_MODE   = 1 << 15,  
00067     PURPLE_CIPHER_CAPS_GET_BATCH_MODE   = 1 << 16,  
00068     PURPLE_CIPHER_CAPS_GET_BLOCK_SIZE   = 1 << 17,  
00069     PURPLE_CIPHER_CAPS_SET_KEY_WITH_LEN = 1 << 18,  
00070     PURPLE_CIPHER_CAPS_UNKNOWN          = 1 << 19   
00071 } PurpleCipherCaps;
00072 
00076 struct _PurpleCipherOps {
00078     void (*set_option)(PurpleCipherContext *context, const gchar *name, void *value);
00079 
00081     void *(*get_option)(PurpleCipherContext *context, const gchar *name);
00082 
00084     void (*init)(PurpleCipherContext *context, void *extra);
00085 
00087     void (*reset)(PurpleCipherContext *context, void *extra);
00088 
00090     void (*uninit)(PurpleCipherContext *context);
00091 
00093     void (*set_iv)(PurpleCipherContext *context, guchar *iv, size_t len);
00094 
00096     void (*append)(PurpleCipherContext *context, const guchar *data, size_t len);
00097 
00099     gboolean (*digest)(PurpleCipherContext *context, size_t in_len, guchar digest[], size_t *out_len);
00100 
00102     int (*encrypt)(PurpleCipherContext *context, const guchar data[], size_t len, guchar output[], size_t *outlen);
00103 
00105     int (*decrypt)(PurpleCipherContext *context, const guchar data[], size_t len, guchar output[], size_t *outlen);
00106 
00108     void (*set_salt)(PurpleCipherContext *context, guchar *salt);
00109 
00111     size_t (*get_salt_size)(PurpleCipherContext *context);
00112 
00114     void (*set_key)(PurpleCipherContext *context, const guchar *key);
00115 
00117     size_t (*get_key_size)(PurpleCipherContext *context);
00118 
00120     void (*set_batch_mode)(PurpleCipherContext *context, PurpleCipherBatchMode mode);
00121 
00123     PurpleCipherBatchMode (*get_batch_mode)(PurpleCipherContext *context);
00124 
00126     size_t (*get_block_size)(PurpleCipherContext *context);
00127 
00129     void (*set_key_with_len)(PurpleCipherContext *context, const guchar *key, size_t len);
00130 };
00131 
00132 #ifdef __cplusplus
00133 extern "C" {
00134 #endif /* __cplusplus */
00135 
00136 /*****************************************************************************/
00138 /*****************************************************************************/
00148 const gchar *purple_cipher_get_name(PurpleCipher *cipher);
00149 
00157 guint purple_cipher_get_capabilities(PurpleCipher *cipher);
00158 
00171 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);
00172 
00174 /******************************************************************************/
00176 /******************************************************************************/
00186 PurpleCipher *purple_ciphers_find_cipher(const gchar *name);
00187 
00196 PurpleCipher *purple_ciphers_register_cipher(const gchar *name, PurpleCipherOps *ops);
00197 
00205 gboolean purple_ciphers_unregister_cipher(PurpleCipher *cipher);
00206 
00213 GList *purple_ciphers_get_ciphers(void);
00214 
00216 /******************************************************************************/
00218 /******************************************************************************/
00226 gpointer purple_ciphers_get_handle(void);
00227 
00231 void purple_ciphers_init(void);
00232 
00236 void purple_ciphers_uninit(void);
00237 
00239 /******************************************************************************/
00241 /******************************************************************************/
00251 void purple_cipher_context_set_option(PurpleCipherContext *context, const gchar *name, gpointer value);
00252 
00260 gpointer purple_cipher_context_get_option(PurpleCipherContext *context, const gchar *name);
00261 
00270 PurpleCipherContext *purple_cipher_context_new(PurpleCipher *cipher, void *extra);
00271 
00280 PurpleCipherContext *purple_cipher_context_new_by_name(const gchar *name, void *extra);
00281 
00289 void purple_cipher_context_reset(PurpleCipherContext *context, gpointer extra);
00290 
00296 void purple_cipher_context_destroy(PurpleCipherContext *context);
00297 
00306 void purple_cipher_context_set_iv(PurpleCipherContext *context, guchar *iv, size_t len);
00307 
00315 void purple_cipher_context_append(PurpleCipherContext *context, const guchar *data, size_t len);
00316 
00325 gboolean purple_cipher_context_digest(PurpleCipherContext *context, size_t in_len, guchar digest[], size_t *out_len);
00326 
00335 gboolean purple_cipher_context_digest_to_str(PurpleCipherContext *context, size_t in_len, gchar digest_s[], size_t *out_len);
00336 
00348 gint purple_cipher_context_encrypt(PurpleCipherContext *context, const guchar data[], size_t len, guchar output[], size_t *outlen);
00349 
00361 gint purple_cipher_context_decrypt(PurpleCipherContext *context, const guchar data[], size_t len, guchar output[], size_t *outlen);
00362 
00369 void purple_cipher_context_set_salt(PurpleCipherContext *context, guchar *salt);
00370 
00378 size_t purple_cipher_context_get_salt_size(PurpleCipherContext *context);
00379 
00386 void purple_cipher_context_set_key(PurpleCipherContext *context, const guchar *key);
00387 
00395 size_t purple_cipher_context_get_key_size(PurpleCipherContext *context);
00396 
00404 void purple_cipher_context_set_batch_mode(PurpleCipherContext *context, PurpleCipherBatchMode mode);
00405 
00413 PurpleCipherBatchMode purple_cipher_context_get_batch_mode(PurpleCipherContext *context);
00414 
00422 size_t purple_cipher_context_get_block_size(PurpleCipherContext *context);
00423 
00432 void purple_cipher_context_set_key_with_len(PurpleCipherContext *context, const guchar *key, size_t len);
00433 
00440 void purple_cipher_context_set_data(PurpleCipherContext *context, gpointer data);
00441 
00449 gpointer purple_cipher_context_get_data(PurpleCipherContext *context);
00450 
00452 /*****************************************************************************/
00454 /*****************************************************************************/
00471 gchar *purple_cipher_http_digest_calculate_session_key(
00472         const gchar *algorithm, const gchar *username,
00473         const gchar *realm, const gchar *password,
00474         const gchar *nonce, const gchar *client_nonce);
00475 
00492 gchar *purple_cipher_http_digest_calculate_response(
00493         const gchar *algorithm, const gchar *method,
00494         const gchar *digest_uri, const gchar *qop,
00495         const gchar *entity, const gchar *nonce,
00496         const gchar *nonce_count, const gchar *client_nonce,
00497         const gchar *session_key);
00498 
00501 #ifdef __cplusplus
00502 }
00503 #endif /* __cplusplus */
00504 
00505 #endif /* PURPLE_CIPHER_H */