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