gobjectification: 5ef88f05: created hash.[ch] which is a new parent ...

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


-----------------------------------------------------------------
Revision: 5ef88f05732d100051a36f4c3ee60f1225d68592
Ancestor: 528815f7556c4cd9f5317f0093761f30fcb43435
Author: grim at pidgin.im
Date: 2009-07-20T04:20:47
Branch: im.pidgin.gobjectification
URL: http://d.pidgin.im/viewmtn/revision/info/5ef88f05732d100051a36f4c3ee60f1225d68592

Added files:
        libpurple/hash.c libpurple/hash.h
Modified files:
        libpurple/Makefile.am libpurple/hmaccipher.c
        libpurple/hmaccipher.h libpurple/md4hash.c
        libpurple/md4hash.h

ChangeLog: 

created hash.[ch] which is a new parent for hashing functions.  (we're splitting ciphers and hash/digests).
added an interface to PurpleHMACCipher that allows for proper testing of hashes that implement the needed stuff for hmac.
renamed PurpleMD4Cipher to PurpleMD4Hash
implemented PurpleHMACFunction in PurpleMD4Hash


-------------- next part --------------
============================================================
--- libpurple/hash.c	1ffac2e03f11c27825ab6414e7dbb7f2874985af
+++ libpurple/hash.c	1ffac2e03f11c27825ab6414e7dbb7f2874985af
@@ -0,0 +1,235 @@
+/*
+ * purple
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ */
+#include "internal.h"
+
+#include "hash.h"
+
+/*******************************************************************************
+ * Structs
+ ******************************************************************************/
+
+/******************************************************************************
+ * Globals
+ *****************************************************************************/
+static GObjectClass *parent_class = NULL;
+
+/******************************************************************************
+ * Object Stuff
+ *****************************************************************************/
+static void
+purple_hash_finalize(GObject *obj) {
+	purple_hash_reset(PURPLE_HASH(obj));
+
+	G_OBJECT_CLASS(parent_class)->finalize(obj);
+}
+
+static void
+purple_hash_class_init(PurpleHashClass *klass) {
+	GObjectClass *obj_class = G_OBJECT_CLASS(klass);
+
+	parent_class = g_type_class_peek_parent(klass);
+
+	obj_class->finalize = purple_hash_finalize;
+}
+
+/******************************************************************************
+ * PurpleHash API
+ *****************************************************************************/
+GType
+purple_hash_get_gtype(void) {
+	static GType type = 0;
+
+	if(type == 0) {
+		static const GTypeInfo info = {
+			sizeof(PurpleHashClass),
+			NULL,
+			NULL,
+			(GClassInitFunc)purple_hash_class_init,
+			NULL,
+			NULL,
+			sizeof(PurpleHash),
+			0,
+			NULL,
+			NULL
+		};
+
+		type = g_type_register_static(G_TYPE_OBJECT,
+									  "PurpleHash",
+									  &info, G_TYPE_FLAG_ABSTRACT);
+	}
+
+	return type;
+}
+
+void
+purple_hash_reset(PurpleHash *hash) {
+	PurpleHashClass *klass = NULL;
+
+	g_return_if_fail(PURPLE_IS_HASH(hash));
+
+	klass = PURPLE_HASH_GET_CLASS(hash);
+
+	if(klass && klass->reset)
+		klass->reset(hash);
+}
+
+void
+purple_hash_set_iv(PurpleHash *hash, guchar *iv, size_t len)
+{
+	PurpleHashClass *klass = NULL;
+
+	g_return_if_fail(PURPLE_IS_HASH(hash));
+	g_return_if_fail(iv);
+
+	klass = PURPLE_HASH_GET_CLASS(hash);
+
+	if(klass && klass->set_iv)
+		klass->set_iv(hash, iv, len);
+}
+
+void
+purple_hash_append(PurpleHash *hash, const guchar *data,
+								size_t len)
+{
+	PurpleHashClass *klass = NULL;
+
+	g_return_if_fail(PURPLE_IS_HASH(hash));
+
+	klass = PURPLE_HASH_GET_CLASS(hash);
+
+	if(klass && klass->append)
+		klass->append(hash, data, len);
+}
+
+gboolean
+purple_hash_digest(PurpleHash *hash, size_t in_len,
+						   guchar digest[], size_t *out_len)
+{
+	PurpleHashClass *klass = NULL;
+
+	g_return_val_if_fail(PURPLE_IS_HASH(hash), FALSE);
+
+	klass = PURPLE_HASH_GET_CLASS(hash);
+
+	if(klass && klass->digest)
+		return klass->digest(hash, in_len, digest, out_len);
+
+	return FALSE;
+}
+
+gboolean
+purple_hash_digest_to_str(PurpleHash *hash, size_t in_len,
+								   gchar digest_s[], size_t *out_len)
+{
+	/* 8k is a bit excessive, will tweak later. */
+	guchar digest[BUF_LEN * 4];
+	gint n = 0;
+	size_t dlen = 0;
+
+	g_return_val_if_fail(hash, FALSE);
+	g_return_val_if_fail(digest_s, FALSE);
+
+	if(!purple_hash_digest(hash, sizeof(digest), digest, &dlen))
+		return FALSE;
+
+	/* in_len must be greater than dlen * 2 so we have room for the NUL. */
+	if(in_len <= dlen * 2)
+		return FALSE;
+
+	for(n = 0; n < dlen; n++)
+		sprintf(digest_s + (n * 2), "%02x", digest[n]);
+
+	digest_s[n * 2] = '\0';
+
+	if(out_len)
+		*out_len = dlen * 2;
+
+	return TRUE;
+}
+
+void
+purple_hash_set_salt(PurpleHash *hash, guchar *salt) {
+	PurpleHashClass *klass = NULL;
+
+	g_return_if_fail(PURPLE_IS_HASH(hash));
+
+	klass = PURPLE_HASH_GET_CLASS(hash);
+
+	if(klass && klass->set_salt)
+		klass->set_salt(hash, salt);
+}
+
+size_t
+purple_hash_get_salt_size(PurpleHash *hash) {
+	PurpleHashClass *klass = NULL;
+
+	g_return_val_if_fail(PURPLE_IS_HASH(hash), -1);
+
+	klass = PURPLE_HASH_GET_CLASS(hash);
+
+	if(klass && klass->get_salt_size)
+		return klass->get_salt_size(hash);
+
+	return -1;
+}
+
+void
+purple_hash_set_key(PurpleHash *hash, const guchar *key) {
+	PurpleHashClass *klass = NULL;
+
+	g_return_if_fail(PURPLE_IS_HASH(hash));
+
+	klass = PURPLE_HASH_GET_CLASS(hash);
+
+	if(klass && klass->set_key)
+		klass->set_key(hash, key);
+}
+
+size_t
+purple_hash_get_key_length(PurpleHash *hash) {
+	PurpleHashClass *klass = NULL;
+
+	g_return_val_if_fail(PURPLE_IS_HASH(hash), -1);
+
+	klass = PURPLE_HASH_GET_CLASS(hash);
+
+	if(klass && klass->get_key_length)
+		return klass->get_key_length(hash);
+
+	return -1;
+}
+
+void
+purple_hash_set_key_with_length(PurpleHash *hash, const guchar *key,
+								size_t length)
+{
+	PurpleHashClass *klass = NULL;
+
+	g_return_if_fail(PURPLE_IS_HASH(hash));
+	g_return_if_fail(key);
+
+	klass = PURPLE_HASH_GET_CLASS(hash);
+
+	if(klass && klass->set_key_with_length)
+		klass->set_key_with_length(hash, key, length);
+}
+
============================================================
--- libpurple/hash.h	4b30649d1971ba3f4bcecb2efa2c46b909441848
+++ libpurple/hash.h	4b30649d1971ba3f4bcecb2efa2c46b909441848
@@ -0,0 +1,192 @@
+/**
+ * @file hash.h Purple Hash API
+ * @ingroup core
+ */
+
+/* purple
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ */
+#ifndef PURPLE_HASH_H
+#define PURPLE_HASH_H
+
+#include <glib.h>
+
+#include <pobject.h>
+
+#define PURPLE_TYPE_HASH				(purple_hash_get_gtype())
+#define PURPLE_HASH(obj)				(G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_HASH, PurpleHash))
+#define PURPLE_HASH_CLASS(klass)		(G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_HASH, PurpleHashClass))
+#define PURPLE_IS_HASH(obj)			(G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_HASH))
+#define PURPLE_IS_HASH_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE((klass), PURPLE_TYPE_HASH))
+#define PURPLE_HASH_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_HASH, PurpleHashClass))
+
+typedef struct _PurpleHash			PurpleHash;
+typedef struct _PurpleHashClass		PurpleHashClass;
+
+struct _PurpleHash {
+	PurpleObject parent;
+
+	void (*_purple_reserved1)(void);
+	void (*_purple_reserved2)(void);
+	void (*_purple_reserved3)(void);
+	void (*_purple_reserved4)(void);
+};
+
+struct _PurpleHashClass {
+	PurpleObjectClass parent;
+
+	/** The reset function */
+	void (*reset)(PurpleHash *hash);
+
+	/** The set initialization vector function */
+	void (*set_iv)(PurpleHash *hash, guchar *iv, size_t len);
+
+	/** The append data function */
+	void (*append)(PurpleHash *hash, const guchar *data, size_t len);
+
+	/** The digest function */
+	gboolean (*digest)(PurpleHash *hash, size_t in_len, guchar digest[], size_t *out_len);
+
+	/** The set salt function */
+	void (*set_salt)(PurpleHash *hash, guchar *salt);
+
+	/** The get salt size function */
+	size_t (*get_salt_size)(PurpleHash *hash);
+
+	/** The set key function */
+	void (*set_key)(PurpleHash *hash, const guchar *key);
+
+	/** The get key size function */
+	size_t (*get_key_length)(PurpleHash *hash);
+
+	/** The set key with length function */
+	void (*set_key_with_length)(PurpleHash *hash, const guchar *key, size_t length);
+
+	void (*_purple_reserved1)(void);
+	void (*_purple_reserved2)(void);
+	void (*_purple_reserved3)(void);
+	void (*_purple_reserved4)(void);
+};
+
+G_BEGIN_DECLS
+
+/*****************************************************************************/
+/** @name PurpleHash API													 */
+/*****************************************************************************/
+/*@{*/
+
+GType purple_hash_get_gtype(void);
+
+/**
+ * Resets a hash to it's default value
+ * @note If you have set an IV you will have to set it after resetting
+ *
+ * @param hash  The hash to reset
+  */
+void purple_hash_reset(PurpleHash *hash);
+
+/**
+ * Sets the initialization vector for a hash
+ * @note This should only be called right after a hash is created or reset
+ *
+ * @param hash  The hash to set the IV to
+ * @param iv      The initialization vector to set
+ * @param len     The len of the IV
+ */
+void purple_hash_set_iv(PurpleHash *hash, guchar *iv, size_t len);
+
+/**
+ * Appends data to the hash
+ *
+ * @param hash  The hash to append data to
+ * @param data    The data to append
+ * @param len     The length of the data
+ */
+void purple_hash_append(PurpleHash *hash, const guchar *data, size_t len);
+
+/**
+ * Digests a hash
+ *
+ * @param hash  The hash to digest
+ * @param in_len  The length of the buffer
+ * @param digest  The return buffer for the digest
+ * @param out_len The length of the returned value
+ */
+gboolean purple_hash_digest(PurpleHash *hash, size_t in_len, guchar digest[], size_t *out_len);
+
+/**
+ * Converts a guchar digest into a hex string
+ *
+ * @param hash   The hash to get a digest from
+ * @param in_len   The length of the buffer
+ * @param digest_s The return buffer for the string digest
+ * @param out_len  The length of the returned value
+ */
+gboolean purple_hash_digest_to_str(PurpleHash *hash, size_t in_len, gchar digest_s[], size_t *out_len);
+
+/**
+ * Sets the salt on a hash
+ *
+ * @param hash  The hash whose salt to set
+ * @param salt    The salt
+ */
+void purple_hash_set_salt(PurpleHash *hash, guchar *salt);
+
+/**
+ * Gets the size of the salt if the hash supports it
+ *
+ * @param hash  The hash whose salt size to get
+ *
+ * @return The size of the salt
+ */
+size_t purple_hash_get_salt_size(PurpleHash *hash);
+
+/**
+ * Sets the key on a hash
+ *
+ * @param hash  The hash whose key to set
+ * @param key     The key
+ */
+void purple_hash_set_key(PurpleHash *hash, const guchar *key);
+
+/**
+ * Gets the key size for a hash
+ *
+ * @param hash  The hash whose key size to get
+ *
+ * @return The size of the key
+ */
+size_t purple_hash_get_key_length(PurpleHash *hash);
+
+/**
+ * Sets the key with a given length on a hash
+ *
+ * @param hash  The hash whose key to set
+ * @param key     The key
+ * @param len     The length of the key
+ *
+ */
+void purple_hash_set_key_with_length(PurpleHash *hash, const guchar *key, size_t length);
+
+/*@}*/
+
+G_END_DECLS
+
+#endif /* PURPLE_HASH_H */
============================================================
--- libpurple/Makefile.am	c83e7e66802f909b608934e2c032fc638498045d
+++ libpurple/Makefile.am	10f7231ceede3849f5d377a0a470905ea19b6d8d
@@ -60,6 +60,7 @@ purple_coresources = \
 	ghash.c \
 	group.c \
 	gsignal.c \
+	hash.c \
 	hmaccipher.c \
 	idle.c \
 	imgstore.c \
@@ -135,6 +136,7 @@ purple_coreheaders = \
 	gaim-compat.h \
 	ghash.h \
 	gsignal.h \
+	hash.h \
 	hmaccipher.h \
 	idle.h \
 	imgstore.h \
============================================================
--- libpurple/hmaccipher.c	6c8ba8959e4ea9f64fe4aceaa0176d8ca365faf1
+++ libpurple/hmaccipher.c	c6cd8f0a72fe6f0617df4849638a522f395988b5
@@ -267,7 +267,7 @@ purple_hmac_cipher_class_init(PurpleHMAC
 }
 
 /******************************************************************************
- * API
+ * PurpleHMACCipher API
  *****************************************************************************/
 GType
 purple_hmac_cipher_get_gtype(void) {
@@ -318,3 +318,47 @@ purple_hmac_cipher_get_hash(const Purple
 	return NULL;
 }
 
+/******************************************************************************
+ * PurpleHMACFunction API
+ *****************************************************************************/
+GType
+purple_hmac_function_get_type(void) {
+	static GType type = 0;
+
+	if(G_UNLIKELY(type == 0)) {
+		static const GTypeInfo info = {
+			sizeof(PurpleHMACFunctionIface),
+			NULL,
+			NULL,
+			NULL,
+			NULL,
+			NULL,
+			0,
+			0,
+			NULL,
+			NULL,
+		};
+
+		type = g_type_register_static(G_TYPE_INTERFACE,
+									  "PurpleHMACFunction",
+									  &info, 0);
+
+	}
+
+	return type;
+}
+
+size_t
+purple_hmac_function_get_block_size(const PurpleHMACFunction *function) {
+	PurpleHMACFunctionIface *iface = NULL;
+
+	g_return_val_if_fail(PURPLE_IS_HMAC_FUNCTION(function), -1);
+
+	iface = PURPLE_HMAC_FUNCTION_GET_IFACE(function);
+
+	if(iface && iface->get_block_size)
+		return iface->get_block_size(function);
+
+	return -1;
+}
+
============================================================
--- libpurple/hmaccipher.h	5d65819b65ff70c2fea297236d7212d1353af9dd
+++ libpurple/hmaccipher.h	4047baa4a510d9d08efc4423ba6e365696e6ad2b
@@ -56,6 +56,20 @@ struct _PurpleHMACCipherClass {
 	void (*_purple_reserved4)(void);
 };
 
+#define PURPLE_TYPE_HMAC_FUNCTION			(purple_hmac_function_get_type())
+#define PURPLE_HMAC_FUNCTION(obj)			(G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_HMAC_FUNCTION, PurpleHMACFunction))
+#define PURPLE_IS_HMAC_FUNCTION(obj)		(G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_HMAC_FUNCTION))
+#define PURPLE_HMAC_FUNCTION_GET_IFACE(obj)	(G_TYPE_INSTANCE_GET_INTERFACE((obj), PURPLE_TYPE_HMAC_FUNCTION, PurpleHMACFunctionIface))
+
+typedef struct _PurpleHMACFunction			PurpleHMACFunction;
+typedef struct _PurpleHMACFunctionIface		PurpleHMACFunctionIface;
+
+struct _PurpleHMACFunctionIface {
+	GTypeInterface parent;
+
+	size_t (*get_block_size)(const PurpleHMACFunction *function);
+};
+
 G_BEGIN_DECLS
 
 GType purple_hmac_cipher_get_gtype(void);
@@ -64,6 +78,10 @@ PurpleCipher *purple_hmac_cipher_get_has
 
 PurpleCipher *purple_hmac_cipher_get_hash(const PurpleHMACCipher *cipher);
 
+GType purple_hmac_function_get_type(void);
+
+size_t purple_hmac_function_get_block_size(const PurpleHMACFunction *function);
+
 G_END_DECLS
 
 #endif /* PURPLE_HMAC_CIPHER_H */
============================================================
--- libpurple/md4hash.c	addb9b36865ec0975e6bef3640c43d07ff5b0b72
+++ libpurple/md4hash.c	4e10b3ef8f10cdb6bd6c155dea48d6f965b81aa3
@@ -15,6 +15,8 @@
  */
 #include "md4hash.h"
 
+#include "hmaccipher.h"
+
 #include <string.h>
 
 #define MD4_DIGEST_SIZE		16
@@ -155,8 +157,8 @@ static inline void
 }
 
 static inline void
-md4_transform_helper(PurpleCipher *cipher) {
-	PurpleMD4HashPrivate *priv = PURPLE_MD4_HASH_GET_PRIVATE(cipher);
+md4_transform_helper(PurpleHash *hash) {
+	PurpleMD4HashPrivate *priv = PURPLE_MD4_HASH_GET_PRIVATE(hash);
 
 	le32_to_cpu_array(priv->block, sizeof(priv->block) / sizeof(guint32));
 	md4_transform(priv->hash, priv->block);
@@ -166,8 +168,8 @@ static void
  * Hash Stuff
  *****************************************************************************/
 static void
-purple_md4_hash_reset(PurpleCipher *cipher) {
-	PurpleMD4HashPrivate *priv = PURPLE_MD4_HASH_GET_PRIVATE(cipher);
+purple_md4_hash_reset(PurpleHash *hash) {
+	PurpleMD4HashPrivate *priv = PURPLE_MD4_HASH_GET_PRIVATE(hash);
 
 	priv->hash[0] = 0x67452301;
 	priv->hash[1] = 0xefcdab89;
@@ -180,8 +182,8 @@ static void
 }
 
 static void
-purple_md4_hash_append(PurpleCipher *cipher, const guchar *data, size_t len) {
-	PurpleMD4HashPrivate *priv = PURPLE_MD4_HASH_GET_PRIVATE(cipher);
+purple_md4_hash_append(PurpleHash *hash, const guchar *data, size_t len) {
+	PurpleMD4HashPrivate *priv = PURPLE_MD4_HASH_GET_PRIVATE(hash);
 	const guint32 avail = sizeof(priv->block) - (priv->byte_count & 0x3f);
 
 	priv->byte_count += len;
@@ -197,13 +199,13 @@ purple_md4_hash_append(PurpleCipher *cip
 		   (sizeof(priv->block) - avail),
 		   data, avail);
 
-	md4_transform_helper(cipher);
+	md4_transform_helper(hash);
 	data += avail;
 	len -= avail;
 
 	while(len >= sizeof(priv->block)) {
 		memcpy(priv->block, data, sizeof(priv->block));
-		md4_transform_helper(cipher);
+		md4_transform_helper(hash);
 		data += sizeof(priv->block);
 		len -= sizeof(priv->block);
 	}
@@ -212,10 +214,10 @@ static gboolean
 }
 
 static gboolean
-purple_md4_hash_digest(PurpleCipher *cipher, size_t in_len, guchar digest[16],
+purple_md4_hash_digest(PurpleHash *hash, size_t in_len, guchar digest[16],
 					   size_t *out_len)
 {
-	PurpleMD4HashPrivate *priv = PURPLE_MD4_HASH_GET_PRIVATE(cipher);
+	PurpleMD4HashPrivate *priv = PURPLE_MD4_HASH_GET_PRIVATE(hash);
 	const unsigned int offset = priv->byte_count & 0x3f;
 	gchar *p = (gchar *)priv->block + offset;
 	gint padding = 56 - (offset + 1);
@@ -230,7 +232,7 @@ purple_md4_hash_digest(PurpleCipher *cip
 
 	if(padding < 0) {
 		memset(p, 0x00, padding + sizeof(guint64));
-		md4_transform_helper(cipher);
+		md4_transform_helper(hash);
 		p = (gchar *)priv->block;
 		padding = 56;
 	}
@@ -248,29 +250,36 @@ purple_md4_hash_digest(PurpleCipher *cip
 	return TRUE;
 }
 
-static size_t
-purple_md4_hash_get_block_size(PurpleCipher *cipher) {
-	return MD4_HMAC_BLOCK_SIZE;
-}
-
 /******************************************************************************
  * Object Stuff
  *****************************************************************************/
 static void
 purple_md4_hash_class_init(PurpleMD4HashClass *klass) {
-	PurpleCipherClass *cipher_class = PURPLE_CIPHER_CLASS(klass);
+	PurpleHashClass *hash_class = PURPLE_HASH_CLASS(klass);
 
 	parent_class = g_type_class_peek_parent(klass);
 
 	g_type_class_add_private(klass, sizeof(PurpleMD4HashPrivate));
 
-	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;
+	hash_class->reset = purple_md4_hash_reset;
+	hash_class->append = purple_md4_hash_append;
+	hash_class->digest = purple_md4_hash_digest;
 }
 
 /******************************************************************************
+ * HMACFunction Stuff
+ *****************************************************************************/
+static size_t
+purple_md4_hash_get_block_size(const PurpleHMACFunction *function) {
+	return MD4_HMAC_BLOCK_SIZE;
+}
+
+static void
+purple_md4_hash_hmac_function_init(PurpleHMACFunctionIface *iface) {
+	iface->get_block_size = purple_md4_hash_get_block_size;
+}
+
+/******************************************************************************
  * API
  *****************************************************************************/
 GType
@@ -291,15 +300,23 @@ purple_md4_hash_get_gtype(void) {
 			NULL,
 		};
 
-		type = g_type_register_static(PURPLE_TYPE_CIPHER,
-									  "PurpleMD4Cipher",
+		static const GInterfaceInfo hmac_info = {
+			(GInterfaceInitFunc)purple_md4_hash_hmac_function_init,
+			NULL,
+			NULL
+		};
+
+		type = g_type_register_static(PURPLE_TYPE_HASH,
+									  "PurpleMD4Hash",
 									  &info, 0);
+
+		g_type_add_interface_static(type, PURPLE_TYPE_HMAC_FUNCTION, &hmac_info);
 	}
 
 	return type;
 }
 
-PurpleCipher *
+PurpleHash *
 purple_md4_hash_new(void) {
 	return g_object_new(PURPLE_TYPE_MD4_HASH, NULL);
 }
============================================================
--- libpurple/md4hash.h	1d48589f0de402419242e55c511e0e342243e3d8
+++ libpurple/md4hash.h	21543c0a2e54804ba4a8f5c55c79f034e4255298
@@ -25,7 +25,7 @@
 #ifndef PURPLE_MD4_HASH_H
 #define PURPLE_MD4_HASH_H
 
-#include <cipher.h>
+#include <hash.h>
 
 #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))
@@ -38,7 +38,7 @@ struct _PurpleMD4Hash {
 typedef struct _PurpleMD4HashClass		PurpleMD4HashClass;
 
 struct _PurpleMD4Hash {
-	PurpleCipher parent;
+	PurpleHash parent;
 
 	void (*_purple_reserved1)(void);
 	void (*_purple_reserved2)(void);
@@ -47,7 +47,7 @@ struct _PurpleMD4HashClass {
 };
 
 struct _PurpleMD4HashClass {
-	PurpleCipherClass parent;
+	PurpleHashClass parent;
 
 	void (*_purple_reserved1)(void);
 	void (*_purple_reserved2)(void);
@@ -59,7 +59,7 @@ GType purple_md4_hash_get_gtype(void);
 
 GType purple_md4_hash_get_gtype(void);
 
-PurpleCipher *purple_md4_hash_new(void);
+PurpleHash *purple_md4_hash_new(void);
 
 G_END_DECLS
 


More information about the Commits mailing list