mw_cipher.h

Go to the documentation of this file.
00001 
00002 /*
00003   Meanwhile - Unofficial Lotus Sametime Community Client Library
00004   Copyright (C) 2004  Christopher (siege) O'Brien
00005   
00006   This library is free software; you can redistribute it and/or
00007   modify it under the terms of the GNU Library General Public
00008   License as published by the Free Software Foundation; either
00009   version 2 of the License, or (at your option) any later version.
00010   
00011   This library is distributed in the hope that it will be useful,
00012   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014   Library General Public License for more details.
00015   
00016   You should have received a copy of the GNU Library General Public
00017   License along with this library; if not, write to the Free
00018   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 */
00020 
00021 #ifndef _MW_CIPHER_H
00022 #define _MW_CIPHER_H
00023 
00024 
00025 #include <glib.h>
00026 #include "mw_common.h"
00027 
00028 
00029 #ifdef __cplusplus
00030 extern "C" {
00031 #endif
00032 
00033 
00034 /* place-holders */
00035 struct mwChannel;
00036 struct mwSession;
00037 
00038 
00041 enum mwCipherType {
00042   mwCipher_RC2_40   = 0x0000,
00043   mwCipher_RC2_128  = 0x0001,
00044 };
00045 
00046 
00047 struct mwCipher;
00048 struct mwCipherInstance;
00049 
00050 
00053 typedef struct mwCipherInstance *(*mwCipherInstantiator)
00054      (struct mwCipher *cipher, struct mwChannel *chan);
00055 
00056 
00061 typedef int (*mwCipherProcessor)
00062      (struct mwCipherInstance *ci, struct mwOpaque *data);
00063 
00064 
00070 struct mwCipher {
00071 
00074   struct mwSession *session;
00075 
00076   guint16 type;               
00077   const char *(*get_name)();  
00078   const char *(*get_desc)();  
00082   mwCipherInstantiator new_instance;
00083 
00084   void (*offered)(struct mwCipherInstance *ci, struct mwEncryptItem *item);
00085   struct mwEncryptItem *(*offer)(struct mwCipherInstance *ci);
00086   void (*accepted)(struct mwCipherInstance *ci, struct mwEncryptItem *item);
00087   struct mwEncryptItem *(*accept)(struct mwCipherInstance *ci);
00088 
00089   mwCipherProcessor encrypt; 
00090   mwCipherProcessor decrypt; 
00094   void (*clear)(struct mwCipher *c);
00095 
00098   void (*clear_instance)(struct mwCipherInstance *ci);
00099 };
00100 
00101 
00105 struct mwCipherInstance {
00106 
00109   struct mwCipher *cipher;
00110 
00113   struct mwChannel *channel;
00114 };
00115 
00116 
00117 struct mwCipher *mwCipher_new_RC2_40(struct mwSession *s);
00118 
00119 
00120 struct mwCipher *mwCipher_new_RC2_128(struct mwSession *s);
00121 
00122 
00123 struct mwSession *mwCipher_getSession(struct mwCipher *cipher);
00124 
00125 
00126 guint16 mwCipher_getType(struct mwCipher *cipher);
00127 
00128 
00129 const char *mwCipher_getName(struct mwCipher *cipher);
00130 
00131 
00132 const char *mwCipher_getDesc(struct mwCipher *cipher);
00133 
00134 
00135 struct mwCipherInstance *mwCipher_newInstance(struct mwCipher *cipher,
00136                                               struct mwChannel *channel);
00137 
00138 
00140 void mwCipher_free(struct mwCipher* cipher);
00141 
00142 
00144 struct mwCipher *mwCipherInstance_getCipher(struct mwCipherInstance *ci);
00145 
00146 
00148 struct mwChannel *mwCipherInstance_getChannel(struct mwCipherInstance *ci);
00149 
00150 
00152 void mwCipherInstance_offered(struct mwCipherInstance *ci,
00153                               struct mwEncryptItem *item);
00154 
00155 
00157 struct mwEncryptItem *
00158 mwCipherInstance_offer(struct mwCipherInstance *ci);
00159 
00160 
00162 void mwCipherInstance_accepted(struct mwCipherInstance *ci,
00163                                struct mwEncryptItem *item);
00164 
00165 
00167 struct mwEncryptItem *
00168 mwCipherInstance_accept(struct mwCipherInstance *ci);
00169 
00170 
00172 int mwCipherInstance_encrypt(struct mwCipherInstance *ci,
00173                              struct mwOpaque *data);
00174 
00175 
00177 int mwCipherInstance_decrypt(struct mwCipherInstance *ci,
00178                              struct mwOpaque *data);
00179 
00180 
00182 void mwCipherInstance_free(struct mwCipherInstance *ci);
00183 
00184 
00191 /* @{ */
00192 
00193 
00198 void mwKeyRandom(guchar *key, gsize keylen);
00199 
00200 
00202 void mwIV_init(guchar *iv);
00203 
00204 
00207 void mwKeyExpand(int *ekey, const guchar *key, gsize keylen);
00208 
00209 
00211 void mwEncryptExpanded(const int *ekey, guchar *iv,
00212                        struct mwOpaque *in,
00213                        struct mwOpaque *out);
00214 
00215 
00217 void mwEncrypt(const guchar *key, gsize keylen, guchar *iv,
00218                struct mwOpaque *in, struct mwOpaque *out);
00219 
00220 
00222 void mwDecryptExpanded(const int *ekey, guchar *iv,
00223                        struct mwOpaque *in,
00224                        struct mwOpaque *out);
00225 
00226 
00228 void mwDecrypt(const guchar *key, gsize keylen, guchar *iv,
00229                struct mwOpaque *in, struct mwOpaque *out);
00230 
00231 
00232 /* @} */
00233 
00234 
00247 /* @{ */
00248 
00249 
00251 struct mwMpi;
00252 
00253 
00255 struct mwMpi *mwMpi_new();
00256 
00257 
00259 void mwMpi_free(struct mwMpi *i);
00260 
00261 
00263 void mwMpi_import(struct mwMpi *i, struct mwOpaque *o);
00264 
00265 
00267 void mwMpi_export(struct mwMpi *i, struct mwOpaque *o);
00268 
00269 
00271 void mwMpi_setDHPrime(struct mwMpi *i);
00272 
00273 
00275 void mwMpi_setDHBase(struct mwMpi *i);
00276 
00277 
00280 void mwMpi_randDHKeypair(struct mwMpi *private_key, struct mwMpi *public_key);
00281 
00282 
00285 void mwMpi_calculateDHShared(struct mwMpi *shared_key, struct mwMpi *remote_key,
00286                              struct mwMpi *private_key);
00287 
00288 
00289 /* @} */
00290 
00291 
00292 #ifdef __cplusplus
00293 }
00294 #endif
00295 
00296 
00297 #endif /* _MW_CIPHER_H */

Generated on Wed May 23 23:43:22 2007 for meanwhile by  doxygen 1.5.2