meanwhile  1.0.2
mw_cipher.h
Go to the documentation of this file.
1 
2 /*
3  Meanwhile - Unofficial Lotus Sametime Community Client Library
4  Copyright (C) 2004 Christopher (siege) O'Brien
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public
17  License along with this library; if not, write to the Free
18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20 
21 #ifndef _MW_CIPHER_H
22 #define _MW_CIPHER_H
23 
24 
25 #include <glib.h>
26 #include "mw_common.h"
27 
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 
34 /* place-holders */
35 struct mwChannel;
36 struct mwSession;
37 
38 
42  mwCipher_RC2_40 = 0x0000,
43  mwCipher_RC2_128 = 0x0001,
44 };
45 
46 
47 struct mwCipher;
48 struct mwCipherInstance;
49 
50 
53 typedef struct mwCipherInstance *(*mwCipherInstantiator)
54  (struct mwCipher *cipher, struct mwChannel *chan);
55 
56 
61 typedef int (*mwCipherProcessor)
62  (struct mwCipherInstance *ci, struct mwOpaque *data);
63 
64 
70 struct mwCipher {
71 
74  struct mwSession *session;
75 
76  guint16 type;
77  const char *(*get_name)();
78  const char *(*get_desc)();
83 
84  void (*offered)(struct mwCipherInstance *ci, struct mwEncryptItem *item);
85  struct mwEncryptItem *(*offer)(struct mwCipherInstance *ci);
86  void (*accepted)(struct mwCipherInstance *ci, struct mwEncryptItem *item);
87  struct mwEncryptItem *(*accept)(struct mwCipherInstance *ci);
88 
94  void (*clear)(struct mwCipher *c);
95 
98  void (*clear_instance)(struct mwCipherInstance *ci);
99 };
100 
101 
106 
109  struct mwCipher *cipher;
110 
114 };
115 
116 
117 struct mwCipher *mwCipher_new_RC2_40(struct mwSession *s);
118 
119 
120 struct mwCipher *mwCipher_new_RC2_128(struct mwSession *s);
121 
122 
123 struct mwSession *mwCipher_getSession(struct mwCipher *cipher);
124 
125 
126 guint16 mwCipher_getType(struct mwCipher *cipher);
127 
128 
129 const char *mwCipher_getName(struct mwCipher *cipher);
130 
131 
132 const char *mwCipher_getDesc(struct mwCipher *cipher);
133 
134 
135 struct mwCipherInstance *mwCipher_newInstance(struct mwCipher *cipher,
136  struct mwChannel *channel);
137 
138 
140 void mwCipher_free(struct mwCipher* cipher);
141 
142 
145 
146 
149 
150 
153  struct mwEncryptItem *item);
154 
155 
157 struct mwEncryptItem *
159 
160 
163  struct mwEncryptItem *item);
164 
165 
167 struct mwEncryptItem *
169 
170 
173  struct mwOpaque *data);
174 
175 
178  struct mwOpaque *data);
179 
180 
182 void mwCipherInstance_free(struct mwCipherInstance *ci);
183 
184 
191 /* @{ */
192 
193 
198 void mwKeyRandom(guchar *key, gsize keylen);
199 
200 
202 void mwIV_init(guchar *iv);
203 
204 
207 void mwKeyExpand(int *ekey, const guchar *key, gsize keylen);
208 
209 
211 void mwEncryptExpanded(const int *ekey, guchar *iv,
212  struct mwOpaque *in,
213  struct mwOpaque *out);
214 
215 
217 void mwEncrypt(const guchar *key, gsize keylen, guchar *iv,
218  struct mwOpaque *in, struct mwOpaque *out);
219 
220 
222 void mwDecryptExpanded(const int *ekey, guchar *iv,
223  struct mwOpaque *in,
224  struct mwOpaque *out);
225 
226 
228 void mwDecrypt(const guchar *key, gsize keylen, guchar *iv,
229  struct mwOpaque *in, struct mwOpaque *out);
230 
231 
232 /* @} */
233 
234 
247 /* @{ */
248 
249 
251 struct mwMpi;
252 
253 
255 struct mwMpi *mwMpi_new();
256 
257 
259 void mwMpi_free(struct mwMpi *i);
260 
261 
263 void mwMpi_import(struct mwMpi *i, struct mwOpaque *o);
264 
265 
267 void mwMpi_export(struct mwMpi *i, struct mwOpaque *o);
268 
269 
271 void mwMpi_setDHPrime(struct mwMpi *i);
272 
273 
275 void mwMpi_setDHBase(struct mwMpi *i);
276 
277 
280 void mwMpi_randDHKeypair(struct mwMpi *private_key, struct mwMpi *public_key);
281 
282 
285 void mwMpi_calculateDHShared(struct mwMpi *shared_key, struct mwMpi *remote_key,
286  struct mwMpi *private_key);
287 
288 
289 /* @} */
290 
291 
292 #ifdef __cplusplus
293 }
294 #endif
295 
296 
297 #endif /* _MW_CIPHER_H */
struct mwSession * mwCipher_getSession(struct mwCipher *cipher)
void mwCipherInstance_accepted(struct mwCipherInstance *ci, struct mwEncryptItem *item)
Indicates an offered cipher has been accepted.
struct mwCipherInstance * mwCipher_newInstance(struct mwCipher *cipher, struct mwChannel *channel)
const char * mwCipher_getDesc(struct mwCipher *cipher)
const char * mwCipher_getName(struct mwCipher *cipher)
void mwIV_init(guchar *iv)
Setup an Initialization Vector.
struct mwSession * session
service this cipher is providing for
Definition: mw_cipher.h:74
struct mwCipher * mwCipher_new_RC2_128(struct mwSession *s)
void mwEncryptExpanded(const int *ekey, guchar *iv, struct mwOpaque *in, struct mwOpaque *out)
Encrypt data using an already-expanded key.
void mwCipherInstance_free(struct mwCipherInstance *ci)
destroy a cipher instance
void mwMpi_randDHKeypair(struct mwMpi *private_key, struct mwMpi *public_key)
sets private to a randomly generated value, and calculates public using the Sametime Prime and Base ...
An instance of a cipher.
Definition: mw_cipher.h:105
void mwCipher_free(struct mwCipher *cipher)
destroy a cipher
struct mwEncryptItem * mwCipherInstance_offer(struct mwCipherInstance *ci)
Offer a cipher.
void mwMpi_free(struct mwMpi *i)
destroy an mpi value
void mwMpi_setDHPrime(struct mwMpi *i)
set a big integer to the Sametime Prime value
void(* clear)(struct mwCipher *c)
prepare this cipher for being free&#39;d
Definition: mw_cipher.h:94
void(* accepted)(struct mwCipherInstance *ci, struct mwEncryptItem *item)
Definition: mw_cipher.h:86
Represents a Sametime client session.
void mwMpi_export(struct mwMpi *i, struct mwOpaque *o)
Export a value into an opaque.
A cipher.
Definition: mw_cipher.h:70
mwCipherType
Common cipher types.
Definition: mw_cipher.h:41
Common data types and functions for handling those types.
int(* mwCipherProcessor)(struct mwCipherInstance *ci, struct mwOpaque *data)
Process (encrypt or decrypt, depending) the given data.
Definition: mw_cipher.h:62
void mwMpi_calculateDHShared(struct mwMpi *shared_key, struct mwMpi *remote_key, struct mwMpi *private_key)
sets the shared key value based on the remote and private keys, using the Sametime Prime and Base ...
struct mwMpi * mwMpi_new()
prepare a new mpi value
void mwEncrypt(const guchar *key, gsize keylen, guchar *iv, struct mwOpaque *in, struct mwOpaque *out)
Encrypt data using an expanded form of the given key.
struct mwChannel * mwCipherInstance_getChannel(struct mwCipherInstance *ci)
reference the channel a cipher instance is attached to
void(* clear_instance)(struct mwCipherInstance *ci)
clean up a cipher instance before being free&#39;d
Definition: mw_cipher.h:98
void(* offered)(struct mwCipherInstance *ci, struct mwEncryptItem *item)
Definition: mw_cipher.h:84
Represents a channel to a service.
Definition: mw_channel.h:95
void mwKeyExpand(int *ekey, const guchar *key, gsize keylen)
Expand a variable-length key into a 128-byte key (represented as an an array of 64 ints) ...
struct mwCipher * cipher
the parent cipher.
Definition: mw_cipher.h:109
mwCipherInstantiator new_instance
Generate a new Cipher Instance for use on a channel.
Definition: mw_cipher.h:82
int mwCipherInstance_decrypt(struct mwCipherInstance *ci, struct mwOpaque *data)
decrypt data
guint16 type
Definition: mw_cipher.h:76
mwCipherProcessor decrypt
Definition: mw_cipher.h:90
void mwMpi_setDHBase(struct mwMpi *i)
set a big integer to the Sametime Base value
A length of binary data, not null-terminated.
Definition: mw_common.h:79
void mwDecryptExpanded(const int *ekey, guchar *iv, struct mwOpaque *in, struct mwOpaque *out)
Decrypt data using an already expanded key.
mwCipherProcessor encrypt
Definition: mw_cipher.h:89
void mwKeyRandom(guchar *key, gsize keylen)
generate some pseudo-random bytes
struct mwCipher * mwCipherInstance_getCipher(struct mwCipherInstance *ci)
reference the parent cipher of an instance
struct mwEncryptItem * mwCipherInstance_accept(struct mwCipherInstance *ci)
Accept a cipher offered to our channel.
Definition: mw_cipher.h:43
void mwDecrypt(const guchar *key, gsize keylen, guchar *iv, struct mwOpaque *in, struct mwOpaque *out)
Decrypt data using an expanded form of the given key.
encryption blocks
Definition: mw_common.h:216
guint16 mwCipher_getType(struct mwCipher *cipher)
void mwMpi_import(struct mwMpi *i, struct mwOpaque *o)
Import a value from an opaque.
Definition: mw_cipher.h:42
struct mwCipher * mwCipher_new_RC2_40(struct mwSession *s)
struct mwChannel * channel
the channel this instances processes
Definition: mw_cipher.h:113
void mwCipherInstance_offered(struct mwCipherInstance *ci, struct mwEncryptItem *item)
Indicates a cipher has been offered to our channel.
struct mwCipherInstance *(* mwCipherInstantiator)(struct mwCipher *cipher, struct mwChannel *chan)
Obtain an instance of a given cipher, which can be used for the processing of a single channel...
Definition: mw_cipher.h:54
guchar * data
data, normally with no NULL termination
Definition: mw_common.h:81
int mwCipherInstance_encrypt(struct mwCipherInstance *ci, struct mwOpaque *data)
encrypt data