pidgin: cipher.h Source File

pidgin 2.14.4

Loading...
Searching...
No Matches
cipher.h
Go to the documentation of this file.
1
7/* purple
8 *
9 * Purple is the legal property of its developers, whose names are too numerous
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
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
26 */
27#ifndef PURPLE_CIPHER_H
28#define PURPLE_CIPHER_H
29
30#include <glib.h>
31#include <string.h>
32
33#define PURPLE_CIPHER(obj) ((PurpleCipher *)(obj))
34#define PURPLE_CIPHER_OPS(obj) ((PurpleCipherOps *)(obj))
35#define PURPLE_CIPHER_CONTEXT(obj) ((PurpleCipherContext *)(obj))
37 typedef struct _PurpleCipher PurpleCipher;
38 typedef struct _PurpleCipherOps PurpleCipherOps;
39 typedef struct _PurpleCipherContext PurpleCipherContext;
44 typedef enum _PurpleCipherBatchMode {
45 PURPLE_CIPHER_BATCH_MODE_ECB,
46 PURPLE_CIPHER_BATCH_MODE_CBC
47} PurpleCipherBatchMode;
48
52 typedef enum _PurpleCipherCaps {
53 PURPLE_CIPHER_CAPS_SET_OPT = 1 << 1,
54 PURPLE_CIPHER_CAPS_GET_OPT = 1 << 2,
55 PURPLE_CIPHER_CAPS_INIT = 1 << 3,
56 PURPLE_CIPHER_CAPS_RESET = 1 << 4,
57 PURPLE_CIPHER_CAPS_UNINIT = 1 << 5,
58 PURPLE_CIPHER_CAPS_SET_IV = 1 << 6,
59 PURPLE_CIPHER_CAPS_APPEND = 1 << 7,
60 PURPLE_CIPHER_CAPS_DIGEST = 1 << 8,
61 PURPLE_CIPHER_CAPS_ENCRYPT = 1 << 9,
62 PURPLE_CIPHER_CAPS_DECRYPT = 1 << 10,
63 PURPLE_CIPHER_CAPS_SET_SALT = 1 << 11,
64 PURPLE_CIPHER_CAPS_GET_SALT_SIZE = 1 << 12,
65 PURPLE_CIPHER_CAPS_SET_KEY = 1 << 13,
66 PURPLE_CIPHER_CAPS_GET_KEY_SIZE = 1 << 14,
67 PURPLE_CIPHER_CAPS_SET_BATCH_MODE = 1 << 15,
68 PURPLE_CIPHER_CAPS_GET_BATCH_MODE = 1 << 16,
69 PURPLE_CIPHER_CAPS_GET_BLOCK_SIZE = 1 << 17,
70 PURPLE_CIPHER_CAPS_SET_KEY_WITH_LEN = 1 << 18,
71 PURPLE_CIPHER_CAPS_UNKNOWN = 1 << 19
72} PurpleCipherCaps;
73
77 struct _PurpleCipherOps {
79 void (*set_option)(PurpleCipherContext *context, const gchar *name, void *value);
80
82 void *(*get_option)(PurpleCipherContext *context, const gchar *name);
83
85 void (*init)(PurpleCipherContext *context, void *extra);
86
88 void (*reset)(PurpleCipherContext *context, void *extra);
89
91 void (*uninit)(PurpleCipherContext *context);
92
94 void (*set_iv)(PurpleCipherContext *context, guchar *iv, size_t len);
95
97 void (*append)(PurpleCipherContext *context, const guchar *data, size_t len);
98
100 gboolean (*digest)(PurpleCipherContext *context, size_t in_len, guchar digest[], size_t *out_len);
101
103 int (*encrypt)(PurpleCipherContext *context, const guchar data[], size_t len, guchar output[], size_t *outlen);
104
106 int (*decrypt)(PurpleCipherContext *context, const guchar data[], size_t len, guchar output[], size_t *outlen);
107
109 void (*set_salt)(PurpleCipherContext *context, guchar *salt);
110
112 size_t (*get_salt_size)(PurpleCipherContext *context);
113
115 void (*set_key)(PurpleCipherContext *context, const guchar *key);
116
118 size_t (*get_key_size)(PurpleCipherContext *context);
119
121 void (*set_batch_mode)(PurpleCipherContext *context, PurpleCipherBatchMode mode);
122
124 PurpleCipherBatchMode (*get_batch_mode)(PurpleCipherContext *context);
125
127 size_t (*get_block_size)(PurpleCipherContext *context);
128
130 void (*set_key_with_len)(PurpleCipherContext *context, const guchar *key, size_t len);
131};
132
133G_BEGIN_DECLS
134
135/*****************************************************************************/
137/*****************************************************************************/
147 const gchar *purple_cipher_get_name(PurpleCipher *cipher);
148
156guint purple_cipher_get_capabilities(PurpleCipher *cipher);
157
170gboolean purple_cipher_digest_region(const gchar *name, const guchar *data, size_t data_len, size_t in_len, guchar digest[], size_t *out_len);
171
173/******************************************************************************/
175/******************************************************************************/
185 PurpleCipher *purple_ciphers_find_cipher(const gchar *name);
186
195 PurpleCipher *purple_ciphers_register_cipher(const gchar *name, PurpleCipherOps *ops);
196
204gboolean purple_ciphers_unregister_cipher(PurpleCipher *cipher);
205
212GList *purple_ciphers_get_ciphers(void);
213
215/******************************************************************************/
217/******************************************************************************/
225gpointer purple_ciphers_get_handle(void);
226
230 void purple_ciphers_init(void);
231
235 void purple_ciphers_uninit(void);
236
238/******************************************************************************/
240/******************************************************************************/
250 void purple_cipher_context_set_option(PurpleCipherContext *context, const gchar *name, gpointer value);
251
259gpointer purple_cipher_context_get_option(PurpleCipherContext *context, const gchar *name);
260
269 PurpleCipherContext *purple_cipher_context_new(PurpleCipher *cipher, void *extra);
270
279 PurpleCipherContext *purple_cipher_context_new_by_name(const gchar *name, void *extra);
280
288 void purple_cipher_context_reset(PurpleCipherContext *context, gpointer extra);
289
295 void purple_cipher_context_destroy(PurpleCipherContext *context);
296
305 void purple_cipher_context_set_iv(PurpleCipherContext *context, guchar *iv, size_t len);
306
314 void purple_cipher_context_append(PurpleCipherContext *context, const guchar *data, size_t len);
315
324gboolean purple_cipher_context_digest(PurpleCipherContext *context, size_t in_len, guchar digest[], size_t *out_len);
325
334gboolean purple_cipher_context_digest_to_str(PurpleCipherContext *context, size_t in_len, gchar digest_s[], size_t *out_len);
335
347gint purple_cipher_context_encrypt(PurpleCipherContext *context, const guchar data[], size_t len, guchar output[], size_t *outlen);
348
360gint purple_cipher_context_decrypt(PurpleCipherContext *context, const guchar data[], size_t len, guchar output[], size_t *outlen);
361
368 void purple_cipher_context_set_salt(PurpleCipherContext *context, guchar *salt);
369
377 size_t purple_cipher_context_get_salt_size(PurpleCipherContext *context);
378
385 void purple_cipher_context_set_key(PurpleCipherContext *context, const guchar *key);
386
394 size_t purple_cipher_context_get_key_size(PurpleCipherContext *context);
395
403 void purple_cipher_context_set_batch_mode(PurpleCipherContext *context, PurpleCipherBatchMode mode);
404
412 PurpleCipherBatchMode purple_cipher_context_get_batch_mode(PurpleCipherContext *context);
413
421 size_t purple_cipher_context_get_block_size(PurpleCipherContext *context);
422
431 void purple_cipher_context_set_key_with_len(PurpleCipherContext *context, const guchar *key, size_t len);
432
439 void purple_cipher_context_set_data(PurpleCipherContext *context, gpointer data);
440
448gpointer purple_cipher_context_get_data(PurpleCipherContext *context);
449
451/*****************************************************************************/
453/*****************************************************************************/
470gchar *purple_cipher_http_digest_calculate_session_key(
471 const gchar *algorithm, const gchar *username,
472 const gchar *realm, const gchar *password,
473 const gchar *nonce, const gchar *client_nonce);
474
491gchar *purple_cipher_http_digest_calculate_response(
492 const gchar *algorithm, const gchar *method,
493 const gchar *digest_uri, const gchar *qop,
494 const gchar *entity, const gchar *nonce,
495 const gchar *nonce_count, const gchar *client_nonce,
496 const gchar *session_key);
497
500G_END_DECLS
501
502#endif /* PURPLE_CIPHER_H */
PurpleCipherBatchMode
enum _PurpleCipherBatchMode PurpleCipherBatchMode
Modes for batch encrypters.
_PurpleCipherBatchMode
_PurpleCipherBatchMode
Modes for batch encrypters.
Definition: cipher.h:44
purple_ciphers_get_ciphers
GList * purple_ciphers_get_ciphers(void)
Gets the list of ciphers.
purple_cipher_digest_region
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)
Gets a digest from a cipher.
purple_cipher_context_set_batch_mode
void purple_cipher_context_set_batch_mode(PurpleCipherContext *context, PurpleCipherBatchMode mode)
Sets the batch mode of a context.
purple_cipher_context_get_option
gpointer purple_cipher_context_get_option(PurpleCipherContext *context, const gchar *name)
Gets the vale of an option on a cipher context.
PurpleCipherContext
struct _PurpleCipherContext PurpleCipherContext
A context for a PurpleCipher
Definition: cipher.h:39
purple_cipher_context_decrypt
gint purple_cipher_context_decrypt(PurpleCipherContext *context, const guchar data[], size_t len, guchar output[], size_t *outlen)
Decrypts data using the context.
purple_cipher_context_set_data
void purple_cipher_context_set_data(PurpleCipherContext *context, gpointer data)
Sets the cipher data for a context.
purple_ciphers_find_cipher
PurpleCipher * purple_ciphers_find_cipher(const gchar *name)
Finds a cipher by it's name.
purple_ciphers_unregister_cipher
gboolean purple_ciphers_unregister_cipher(PurpleCipher *cipher)
Unregisters a cipher.
purple_cipher_context_get_key_size
size_t purple_cipher_context_get_key_size(PurpleCipherContext *context)
Gets the key size for a context.
purple_ciphers_uninit
void purple_ciphers_uninit(void)
Uninitializes the cipher core.
purple_cipher_context_set_salt
void purple_cipher_context_set_salt(PurpleCipherContext *context, guchar *salt)
Sets the salt on a context.
purple_cipher_context_get_salt_size
size_t purple_cipher_context_get_salt_size(PurpleCipherContext *context)
Gets the size of the salt if the cipher supports it.
purple_cipher_context_set_key_with_len
void purple_cipher_context_set_key_with_len(PurpleCipherContext *context, const guchar *key, size_t len)
Sets the key with a given length on a context.
purple_cipher_context_digest_to_str
gboolean purple_cipher_context_digest_to_str(PurpleCipherContext *context, size_t in_len, gchar digest_s[], size_t *out_len)
Converts a guchar digest into a hex string.
purple_cipher_context_set_key
void purple_cipher_context_set_key(PurpleCipherContext *context, const guchar *key)
Sets the key on a context.
purple_cipher_context_set_iv
void purple_cipher_context_set_iv(PurpleCipherContext *context, guchar *iv, size_t len)
Sets the initialization vector for a context.
purple_cipher_get_capabilities
guint purple_cipher_get_capabilities(PurpleCipher *cipher)
Gets a cipher's capabilities.
purple_cipher_http_digest_calculate_response
gchar * purple_cipher_http_digest_calculate_response(const gchar *algorithm, const gchar *method, const gchar *digest_uri, const gchar *qop, const gchar *entity, const gchar *nonce, const gchar *nonce_count, const gchar *client_nonce, const gchar *session_key)
Calculate a response for HTTP Digest authentication.
purple_ciphers_get_handle
gpointer purple_ciphers_get_handle(void)
Gets the handle to the cipher subsystem.
purple_cipher_context_destroy
void purple_cipher_context_destroy(PurpleCipherContext *context)
Destorys a cipher context and deinitializes it.
purple_cipher_context_reset
void purple_cipher_context_reset(PurpleCipherContext *context, gpointer extra)
Resets a cipher context to it's default value.
_PurpleCipherCaps
_PurpleCipherCaps
The operation flags for a cipher.
Definition: cipher.h:52
PURPLE_CIPHER_CAPS_GET_OPT
@ PURPLE_CIPHER_CAPS_GET_OPT
Get option flag.
Definition: cipher.h:54
PURPLE_CIPHER_CAPS_SET_KEY
@ PURPLE_CIPHER_CAPS_SET_KEY
Set key flag
Definition: cipher.h:65
PURPLE_CIPHER_CAPS_SET_IV
@ PURPLE_CIPHER_CAPS_SET_IV
Set IV flag
Definition: cipher.h:58
PURPLE_CIPHER_CAPS_UNINIT
@ PURPLE_CIPHER_CAPS_UNINIT
Uninit flag
Definition: cipher.h:57
PURPLE_CIPHER_CAPS_ENCRYPT
@ PURPLE_CIPHER_CAPS_ENCRYPT
Encrypt flag
Definition: cipher.h:61
PURPLE_CIPHER_CAPS_GET_SALT_SIZE
@ PURPLE_CIPHER_CAPS_GET_SALT_SIZE
Get salt size flag
Definition: cipher.h:64
PURPLE_CIPHER_CAPS_SET_OPT
@ PURPLE_CIPHER_CAPS_SET_OPT
Set option flag.
Definition: cipher.h:53
PURPLE_CIPHER_CAPS_INIT
@ PURPLE_CIPHER_CAPS_INIT
Init flag
Definition: cipher.h:55
PURPLE_CIPHER_CAPS_GET_BLOCK_SIZE
@ PURPLE_CIPHER_CAPS_GET_BLOCK_SIZE
The get block size flag.
Definition: cipher.h:69
PURPLE_CIPHER_CAPS_SET_KEY_WITH_LEN
@ PURPLE_CIPHER_CAPS_SET_KEY_WITH_LEN
The set key with length flag.
Definition: cipher.h:70
PURPLE_CIPHER_CAPS_DECRYPT
@ PURPLE_CIPHER_CAPS_DECRYPT
Decrypt flag
Definition: cipher.h:62
PURPLE_CIPHER_CAPS_UNKNOWN
@ PURPLE_CIPHER_CAPS_UNKNOWN
Unknown
Definition: cipher.h:71
PURPLE_CIPHER_CAPS_SET_SALT
@ PURPLE_CIPHER_CAPS_SET_SALT
Set salt flag
Definition: cipher.h:63
PURPLE_CIPHER_CAPS_RESET
@ PURPLE_CIPHER_CAPS_RESET
Reset flag
Definition: cipher.h:56
PURPLE_CIPHER_CAPS_GET_BATCH_MODE
@ PURPLE_CIPHER_CAPS_GET_BATCH_MODE
Get batch mode flag.
Definition: cipher.h:68
PURPLE_CIPHER_CAPS_SET_BATCH_MODE
@ PURPLE_CIPHER_CAPS_SET_BATCH_MODE
Set batch mode flag.
Definition: cipher.h:67
PURPLE_CIPHER_CAPS_DIGEST
@ PURPLE_CIPHER_CAPS_DIGEST
Digest flag
Definition: cipher.h:60
PURPLE_CIPHER_CAPS_APPEND
@ PURPLE_CIPHER_CAPS_APPEND
Append flag
Definition: cipher.h:59
PURPLE_CIPHER_CAPS_GET_KEY_SIZE
@ PURPLE_CIPHER_CAPS_GET_KEY_SIZE
Get key size flag
Definition: cipher.h:66
purple_cipher_http_digest_calculate_session_key
gchar * purple_cipher_http_digest_calculate_session_key(const gchar *algorithm, const gchar *username, const gchar *realm, const gchar *password, const gchar *nonce, const gchar *client_nonce)
Calculates a session key for HTTP Digest authentation.
purple_cipher_context_encrypt
gint purple_cipher_context_encrypt(PurpleCipherContext *context, const guchar data[], size_t len, guchar output[], size_t *outlen)
Encrypts data using the context.
purple_cipher_context_new_by_name
PurpleCipherContext * purple_cipher_context_new_by_name(const gchar *name, void *extra)
Creates a new cipher context by the cipher name and initializes it.
purple_cipher_context_get_batch_mode
PurpleCipherBatchMode purple_cipher_context_get_batch_mode(PurpleCipherContext *context)
Gets the batch mode of a context.
purple_cipher_context_new
PurpleCipherContext * purple_cipher_context_new(PurpleCipher *cipher, void *extra)
Creates a new cipher context and initializes it.
purple_cipher_context_get_data
gpointer purple_cipher_context_get_data(PurpleCipherContext *context)
Gets the cipher data for a context.
purple_cipher_context_append
void purple_cipher_context_append(PurpleCipherContext *context, const guchar *data, size_t len)
Appends data to the context.
purple_cipher_get_name
const gchar * purple_cipher_get_name(PurpleCipher *cipher)
Gets a cipher's name.
PurpleCipherCaps
enum _PurpleCipherCaps PurpleCipherCaps
The operation flags for a cipher.
purple_cipher_context_digest
gboolean purple_cipher_context_digest(PurpleCipherContext *context, size_t in_len, guchar digest[], size_t *out_len)
Digests a context.
purple_ciphers_init
void purple_ciphers_init(void)
Initializes the cipher core.
PurpleCipher
struct _PurpleCipher PurpleCipher
A handle to a PurpleCipher
Definition: cipher.h:37
purple_cipher_context_set_option
void purple_cipher_context_set_option(PurpleCipherContext *context, const gchar *name, gpointer value)
Sets the value an option on a cipher context.
purple_ciphers_register_cipher
PurpleCipher * purple_ciphers_register_cipher(const gchar *name, PurpleCipherOps *ops)
Registers a cipher as a usable cipher.
purple_cipher_context_get_block_size
size_t purple_cipher_context_get_block_size(PurpleCipherContext *context)
Gets the block size of a context.
_PurpleCipherOps
The operations of a cipher.
Definition: cipher.h:77
_PurpleCipherOps::set_option
void(* set_option)(PurpleCipherContext *context, const gchar *name, void *value)
The set option function.
Definition: cipher.h:79
_PurpleCipherOps::decrypt
int(* decrypt)(PurpleCipherContext *context, const guchar data[], size_t len, guchar output[], size_t *outlen)
The decrypt function.
Definition: cipher.h:106
_PurpleCipherOps::uninit
void(* uninit)(PurpleCipherContext *context)
The uninit function.
Definition: cipher.h:91
_PurpleCipherOps::set_key
void(* set_key)(PurpleCipherContext *context, const guchar *key)
The set key function.
Definition: cipher.h:115
_PurpleCipherOps::digest
gboolean(* digest)(PurpleCipherContext *context, size_t in_len, guchar digest[], size_t *out_len)
The digest function.
Definition: cipher.h:100
_PurpleCipherOps::get_batch_mode
PurpleCipherBatchMode(* get_batch_mode)(PurpleCipherContext *context)
The get batch mode function.
Definition: cipher.h:124
_PurpleCipherOps::reset
void(* reset)(PurpleCipherContext *context, void *extra)
The reset function.
Definition: cipher.h:88
_PurpleCipherOps::get_salt_size
size_t(* get_salt_size)(PurpleCipherContext *context)
The get salt size function.
Definition: cipher.h:112
_PurpleCipherOps::get_block_size
size_t(* get_block_size)(PurpleCipherContext *context)
The get block size function.
Definition: cipher.h:127
_PurpleCipherOps::encrypt
int(* encrypt)(PurpleCipherContext *context, const guchar data[], size_t len, guchar output[], size_t *outlen)
The encrypt function.
Definition: cipher.h:103
_PurpleCipherOps::get_key_size
size_t(* get_key_size)(PurpleCipherContext *context)
The get key size function.
Definition: cipher.h:118
_PurpleCipherOps::append
void(* append)(PurpleCipherContext *context, const guchar *data, size_t len)
The append data function.
Definition: cipher.h:97
_PurpleCipherOps::set_key_with_len
void(* set_key_with_len)(PurpleCipherContext *context, const guchar *key, size_t len)
The set key with length function.
Definition: cipher.h:130
_PurpleCipherOps::set_batch_mode
void(* set_batch_mode)(PurpleCipherContext *context, PurpleCipherBatchMode mode)
The set batch mode function.
Definition: cipher.h:121
_PurpleCipherOps::set_salt
void(* set_salt)(PurpleCipherContext *context, guchar *salt)
The set salt function.
Definition: cipher.h:109
_PurpleCipherOps::set_iv
void(* set_iv)(PurpleCipherContext *context, guchar *iv, size_t len)
The set initialization vector function.
Definition: cipher.h:94
_PurpleCipherOps::init
void(* init)(PurpleCipherContext *context, void *extra)
The init function.
Definition: cipher.h:85