gobjectification: 528815f7: renamed PurpleMD4Cipher to PurpleMD4Hash

grim at pidgin.im grim at pidgin.im
Mon Jul 20 00:25:34 EDT 2009


-----------------------------------------------------------------
Revision: 528815f7556c4cd9f5317f0093761f30fcb43435
Ancestor: f1583da109b3ebcb9a5e1da3fe423b97037e5773
Author: grim at pidgin.im
Date: 2009-07-20T00:31:29
Branch: im.pidgin.gobjectification
URL: http://d.pidgin.im/viewmtn/revision/info/528815f7556c4cd9f5317f0093761f30fcb43435

Renamed entries:
        libpurple/md4cipher.c to libpurple/md4hash.c
        libpurple/md4cipher.h to libpurple/md4hash.h
Modified files:
        libpurple/Makefile.am libpurple/md4hash.c
        libpurple/md4hash.h libpurple/ntlm.c

ChangeLog: 

renamed PurpleMD4Cipher to PurpleMD4Hash


-------------- next part --------------
============================================================
--- libpurple/Makefile.am	27224eeb995a50d60c283c9119e968510a9ef802
+++ libpurple/Makefile.am	c83e7e66802f909b608934e2c032fc638498045d
@@ -64,7 +64,7 @@ purple_coresources = \
 	idle.c \
 	imgstore.c \
 	log.c \
-	md4cipher.c \
+	md4hash.c \
 	md5cipher.c \
 	media.c \
 	mediamanager.c \
@@ -139,7 +139,7 @@ purple_coreheaders = \
 	idle.h \
 	imgstore.h \
 	log.h \
-	md4cipher.h \
+	md4hash.h \
 	md5cipher.h \
 	media.h \
 	media-gst.h \
============================================================
--- libpurple/md4cipher.c	e55e3879be47e2a9800475ab7452d873f540073c
+++ libpurple/md4hash.c	addb9b36865ec0975e6bef3640c43d07ff5b0b72
@@ -13,7 +13,7 @@
  * Copyright (c) 2002 David S. Miller (davem at redhat.com)
  * Copyright (c) 2002 James Morris <jmorris at intercode.com.au>
  */
-#include "md4cipher.h"
+#include "md4hash.h"
 
 #include <string.h>
 
@@ -22,14 +22,17 @@
 #define MD4_BLOCK_WORDS		16
 #define MD4_HASH_WORDS		4
 
+#define PURPLE_MD4_HASH_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_MD4_HASH, PurpleMD4HashPrivate))
+
 /******************************************************************************
  * Structs
  *****************************************************************************/
-struct _PurpleMD4CipherPriv {
+typedef struct {
 	guint32 hash[MD4_HASH_WORDS];
 	guint32 block[MD4_BLOCK_WORDS];
 	guint64 byte_count;
-};
+} PurpleMD4HashPrivate;
 
 /******************************************************************************
  * Globals
@@ -85,24 +88,7 @@ cpu_to_le32_array(guint32 *buf, unsigned
 	}
 }
 
-/******************************************************************************
- * Cipher Stuff
- *****************************************************************************/
 static void
-purple_md4_cipher_reset(PurpleCipher *cipher) {
-	PurpleMD4Cipher *md4_cipher = PURPLE_MD4_CIPHER(cipher);
-
-	md4_cipher->priv->hash[0] = 0x67452301;
-	md4_cipher->priv->hash[1] = 0xefcdab89;
-	md4_cipher->priv->hash[2] = 0x98badcfe;
-	md4_cipher->priv->hash[3] = 0x10325476;
-
-	md4_cipher->priv->byte_count = 0;
-
-	memset(md4_cipher->priv->block, 0, sizeof(md4_cipher->priv->block));
-}
-
-static void
 md4_transform(guint32 *hash, guint32 const *in) {
 	guint32 a, b, c, d;
 
@@ -169,54 +155,69 @@ static inline void
 }
 
 static inline void
-md4_transform_helper(PurpleMD4Cipher *md4_cipher) {
-	le32_to_cpu_array(md4_cipher->priv->block,
-					  sizeof(md4_cipher->priv->block) / sizeof(guint32));
-	md4_transform(md4_cipher->priv->hash, md4_cipher->priv->block);
+md4_transform_helper(PurpleCipher *cipher) {
+	PurpleMD4HashPrivate *priv = PURPLE_MD4_HASH_GET_PRIVATE(cipher);
+
+	le32_to_cpu_array(priv->block, sizeof(priv->block) / sizeof(guint32));
+	md4_transform(priv->hash, priv->block);
 }
 
+/******************************************************************************
+ * Hash Stuff
+ *****************************************************************************/
 static void
-purple_md4_cipher_append(PurpleCipher *cipher, const guchar *data,
-						 size_t len)
-{
-	PurpleMD4Cipher *md4_cipher = PURPLE_MD4_CIPHER(cipher);
-	const guint32 avail = sizeof(md4_cipher->priv->block) -
-						  (md4_cipher->priv->byte_count & 0x3f);
+purple_md4_hash_reset(PurpleCipher *cipher) {
+	PurpleMD4HashPrivate *priv = PURPLE_MD4_HASH_GET_PRIVATE(cipher);
 
-	md4_cipher->priv->byte_count += len;
+	priv->hash[0] = 0x67452301;
+	priv->hash[1] = 0xefcdab89;
+	priv->hash[2] = 0x98badcfe;
+	priv->hash[3] = 0x10325476;
 
+	priv->byte_count = 0;
+
+	memset(priv->block, 0, sizeof(priv->block));
+}
+
+static void
+purple_md4_hash_append(PurpleCipher *cipher, const guchar *data, size_t len) {
+	PurpleMD4HashPrivate *priv = PURPLE_MD4_HASH_GET_PRIVATE(cipher);
+	const guint32 avail = sizeof(priv->block) - (priv->byte_count & 0x3f);
+
+	priv->byte_count += len;
+
 	if(avail > len) {
-		memcpy((char *)md4_cipher->priv->block +
-			   (sizeof(md4_cipher->priv->block) - avail),
+		memcpy((char *)priv->block +
+			   (sizeof(priv->block) - avail),
 			   data, len);
 		return;
 	}
 
-	memcpy((char *)md4_cipher->priv->block +
-		   (sizeof(md4_cipher->priv->block) - avail),
+	memcpy((char *)priv->block +
+		   (sizeof(priv->block) - avail),
 		   data, avail);
 
-	md4_transform_helper(md4_cipher);
+	md4_transform_helper(cipher);
 	data += avail;
 	len -= avail;
 
-	while(len >= sizeof(md4_cipher->priv->block)) {
-		memcpy(md4_cipher->priv->block, data, sizeof(md4_cipher->priv->block));
-		md4_transform_helper(md4_cipher);
-		data += sizeof(md4_cipher->priv->block);
-		len -= sizeof(md4_cipher->priv->block);
+	while(len >= sizeof(priv->block)) {
+		memcpy(priv->block, data, sizeof(priv->block));
+		md4_transform_helper(cipher);
+		data += sizeof(priv->block);
+		len -= sizeof(priv->block);
 	}
 
-	memcpy(md4_cipher->priv->block, data, len);
+	memcpy(priv->block, data, len);
 }
 
 static gboolean
-purple_md4_cipher_digest(PurpleCipher *cipher, size_t in_len,
-						 guchar digest[16], size_t *out_len)
+purple_md4_hash_digest(PurpleCipher *cipher, size_t in_len, guchar digest[16],
+					   size_t *out_len)
 {
-	PurpleMD4Cipher *md4_cipher = PURPLE_MD4_CIPHER(cipher);
-	const unsigned int offset = md4_cipher->priv->byte_count & 0x3f;
-	gchar *p = (gchar *)md4_cipher->priv->block + offset;
+	PurpleMD4HashPrivate *priv = PURPLE_MD4_HASH_GET_PRIVATE(cipher);
+	const unsigned int offset = priv->byte_count & 0x3f;
+	gchar *p = (gchar *)priv->block + offset;
 	gint padding = 56 - (offset + 1);
 
 	if(in_len < 16)
@@ -229,28 +230,26 @@ purple_md4_cipher_digest(PurpleCipher *c
 
 	if(padding < 0) {
 		memset(p, 0x00, padding + sizeof(guint64));
-		md4_transform_helper(md4_cipher);
-		p = (gchar *)md4_cipher->priv->block;
+		md4_transform_helper(cipher);
+		p = (gchar *)priv->block;
 		padding = 56;
 	}
 
 	memset(p, 0, padding);
-	md4_cipher->priv->block[14] = md4_cipher->priv->byte_count << 3;
-	md4_cipher->priv->block[15] = md4_cipher->priv->byte_count >> 29;
-	le32_to_cpu_array(md4_cipher->priv->block,
-					  (sizeof(md4_cipher->priv->block) - sizeof(guint64)) /
+	priv->block[14] = priv->byte_count << 3;
+	priv->block[15] = priv->byte_count >> 29;
+	le32_to_cpu_array(priv->block,
+					  (sizeof(priv->block) - sizeof(guint64)) /
 					  sizeof(guint32));
-	md4_transform(md4_cipher->priv->hash, md4_cipher->priv->block);
-	cpu_to_le32_array(md4_cipher->priv->hash,
-					  sizeof(md4_cipher->priv->hash) / sizeof(guint32));
-	memcpy(digest, md4_cipher->priv->hash, sizeof(md4_cipher->priv->hash));
+	md4_transform(priv->hash, priv->block);
+	cpu_to_le32_array(priv->hash, sizeof(priv->hash) / sizeof(guint32));
+	memcpy(digest, priv->hash, sizeof(priv->hash));
 
 	return TRUE;
 }
 
 static size_t
-purple_md4_cipher_get_block_size(PurpleCipher *cipher)
-{
+purple_md4_hash_get_block_size(PurpleCipher *cipher) {
 	return MD4_HMAC_BLOCK_SIZE;
 }
 
@@ -258,59 +257,38 @@ static void
  * Object Stuff
  *****************************************************************************/
 static void
-purple_md4_cipher_finalize(GObject *obj) {
-	PurpleCipher *cipher = PURPLE_CIPHER(obj);
-	PurpleMD4Cipher *md4_cipher = PURPLE_MD4_CIPHER(obj);
-
-	/* reset the cipher so we don't leave any data around... */
-	purple_md4_cipher_reset(cipher);
-
-	g_free(md4_cipher->priv);
-}
-
-static void
-purple_md4_cipher_class_init(PurpleMD4CipherClass *klass) {
-	GObjectClass *obj_class = G_OBJECT_CLASS(klass);
+purple_md4_hash_class_init(PurpleMD4HashClass *klass) {
 	PurpleCipherClass *cipher_class = PURPLE_CIPHER_CLASS(klass);
 
 	parent_class = g_type_class_peek_parent(klass);
 
-	obj_class->finalize = purple_md4_cipher_finalize;
+	g_type_class_add_private(klass, sizeof(PurpleMD4HashPrivate));
 
-	cipher_class->reset = purple_md4_cipher_reset;
-	cipher_class->append = purple_md4_cipher_append;
-	cipher_class->digest = purple_md4_cipher_digest;
-	cipher_class->get_block_size = purple_md4_cipher_get_block_size;
+	cipher_class->reset = purple_md4_hash_reset;
+	cipher_class->append = purple_md4_hash_append;
+	cipher_class->digest = purple_md4_hash_digest;
+	cipher_class->get_block_size = purple_md4_hash_get_block_size;
 }
 
-static void
-purple_md4_cipher_init(PurpleCipher *cipher) {
-	PurpleMD4Cipher *md4_cipher = PURPLE_MD4_CIPHER(cipher);
-
-	md4_cipher->priv = g_new0(PurpleMD4CipherPriv, 1);
-
-	purple_md4_cipher_reset(cipher);
-}
-
 /******************************************************************************
  * API
  *****************************************************************************/
 GType
-purple_md4_cipher_get_gtype(void) {
+purple_md4_hash_get_gtype(void) {
 	static GType type = 0;
 
 	if(type == 0) {
 		static const GTypeInfo info = {
-			sizeof(PurpleMD4CipherClass),
+			sizeof(PurpleMD4HashClass),
 			NULL,
 			NULL,
-			(GClassInitFunc)purple_md4_cipher_class_init,
+			(GClassInitFunc)purple_md4_hash_class_init,
 			NULL,
 			NULL,
-			sizeof(PurpleMD4Cipher),
+			sizeof(PurpleMD4Hash),
 			0,
-			(GInstanceInitFunc)purple_md4_cipher_init,
 			NULL,
+			NULL,
 		};
 
 		type = g_type_register_static(PURPLE_TYPE_CIPHER,
@@ -322,6 +300,6 @@ PurpleCipher *
 }
 
 PurpleCipher *
-purple_md4_cipher_new(void) {
-	return g_object_new(PURPLE_TYPE_MD4_CIPHER, NULL);
+purple_md4_hash_new(void) {
+	return g_object_new(PURPLE_TYPE_MD4_HASH, NULL);
 }
============================================================
--- libpurple/md4cipher.h	ae7ca108eed74a18ebb74b138932f97803bf4a96
+++ libpurple/md4hash.h	1d48589f0de402419242e55c511e0e342243e3d8
@@ -1,5 +1,5 @@
 /**
- * @file cipher.h Purple Cipher API
+ * @file hash.h Purple Hash API
  * @ingroup core
  *
  * purple
@@ -22,35 +22,32 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
-#ifndef PURPLE_MD4_CIPHER_H
-#define PURPLE_MD4_CIPHER_H
+#ifndef PURPLE_MD4_HASH_H
+#define PURPLE_MD4_HASH_H
 
 #include <cipher.h>
 
-#define PURPLE_TYPE_MD4_CIPHER				(purple_md4_cipher_get_gtype())
-#define PURPLE_MD4_CIPHER(obj)				(G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_MD4_CIPHER, PurpleMD4Cipher))
-#define PURPLE_MD4_CIPHER_CLASS(klass)		(G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_MD4_CIPHER, PurpleMD4CipherClass))
-#define PURPLE_IS_MD4_CIPHER(obj)			(G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_MD4_CIPHER))
-#define PURPLE_IS_MD4_CIPHER_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE((obj), PURPLE_TYPE_MD4_CIPHER))
-#define PURPLE_MD4_CIPHER_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_MD4_CIPHER, PurpleMD4CipherClass))
+#define PURPLE_TYPE_MD4_HASH				(purple_md4_hash_get_gtype())
+#define PURPLE_MD4_HASH(obj)				(G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_MD4_HASH, PurpleMD4Hash))
+#define PURPLE_MD4_HASH_CLASS(klass)		(G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_MD4_HASH, PurpleMD4HashClass))
+#define PURPLE_IS_MD4_HASH(obj)			(G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_MD4_HASH))
+#define PURPLE_IS_MD4_HASH_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE((obj), PURPLE_TYPE_MD4_HASH))
+#define PURPLE_MD4_HASH_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_MD4_HASH, PurpleMD4HashClass))
 
-typedef struct _PurpleMD4Cipher				PurpleMD4Cipher;
-typedef struct _PurpleMD4CipherPriv			PurpleMD4CipherPriv;
-typedef struct _PurpleMD4CipherClass		PurpleMD4CipherClass;
+typedef struct _PurpleMD4Hash				PurpleMD4Hash;
+typedef struct _PurpleMD4HashClass		PurpleMD4HashClass;
 
-struct _PurpleMD4Cipher {
-	PurpleCipher gparent;
+struct _PurpleMD4Hash {
+	PurpleCipher parent;
 
-	PurpleMD4CipherPriv *priv;
-
 	void (*_purple_reserved1)(void);
 	void (*_purple_reserved2)(void);
 	void (*_purple_reserved3)(void);
 	void (*_purple_reserved4)(void);
 };
 
-struct _PurpleMD4CipherClass {
-	PurpleCipherClass gparent;
+struct _PurpleMD4HashClass {
+	PurpleCipherClass parent;
 
 	void (*_purple_reserved1)(void);
 	void (*_purple_reserved2)(void);
@@ -60,10 +57,10 @@ G_BEGIN_DECLS
 
 G_BEGIN_DECLS
 
-GType purple_md4_cipher_get_gtype(void);
+GType purple_md4_hash_get_gtype(void);
 
-PurpleCipher *purple_md4_cipher_new(void);
+PurpleCipher *purple_md4_hash_new(void);
 
 G_END_DECLS
 
-#endif /* PURPLE_MD4_CIPHER_H */
+#endif /* PURPLE_MD4_HASH_H */
============================================================
--- libpurple/ntlm.c	6857d691a565b97a2111c02891bf06581f1d412a
+++ libpurple/ntlm.c	227277b95b0efa1575a95a21edbcd42589742443
@@ -32,7 +32,7 @@
 #include "ntlm.h"
 #include "debug.h"
 #include "descipher.h"
-#include "md4cipher.h"
+#include "md4hash.h"
 #include <string.h>
 
 #define NTLM_NEGOTIATE_NTLM2_KEY 0x00080000
@@ -344,7 +344,7 @@ purple_ntlm_gen_type3(const gchar *usern
 		nt_pw[2 * idx + 1] = 0;
 	}
 
-	cipher = purple_md4_cipher_new();
+	cipher = purple_md4_hash_new();
 	purple_cipher_append(cipher, (guint8 *)nt_pw, 2 * lennt);
 	purple_cipher_digest(cipher, 21, nt_hpw, NULL);
 	g_object_unref(G_OBJECT(cipher));


More information about the Commits mailing list