00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00030 struct mwChannel;
00031 struct mwSession;
00032
00033
00036 enum mwCipherType {
00037 mwCipher_RC2_40 = 0x0000,
00038 mwCipher_RC2_128 = 0x0001,
00039 };
00040
00041
00042 struct mwCipher;
00043 struct mwCipherInstance;
00044
00045
00048 typedef struct mwCipherInstance *(*mwCipherInstantiator)
00049 (struct mwCipher *cipher, struct mwChannel *chan);
00050
00051
00057 typedef struct mwEncryptItem *(*mwCipherDescriptor)
00058 (struct mwCipherInstance *instance);
00059
00060
00065 typedef int (*mwCipherProcessor)
00066 (struct mwCipherInstance *ci, struct mwOpaque *data);
00067
00068
00074 struct mwCipher {
00075
00078 struct mwSession *session;
00079
00080 guint16 type;
00081 const char *(*get_name)();
00082 const char *(*get_desc)();
00086 mwCipherInstantiator new_instance;
00087
00091 mwCipherDescriptor new_item;
00092
00093 void (*offered)(struct mwCipherInstance *ci, struct mwEncryptItem *item);
00094 struct mwEncryptItem *(*offer)(struct mwCipherInstance *ci);
00095 void (*accepted)(struct mwCipherInstance *ci, struct mwEncryptItem *item);
00096 struct mwEncryptItem *(*accept)(struct mwCipherInstance *ci);
00097
00098 mwCipherProcessor encrypt;
00099 mwCipherProcessor decrypt;
00103 void (*clear)(struct mwCipher *c);
00104
00107 void (*clear_instance)(struct mwCipherInstance *ci);
00108 };
00109
00110
00114 struct mwCipherInstance {
00115
00118 struct mwCipher *cipher;
00119
00122 struct mwChannel *channel;
00123 };
00124
00125
00126 struct mwCipher *mwCipher_new_RC2_40(struct mwSession *s);
00127
00128
00129 struct mwCipher *mwCipher_new_RC2_128(struct mwSession *s);
00130
00131
00132 struct mwSession *mwCipher_getSession(struct mwCipher *cipher);
00133
00134
00135 guint16 mwCipher_getType(struct mwCipher *cipher);
00136
00137
00138 const char *mwCipher_getName(struct mwCipher *cipher);
00139
00140
00141 const char *mwCipher_getDesc(struct mwCipher *cipher);
00142
00143
00144 struct mwCipherInstance *mwCipher_newInstance(struct mwCipher *cipher,
00145 struct mwChannel *channel);
00146
00147
00149 void mwCipher_free(struct mwCipher* cipher);
00150
00151
00153 struct mwCipher *mwCipherInstance_getCipher(struct mwCipherInstance *ci);
00154
00155
00160 struct mwEncryptItem *mwCipherInstance_newItem(struct mwCipherInstance *ci);
00161
00162
00164 void mwCipherInstance_offered(struct mwCipherInstance *ci,
00165 struct mwEncryptItem *item);
00166
00167
00169 struct mwEncryptItem *
00170 mwCipherInstance_offer(struct mwCipherInstance *ci);
00171
00172
00174 void mwCipherInstance_accepted(struct mwCipherInstance *ci,
00175 struct mwEncryptItem *item);
00176
00177
00179 struct mwEncryptItem *
00180 mwCipherInstance_accept(struct mwCipherInstance *ci);
00181
00182
00184 int mwCipherInstance_encrypt(struct mwCipherInstance *ci,
00185 struct mwOpaque *data);
00186
00187
00189 int mwCipherInstance_decrypt(struct mwCipherInstance *ci,
00190 struct mwOpaque *data);
00191
00192
00194 void mwCipherInstance_free(struct mwCipherInstance *ci);
00195
00196
00203
00204
00205
00210 void mwKeyRandom(char *key, gsize keylen);
00211
00212
00214 void mwIV_init(char *iv);
00215
00216
00219 void mwKeyExpand(int *ekey, const char *key, gsize keylen);
00220
00221
00223 void mwEncryptExpanded(const int *ekey, char *iv,
00224 struct mwOpaque *in,
00225 struct mwOpaque *out);
00226
00227
00229 void mwEncrypt(const char *key, gsize keylen, char *iv,
00230 struct mwOpaque *in, struct mwOpaque *out);
00231
00232
00234 void mwDecryptExpanded(const int *ekey, char *iv,
00235 struct mwOpaque *in,
00236 struct mwOpaque *out);
00237
00238
00240 void mwDecrypt(const char *key, gsize keylen, char *iv,
00241 struct mwOpaque *in, struct mwOpaque *out);
00242
00243
00244
00245
00246
00254
00255 #ifdef __GMP_H__
00256
00257
00259 void mwInitDHPrime(mpz_t z);
00260
00261
00263 void mwInitDHBase(mpz_t z);
00264
00265
00268 void mwDHRandKeypair(mpz_t private, mpz_t public);
00269
00270
00273 void mwDHCalculateShared(mpz_t shared, mpz_t remote, mpz_t private);
00274
00275
00277 void mwDHImportKey(mpz_t key, struct mwOpaque *o);
00278
00279
00281 void mwDHExportKey(mpz_t key, struct mwOpaque *o);
00282
00283
00284 #endif
00285
00286
00287
00288 #endif
00289
00290