pidgin/android/libpurple

78b42fd69e02
Parents 1046f312d35e
Children 773899cbd05a
ciphers cleanup: passing keys with length by default
--- a/libpurple/cipher.c Wed May 01 11:48:56 2013 +0200
+++ b/libpurple/cipher.c Sun May 05 13:15:07 2013 +0200
@@ -106,16 +106,12 @@
caps |= PURPLE_CIPHER_CAPS_GET_SALT_SIZE;
if(ops->set_key)
caps |= PURPLE_CIPHER_CAPS_SET_KEY;
- if(ops->get_key_size)
- caps |= PURPLE_CIPHER_CAPS_GET_KEY_SIZE;
if(ops->set_batch_mode)
caps |= PURPLE_CIPHER_CAPS_SET_BATCH_MODE;
if(ops->get_batch_mode)
caps |= PURPLE_CIPHER_CAPS_GET_BATCH_MODE;
if(ops->get_block_size)
caps |= PURPLE_CIPHER_CAPS_GET_BLOCK_SIZE;
- if(ops->set_key_with_len)
- caps |= PURPLE_CIPHER_CAPS_SET_KEY_WITH_LEN;
return caps;
}
@@ -539,7 +535,7 @@
}
void
-purple_cipher_context_set_key(PurpleCipherContext *context, const guchar *key) {
+purple_cipher_context_set_key(PurpleCipherContext *context, const guchar *key, size_t len) {
PurpleCipher *cipher = NULL;
g_return_if_fail(context);
@@ -548,31 +544,12 @@
g_return_if_fail(cipher);
if(cipher->ops && cipher->ops->set_key)
- cipher->ops->set_key(context, key);
+ cipher->ops->set_key(context, key, len);
else
purple_debug_warning("cipher", "the %s cipher does not support the "
"set_key operation\n", cipher->name);
}
-size_t
-purple_cipher_context_get_key_size(PurpleCipherContext *context) {
- PurpleCipher *cipher = NULL;
-
- g_return_val_if_fail(context, -1);
-
- cipher = context->cipher;
- g_return_val_if_fail(cipher, -1);
-
- if(cipher->ops && cipher->ops->get_key_size)
- return cipher->ops->get_key_size(context);
- else {
- purple_debug_warning("cipher", "the %s cipher does not support the "
- "get_key_size operation\n", cipher->name);
-
- return -1;
- }
-}
-
void
purple_cipher_context_set_batch_mode(PurpleCipherContext *context,
PurpleCipherBatchMode mode)
@@ -630,24 +607,6 @@
}
void
-purple_cipher_context_set_key_with_len(PurpleCipherContext *context,
- const guchar *key, size_t len)
-{
- PurpleCipher *cipher = NULL;
-
- g_return_if_fail(context);
-
- cipher = context->cipher;
- g_return_if_fail(cipher);
-
- if(cipher->ops && cipher->ops->set_key_with_len)
- cipher->ops->set_key_with_len(context, key, len);
- else
- purple_debug_warning("cipher", "The %s cipher does not support the "
- "set_key_with_len operation\n", cipher->name);
-}
-
-void
purple_cipher_context_set_data(PurpleCipherContext *context, gpointer data) {
g_return_if_fail(context);
--- a/libpurple/cipher.h Wed May 01 11:48:56 2013 +0200
+++ b/libpurple/cipher.h Sun May 05 13:15:07 2013 +0200
@@ -63,12 +63,10 @@
PURPLE_CIPHER_CAPS_SET_SALT = 1 << 11, /**< Set salt flag */
PURPLE_CIPHER_CAPS_GET_SALT_SIZE = 1 << 12, /**< Get salt size flag */
PURPLE_CIPHER_CAPS_SET_KEY = 1 << 13, /**< Set key flag */
- PURPLE_CIPHER_CAPS_GET_KEY_SIZE = 1 << 14, /**< Get key size flag */
- PURPLE_CIPHER_CAPS_SET_BATCH_MODE = 1 << 15, /**< Set batch mode flag */
- PURPLE_CIPHER_CAPS_GET_BATCH_MODE = 1 << 16, /**< Get batch mode flag */
- PURPLE_CIPHER_CAPS_GET_BLOCK_SIZE = 1 << 17, /**< The get block size flag */
- PURPLE_CIPHER_CAPS_SET_KEY_WITH_LEN = 1 << 18, /**< The set key with length flag */
- PURPLE_CIPHER_CAPS_UNKNOWN = 1 << 19 /**< Unknown */
+ PURPLE_CIPHER_CAPS_SET_BATCH_MODE = 1 << 14, /**< Set batch mode flag */
+ PURPLE_CIPHER_CAPS_GET_BATCH_MODE = 1 << 15, /**< Get batch mode flag */
+ PURPLE_CIPHER_CAPS_GET_BLOCK_SIZE = 1 << 16, /**< The get block size flag */
+ PURPLE_CIPHER_CAPS_UNKNOWN = 1 << 17 /**< Unknown */
} PurpleCipherCaps;
/**
@@ -112,10 +110,7 @@
size_t (*get_salt_size)(PurpleCipherContext *context);
/** The set key function */
- void (*set_key)(PurpleCipherContext *context, const guchar *key);
-
- /** The get key size function */
- size_t (*get_key_size)(PurpleCipherContext *context);
+ void (*set_key)(PurpleCipherContext *context, const guchar *key, size_t len);
/** The set batch mode function */
void (*set_batch_mode)(PurpleCipherContext *context, PurpleCipherBatchMode mode);
@@ -126,8 +121,10 @@
/** The get block size function */
size_t (*get_block_size)(PurpleCipherContext *context);
- /** The set key with length function */
- void (*set_key_with_len)(PurpleCipherContext *context, const guchar *key, size_t len);
+ void (*_purple_reserved1)(void);
+ void (*_purple_reserved2)(void);
+ void (*_purple_reserved3)(void);
+ void (*_purple_reserved4)(void);
};
G_BEGIN_DECLS
@@ -381,17 +378,9 @@
*
* @param context The context whose key to set
* @param key The key
+ * @param len The size of the key
*/
-void purple_cipher_context_set_key(PurpleCipherContext *context, const guchar *key);
-
-/**
- * Gets the key size for a context
- *
- * @param context The context whose key size to get
- *
- * @return The size of the key
- */
-size_t purple_cipher_context_get_key_size(PurpleCipherContext *context);
+void purple_cipher_context_set_key(PurpleCipherContext *context, const guchar *key, size_t len);
/**
* Sets the batch mode of a context
@@ -421,16 +410,6 @@
size_t purple_cipher_context_get_block_size(PurpleCipherContext *context);
/**
- * Sets the key with a given length on a context
- *
- * @param context The context whose key to set
- * @param key The key
- * @param len The length of the key
- *
- */
-void purple_cipher_context_set_key_with_len(PurpleCipherContext *context, const guchar *key, size_t len);
-
-/**
* Sets the cipher data for a context
*
* @param context The context whose cipher data to set
--- a/libpurple/ciphers/des.c Wed May 01 11:48:56 2013 +0200
+++ b/libpurple/ciphers/des.c Sun May 05 13:15:07 2013 +0200
@@ -335,11 +335,13 @@
* Does not check for weak keys.
**/
static void
-des_set_key (PurpleCipherContext *context, const guchar * key)
+des_set_key (PurpleCipherContext *context, const guchar * key, size_t len)
{
struct _des_ctx *ctx = purple_cipher_context_get_data(context);
int i;
+ g_return_if_fail(len != 8);
+
des_key_schedule (key, ctx->encrypt_subkeys);
for(i=0; i<32; i+=2)
@@ -478,7 +480,6 @@
NULL, /* set batch mode */
NULL, /* get batch mode */
NULL, /* get block size */
- NULL /* set key with len */
};
/******************************************************************************
@@ -503,11 +504,13 @@
* Does not check for weak keys.
**/
static void
-des3_set_key(PurpleCipherContext *context, const guchar * key)
+des3_set_key(PurpleCipherContext *context, const guchar * key, size_t len)
{
struct _des3_ctx *ctx = purple_cipher_context_get_data(context);
int i;
+ g_return_if_fail(len != 24);
+
des_key_schedule (key + 0, ctx->key1.encrypt_subkeys);
des_key_schedule (key + 8, ctx->key2.encrypt_subkeys);
des_key_schedule (key + 16, ctx->key3.encrypt_subkeys);
@@ -825,11 +828,9 @@
NULL, /* set salt */
NULL, /* get salt size */
des3_set_key, /* set key */
- NULL, /* get key size */
des3_set_batch, /* set batch mode */
des3_get_batch, /* get batch mode */
NULL, /* get block size */
- NULL /* set key with len */
};
/******************************************************************************
@@ -844,4 +845,3 @@
purple_des3_cipher_get_ops(void) {
return &DES3Ops;
}
-
--- a/libpurple/ciphers/gchecksum.c Wed May 01 11:48:56 2013 +0200
+++ b/libpurple/ciphers/gchecksum.c Sun May 05 13:15:07 2013 +0200
@@ -114,11 +114,9 @@
NULL, /* set salt */ \
NULL, /* get salt size */ \
NULL, /* set key */ \
- NULL, /* get key size */ \
NULL, /* set batch mode */ \
NULL, /* get batch mode */ \
lower##_get_block_size, /* get block size */ \
- NULL /* set key with len */ \
}; \
\
PurpleCipherOps * \
--- a/libpurple/ciphers/hmac.c Wed May 01 11:48:56 2013 +0200
+++ b/libpurple/ciphers/hmac.c Sun May 05 13:15:07 2013 +0200
@@ -137,7 +137,7 @@
}
static void
-hmac_set_key_with_len(PurpleCipherContext *context, const guchar * key, size_t key_len)
+hmac_set_key(PurpleCipherContext *context, const guchar * key, size_t key_len)
{
struct HMAC_Context *hctx = purple_cipher_context_get_data(context);
int blocksize, i;
@@ -177,12 +177,6 @@
g_free(ipad);
}
- static void
-hmac_set_key(PurpleCipherContext *context, const guchar * key)
-{
- hmac_set_key_with_len(context, key, strlen((char *)key));
-}
-
static size_t
hmac_get_block_size(PurpleCipherContext *context)
{
@@ -205,11 +199,9 @@
NULL, /* set salt */
NULL, /* get salt size */
hmac_set_key, /* set key */
- NULL, /* get key size */
NULL, /* set batch mode */
NULL, /* get batch mode */
hmac_get_block_size, /* get block size */
- hmac_set_key_with_len /* set key with len */
};
PurpleCipherOps *
--- a/libpurple/ciphers/md4.c Wed May 01 11:48:56 2013 +0200
+++ b/libpurple/ciphers/md4.c Sun May 05 13:15:07 2013 +0200
@@ -284,11 +284,9 @@
NULL, /* set salt */
NULL, /* get salt size */
NULL, /* set key */
- NULL, /* get key size */
NULL, /* set batch mode */
NULL, /* get batch mode */
md4_get_block_size, /* get block size */
- NULL /* set key with len */
};
PurpleCipherOps *
--- a/libpurple/ciphers/rc4.c Wed May 01 11:48:56 2013 +0200
+++ b/libpurple/ciphers/rc4.c Sun May 05 13:15:07 2013 +0200
@@ -72,7 +72,7 @@
static void
-rc4_set_key (PurpleCipherContext *context, const guchar * key) {
+rc4_set_key (PurpleCipherContext *context, const guchar * key, size_t len) {
struct RC4Context *ctx;
guchar *state;
guchar temp_swap;
@@ -84,54 +84,17 @@
x = 0;
y = 0;
state = &ctx->state[0];
+ ctx->key_len = len;
for(i = 0; i < 256; i++)
{
y = (key[x] + state[i] + y) % 256;
temp_swap = state[i];
state[i] = state[y];
state[y] = temp_swap;
- x = (x + 1) % ctx->key_len;
- }
-}
-
-static void
-rc4_set_opt(PurpleCipherContext *context, const gchar *name, void *value) {
- struct RC4Context *ctx;
-
- ctx = purple_cipher_context_get_data(context);
-
- if(purple_strequal(name, "key_len")) {
- ctx->key_len = GPOINTER_TO_INT(value);
+ x = (x + 1) % len;
}
}
-static size_t
-rc4_get_key_size (PurpleCipherContext *context)
-{
- struct RC4Context *ctx;
-
- g_return_val_if_fail(context, -1);
-
- ctx = purple_cipher_context_get_data(context);
-
- g_return_val_if_fail(ctx, -1);
-
- return ctx->key_len;
-}
-
-static void *
-rc4_get_opt(PurpleCipherContext *context, const gchar *name) {
- struct RC4Context *ctx;
-
- ctx = purple_cipher_context_get_data(context);
-
- if(purple_strequal(name, "key_len")) {
- return GINT_TO_POINTER(ctx->key_len);
- }
-
- return NULL;
-}
-
static gint
rc4_encrypt(PurpleCipherContext *context, const guchar data[],
size_t len, guchar output[], size_t *outlen) {
@@ -166,8 +129,8 @@
}
static PurpleCipherOps RC4Ops = {
- rc4_set_opt, /* Set Option */
- rc4_get_opt, /* Get Option */
+ NULL, /* Set Option */
+ NULL, /* Get Option */
rc4_init, /* init */
rc4_reset, /* reset */
rc4_uninit, /* uninit */
@@ -179,11 +142,9 @@
NULL, /* set salt */
NULL, /* get salt size */
rc4_set_key, /* set key */
- rc4_get_key_size, /* get key size */
NULL, /* set batch mode */
NULL, /* get batch mode */
NULL, /* get block size */
- NULL /* set key with len */
};
PurpleCipherOps *
--- a/libpurple/ntlm.c Wed May 01 11:48:56 2013 +0200
+++ b/libpurple/ntlm.c Sun May 05 13:15:07 2013 +0200
@@ -196,7 +196,7 @@
cipher = purple_ciphers_find_cipher("des");
context = purple_cipher_context_new(cipher, NULL);
- purple_cipher_context_set_key(context, key);
+ purple_cipher_context_set_key(context, key, 8);
purple_cipher_context_encrypt(context, plaintext, 8, result, &outlen);
purple_cipher_context_destroy(context);
}
--- a/libpurple/protocols/gg/oauth/oauth.c Wed May 01 11:48:56 2013 +0200
+++ b/libpurple/protocols/gg/oauth/oauth.c Sun May 05 13:15:07 2013 +0200
@@ -53,7 +53,7 @@
context = purple_cipher_context_new_by_name("hmac", NULL);
purple_cipher_context_set_option(context, "hash", "sha1");
- purple_cipher_context_set_key(context, (guchar *)key);
+ purple_cipher_context_set_key(context, (guchar *)key, strlen(key));
purple_cipher_context_append(context, (guchar *)message, strlen(message));
purple_cipher_context_digest(context, sizeof(digest), digest, NULL);
purple_cipher_context_destroy(context);
--- a/libpurple/protocols/jabber/auth.c Wed May 01 11:48:56 2013 +0200
+++ b/libpurple/protocols/jabber/auth.c Sun May 05 13:15:07 2013 +0200
@@ -282,7 +282,7 @@
challenge = xmlnode_get_attrib(x, "challenge");
hmac = purple_cipher_context_new_by_name("hmac", NULL);
purple_cipher_context_set_option(hmac, "hash", "md5");
- purple_cipher_context_set_key(hmac, (guchar *)pw);
+ purple_cipher_context_set_key(hmac, (guchar *)pw, strlen(pw));
purple_cipher_context_append(hmac, (guchar *)challenge, strlen(challenge));
purple_cipher_context_digest_to_str(hmac, 33, digest, NULL);
purple_cipher_context_destroy(hmac);
--- a/libpurple/protocols/jabber/auth_scram.c Wed May 01 11:48:56 2013 +0200
+++ b/libpurple/protocols/jabber/auth_scram.c Sun May 05 13:15:07 2013 +0200
@@ -98,7 +98,7 @@
/* Compute U0 */
purple_cipher_context_set_option(context, "hash", (gpointer)hash->name);
- purple_cipher_context_set_key_with_len(context, (guchar *)str->str, str->len);
+ purple_cipher_context_set_key(context, (guchar *)str->str, str->len);
purple_cipher_context_append(context, (guchar *)salt->str, salt->len);
purple_cipher_context_digest(context, hash->size, result, NULL);
@@ -108,7 +108,7 @@
for (i = 1; i < iterations; ++i) {
guint j;
purple_cipher_context_set_option(context, "hash", (gpointer)hash->name);
- purple_cipher_context_set_key_with_len(context, (guchar *)str->str, str->len);
+ purple_cipher_context_set_key(context, (guchar *)str->str, str->len);
purple_cipher_context_append(context, prev, hash->size);
purple_cipher_context_digest(context, hash->size, tmp, NULL);
@@ -140,7 +140,7 @@
context = purple_cipher_context_new_by_name("hmac", NULL);
purple_cipher_context_set_option(context, "hash", (gpointer)hash->name);
- purple_cipher_context_set_key_with_len(context, key, hash->size);
+ purple_cipher_context_set_key(context, key, hash->size);
purple_cipher_context_append(context, (guchar *)str, strlen(str));
purple_cipher_context_digest(context, hash->size, out, NULL);
purple_cipher_context_destroy(context);
--- a/libpurple/protocols/msn/nexus.c Wed May 01 11:48:56 2013 +0200
+++ b/libpurple/protocols/msn/nexus.c Sun May 05 13:15:07 2013 +0200
@@ -106,14 +106,14 @@
hmac = purple_cipher_context_new_by_name("hmac", NULL);
purple_cipher_context_set_option(hmac, "hash", "sha1");
- purple_cipher_context_set_key_with_len(hmac, (guchar *)key, key_len);
+ purple_cipher_context_set_key(hmac, (guchar *)key, key_len);
purple_cipher_context_append(hmac, magic, magic_len);
purple_cipher_context_append(hmac, (guchar *)data, data_len);
purple_cipher_context_digest(hmac, sizeof(hash1), hash1, NULL);
purple_cipher_context_reset(hmac, NULL);
purple_cipher_context_set_option(hmac, "hash", "sha1");
- purple_cipher_context_set_key_with_len(hmac, (guchar *)key, key_len);
+ purple_cipher_context_set_key(hmac, (guchar *)key, key_len);
purple_cipher_context_append(hmac, hash1, 20);
purple_cipher_context_append(hmac, magic, magic_len);
purple_cipher_context_append(hmac, (guchar *)data, data_len);
@@ -121,13 +121,13 @@
purple_cipher_context_reset(hmac, NULL);
purple_cipher_context_set_option(hmac, "hash", "sha1");
- purple_cipher_context_set_key_with_len(hmac, (guchar *)key, key_len);
+ purple_cipher_context_set_key(hmac, (guchar *)key, key_len);
purple_cipher_context_append(hmac, hash1, 20);
purple_cipher_context_digest(hmac, sizeof(hash3), hash3, NULL);
purple_cipher_context_reset(hmac, NULL);
purple_cipher_context_set_option(hmac, "hash", "sha1");
- purple_cipher_context_set_key_with_len(hmac, (guchar *)key, key_len);
+ purple_cipher_context_set_key(hmac, (guchar *)key, key_len);
purple_cipher_context_append(hmac, hash3, sizeof(hash3));
purple_cipher_context_append(hmac, magic, magic_len);
purple_cipher_context_append(hmac, (guchar *)data, data_len);
@@ -150,7 +150,7 @@
size_t outlen;
des3 = purple_cipher_context_new_by_name("des3", NULL);
- purple_cipher_context_set_key(des3, (guchar *)key);
+ purple_cipher_context_set_key(des3, (guchar *)key, 24);
purple_cipher_context_set_batch_mode(des3, PURPLE_CIPHER_BATCH_MODE_CBC);
purple_cipher_context_set_iv(des3, (guchar *)iv, 8);
@@ -208,7 +208,7 @@
len = strlen(nexus->nonce);
hmac = purple_cipher_context_new_by_name("hmac", NULL);
purple_cipher_context_set_option(hmac, "hash", "sha1");
- purple_cipher_context_set_key_with_len(hmac, (guchar *)key2, 24);
+ purple_cipher_context_set_key(hmac, (guchar *)key2, 24);
purple_cipher_context_append(hmac, (guchar *)nexus->nonce, len);
purple_cipher_context_digest(hmac, 20, hash, NULL);
purple_cipher_context_destroy(hmac);
@@ -607,7 +607,7 @@
key = rps_create_key(nexus->secret, 24, (char *)nonce, sizeof(nonce));
hmac = purple_cipher_context_new_by_name("hmac", NULL);
purple_cipher_context_set_option(hmac, "hash", "sha1");
- purple_cipher_context_set_key_with_len(hmac, (guchar *)key, 24);
+ purple_cipher_context_set_key(hmac, (guchar *)key, 24);
purple_cipher_context_append(hmac, (guchar *)signedinfo, strlen(signedinfo));
purple_cipher_context_digest(hmac, 20, signature, NULL);
purple_cipher_context_destroy(hmac);
--- a/libpurple/protocols/myspace/myspace.c Wed May 01 11:48:56 2013 +0200
+++ b/libpurple/protocols/myspace/myspace.c Sun May 05 13:15:07 2013 +0200
@@ -614,8 +614,7 @@
/* Note: 'key' variable is 0x14 bytes (from SHA-1 hash),
* but only first 0x10 used for the RC4 key. */
- purple_cipher_context_set_option(rc4, "key_len", (gpointer)0x10);
- purple_cipher_context_set_key(rc4, key);
+ purple_cipher_context_set_key(rc4, key, 0x10);
/* rc4 encrypt:
* nonce1+email+IP list */
--- a/libpurple/protocols/oscar/clientlogin.c Wed May 01 11:48:56 2013 +0200
+++ b/libpurple/protocols/oscar/clientlogin.c Sun May 05 13:15:07 2013 +0200
@@ -133,7 +133,7 @@
context = purple_cipher_context_new_by_name("hmac", NULL);
purple_cipher_context_set_option(context, "hash", "sha256");
- purple_cipher_context_set_key(context, (guchar *)key);
+ purple_cipher_context_set_key(context, (guchar *)key, strlen(key));
purple_cipher_context_append(context, (guchar *)message, strlen(message));
purple_cipher_context_digest(context, sizeof(digest), digest, NULL);
purple_cipher_context_destroy(context);