/pidgin/main: 78b42fd69e02: ciphers cleanup: passing keys with l...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Sun May 5 07:15:16 EDT 2013


Changeset: 78b42fd69e02af4d089316723a05e5e2ea428f36
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2013-05-05 13:15 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/78b42fd69e02

Description:

ciphers cleanup: passing keys with length by default

diffstat:

 libpurple/cipher.c                      |  45 +----------------------------
 libpurple/cipher.h                      |  43 +++++++---------------------
 libpurple/ciphers/des.c                 |  12 ++++----
 libpurple/ciphers/gchecksum.c           |   2 -
 libpurple/ciphers/hmac.c                |  10 +------
 libpurple/ciphers/md4.c                 |   2 -
 libpurple/ciphers/rc4.c                 |  49 +++-----------------------------
 libpurple/ntlm.c                        |   2 +-
 libpurple/protocols/gg/oauth/oauth.c    |   2 +-
 libpurple/protocols/jabber/auth.c       |   2 +-
 libpurple/protocols/jabber/auth_scram.c |   6 ++--
 libpurple/protocols/msn/nexus.c         |  14 ++++----
 libpurple/protocols/myspace/myspace.c   |   3 +-
 libpurple/protocols/oscar/clientlogin.c |   2 +-
 14 files changed, 40 insertions(+), 154 deletions(-)

diffs (truncated from 540 to 300 lines):

diff --git a/libpurple/cipher.c b/libpurple/cipher.c
--- a/libpurple/cipher.c
+++ b/libpurple/cipher.c
@@ -106,16 +106,12 @@ purple_cipher_get_capabilities(PurpleCip
 		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 @@ purple_cipher_context_get_salt_size(Purp
 }
 
 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 @@ purple_cipher_context_set_key(PurpleCiph
 	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 @@ purple_cipher_context_get_block_size(Pur
 }
 
 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);
 
diff --git a/libpurple/cipher.h b/libpurple/cipher.h
--- a/libpurple/cipher.h
+++ b/libpurple/cipher.h
@@ -63,12 +63,10 @@ typedef enum {
 	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 @@ struct _PurpleCipherOps {
 	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 @@ struct _PurpleCipherOps {
 	/** 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 @@ size_t purple_cipher_context_get_salt_si
  *
  * @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 @@ PurpleCipherBatchMode purple_cipher_cont
 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
diff --git a/libpurple/ciphers/des.c b/libpurple/ciphers/des.c
--- a/libpurple/ciphers/des.c
+++ b/libpurple/ciphers/des.c
@@ -335,11 +335,13 @@ des_key_schedule (const guint8 * rawkey,
  *  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 @@ static PurpleCipherOps DESOps = {
 	NULL,              /* set batch mode */
 	NULL,              /* get batch mode */
 	NULL,              /* get block size */
-	NULL               /* set key with len */
 };
 
 /******************************************************************************
@@ -503,11 +504,13 @@ typedef struct _des3_ctx
  *  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 @@ static PurpleCipherOps DES3Ops = {
 	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 @@ PurpleCipherOps *
 purple_des3_cipher_get_ops(void) {
 	return &DES3Ops;
 }
-
diff --git a/libpurple/ciphers/gchecksum.c b/libpurple/ciphers/gchecksum.c
--- a/libpurple/ciphers/gchecksum.c
+++ b/libpurple/ciphers/gchecksum.c
@@ -114,11 +114,9 @@ purple_g_checksum_digest(PurpleCipherCon
 		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 * \
diff --git a/libpurple/ciphers/hmac.c b/libpurple/ciphers/hmac.c
--- a/libpurple/ciphers/hmac.c
+++ b/libpurple/ciphers/hmac.c
@@ -137,7 +137,7 @@ hmac_uninit(PurpleCipherContext *context
 }
 
 	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 @@ hmac_set_key_with_len(PurpleCipherContex
 	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 @@ static PurpleCipherOps HMACOps = {
 	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 *
diff --git a/libpurple/ciphers/md4.c b/libpurple/ciphers/md4.c
--- a/libpurple/ciphers/md4.c
+++ b/libpurple/ciphers/md4.c
@@ -284,11 +284,9 @@ static PurpleCipherOps MD4Ops = {
 	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 *
diff --git a/libpurple/ciphers/rc4.c b/libpurple/ciphers/rc4.c
--- a/libpurple/ciphers/rc4.c
+++ b/libpurple/ciphers/rc4.c
@@ -72,7 +72,7 @@ rc4_uninit(PurpleCipherContext *context)
 
 



More information about the Commits mailing list