Mercurial > pidgin
annotate src/protocols/sametime/meanwhile/mw_cipher.h @ 11980:67fbd2ff4c4e
[gaim-migrate @ 14273]
Mono cleanup patch from Eoin Coffey
First, I changed mono_loader_ to ml_, since I was
getting sick of typing mono_loader_ :-D
Moved the mono runtime init and deinit code out of
mono.c into ml_init and ml_uninit in mono-helper.c
Added api/Status.cs and loader/status-glue.c so the
.net api now knows very little (as in the 'id') of
statuses.
committer: Tailor Script <tailor@pidgin.im>
| author | Gary Kramlich <grim@reaperworld.com> |
|---|---|
| date | Sat, 05 Nov 2005 02:09:30 +0000 |
| parents | 0110fc7c6a8a |
| children | 2edf5dc1b2ea |
| rev | line source |
|---|---|
| 10969 | 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 /* place-holders */ | |
| 30 struct mwChannel; | |
| 31 struct mwSession; | |
| 32 | |
| 33 | |
|
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
34 /** @enum mwCipherType |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
35 Common cipher types */ |
| 10969 | 36 enum mwCipherType { |
| 37 mwCipher_RC2_40 = 0x0000, | |
| 38 mwCipher_RC2_128 = 0x0001, | |
| 39 }; | |
| 40 | |
| 41 | |
| 42 struct mwCipher; | |
| 43 struct mwCipherInstance; | |
| 44 | |
| 45 | |
| 46 /** Obtain an instance of a given cipher, which can be used for the | |
| 47 processing of a single channel. */ | |
| 48 typedef struct mwCipherInstance *(*mwCipherInstantiator) | |
| 49 (struct mwCipher *cipher, struct mwChannel *chan); | |
| 50 | |
| 51 | |
| 52 /** Generate a descriptor for use in a channel create message to | |
|
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
53 indicate the availability of this cipher |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
54 |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
55 @todo remove for 1.0 |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
56 */ |
| 10969 | 57 typedef struct mwEncryptItem *(*mwCipherDescriptor) |
| 58 (struct mwCipherInstance *instance); | |
| 59 | |
| 60 | |
| 61 /** Process (encrypt or decrypt, depending) the given data. The passed | |
| 62 buffer may be freed in processing and be replaced with a freshly | |
| 63 allocated buffer. The post-processed buffer must in turn be freed | |
| 64 after use */ | |
| 65 typedef int (*mwCipherProcessor) | |
| 66 (struct mwCipherInstance *ci, struct mwOpaque *data); | |
| 67 | |
| 68 | |
| 69 /** A cipher. Ciphers are primarily used to provide cipher instances | |
| 70 for bi-directional encryption on channels, but some may be used | |
| 71 for other activities. Expand upon this structure to create a | |
| 72 custom encryption provider. | |
| 73 @see mwCipherInstance */ | |
| 74 struct mwCipher { | |
| 75 | |
| 76 /** service this cipher is providing for | |
| 77 @see mwCipher_getSession */ | |
| 78 struct mwSession *session; | |
| 79 | |
| 80 guint16 type; /**< @see mwCipher_getType */ | |
| 81 const char *(*get_name)(); /**< @see mwCipher_getName */ | |
| 82 const char *(*get_desc)(); /**< @see mwCipher_getDesc */ | |
| 83 | |
| 84 /** Generate a new Cipher Instance for use on a channel | |
| 85 @see mwCipher_newInstance */ | |
| 86 mwCipherInstantiator new_instance; | |
| 87 | |
|
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
88 /** @see mwCipher_newItem |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
89 @todo remove for 1.0 |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
90 */ |
| 10969 | 91 mwCipherDescriptor new_item; |
| 92 | |
| 93 void (*offered)(struct mwCipherInstance *ci, struct mwEncryptItem *item); | |
|
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
94 struct mwEncryptItem *(*offer)(struct mwCipherInstance *ci); |
| 10969 | 95 void (*accepted)(struct mwCipherInstance *ci, struct mwEncryptItem *item); |
|
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
96 struct mwEncryptItem *(*accept)(struct mwCipherInstance *ci); |
| 10969 | 97 |
| 98 mwCipherProcessor encrypt; /**< @see mwCipherInstance_encrypt */ | |
| 99 mwCipherProcessor decrypt; /**< @see mwCipherInstance_decrypt */ | |
| 100 | |
| 101 /** prepare this cipher for being free'd | |
| 102 @see mwCipher_free */ | |
| 103 void (*clear)(struct mwCipher *c); | |
| 104 | |
| 105 /** clean up a cipher instance before being free'd | |
| 106 @see mwCipherInstance_free */ | |
| 107 void (*clear_instance)(struct mwCipherInstance *ci); | |
| 108 }; | |
| 109 | |
| 110 | |
| 111 /** An instance of a cipher. Expand upon this structure to contain | |
| 112 necessary state data | |
| 113 @see mwCipher */ | |
| 114 struct mwCipherInstance { | |
| 115 | |
| 116 /** the parent cipher. | |
| 117 @see mwCipherInstance_getCipher */ | |
| 118 struct mwCipher *cipher; | |
| 119 | |
| 120 /** the channel this instances processes | |
| 121 @see mwCipherInstance_getChannel */ | |
| 122 struct mwChannel *channel; | |
| 123 }; | |
| 124 | |
| 125 | |
| 126 struct mwCipher *mwCipher_new_RC2_40(struct mwSession *s); | |
| 127 | |
| 128 | |
|
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
129 struct mwCipher *mwCipher_new_RC2_128(struct mwSession *s); |
| 10969 | 130 |
| 131 | |
| 132 struct mwSession *mwCipher_getSession(struct mwCipher *cipher); | |
| 133 | |
| 134 | |
| 135 guint16 mwCipher_getType(struct mwCipher *cipher); | |
| 136 | |
| 137 | |
| 138 const char *mwCipher_getName(struct mwCipher *cipher); | |
| 139 | |
| 140 | |
| 141 const char *mwCipher_getDesc(struct mwCipher *cipher); | |
| 142 | |
| 143 | |
| 144 struct mwCipherInstance *mwCipher_newInstance(struct mwCipher *cipher, | |
| 145 struct mwChannel *channel); | |
| 146 | |
| 147 | |
| 148 /** destroy a cipher */ | |
| 149 void mwCipher_free(struct mwCipher* cipher); | |
| 150 | |
| 151 | |
| 152 /** reference the parent cipher of an instance */ | |
| 153 struct mwCipher *mwCipherInstance_getCipher(struct mwCipherInstance *ci); | |
| 154 | |
| 155 | |
|
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
156 /** |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
157 Deprecated in favor of the methods mwCipherInstance_offer and |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
158 mwCipherInstance_accept |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
159 */ |
| 10969 | 160 struct mwEncryptItem *mwCipherInstance_newItem(struct mwCipherInstance *ci); |
| 161 | |
| 162 | |
| 163 /** Indicates a cipher has been offered to our channel */ | |
| 164 void mwCipherInstance_offered(struct mwCipherInstance *ci, | |
| 165 struct mwEncryptItem *item); | |
| 166 | |
| 167 | |
| 168 /** Offer a cipher */ | |
|
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
169 struct mwEncryptItem * |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
170 mwCipherInstance_offer(struct mwCipherInstance *ci); |
| 10969 | 171 |
| 172 | |
| 173 /** Indicates an offered cipher has been accepted */ | |
| 174 void mwCipherInstance_accepted(struct mwCipherInstance *ci, | |
| 175 struct mwEncryptItem *item); | |
| 176 | |
| 177 | |
| 178 /** Accept a cipher offered to our channel */ | |
|
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
179 struct mwEncryptItem * |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
180 mwCipherInstance_accept(struct mwCipherInstance *ci); |
| 10969 | 181 |
| 182 | |
| 183 /** encrypt data */ | |
| 184 int mwCipherInstance_encrypt(struct mwCipherInstance *ci, | |
| 185 struct mwOpaque *data); | |
| 186 | |
| 187 | |
| 188 /** decrypt data */ | |
| 189 int mwCipherInstance_decrypt(struct mwCipherInstance *ci, | |
| 190 struct mwOpaque *data); | |
| 191 | |
| 192 | |
| 193 /** destroy a cipher instance */ | |
| 194 void mwCipherInstance_free(struct mwCipherInstance *ci); | |
| 195 | |
| 196 | |
| 197 /** | |
| 198 @section General Cipher Functions | |
| 199 | |
|
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
200 These functions are reused where encryption is necessary outside of |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
201 a channel (eg. session authentication) |
| 10969 | 202 */ |
| 203 /* @{ */ | |
| 204 | |
| 205 | |
| 206 /** generate some pseudo-random bytes | |
| 207 @param keylen count of bytes to write into key | |
| 208 @param key buffer to write keys into | |
| 209 */ | |
|
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
210 void mwKeyRandom(char *key, gsize keylen); |
| 10969 | 211 |
| 212 | |
|
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
213 /** Setup an Initialization Vector. IV must be at least 8 bytes */ |
| 10969 | 214 void mwIV_init(char *iv); |
| 215 | |
| 216 | |
| 217 /** Expand a variable-length key into a 128-byte key (represented as | |
| 218 an an array of 64 ints) */ | |
| 219 void mwKeyExpand(int *ekey, const char *key, gsize keylen); | |
| 220 | |
| 221 | |
| 222 /** Encrypt data using an already-expanded key */ | |
| 223 void mwEncryptExpanded(const int *ekey, char *iv, | |
| 224 struct mwOpaque *in, | |
| 225 struct mwOpaque *out); | |
| 226 | |
| 227 | |
| 228 /** Encrypt data using an expanded form of the given key */ | |
| 229 void mwEncrypt(const char *key, gsize keylen, char *iv, | |
| 230 struct mwOpaque *in, struct mwOpaque *out); | |
| 231 | |
| 232 | |
| 233 /** Decrypt data using an already expanded key */ | |
| 234 void mwDecryptExpanded(const int *ekey, char *iv, | |
| 235 struct mwOpaque *in, | |
| 236 struct mwOpaque *out); | |
| 237 | |
| 238 | |
| 239 /** Decrypt data using an expanded form of the given key */ | |
| 240 void mwDecrypt(const char *key, gsize keylen, char *iv, | |
| 241 struct mwOpaque *in, struct mwOpaque *out); | |
| 242 | |
| 243 | |
| 244 /* @} */ | |
| 245 | |
| 246 | |
|
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
247 /** |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
248 @section Diffie-Hellman Functions |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
249 |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
250 These functions are reused where DH Key negotiation is necessary |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
251 outside of a channel (eg. session authentication). You'll need to |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
252 include <gmp.h> in order to use these functions. |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
253 */ |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
254 /* @{ */ |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
255 #ifdef __GMP_H__ |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
256 |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
257 |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
258 /** initialize and set a big integer to the Sametime Prime value */ |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
259 void mwInitDHPrime(mpz_t z); |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
260 |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
261 |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
262 /** initialize and set a big integer to the Sametime Base value */ |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
263 void mwInitDHBase(mpz_t z); |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
264 |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
265 |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
266 /** sets private to a randomly generated value, and calculates public |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
267 using the Sametime Prime and Base */ |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
268 void mwDHRandKeypair(mpz_t private, mpz_t public); |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
269 |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
270 |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
271 /** sets the shared key value based on the remote and private keys, |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
272 using the Sametime Prime and Base */ |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
273 void mwDHCalculateShared(mpz_t shared, mpz_t remote, mpz_t private); |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
274 |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
275 |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
276 /** Import a DH key from an opaque */ |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
277 void mwDHImportKey(mpz_t key, struct mwOpaque *o); |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
278 |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
279 |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
280 /** Export a DH key into an opaque */ |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
281 void mwDHExportKey(mpz_t key, struct mwOpaque *o); |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
282 |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
283 |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
284 #endif |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
285 /* @} */ |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
286 |
|
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
10969
diff
changeset
|
287 |
| 10969 | 288 #endif |
| 289 | |
| 290 |
