Refactored protocols msn, myspace, oscar, simple, yahoo to use GObject-based PurpleCipher soc.2013.gobjectification

Sat, 15 Jun 2013 20:21:51 +0530

author
Ankit Vani <a@nevitus.org>
date
Sat, 15 Jun 2013 20:21:51 +0530
branch
soc.2013.gobjectification
changeset 34557
295cd5bf4c41
parent 34556
087db73b115d
child 34558
2e1dc888240d

Refactored protocols msn, myspace, oscar, simple, yahoo to use GObject-based PurpleCipher

libpurple/protocols/msn/directconn.c file | annotate | diff | comparison | revisions
libpurple/protocols/msn/msnutils.c file | annotate | diff | comparison | revisions
libpurple/protocols/msn/nexus.c file | annotate | diff | comparison | revisions
libpurple/protocols/msn/notification.c file | annotate | diff | comparison | revisions
libpurple/protocols/msn/object.c file | annotate | diff | comparison | revisions
libpurple/protocols/myspace/myspace.c file | annotate | diff | comparison | revisions
libpurple/protocols/myspace/myspace.h file | annotate | diff | comparison | revisions
libpurple/protocols/oscar/clientlogin.c file | annotate | diff | comparison | revisions
libpurple/protocols/oscar/family_auth.c file | annotate | diff | comparison | revisions
libpurple/protocols/oscar/family_oservice.c file | annotate | diff | comparison | revisions
libpurple/protocols/oscar/oscar.c file | annotate | diff | comparison | revisions
libpurple/protocols/simple/simple.c file | annotate | diff | comparison | revisions
libpurple/protocols/yahoo/libymsg.c file | annotate | diff | comparison | revisions
--- a/libpurple/protocols/msn/directconn.c	Sat Jun 15 14:28:31 2013 +0530
+++ b/libpurple/protocols/msn/directconn.c	Sat Jun 15 20:21:51 2013 +0530
@@ -23,7 +23,7 @@
  */
 
 #include "internal.h"
-#include "cipher.h"
+#include "ciphers/sha1.h"
 #include "debug.h"
 
 #include "msn.h"
@@ -44,11 +44,10 @@
 	guchar digest[20];
 
 	if (type == DC_NONCE_SHA1) {
-		PurpleCipher *cipher = purple_ciphers_find_cipher("sha1");
-		PurpleCipherContext *context = purple_cipher_context_new(cipher, NULL);
-		purple_cipher_context_append(context, nonce, nonce_len);
-		purple_cipher_context_digest(context, digest, sizeof(digest));
-		purple_cipher_context_destroy(context);
+		PurpleCipher *cipher = purple_sha1_cipher_new();
+		purple_cipher_append(cipher, nonce, nonce_len);
+		purple_cipher_digest(cipher, digest, sizeof(digest));
+		g_object_unref(cipher);
 	} else if (type == DC_NONCE_PLAIN) {
 		memcpy(digest, nonce, nonce_len);
 	} else {
--- a/libpurple/protocols/msn/msnutils.c	Sat Jun 15 14:28:31 2013 +0530
+++ b/libpurple/protocols/msn/msnutils.c	Sat Jun 15 20:21:51 2013 +0530
@@ -27,7 +27,7 @@
 #include "msn.h"
 #include "msnutils.h"
 
-#include "cipher.h"
+#include "ciphers/md5.h"
 
 /**************************************************************************
  * Util
@@ -543,7 +543,6 @@
 msn_handle_chl(char *input, char *output)
 {
 	PurpleCipher *cipher;
-	PurpleCipherContext *context;
 	const guchar productKey[] = MSNP15_WLM_PRODUCT_KEY;
 	const guchar productID[]  = MSNP15_WLM_PRODUCT_ID;
 	const char hexChars[]     = "0123456789abcdef";
@@ -560,13 +559,12 @@
 	int i;
 
 	/* Create the MD5 hash by using Purple MD5 algorithm */
-	cipher = purple_ciphers_find_cipher("md5");
-	context = purple_cipher_context_new(cipher, NULL);
+	cipher = purple_md5_cipher_new();
 
-	purple_cipher_context_append(context, (guchar *)input, strlen(input));
-	purple_cipher_context_append(context, productKey, sizeof(productKey) - 1);
-	purple_cipher_context_digest(context, md5Hash, sizeof(md5Hash));
-	purple_cipher_context_destroy(context);
+	purple_cipher_append(cipher, (guchar *)input, strlen(input));
+	purple_cipher_append(cipher, productKey, sizeof(productKey) - 1);
+	purple_cipher_digest(cipher, md5Hash, sizeof(md5Hash));
+	g_object_unref(cipher);
 
 	/* Split it into four integers */
 	md5Parts = (unsigned int *)md5Hash;
--- a/libpurple/protocols/msn/nexus.c	Sat Jun 15 14:28:31 2013 +0530
+++ b/libpurple/protocols/msn/nexus.c	Sat Jun 15 20:21:51 2013 +0530
@@ -23,7 +23,6 @@
  */
 
 #include "internal.h"
-#include "cipher.h"
 #include "debug.h"
 
 #include "msnutils.h"
@@ -31,6 +30,10 @@
 #include "nexus.h"
 #include "notification.h"
 
+#include "ciphers/des3.h"
+#include "ciphers/hmac.h"
+#include "ciphers/sha1.h"
+
 /**************************************************************************
  * Valid Ticket Tokens
  **************************************************************************/
@@ -99,35 +102,36 @@
 	const guchar magic[] = "WS-SecureConversation";
 	const int magic_len = sizeof(magic) - 1;
 
-	PurpleCipherContext *hmac;
+	PurpleCipher *hmac, *hash;
 	guchar hash1[20], hash2[20], hash3[20], hash4[20];
 	char *result;
 
-	hmac = purple_cipher_context_new_by_name("hmac", NULL);
-	purple_cipher_context_set_option(hmac, "hash", "sha1");
-	purple_cipher_context_set_key(hmac, (guchar *)key, key_len);
+	hash = purple_sha1_cipher_new();
+	hmac = purple_hmac_cipher_new(hash);
+	purple_cipher_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, hash1, sizeof(hash1));
+	purple_cipher_append(hmac, magic, magic_len);
+	purple_cipher_append(hmac, (guchar *)data, data_len);
+	purple_cipher_digest(hmac, hash1, sizeof(hash1));
 
-	purple_cipher_context_reset_state(hmac, NULL);
-	purple_cipher_context_append(hmac, hash1, 20);
-	purple_cipher_context_append(hmac, magic, magic_len);
-	purple_cipher_context_append(hmac, (guchar *)data, data_len);
-	purple_cipher_context_digest(hmac, hash2, sizeof(hash2));
+	purple_cipher_reset_state(hmac);
+	purple_cipher_append(hmac, hash1, 20);
+	purple_cipher_append(hmac, magic, magic_len);
+	purple_cipher_append(hmac, (guchar *)data, data_len);
+	purple_cipher_digest(hmac, hash2, sizeof(hash2));
 
-	purple_cipher_context_reset_state(hmac, NULL);
-	purple_cipher_context_append(hmac, hash1, 20);
-	purple_cipher_context_digest(hmac, hash3, sizeof(hash3));
+	purple_cipher_reset_state(hmac);
+	purple_cipher_append(hmac, hash1, 20);
+	purple_cipher_digest(hmac, hash3, sizeof(hash3));
 
-	purple_cipher_context_reset_state(hmac, NULL);
-	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);
-	purple_cipher_context_digest(hmac, hash4, sizeof(hash4));
+	purple_cipher_reset_state(hmac);
+	purple_cipher_append(hmac, hash3, sizeof(hash3));
+	purple_cipher_append(hmac, magic, magic_len);
+	purple_cipher_append(hmac, (guchar *)data, data_len);
+	purple_cipher_digest(hmac, hash4, sizeof(hash4));
 
-	purple_cipher_context_destroy(hmac);
+	g_object_unref(hmac);
+	g_object_unref(hash);
 
 	result = g_malloc(24);
 	memcpy(result, hash2, sizeof(hash2));
@@ -139,21 +143,21 @@
 static char *
 des3_cbc(const char *key, const char *iv, const char *data, int len, gboolean decrypt)
 {
-	PurpleCipherContext *des3;
+	PurpleCipher *des3;
 	char *out;
 
-	des3 = purple_cipher_context_new_by_name("des3", NULL);
-	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);
+	des3 = purple_des3_cipher_new();
+	purple_cipher_set_key(des3, (guchar *)key, 24);
+	purple_cipher_set_batch_mode(des3, PURPLE_CIPHER_BATCH_MODE_CBC);
+	purple_cipher_set_iv(des3, (guchar *)iv, 8);
 
 	out = g_malloc(len);
 	if (decrypt)
-		purple_cipher_context_decrypt(des3, (guchar *)data, len, (guchar *)out, len);
+		purple_cipher_decrypt(des3, (guchar *)data, len, (guchar *)out, len);
 	else
-		purple_cipher_context_encrypt(des3, (guchar *)data, len, (guchar *)out, len);
+		purple_cipher_encrypt(des3, (guchar *)data, len, (guchar *)out, len);
 
-	purple_cipher_context_destroy(des3);
+	g_object_unref(des3);
 
 	return out;
 }
@@ -168,7 +172,7 @@
 	char usr_key_base[MSN_USER_KEY_SIZE], *usr_key;
 	const char magic1[] = "SESSION KEY HASH";
 	const char magic2[] = "SESSION KEY ENCRYPTION";
-	PurpleCipherContext *hmac;
+	PurpleCipher *hmac, *hasher;
 	size_t len;
 	guchar *hash;
 	char *key1, *key2, *key3;
@@ -199,12 +203,13 @@
 	key3 = rps_create_key(key1, key1_len, magic2, sizeof(magic2) - 1);
 
 	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(hmac, (guchar *)key2, 24);
-	purple_cipher_context_append(hmac, (guchar *)nexus->nonce, len);
-	purple_cipher_context_digest(hmac, hash, 20);
-	purple_cipher_context_destroy(hmac);
+	hasher = purple_sha1_cipher_new();
+	hmac = purple_hmac_cipher_new(hasher);
+	purple_cipher_set_key(hmac, (guchar *)key2, 24);
+	purple_cipher_append(hmac, (guchar *)nexus->nonce, len);
+	purple_cipher_digest(hmac, hash, 20);
+	g_object_unref(hmac);
+	g_object_unref(hasher);
 
 	/* We need to pad this to 72 bytes, apparently */
 	nonce_fixed = g_malloc(len + 8);
@@ -508,8 +513,8 @@
 	MsnSession *session = nexus->session;
 	MsnNexusUpdateData *ud;
 	MsnNexusUpdateCallback *update;
-	PurpleCipherContext *sha1;
-	PurpleCipherContext *hmac;
+	PurpleCipher *sha1;
+	PurpleCipher *hmac;
 
 	char *key;
 
@@ -560,7 +565,7 @@
 	ud->nexus = nexus;
 	ud->id = id;
 
-	sha1 = purple_cipher_context_new_by_name("sha1", NULL);
+	sha1 = purple_sha1_cipher_new();
 
 	domain = g_strdup_printf(MSN_SSO_RST_TEMPLATE,
 	                         id,
@@ -568,8 +573,8 @@
 	                         ticket_domains[id][SSO_VALID_TICKET_POLICY] != NULL ?
 	                             ticket_domains[id][SSO_VALID_TICKET_POLICY] :
 	                             nexus->policy);
-	purple_cipher_context_append(sha1, (guchar *)domain, strlen(domain));
-	purple_cipher_context_digest(sha1, digest, 20);
+	purple_cipher_append(sha1, (guchar *)domain, strlen(domain));
+	purple_cipher_digest(sha1, digest, 20);
 	domain_b64 = purple_base64_encode(digest, 20);
 
 	now = time(NULL);
@@ -580,13 +585,13 @@
 	timestamp = g_strdup_printf(MSN_SSO_TIMESTAMP_TEMPLATE,
 	                            now_str,
 	                            purple_utf8_strftime("%Y-%m-%dT%H:%M:%SZ", tm));
-	purple_cipher_context_reset(sha1, NULL);
-	purple_cipher_context_append(sha1, (guchar *)timestamp, strlen(timestamp));
-	purple_cipher_context_digest(sha1, digest, 20);
+	purple_cipher_reset(sha1);
+	purple_cipher_append(sha1, (guchar *)timestamp, strlen(timestamp));
+	purple_cipher_digest(sha1, digest, 20);
 	timestamp_b64 = purple_base64_encode(digest, 20);
 	g_free(now_str);
 
-	purple_cipher_context_destroy(sha1);
+	purple_cipher_reset(sha1);
 
 	signedinfo = g_strdup_printf(MSN_SSO_SIGNEDINFO_TEMPLATE,
 	                             id,
@@ -598,12 +603,14 @@
 	nonce_b64 = purple_base64_encode((guchar *)&nonce, sizeof(nonce));
 
 	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(hmac, (guchar *)key, 24);
-	purple_cipher_context_append(hmac, (guchar *)signedinfo, strlen(signedinfo));
-	purple_cipher_context_digest(hmac, signature, 20);
-	purple_cipher_context_destroy(hmac);
+	hmac = purple_hmac_cipher_new(sha1);
+	purple_cipher_set_key(hmac, (guchar *)key, 24);
+	purple_cipher_append(hmac, (guchar *)signedinfo, strlen(signedinfo));
+	purple_cipher_digest(hmac, signature, 20);
+
+	g_object_unref(hmac);
+	g_object_unref(sha1);
+
 	signature_b64 = purple_base64_encode(signature, 20);
 
 	request = g_strdup_printf(MSN_SSO_TOKEN_UPDATE_TEMPLATE,
--- a/libpurple/protocols/msn/notification.c	Sat Jun 15 14:28:31 2013 +0530
+++ b/libpurple/protocols/msn/notification.c	Sat Jun 15 20:21:51 2013 +0530
@@ -23,7 +23,7 @@
  */
 
 #include "internal.h"
-#include "cipher.h"
+#include "ciphers/md5.h"
 #include "core.h"
 #include "debug.h"
 
@@ -1394,7 +1394,7 @@
 	PurpleAccount *account;
 	const char *rru;
 	const char *url;
-	PurpleCipherContext *cipher;
+	PurpleCipher *cipher;
 	gchar creds[33];
 	char *buf;
 
@@ -1415,10 +1415,10 @@
 	                      tmp_timestamp,
 	                      purple_connection_get_password(gc));
 
-	cipher = purple_cipher_context_new_by_name("md5", NULL);
-	purple_cipher_context_append(cipher, (const guchar *)buf, strlen(buf));
-	purple_cipher_context_digest_to_str(cipher, creds, sizeof(creds));
-	purple_cipher_context_destroy(cipher);
+	cipher = purple_md5_cipher_new();
+	purple_cipher_append(cipher, (const guchar *)buf, strlen(buf));
+	purple_cipher_digest_to_str(cipher, creds, sizeof(creds));
+	g_object_unref(cipher);
 	g_free(buf);
 
 	g_free(session->passport_info.mail_url);
--- a/libpurple/protocols/msn/object.c	Sat Jun 15 14:28:31 2013 +0530
+++ b/libpurple/protocols/msn/object.c	Sat Jun 15 20:21:51 2013 +0530
@@ -26,7 +26,7 @@
 #include "object.h"
 #include "debug.h"
 /* Sha1 stuff */
-#include "cipher.h"
+#include "ciphers/sha1.h"
 /* Base64 stuff */
 #include "util.h"
 
@@ -130,7 +130,7 @@
 {
 	MsnObject *msnobj;
 
-	PurpleCipherContext *ctx;
+	PurpleCipher *cipher;
 	char *buf;
 	gconstpointer data;
 	size_t size;
@@ -157,9 +157,9 @@
 	/* Compute the SHA1D field. */
 	memset(digest, 0, sizeof(digest));
 
-	ctx = purple_cipher_context_new_by_name("sha1", NULL);
-	purple_cipher_context_append(ctx, data, size);
-	purple_cipher_context_digest(ctx, digest, sizeof(digest));
+	cipher = purple_sha1_cipher_new();
+	purple_cipher_append(cipher, data, size);
+	purple_cipher_digest(cipher, digest, sizeof(digest));
 
 	base64 = purple_base64_encode(digest, sizeof(digest));
 	msn_object_set_sha1d(msnobj, base64);
@@ -179,10 +179,10 @@
 
 	memset(digest, 0, sizeof(digest));
 
-	purple_cipher_context_reset(ctx, NULL);
-	purple_cipher_context_append(ctx, (const guchar *)buf, strlen(buf));
-	purple_cipher_context_digest(ctx, digest, sizeof(digest));
-	purple_cipher_context_destroy(ctx);
+	purple_cipher_reset(cipher);
+	purple_cipher_append(cipher, (const guchar *)buf, strlen(buf));
+	purple_cipher_digest(cipher, digest, sizeof(digest));
+	g_object_unref(cipher);
 	g_free(buf);
 
 	base64 = purple_base64_encode(digest, sizeof(digest));
--- a/libpurple/protocols/myspace/myspace.c	Sat Jun 15 14:28:31 2013 +0530
+++ b/libpurple/protocols/myspace/myspace.c	Sat Jun 15 20:21:51 2013 +0530
@@ -532,9 +532,8 @@
 msim_compute_login_response(const gchar nonce[2 * NONCE_SIZE],
 		const gchar *email, const gchar *password, guint *response_len)
 {
-	PurpleCipherContext *key_context;
 	PurpleCipher *sha1;
-	PurpleCipherContext *rc4;
+	PurpleCipher *rc4;
 
 	guchar hash_pw[HASH_SIZE];
 	guchar key[HASH_SIZE];
@@ -583,8 +582,11 @@
 	}
 
 	/* Compute password hash */
-	purple_cipher_digest_region("sha1", (guchar *)password_utf16le,
-			conv_bytes_written, hash_pw, sizeof(hash_pw));
+	sha1 = purple_sha1_cipher_new();
+	purple_cipher_append(sha1, (guchar *)password_utf16le,
+					   conv_bytes_written);
+	purple_cipher_digest(sha1, hash_pw, sizeof(hash_pw));
+	purple_cipher_reset(sha1);
 	g_free(password_utf16le);
 
 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE
@@ -595,12 +597,10 @@
 #endif
 
 	/* key = sha1(sha1(pw) + nonce2) */
-	sha1 = purple_ciphers_find_cipher("sha1");
-	key_context = purple_cipher_context_new(sha1, NULL);
-	purple_cipher_context_append(key_context, hash_pw, HASH_SIZE);
-	purple_cipher_context_append(key_context, (guchar *)(nonce + NONCE_SIZE), NONCE_SIZE);
-	purple_cipher_context_digest(key_context, key, sizeof(key));
-	purple_cipher_context_destroy(key_context);
+	purple_cipher_append(sha1, hash_pw, HASH_SIZE);
+	purple_cipher_append(sha1, (guchar *)(nonce + NONCE_SIZE), NONCE_SIZE);
+	purple_cipher_digest(sha1, key, sizeof(key));
+	g_object_unref(sha1);
 
 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE
 	purple_debug_info("msim", "key = ");
@@ -610,11 +610,11 @@
 	purple_debug_info("msim", "\n");
 #endif
 
-	rc4 = purple_cipher_context_new_by_name("rc4", NULL);
+	rc4 = purple_rc4_cipher_new();
 
 	/* Note: 'key' variable is 0x14 bytes (from SHA-1 hash),
 	 * but only first 0x10 used for the RC4 key. */
-	purple_cipher_context_set_key(rc4, key, 0x10);
+	purple_cipher_set_key(rc4, key, 0x10);
 
 	/* rc4 encrypt:
 	 * nonce1+email+IP list */
@@ -640,9 +640,9 @@
 
 	data_out = g_new0(guchar, data->len);
 
-	data_out_len = purple_cipher_context_encrypt(rc4,
+	data_out_len = purple_cipher_encrypt(rc4,
 		(const guchar *)data->str, data->len, data_out, data->len);
-	purple_cipher_context_destroy(rc4);
+	g_object_unref(rc4);
 
 	if (data_out_len != data->len) {
 		purple_debug_info("msim", "msim_compute_login_response: "
@@ -3089,16 +3089,6 @@
 static gboolean
 msim_load(PurplePlugin *plugin)
 {
-	/* If compiled to use RC4 from libpurple, check if it is really there. */
-	if (!purple_ciphers_find_cipher("rc4")) {
-		purple_debug_error("msim", "rc4 not in libpurple, but it is required - not loading MySpaceIM plugin!\n");
-		purple_notify_error(plugin, _("Missing Cipher"),
-				_("The RC4 cipher could not be found"),
-				_("Upgrade "
-					"to a libpurple with RC4 support (>= 2.0.1). MySpaceIM "
-					"plugin will not be loaded."));
-		return FALSE;
-	}
 	return TRUE;
 }
 
--- a/libpurple/protocols/myspace/myspace.h	Sat Jun 15 14:28:31 2013 +0530
+++ b/libpurple/protocols/myspace/myspace.h	Sat Jun 15 20:21:51 2013 +0530
@@ -42,7 +42,6 @@
 #include "plugin.h"
 #include "accountopt.h"
 #include "version.h"
-#include "cipher.h"     /* for SHA-1 */
 #include "util.h"       /* for base64 */
 #include "debug.h"      /* for purple_debug_info */
 #include "request.h"    /* For dialogs used in setting the username */
@@ -50,6 +49,10 @@
 #include "core.h"
 #include "conversation.h" /* For late normalization */
 
+/* Ciphers */
+#include "ciphers/rc4.h"
+#include "ciphers/sha1.h"
+
 /* MySpaceIM includes */
 #include "persist.h"
 #include "message.h"
--- a/libpurple/protocols/oscar/clientlogin.c	Sat Jun 15 14:28:31 2013 +0530
+++ b/libpurple/protocols/oscar/clientlogin.c	Sat Jun 15 20:21:51 2013 +0530
@@ -38,9 +38,10 @@
 
 #include "oscar.h"
 #include "oscarcommon.h"
+#include "core.h"
 
-#include "cipher.h"
-#include "core.h"
+#include "ciphers/hmac.h"
+#include "ciphers/sha256.h"
 
 #define AIM_LOGIN_HOST "api.screenname.aol.com"
 #define ICQ_LOGIN_HOST "api.login.icq.net"
@@ -128,15 +129,16 @@
  */
 static gchar *hmac_sha256(const char *key, const char *message)
 {
-	PurpleCipherContext *context;
+	PurpleCipher *cipher, *hash;
 	guchar digest[32];
 
-	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, strlen(key));
-	purple_cipher_context_append(context, (guchar *)message, strlen(message));
-	purple_cipher_context_digest(context, digest, sizeof(digest));
-	purple_cipher_context_destroy(context);
+	hash = purple_sha256_cipher_new();
+	cipher = purple_hmac_cipher_new(hash);
+	purple_cipher_set_key(cipher, (guchar *)key, strlen(key));
+	purple_cipher_append(cipher, (guchar *)message, strlen(message));
+	purple_cipher_digest(cipher, digest, sizeof(digest));
+	g_object_unref(cipher);
+	g_object_unref(hash);
 
 	return purple_base64_encode(digest, sizeof(digest));
 }
--- a/libpurple/protocols/oscar/family_auth.c	Sat Jun 15 14:28:31 2013 +0530
+++ b/libpurple/protocols/oscar/family_auth.c	Sat Jun 15 20:21:51 2013 +0530
@@ -31,7 +31,7 @@
 
 #include <ctype.h>
 
-#include "cipher.h"
+#include "ciphers/md5.h"
 
 /* #define USE_XOR_FOR_ICQ */
 
@@ -91,22 +91,18 @@
 aim_encode_password_md5(const char *password, size_t password_len, const char *key, guint8 *digest)
 {
 	PurpleCipher *cipher;
-	PurpleCipherContext *context;
 	guchar passdigest[16];
 
-	cipher = purple_ciphers_find_cipher("md5");
-
-	context = purple_cipher_context_new(cipher, NULL);
-	purple_cipher_context_append(context, (const guchar *)password, password_len);
-	purple_cipher_context_digest(context, passdigest, sizeof(passdigest));
-	purple_cipher_context_destroy(context);
+	cipher = purple_md5_cipher_new();
+	purple_cipher_append(cipher, (const guchar *)password, password_len);
+	purple_cipher_digest(cipher, passdigest, sizeof(passdigest));
+	purple_cipher_reset(cipher);
 
-	context = purple_cipher_context_new(cipher, NULL);
-	purple_cipher_context_append(context, (const guchar *)key, strlen(key));
-	purple_cipher_context_append(context, passdigest, 16);
-	purple_cipher_context_append(context, (const guchar *)AIM_MD5_STRING, strlen(AIM_MD5_STRING));
-	purple_cipher_context_digest(context, digest, 16);
-	purple_cipher_context_destroy(context);
+	purple_cipher_append(cipher, (const guchar *)key, strlen(key));
+	purple_cipher_append(cipher, passdigest, 16);
+	purple_cipher_append(cipher, (const guchar *)AIM_MD5_STRING, strlen(AIM_MD5_STRING));
+	purple_cipher_digest(cipher, digest, 16);
+	g_object_unref(cipher);
 
 	return 0;
 }
--- a/libpurple/protocols/oscar/family_oservice.c	Sat Jun 15 14:28:31 2013 +0530
+++ b/libpurple/protocols/oscar/family_oservice.c	Sat Jun 15 20:21:51 2013 +0530
@@ -25,7 +25,7 @@
 
 #include "oscar.h"
 
-#include "cipher.h"
+#include "ciphers/md5.h"
 
 /*
  * Each time we make a FLAP connection to an oscar server the server gives
@@ -972,18 +972,18 @@
 		byte_stream_putraw(&bs, buf, 0x10);
 
 	} else if (buf && (len > 0)) { /* use input buffer */
-		PurpleCipherContext *context;
+		PurpleCipher *cipher;
 		guchar digest[16];
 
-		context = purple_cipher_context_new_by_name("md5", NULL);
-		purple_cipher_context_append(context, buf, len);
-		purple_cipher_context_digest(context, digest, sizeof(digest));
-		purple_cipher_context_destroy(context);
+		cipher = purple_md5_cipher_new();
+		purple_cipher_append(cipher, buf, len);
+		purple_cipher_digest(cipher, digest, sizeof(digest));
+		g_object_unref(cipher);
 
 		byte_stream_putraw(&bs, digest, 0x10);
 
 	} else if (len == 0) { /* no length, just hash NULL (buf is optional) */
-		PurpleCipherContext *context;
+		PurpleCipher *cipher;
 		guchar digest[16];
 		guint8 nil = '\0';
 
@@ -991,10 +991,10 @@
 		 * I'm not sure if we really need the empty append with the
 		 * new MD5 functions, so I'll leave it in, just in case.
 		 */
-		context = purple_cipher_context_new_by_name("md5", NULL);
-		purple_cipher_context_append(context, &nil, 0);
-		purple_cipher_context_digest(context, digest, sizeof(digest));
-		purple_cipher_context_destroy(context);
+		cipher = purple_md5_cipher_new();
+		purple_cipher_append(cipher, &nil, 0);
+		purple_cipher_digest(cipher, digest, sizeof(digest));
+		g_object_unref(cipher);
 
 		byte_stream_putraw(&bs, digest, 0x10);
 
--- a/libpurple/protocols/oscar/oscar.c	Sat Jun 15 14:28:31 2013 +0530
+++ b/libpurple/protocols/oscar/oscar.c	Sat Jun 15 20:21:51 2013 +0530
@@ -33,7 +33,7 @@
 #include "account.h"
 #include "accountopt.h"
 #include "buddyicon.h"
-#include "cipher.h"
+#include "ciphers/md5.h"
 #include "conversation.h"
 #include "core.h"
 #include "debug.h"
@@ -5336,15 +5336,15 @@
 	if (img == NULL) {
 		aim_ssi_delicon(od);
 	} else {
-		PurpleCipherContext *context;
+		PurpleCipher *cipher;
 		guchar md5[16];
 		gconstpointer data = purple_imgstore_get_data(img);
 		size_t len = purple_imgstore_get_size(img);
 
-		context = purple_cipher_context_new_by_name("md5", NULL);
-		purple_cipher_context_append(context, data, len);
-		purple_cipher_context_digest(context, md5, sizeof(md5));
-		purple_cipher_context_destroy(context);
+		cipher = purple_md5_cipher_new();
+		purple_cipher_append(cipher, data, len);
+		purple_cipher_digest(cipher, md5, sizeof(md5));
+		g_object_unref(cipher);
 
 		aim_ssi_seticon(od, md5, 16);
 	}
--- a/libpurple/protocols/simple/simple.c	Sat Jun 15 14:28:31 2013 +0530
+++ b/libpurple/protocols/simple/simple.c	Sat Jun 15 20:21:51 2013 +0530
@@ -274,7 +274,7 @@
 
 	if(auth->type == 1) { /* Digest */
 		sprintf(noncecount, "%08d", auth->nc++);
-		response = purple_cipher_http_digest_calculate_response(
+		response = purple_http_digest_calculate_response(
 							"md5", method, target, NULL, NULL,
 							auth->nonce, noncecount, NULL, auth->digest_session_key);
 		purple_debug(PURPLE_DEBUG_MISC, "simple", "response %s\n", response);
@@ -295,7 +295,7 @@
 	}
 
 	sprintf(noncecount, "%08d", auth->nc++);
-	response = purple_cipher_http_digest_calculate_response(
+	response = purple_http_digest_calculate_response(
 						"md5", method, target, NULL, NULL,
 						auth->nonce, noncecount, NULL, auth->digest_session_key);
 	purple_debug(PURPLE_DEBUG_MISC, "simple", "response %s\n", response);
@@ -399,7 +399,7 @@
 					 auth->realm ? auth->realm : "(null)");
 
 		if(auth->realm) {
-			auth->digest_session_key = purple_cipher_http_digest_calculate_session_key(
+			auth->digest_session_key = purple_http_digest_calculate_session_key(
 				"md5", authuser, auth->realm, sip->password, auth->nonce, NULL);
 
 			auth->nc = 1;
--- a/libpurple/protocols/yahoo/libymsg.c	Sat Jun 15 14:28:31 2013 +0530
+++ b/libpurple/protocols/yahoo/libymsg.c	Sat Jun 15 20:21:51 2013 +0530
@@ -27,7 +27,7 @@
 #include "account.h"
 #include "accountopt.h"
 #include "blist.h"
-#include "cipher.h"
+#include "ciphers/md5.h"
 #include "cmds.h"
 #include "core.h"
 #include "debug.h"
@@ -1693,17 +1693,15 @@
 	PurpleAccount *account = purple_connection_get_account(gc);
 	const char *name = purple_normalize(account, purple_account_get_username(account));
 	PurpleCipher *md5_cipher;
-	PurpleCipherContext *md5_ctx;
 	guchar md5_digest[16];
 	gchar base64_string[25];
 	struct yahoo_packet *pkt;
 
 	purple_debug_info("yahoo","Authentication: In yahoo_auth16_stage3\n");
 
-	md5_cipher = purple_ciphers_find_cipher("md5");
-	md5_ctx = purple_cipher_context_new(md5_cipher, NULL);
-	purple_cipher_context_append(md5_ctx, (guchar *)crypt, strlen(crypt));
-	purple_cipher_context_digest(md5_ctx, md5_digest, sizeof(md5_digest));
+	md5_cipher = purple_md5_cipher_new();
+	purple_cipher_append(md5_cipher, (guchar *)crypt, strlen(crypt));
+	purple_cipher_digest(md5_cipher, md5_digest, sizeof(md5_digest));
 
 	to_y64(base64_string, md5_digest, 16);
 
@@ -1741,7 +1739,7 @@
 		yahoo_packet_hash_int(pkt, 192, yd->picture_checksum);
 	yahoo_packet_send_and_free(pkt, yd);
 
-	purple_cipher_context_destroy(md5_ctx);
+	g_object_unref(md5_cipher);
 }
 
 static gchar *yahoo_auth16_get_cookie_b(gchar *headers)

mercurial