Mon, 25 Jun 2012 01:25:45 -0400
Fix minor indent issue.
| 10684 | 1 | /** |
| 15884 | 2 | * @file cipher.h Purple Cipher API |
| 10684 | 3 | * @ingroup core |
|
20889
3d0ef192f98c
All the links to libpurple signal pages were in the comment containing the
Will Thompson <resiak@pidgin.im>
parents:
20147
diff
changeset
|
4 | * @see @ref cipher-signals |
|
20147
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
5 | */ |
|
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
6 | |
|
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
7 | /* purple |
| 10684 | 8 | * |
| 15884 | 9 | * Purple is the legal property of its developers, whose names are too numerous |
| 10684 | 10 | * to list here. Please refer to the COPYRIGHT file distributed with this |
| 11 | * source distribution. | |
| 12 | * | |
| 13 | * This program is free software; you can redistribute it and/or modify | |
| 14 | * it under the terms of the GNU General Public License as published by | |
| 15 | * the Free Software Foundation; either version 2 of the License, or | |
| 16 | * (at your option) any later version. | |
| 17 | * | |
| 18 | * This program is distributed in the hope that it will be useful, | |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 21 | * GNU General Public License for more details. | |
| 22 | * | |
| 23 | * You should have received a copy of the GNU General Public License | |
| 24 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18412
diff
changeset
|
25 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 10684 | 26 | */ |
| 15884 | 27 | #ifndef PURPLE_CIPHER_H |
| 28 | #define PURPLE_CIPHER_H | |
| 10684 | 29 | |
| 30 | #include <glib.h> | |
|
31428
f392265bbe2d
included string.h in cipher.h since almost all of the ciphers use it.
Gary Kramlich <grim@reaperworld.com>
parents:
31421
diff
changeset
|
31 | #include <string.h> |
| 10684 | 32 | |
| 15884 | 33 | #define PURPLE_CIPHER(obj) ((PurpleCipher *)(obj)) /**< PurpleCipher typecast helper */ |
| 34 | #define PURPLE_CIPHER_OPS(obj) ((PurpleCipherOps *)(obj)) /**< PurpleCipherInfo typecase helper */ | |
| 35 | #define PURPLE_CIPHER_CONTEXT(obj) ((PurpleCipherContext *)(obj)) /**< PurpleCipherContext typecast helper */ | |
| 10684 | 36 | |
| 15884 | 37 | typedef struct _PurpleCipher PurpleCipher; /**< A handle to a PurpleCipher */ |
| 38 | typedef struct _PurpleCipherOps PurpleCipherOps; /**< Ops for a PurpleCipher */ | |
| 39 | typedef struct _PurpleCipherContext PurpleCipherContext; /**< A context for a PurpleCipher */ | |
| 10684 | 40 | |
|
22024
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
41 | /** |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
42 | * Modes for batch encrypters |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
43 | */ |
|
32206
a2c62b07ae5a
Please correct me if I'm wrong, but I don't think we gain anything
Mark Doliner <markdoliner@pidgin.im>
parents:
31430
diff
changeset
|
44 | typedef enum { |
|
22024
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
45 | PURPLE_CIPHER_BATCH_MODE_ECB, |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
46 | PURPLE_CIPHER_BATCH_MODE_CBC |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
47 | } PurpleCipherBatchMode; |
| 10684 | 48 | |
| 49 | /** | |
| 50 | * The operation flags for a cipher | |
| 51 | */ | |
|
32206
a2c62b07ae5a
Please correct me if I'm wrong, but I don't think we gain anything
Mark Doliner <markdoliner@pidgin.im>
parents:
31430
diff
changeset
|
52 | typedef enum { |
|
22024
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
53 | PURPLE_CIPHER_CAPS_SET_OPT = 1 << 1, /**< Set option flag */ |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
54 | PURPLE_CIPHER_CAPS_GET_OPT = 1 << 2, /**< Get option flag */ |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
55 | PURPLE_CIPHER_CAPS_INIT = 1 << 3, /**< Init flag */ |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
56 | PURPLE_CIPHER_CAPS_RESET = 1 << 4, /**< Reset flag */ |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
57 | PURPLE_CIPHER_CAPS_UNINIT = 1 << 5, /**< Uninit flag */ |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
58 | PURPLE_CIPHER_CAPS_SET_IV = 1 << 6, /**< Set IV flag */ |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
59 | PURPLE_CIPHER_CAPS_APPEND = 1 << 7, /**< Append flag */ |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
60 | PURPLE_CIPHER_CAPS_DIGEST = 1 << 8, /**< Digest flag */ |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
61 | PURPLE_CIPHER_CAPS_ENCRYPT = 1 << 9, /**< Encrypt flag */ |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
62 | PURPLE_CIPHER_CAPS_DECRYPT = 1 << 10, /**< Decrypt flag */ |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
63 | PURPLE_CIPHER_CAPS_SET_SALT = 1 << 11, /**< Set salt flag */ |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
64 | PURPLE_CIPHER_CAPS_GET_SALT_SIZE = 1 << 12, /**< Get salt size flag */ |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
65 | PURPLE_CIPHER_CAPS_SET_KEY = 1 << 13, /**< Set key flag */ |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
66 | PURPLE_CIPHER_CAPS_GET_KEY_SIZE = 1 << 14, /**< Get key size flag */ |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
67 | PURPLE_CIPHER_CAPS_SET_BATCH_MODE = 1 << 15, /**< Set batch mode flag */ |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
68 | PURPLE_CIPHER_CAPS_GET_BATCH_MODE = 1 << 16, /**< Get batch mode flag */ |
|
22025
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
69 | PURPLE_CIPHER_CAPS_GET_BLOCK_SIZE = 1 << 17, /**< The get block size flag */ |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
70 | PURPLE_CIPHER_CAPS_SET_KEY_WITH_LEN = 1 << 18, /**< The set key with length flag */ |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
71 | PURPLE_CIPHER_CAPS_UNKNOWN = 1 << 19 /**< Unknown */ |
| 15884 | 72 | } PurpleCipherCaps; |
| 10684 | 73 | |
| 74 | /** | |
| 75 | * The operations of a cipher. Every cipher must implement one of these. | |
| 76 | */ | |
| 15884 | 77 | struct _PurpleCipherOps { |
| 10684 | 78 | /** The set option function */ |
| 15884 | 79 | void (*set_option)(PurpleCipherContext *context, const gchar *name, void *value); |
| 10684 | 80 | |
| 81 | /** The get option function */ | |
| 15884 | 82 | void *(*get_option)(PurpleCipherContext *context, const gchar *name); |
| 10684 | 83 | |
| 84 | /** The init function */ | |
| 15884 | 85 | void (*init)(PurpleCipherContext *context, void *extra); |
| 10684 | 86 | |
| 87 | /** The reset function */ | |
| 15884 | 88 | void (*reset)(PurpleCipherContext *context, void *extra); |
| 10684 | 89 | |
| 90 | /** The uninit function */ | |
| 15884 | 91 | void (*uninit)(PurpleCipherContext *context); |
| 10684 | 92 | |
| 93 | /** The set initialization vector function */ | |
| 15884 | 94 | void (*set_iv)(PurpleCipherContext *context, guchar *iv, size_t len); |
| 10684 | 95 | |
| 96 | /** The append data function */ | |
| 15884 | 97 | void (*append)(PurpleCipherContext *context, const guchar *data, size_t len); |
| 10684 | 98 | |
| 99 | /** The digest function */ | |
| 15884 | 100 | gboolean (*digest)(PurpleCipherContext *context, size_t in_len, guchar digest[], size_t *out_len); |
| 10684 | 101 | |
| 102 | /** The encrypt function */ | |
| 15884 | 103 | int (*encrypt)(PurpleCipherContext *context, const guchar data[], size_t len, guchar output[], size_t *outlen); |
| 10684 | 104 | |
| 105 | /** The decrypt function */ | |
| 15884 | 106 | int (*decrypt)(PurpleCipherContext *context, const guchar data[], size_t len, guchar output[], size_t *outlen); |
| 10684 | 107 | |
| 108 | /** The set salt function */ | |
| 15884 | 109 | void (*set_salt)(PurpleCipherContext *context, guchar *salt); |
| 10684 | 110 | |
| 111 | /** The get salt size function */ | |
| 15884 | 112 | size_t (*get_salt_size)(PurpleCipherContext *context); |
| 10684 | 113 | |
| 114 | /** The set key function */ | |
| 15884 | 115 | void (*set_key)(PurpleCipherContext *context, const guchar *key); |
| 10684 | 116 | |
| 117 | /** The get key size function */ | |
| 15884 | 118 | size_t (*get_key_size)(PurpleCipherContext *context); |
|
16743
1ce5ffe12e2a
Initial addition of padding for ui_ops and other class-like structs
Gary Kramlich <grim@reaperworld.com>
parents:
15884
diff
changeset
|
119 | |
|
22024
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
120 | /** The set batch mode function */ |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
121 | void (*set_batch_mode)(PurpleCipherContext *context, PurpleCipherBatchMode mode); |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
122 | |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
123 | /** The get batch mode function */ |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
124 | PurpleCipherBatchMode (*get_batch_mode)(PurpleCipherContext *context); |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
125 | |
|
22025
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
126 | /** The get block size function */ |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
127 | size_t (*get_block_size)(PurpleCipherContext *context); |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
128 | |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
129 | /** The set key with length function */ |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
130 | void (*set_key_with_len)(PurpleCipherContext *context, const guchar *key, size_t len); |
| 10684 | 131 | }; |
| 132 | ||
|
31421
713fb035d563
Created a new branch to break the ciphers out to their own files. Also I've now exposed purple_g_checksum_* if we're on glib >= 2.16.0
Gary Kramlich <grim@reaperworld.com>
parents:
25888
diff
changeset
|
133 | G_BEGIN_DECLS |
| 10684 | 134 | |
| 135 | /*****************************************************************************/ | |
| 15884 | 136 | /** @name PurpleCipher API */ |
| 10684 | 137 | /*****************************************************************************/ |
| 138 | /*@{*/ | |
| 139 | ||
| 140 | /** | |
| 141 | * Gets a cipher's name | |
| 142 | * | |
| 143 | * @param cipher The cipher handle | |
| 144 | * | |
| 145 | * @return The cipher's name | |
| 146 | */ | |
| 15884 | 147 | const gchar *purple_cipher_get_name(PurpleCipher *cipher); |
| 10684 | 148 | |
| 149 | /** | |
| 150 | * Gets a cipher's capabilities | |
| 151 | * | |
| 152 | * @param cipher The cipher handle | |
| 153 | * | |
| 154 | * @return The cipher's info | |
| 155 | */ | |
| 15884 | 156 | guint purple_cipher_get_capabilities(PurpleCipher *cipher); |
| 10684 | 157 | |
| 158 | /** | |
| 159 | * Gets a digest from a cipher | |
| 160 | * | |
| 10687 | 161 | * @param name The cipher's name |
| 162 | * @param data The data to hash | |
| 163 | * @param data_len The length of the data | |
| 164 | * @param in_len The length of the buffer | |
| 165 | * @param digest The returned digest | |
| 166 | * @param out_len The length written | |
| 167 | * | |
| 168 | * @return @c TRUE if successful, @c FALSE otherwise | |
| 10684 | 169 | */ |
| 15884 | 170 | gboolean purple_cipher_digest_region(const gchar *name, const guchar *data, size_t data_len, size_t in_len, guchar digest[], size_t *out_len); |
| 10684 | 171 | |
| 172 | /*@}*/ | |
| 173 | /******************************************************************************/ | |
| 15884 | 174 | /** @name PurpleCiphers API */ |
| 10684 | 175 | /******************************************************************************/ |
| 176 | /*@{*/ | |
| 177 | ||
| 178 | /** | |
| 179 | * Finds a cipher by it's name | |
| 180 | * | |
| 181 | * @param name The name of the cipher to find | |
| 182 | * | |
| 183 | * @return The cipher handle or @c NULL | |
| 184 | */ | |
| 15884 | 185 | PurpleCipher *purple_ciphers_find_cipher(const gchar *name); |
| 10684 | 186 | |
| 187 | /** | |
| 188 | * Registers a cipher as a usable cipher | |
| 189 | * | |
| 190 | * @param name The name of the new cipher | |
| 191 | * @param ops The cipher ops to register | |
| 192 | * | |
| 193 | * @return The handle to the new cipher or @c NULL if it failed | |
| 194 | */ | |
| 15884 | 195 | PurpleCipher *purple_ciphers_register_cipher(const gchar *name, PurpleCipherOps *ops); |
| 10684 | 196 | |
| 197 | /** | |
| 198 | * Unregisters a cipher | |
| 199 | * | |
| 200 | * @param cipher The cipher handle to unregister | |
| 201 | * | |
| 202 | * @return Whether or not the cipher was successfully unloaded | |
| 203 | */ | |
| 15884 | 204 | gboolean purple_ciphers_unregister_cipher(PurpleCipher *cipher); |
| 10684 | 205 | |
| 206 | /** | |
| 207 | * Gets the list of ciphers | |
| 208 | * | |
| 209 | * @return The list of available ciphers | |
| 210 | * @note This list should not be modified, it is owned by the cipher core | |
| 211 | */ | |
| 15884 | 212 | GList *purple_ciphers_get_ciphers(void); |
| 10684 | 213 | |
| 214 | /*@}*/ | |
| 215 | /******************************************************************************/ | |
| 15884 | 216 | /** @name PurpleCipher Subsystem API */ |
| 10684 | 217 | /******************************************************************************/ |
| 218 | /*@{*/ | |
| 219 | ||
| 220 | /** | |
| 221 | * Gets the handle to the cipher subsystem | |
| 222 | * | |
| 223 | * @return The handle to the cipher subsystem | |
| 224 | */ | |
| 15884 | 225 | gpointer purple_ciphers_get_handle(void); |
| 10684 | 226 | |
| 227 | /** | |
| 228 | * Initializes the cipher core | |
| 229 | */ | |
| 15884 | 230 | void purple_ciphers_init(void); |
| 10684 | 231 | |
| 232 | /** | |
| 233 | * Uninitializes the cipher core | |
| 234 | */ | |
| 15884 | 235 | void purple_ciphers_uninit(void); |
| 10684 | 236 | |
| 237 | /*@}*/ | |
| 238 | /******************************************************************************/ | |
| 15884 | 239 | /** @name PurpleCipherContext API */ |
| 10684 | 240 | /******************************************************************************/ |
| 241 | /*@{*/ | |
| 242 | ||
| 243 | /** | |
| 244 | * Sets the value an option on a cipher context | |
| 245 | * | |
| 246 | * @param context The cipher context | |
| 247 | * @param name The name of the option | |
| 248 | * @param value The value to set | |
| 249 | */ | |
| 15884 | 250 | void purple_cipher_context_set_option(PurpleCipherContext *context, const gchar *name, gpointer value); |
| 10684 | 251 | |
| 252 | /** | |
| 253 | * Gets the vale of an option on a cipher context | |
| 254 | * | |
| 255 | * @param context The cipher context | |
| 256 | * @param name The name of the option | |
| 257 | * @return The value of the option | |
| 258 | */ | |
| 15884 | 259 | gpointer purple_cipher_context_get_option(PurpleCipherContext *context, const gchar *name); |
| 10684 | 260 | |
| 261 | /** | |
| 262 | * Creates a new cipher context and initializes it | |
| 263 | * | |
| 264 | * @param cipher The cipher to use | |
| 265 | * @param extra Extra data for the specific cipher | |
| 266 | * | |
| 267 | * @return The new cipher context | |
| 268 | */ | |
| 15884 | 269 | PurpleCipherContext *purple_cipher_context_new(PurpleCipher *cipher, void *extra); |
| 10684 | 270 | |
| 271 | /** | |
| 272 | * Creates a new cipher context by the cipher name and initializes it | |
| 273 | * | |
| 274 | * @param name The cipher's name | |
| 275 | * @param extra Extra data for the specific cipher | |
| 276 | * | |
| 277 | * @return The new cipher context | |
| 278 | */ | |
| 15884 | 279 | PurpleCipherContext *purple_cipher_context_new_by_name(const gchar *name, void *extra); |
| 10684 | 280 | |
| 281 | /** | |
| 282 | * Resets a cipher context to it's default value | |
| 283 | * @note If you have set an IV you will have to set it after resetting | |
| 284 | * | |
| 285 | * @param context The context to reset | |
| 286 | * @param extra Extra data for the specific cipher | |
| 287 | */ | |
| 15884 | 288 | void purple_cipher_context_reset(PurpleCipherContext *context, gpointer extra); |
| 10684 | 289 | |
| 290 | /** | |
| 291 | * Destorys a cipher context and deinitializes it | |
| 292 | * | |
| 293 | * @param context The cipher context to destory | |
| 294 | */ | |
| 15884 | 295 | void purple_cipher_context_destroy(PurpleCipherContext *context); |
| 10684 | 296 | |
| 297 | /** | |
| 298 | * Sets the initialization vector for a context | |
| 299 | * @note This should only be called right after a cipher context is created or reset | |
| 300 | * | |
| 301 | * @param context The context to set the IV to | |
| 302 | * @param iv The initialization vector to set | |
| 303 | * @param len The len of the IV | |
| 304 | */ | |
| 15884 | 305 | void purple_cipher_context_set_iv(PurpleCipherContext *context, guchar *iv, size_t len); |
| 10684 | 306 | |
| 307 | /** | |
| 308 | * Appends data to the context | |
| 309 | * | |
| 310 | * @param context The context to append data to | |
| 311 | * @param data The data to append | |
| 312 | * @param len The length of the data | |
| 313 | */ | |
| 15884 | 314 | void purple_cipher_context_append(PurpleCipherContext *context, const guchar *data, size_t len); |
| 10684 | 315 | |
| 316 | /** | |
| 317 | * Digests a context | |
| 318 | * | |
| 319 | * @param context The context to digest | |
| 10687 | 320 | * @param in_len The length of the buffer |
| 10684 | 321 | * @param digest The return buffer for the digest |
| 10687 | 322 | * @param out_len The length of the returned value |
| 10684 | 323 | */ |
| 15884 | 324 | gboolean purple_cipher_context_digest(PurpleCipherContext *context, size_t in_len, guchar digest[], size_t *out_len); |
| 10684 | 325 | |
| 326 | /** | |
|
11183
be87fe695c93
[gaim-migrate @ 13295]
Mark Doliner <markdoliner@pidgin.im>
parents:
10687
diff
changeset
|
327 | * Converts a guchar digest into a hex string |
| 10684 | 328 | * |
| 329 | * @param context The context to get a digest from | |
| 10687 | 330 | * @param in_len The length of the buffer |
| 10684 | 331 | * @param digest_s The return buffer for the string digest |
| 10687 | 332 | * @param out_len The length of the returned value |
| 10684 | 333 | */ |
| 15884 | 334 | gboolean purple_cipher_context_digest_to_str(PurpleCipherContext *context, size_t in_len, gchar digest_s[], size_t *out_len); |
| 10684 | 335 | |
| 336 | /** | |
| 337 | * Encrypts data using the context | |
| 338 | * | |
| 339 | * @param context The context | |
| 340 | * @param data The data to encrypt | |
| 341 | * @param len The length of the data | |
| 342 | * @param output The output buffer | |
| 343 | * @param outlen The len of data that was outputed | |
| 344 | * | |
| 345 | * @return A cipher specific status code | |
| 346 | */ | |
| 15884 | 347 | gint purple_cipher_context_encrypt(PurpleCipherContext *context, const guchar data[], size_t len, guchar output[], size_t *outlen); |
| 10684 | 348 | |
| 349 | /** | |
| 350 | * Decrypts data using the context | |
| 351 | * | |
| 352 | * @param context The context | |
| 353 | * @param data The data to encrypt | |
| 354 | * @param len The length of the returned value | |
| 355 | * @param output The output buffer | |
| 356 | * @param outlen The len of data that was outputed | |
| 357 | * | |
| 358 | * @return A cipher specific status code | |
| 359 | */ | |
| 15884 | 360 | gint purple_cipher_context_decrypt(PurpleCipherContext *context, const guchar data[], size_t len, guchar output[], size_t *outlen); |
| 10684 | 361 | |
| 362 | /** | |
| 363 | * Sets the salt on a context | |
| 364 | * | |
|
22024
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
365 | * @param context The context whose salt to set |
| 10684 | 366 | * @param salt The salt |
| 367 | */ | |
| 15884 | 368 | void purple_cipher_context_set_salt(PurpleCipherContext *context, guchar *salt); |
| 10684 | 369 | |
| 370 | /** | |
| 371 | * Gets the size of the salt if the cipher supports it | |
| 372 | * | |
|
22024
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
373 | * @param context The context whose salt size to get |
| 10684 | 374 | * |
| 375 | * @return The size of the salt | |
| 376 | */ | |
| 15884 | 377 | size_t purple_cipher_context_get_salt_size(PurpleCipherContext *context); |
| 10684 | 378 | |
| 379 | /** | |
| 380 | * Sets the key on a context | |
| 381 | * | |
|
22024
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
382 | * @param context The context whose key to set |
| 10684 | 383 | * @param key The key |
| 384 | */ | |
| 15884 | 385 | void purple_cipher_context_set_key(PurpleCipherContext *context, const guchar *key); |
| 10684 | 386 | |
| 387 | /** | |
| 388 | * Gets the key size for a context | |
| 389 | * | |
|
22024
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
390 | * @param context The context whose key size to get |
| 10684 | 391 | * |
| 392 | * @return The size of the key | |
| 393 | */ | |
| 15884 | 394 | size_t purple_cipher_context_get_key_size(PurpleCipherContext *context); |
| 10684 | 395 | |
| 396 | /** | |
|
22024
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
397 | * Sets the batch mode of a context |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
398 | * |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
399 | * @param context The context whose batch mode to set |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
400 | * @param mode The batch mode under which the cipher should operate |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
401 | * |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
402 | */ |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
403 | void purple_cipher_context_set_batch_mode(PurpleCipherContext *context, PurpleCipherBatchMode mode); |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
404 | |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
405 | /** |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
406 | * Gets the batch mode of a context |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
407 | * |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
408 | * @param context The context whose batch mode to get |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
409 | * |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
410 | * @return The batch mode under which the cipher is operating |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
411 | */ |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
412 | PurpleCipherBatchMode purple_cipher_context_get_batch_mode(PurpleCipherContext *context); |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
413 | |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
414 | /** |
|
22025
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
415 | * Gets the block size of a context |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
416 | * |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
417 | * @param context The context whose block size to get |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
418 | * |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
419 | * @return The block size of the context |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
420 | */ |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
421 | size_t purple_cipher_context_get_block_size(PurpleCipherContext *context); |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
422 | |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
423 | /** |
|
25888
d0fdd378a635
Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents:
22025
diff
changeset
|
424 | * Sets the key with a given length on a context |
|
22025
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
425 | * |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
426 | * @param context The context whose key to set |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
427 | * @param key The key |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
428 | * @param len The length of the key |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
429 | * |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
430 | */ |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
431 | void purple_cipher_context_set_key_with_len(PurpleCipherContext *context, const guchar *key, size_t len); |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
432 | |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
433 | /** |
| 10684 | 434 | * Sets the cipher data for a context |
| 435 | * | |
|
22024
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
436 | * @param context The context whose cipher data to set |
| 10684 | 437 | * @param data The cipher data to set |
| 438 | */ | |
| 15884 | 439 | void purple_cipher_context_set_data(PurpleCipherContext *context, gpointer data); |
| 10684 | 440 | |
| 441 | /** | |
| 442 | * Gets the cipher data for a context | |
| 443 | * | |
|
22024
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20889
diff
changeset
|
444 | * @param context The context whose cipher data to get |
| 10684 | 445 | * |
| 446 | * @return The cipher data | |
| 447 | */ | |
| 15884 | 448 | gpointer purple_cipher_context_get_data(PurpleCipherContext *context); |
| 10684 | 449 | |
|
12388
3a25d96abdaf
[gaim-migrate @ 14694]
Richard Laager <rlaager@pidgin.im>
parents:
12382
diff
changeset
|
450 | /*@}*/ |
|
3a25d96abdaf
[gaim-migrate @ 14694]
Richard Laager <rlaager@pidgin.im>
parents:
12382
diff
changeset
|
451 | /*****************************************************************************/ |
| 15884 | 452 | /** @name Purple Cipher HTTP Digest Helper Functions */ |
|
12388
3a25d96abdaf
[gaim-migrate @ 14694]
Richard Laager <rlaager@pidgin.im>
parents:
12382
diff
changeset
|
453 | /*****************************************************************************/ |
|
3a25d96abdaf
[gaim-migrate @ 14694]
Richard Laager <rlaager@pidgin.im>
parents:
12382
diff
changeset
|
454 | /*@{*/ |
|
3a25d96abdaf
[gaim-migrate @ 14694]
Richard Laager <rlaager@pidgin.im>
parents:
12382
diff
changeset
|
455 | |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
456 | /** |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
457 | * Calculates a session key for HTTP Digest authentation |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
458 | * |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
459 | * See RFC 2617 for more information. |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
460 | * |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
461 | * @param algorithm The hash algorithm to use |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
462 | * @param username The username provided by the user |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
463 | * @param realm The authentication realm provided by the server |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
464 | * @param password The password provided by the user |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
465 | * @param nonce The nonce provided by the server |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
466 | * @param client_nonce The nonce provided by the client |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
467 | * |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
468 | * @return The session key, or @c NULL if an error occurred. |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
469 | */ |
| 15884 | 470 | gchar *purple_cipher_http_digest_calculate_session_key( |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
471 | const gchar *algorithm, const gchar *username, |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
472 | const gchar *realm, const gchar *password, |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
473 | const gchar *nonce, const gchar *client_nonce); |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
474 | |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
475 | /** Calculate a response for HTTP Digest authentication |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
476 | * |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
477 | * See RFC 2617 for more information. |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
478 | * |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
479 | * @param algorithm The hash algorithm to use |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
480 | * @param method The HTTP method in use |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
481 | * @param digest_uri The URI from the initial request |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
482 | * @param qop The "quality of protection" |
|
12389
7196ba664097
[gaim-migrate @ 14695]
Richard Laager <rlaager@pidgin.im>
parents:
12388
diff
changeset
|
483 | * @param entity The entity body |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
484 | * @param nonce The nonce provided by the server |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
485 | * @param nonce_count The nonce count |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
486 | * @param client_nonce The nonce provided by the client |
| 15884 | 487 | * @param session_key The session key from purple_cipher_http_digest_calculate_session_key() |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
488 | * |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
489 | * @return The hashed response, or @c NULL if an error occurred. |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
490 | */ |
| 15884 | 491 | gchar *purple_cipher_http_digest_calculate_response( |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
492 | const gchar *algorithm, const gchar *method, |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
493 | const gchar *digest_uri, const gchar *qop, |
|
12389
7196ba664097
[gaim-migrate @ 14695]
Richard Laager <rlaager@pidgin.im>
parents:
12388
diff
changeset
|
494 | const gchar *entity, const gchar *nonce, |
|
7196ba664097
[gaim-migrate @ 14695]
Richard Laager <rlaager@pidgin.im>
parents:
12388
diff
changeset
|
495 | const gchar *nonce_count, const gchar *client_nonce, |
|
7196ba664097
[gaim-migrate @ 14695]
Richard Laager <rlaager@pidgin.im>
parents:
12388
diff
changeset
|
496 | const gchar *session_key); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
497 | |
| 10684 | 498 | /*@}*/ |
|
31421
713fb035d563
Created a new branch to break the ciphers out to their own files. Also I've now exposed purple_g_checksum_* if we're on glib >= 2.16.0
Gary Kramlich <grim@reaperworld.com>
parents:
25888
diff
changeset
|
499 | |
|
713fb035d563
Created a new branch to break the ciphers out to their own files. Also I've now exposed purple_g_checksum_* if we're on glib >= 2.16.0
Gary Kramlich <grim@reaperworld.com>
parents:
25888
diff
changeset
|
500 | G_END_DECLS |
| 10684 | 501 | |
| 15884 | 502 | #endif /* PURPLE_CIPHER_H */ |