meanwhile 1.1.0
mw_cipher.h
Go to the documentation of this file.
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
30extern "C" {
31#endif
32
33
34/* place-holders */
35struct mwChannel;
36struct mwSession;
37
38
44};
45
46
47struct mwCipher;
48struct mwCipherInstance;
49
50
53typedef struct mwCipherInstance *(*mwCipherInstantiator)
54 (struct mwCipher *cipher, struct mwChannel *chan);
55
56
61typedef int (*mwCipherProcessor)
62 (struct mwCipherInstance *ci, struct mwOpaque *data);
63
64
70struct mwCipher {
71
75
76 guint16 type;
77 const char *(*get_name)(void);
78 const char *(*get_desc)(void);
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
110
114};
115
116
118
119
121
122
123struct mwSession *mwCipher_getSession(struct mwCipher *cipher);
124
125
126guint16 mwCipher_getType(struct mwCipher *cipher);
127
128
129const char *mwCipher_getName(struct mwCipher *cipher);
130
131
132const char *mwCipher_getDesc(struct mwCipher *cipher);
133
134
136 struct mwChannel *channel);
137
138
141
142
145
146
149
150
153 struct mwEncryptItem *item);
154
155
157struct mwEncryptItem *
159
160
163 struct mwEncryptItem *item);
164
165
167struct mwEncryptItem *
169
170
173 struct mwOpaque *data);
174
175
178 struct mwOpaque *data);
179
180
183
184
191/* @{ */
192
193
198void mwKeyRandom(guchar *key, gsize keylen);
199
200
202void mwIV_init(guchar *iv);
203
204
207void mwKeyExpand(int *ekey, const guchar *key, gsize keylen);
208
209
211void mwEncryptExpanded(const int *ekey, guchar *iv,
212 struct mwOpaque *in,
213 struct mwOpaque *out);
214
215
217void mwEncrypt(const guchar *key, gsize keylen, guchar *iv,
218 struct mwOpaque *in, struct mwOpaque *out);
219
220
222void mwDecryptExpanded(const int *ekey, guchar *iv,
223 struct mwOpaque *in,
224 struct mwOpaque *out);
225
226
228void mwDecrypt(const guchar *key, gsize keylen, guchar *iv,
229 struct mwOpaque *in, struct mwOpaque *out);
230
231
232/* @} */
233
234
247/* @{ */
248
249
251struct mwMpi;
252
253
255struct mwMpi *mwMpi_new(void);
256
257
259void mwMpi_free(struct mwMpi *i);
260
261
263void mwMpi_import(struct mwMpi *i, struct mwOpaque *o);
264
265
267void mwMpi_export(struct mwMpi *i, struct mwOpaque *o);
268
269
271void mwMpi_setDHPrime(struct mwMpi *i);
272
273
275void mwMpi_setDHBase(struct mwMpi *i);
276
277
280void mwMpi_randDHKeypair(struct mwMpi *private_key, struct mwMpi *public_key);
281
282
285void 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 mwEncryptItem * mwCipherInstance_accept(struct mwCipherInstance *ci)
Accept a cipher offered to our channel.
void mwCipherInstance_accepted(struct mwCipherInstance *ci, struct mwEncryptItem *item)
Indicates an offered cipher has been accepted.
const char * mwCipher_getName(struct mwCipher *cipher)
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.
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)
int mwCipherInstance_decrypt(struct mwCipherInstance *ci, struct mwOpaque *data)
decrypt data
void mwCipherInstance_free(struct mwCipherInstance *ci)
destroy a cipher instance
void mwMpi_export(struct mwMpi *i, struct mwOpaque *o)
Export a value into an opaque.
mwCipherType
Common cipher types.
Definition mw_cipher.h:41
@ mwCipher_RC2_40
Definition mw_cipher.h:42
@ mwCipher_RC2_128
Definition mw_cipher.h:43
struct mwCipher * mwCipher_new_RC2_40(struct mwSession *s)
void mwIV_init(guchar *iv)
Setup an Initialization Vector.
void mwKeyRandom(guchar *key, gsize keylen)
generate some pseudo-random bytes
struct mwEncryptItem * mwCipherInstance_offer(struct mwCipherInstance *ci)
Offer a cipher.
void mwCipher_free(struct mwCipher *cipher)
destroy a cipher
void mwMpi_import(struct mwMpi *i, struct mwOpaque *o)
Import a value from an opaque.
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.
const char * mwCipher_getDesc(struct mwCipher *cipher)
void mwMpi_free(struct mwMpi *i)
destroy an mpi value
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
void mwMpi_setDHPrime(struct mwMpi *i)
set a big integer to the Sametime Prime value
void mwEncryptExpanded(const int *ekey, guchar *iv, struct mwOpaque *in, struct mwOpaque *out)
Encrypt data using an already-expanded key.
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
struct mwCipher * mwCipher_new_RC2_128(struct mwSession *s)
guint16 mwCipher_getType(struct mwCipher *cipher)
struct mwChannel * mwCipherInstance_getChannel(struct mwCipherInstance *ci)
reference the channel a cipher instance is attached to
struct mwSession * mwCipher_getSession(struct mwCipher *cipher)
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
void mwDecryptExpanded(const int *ekey, guchar *iv, struct mwOpaque *in, struct mwOpaque *out)
Decrypt data using an already expanded key.
struct mwCipher * mwCipherInstance_getCipher(struct mwCipherInstance *ci)
reference the parent cipher of an instance
struct mwCipherInstance * mwCipher_newInstance(struct mwCipher *cipher, struct mwChannel *channel)
void mwMpi_setDHBase(struct mwMpi *i)
set a big integer to the Sametime Base value
struct mwMpi * mwMpi_new(void)
prepare a new mpi value
int mwCipherInstance_encrypt(struct mwCipherInstance *ci, struct mwOpaque *data)
encrypt data
Common data types and functions for handling those types.
Represents a channel to a service.
An instance of a cipher.
Definition mw_cipher.h:105
struct mwCipher * cipher
the parent cipher.
Definition mw_cipher.h:109
struct mwChannel * channel
the channel this instances processes
Definition mw_cipher.h:113
A cipher.
Definition mw_cipher.h:70
void(* accepted)(struct mwCipherInstance *ci, struct mwEncryptItem *item)
Definition mw_cipher.h:86
mwCipherProcessor decrypt
Definition mw_cipher.h:90
guint16 type
Definition mw_cipher.h:76
mwCipherProcessor encrypt
Definition mw_cipher.h:89
void(* clear)(struct mwCipher *c)
prepare this cipher for being free'd
Definition mw_cipher.h:94
void(* offered)(struct mwCipherInstance *ci, struct mwEncryptItem *item)
Definition mw_cipher.h:84
mwCipherInstantiator new_instance
Generate a new Cipher Instance for use on a channel.
Definition mw_cipher.h:82
struct mwSession * session
service this cipher is providing for
Definition mw_cipher.h:74
void(* clear_instance)(struct mwCipherInstance *ci)
clean up a cipher instance before being free'd
Definition mw_cipher.h:98
encryption blocks
Definition mw_common.h:220
A length of binary data, not null-terminated.
Definition mw_common.h:79
guchar * data
data, normally with no NULL termination
Definition mw_common.h:81
Represents a Sametime client session.