/soc/2013/ankitkv/gobjectification: e0f887dee077: Split PurpleCi...

Ankit Vani a at nevitus.org
Sat Jun 15 20:29:55 EDT 2013


Changeset: e0f887dee077d1bae605046788082e399c7ebdbc
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-06-16 03:46 +0530
Branch:	 soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/e0f887dee077

Description:

Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.

diffstat:

 libpurple/Makefile.am         |    2 +
 libpurple/cipher.c            |   44 +------
 libpurple/cipher.h            |    4 -
 libpurple/ciphers/Makefile.am |   22 +-
 libpurple/ciphers/aes.c       |    2 +-
 libpurple/ciphers/aes.h       |    0 
 libpurple/ciphers/des3.c      |    4 +-
 libpurple/ciphers/des3.h      |    0 
 libpurple/ciphers/des.c       |    2 +-
 libpurple/ciphers/des.h       |    0 
 libpurple/ciphers/hmac.c      |   64 ++++----
 libpurple/ciphers/hmac.h      |    7 +-
 libpurple/ciphers/md4.c       |   76 +++++-----
 libpurple/ciphers/md4.h       |   36 ++--
 libpurple/ciphers/md5.c       |   92 ++++++------
 libpurple/ciphers/md5.h       |   38 ++--
 libpurple/ciphers/pbkdf2.c    |   16 +-
 libpurple/ciphers/pbkdf2.h    |    7 +-
 libpurple/ciphers/rc4.c       |    2 +-
 libpurple/ciphers/rc4.h       |    0 
 libpurple/ciphers/sha1.c      |   92 ++++++------
 libpurple/ciphers/sha1.h      |   38 ++--
 libpurple/ciphers/sha256.c    |   92 ++++++------
 libpurple/ciphers/sha256.h    |   38 ++--
 libpurple/hash.c              |  297 ++++++++++++++++++++++++++++++++++++++++++
 libpurple/hash.h              |  119 ++++++++++++++++
 26 files changed, 733 insertions(+), 361 deletions(-)

diffs (truncated from 2062 to 300 lines):

diff --git a/libpurple/Makefile.am b/libpurple/Makefile.am
--- a/libpurple/Makefile.am
+++ b/libpurple/Makefile.am
@@ -52,6 +52,7 @@ purple_coresources = \
 	desktopitem.c \
 	eventloop.c \
 	ft.c \
+	hash.c \
 	http.c \
 	idle.c \
 	imgstore.c \
@@ -122,6 +123,7 @@ purple_coreheaders = \
 	desktopitem.h \
 	eventloop.h \
 	ft.h \
+	hash.h \
 	http.h \
 	idle.h \
 	imgstore.h \
diff --git a/libpurple/cipher.c b/libpurple/cipher.c
--- a/libpurple/cipher.c
+++ b/libpurple/cipher.c
@@ -1,24 +1,9 @@
-/*
- * purple
+/* 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.
  *
- * Original des taken from gpg
- *
- * des.c - DES and Triple-DES encryption/decryption Algorithm
- *	Copyright (C) 1998 Free Software Foundation, Inc.
- *
- *	Please see below for more legal information!
- *
- *	 According to the definition of DES in FIPS PUB 46-2 from December 1993.
- *	 For a description of triple encryption, see:
- *	   Bruce Schneier: Applied Cryptography. Second Edition.
- *	   John Wiley & Sons, 1996. ISBN 0-471-12845-7. Pages 358 ff.
- *
- *	 This file is part of GnuPG.
- *
  * 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
@@ -51,7 +36,6 @@ purple_cipher_class_init(PurpleCipherCla
 	klass->encrypt = NULL;
 	klass->decrypt = NULL;
 	klass->set_salt = NULL;
-	klass->get_salt_size = NULL;
 	klass->set_key = NULL;
 	klass->get_key_size = NULL;
 	klass->set_batch_mode = NULL;
@@ -402,32 +386,6 @@ purple_cipher_set_salt(PurpleCipher *cip
 }
 
 /**
- * purple_cipher_get_salt_size:
- * @cipher: The cipher whose salt size to get
- *
- * Gets the size of the salt if the cipher supports it
- *
- * Return Value: The size of the salt
- */
-size_t
-purple_cipher_get_salt_size(PurpleCipher *cipher) {
-	PurpleCipherClass *klass = NULL;
-
-	g_return_val_if_fail(PURPLE_IS_CIPHER(cipher), -1);
-
-	klass = PURPLE_CIPHER_GET_CLASS(cipher);
-
-	if(klass && klass->get_salt_size)
-		return klass->get_salt_size(cipher);
-	else
-		purple_debug_warning("cipher", "the %s cipher does not implement the "
-						"get_salt_size method\n",
-						klass->get_name ? klass->get_name(cipher) : "");
-
-	return -1;
-}
-
-/**
  * purple_cipher_set_key:
  * @cipher: The cipher whose key to set
  * @key: The key
diff --git a/libpurple/cipher.h b/libpurple/cipher.h
--- a/libpurple/cipher.h
+++ b/libpurple/cipher.h
@@ -108,9 +108,6 @@ struct _PurpleCipherClass {
 	/** The set salt function */
 	void (*set_salt)(PurpleCipher *cipher, const guchar *salt, size_t len);
 
-	/** The get salt size function */
-	size_t (*get_salt_size)(PurpleCipher *cipher);
-
 	/** The set key function */
 	void (*set_key)(PurpleCipher *cipher, const guchar *key, size_t len);
 
@@ -155,7 +152,6 @@ ssize_t purple_cipher_encrypt(PurpleCiph
 ssize_t purple_cipher_decrypt(PurpleCipher *cipher, const guchar input[], size_t in_len, guchar output[], size_t out_size);
 
 void purple_cipher_set_salt(PurpleCipher *cipher, const guchar *salt, size_t len);
-size_t purple_cipher_get_salt_size(PurpleCipher *cipher);
 
 void purple_cipher_set_key(PurpleCipher *cipher, const guchar *key, size_t len);
 size_t purple_cipher_get_key_size(PurpleCipher *cipher);
diff --git a/libpurple/ciphers/Makefile.am b/libpurple/ciphers/Makefile.am
--- a/libpurple/ciphers/Makefile.am
+++ b/libpurple/ciphers/Makefile.am
@@ -2,23 +2,23 @@ noinst_LTLIBRARIES=libpurple-ciphers.la
 # XXX: cipher.lo won't be updated after a change in cipher files
 
 if USE_NSS
-AES_SOURCE = aes.c
+AES_SOURCE = aescipher.c
 endif
 if USE_GNUTLS
-AES_SOURCE = aes.c
+AES_SOURCE = aescipher.c
 endif
 
 libpurple_ciphers_la_SOURCES=\
 	$(AES_SOURCE) \
-	des.c \
-	des3.c \
-	hmac.c \
-	md4.c \
-	md5.c \
-	pbkdf2.c \
-	rc4.c \
-	sha1.c \
-	sha256.c
+	descipher.c \
+	des3cipher.c \
+	hmaccipher.c \
+	md4hash.c \
+	md5hash.c \
+	pbkdf2cipher.c \
+	rc4cipher.c \
+	sha1hash.c \
+	sha256hash.c
 
 INCLUDES = -I$(top_srcdir)/libpurple
 
diff --git a/libpurple/ciphers/aes.c b/libpurple/ciphers/aescipher.c
rename from libpurple/ciphers/aes.c
rename to libpurple/ciphers/aescipher.c
--- a/libpurple/ciphers/aes.c
+++ b/libpurple/ciphers/aescipher.c
@@ -22,7 +22,7 @@
  * Written by Tomek Wasilczyk <tomkiewicz at cpw.pidgin.im>
  */
 
-#include "aes.h"
+#include "aescipher.h"
 #include "debug.h"
 
 #include <string.h>
diff --git a/libpurple/ciphers/aes.h b/libpurple/ciphers/aescipher.h
rename from libpurple/ciphers/aes.h
rename to libpurple/ciphers/aescipher.h
diff --git a/libpurple/ciphers/des3.c b/libpurple/ciphers/des3cipher.c
rename from libpurple/ciphers/des3.c
rename to libpurple/ciphers/des3cipher.c
--- a/libpurple/ciphers/des3.c
+++ b/libpurple/ciphers/des3cipher.c
@@ -29,8 +29,8 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
  */
-#include "des3.h"
-#include "des.h"
+#include "des3cipher.h"
+#include "descipher.h"
 
 #include <string.h>
 
diff --git a/libpurple/ciphers/des3.h b/libpurple/ciphers/des3cipher.h
rename from libpurple/ciphers/des3.h
rename to libpurple/ciphers/des3cipher.h
diff --git a/libpurple/ciphers/des.c b/libpurple/ciphers/descipher.c
rename from libpurple/ciphers/des.c
rename to libpurple/ciphers/descipher.c
--- a/libpurple/ciphers/des.c
+++ b/libpurple/ciphers/descipher.c
@@ -29,7 +29,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
  */
-#include "des.h"
+#include "descipher.h"
 
 #include <string.h>
 
diff --git a/libpurple/ciphers/des.h b/libpurple/ciphers/descipher.h
rename from libpurple/ciphers/des.h
rename to libpurple/ciphers/descipher.h
diff --git a/libpurple/ciphers/hmac.c b/libpurple/ciphers/hmaccipher.c
rename from libpurple/ciphers/hmac.c
rename to libpurple/ciphers/hmaccipher.c
--- a/libpurple/ciphers/hmac.c
+++ b/libpurple/ciphers/hmaccipher.c
@@ -19,7 +19,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
  */
-#include "hmac.h"
+#include "hmaccipher.h"
 
 #include <string.h>
 
@@ -30,7 +30,7 @@
 	(G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_HMAC_CIPHER, PurpleHMACCipherPrivate))
 
 typedef struct {
-	PurpleCipher *hash;
+	PurpleHash *hash;
 	guchar *ipad;
 	guchar *opad;
 } PurpleHMACCipherPrivate;
@@ -69,8 +69,8 @@ static void
 purple_hmac_cipher_reset(PurpleCipher *cipher) {
 	PurpleHMACCipherPrivate *priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
 
-	if(PURPLE_IS_CIPHER(priv->hash))
-		purple_cipher_reset(priv->hash);
+	if(PURPLE_IS_HASH(priv->hash))
+		purple_hash_reset(priv->hash);
 
 	if(priv->ipad) {
 		g_free(priv->ipad);
@@ -86,10 +86,10 @@ static void
 purple_hmac_cipher_reset_state(PurpleCipher *cipher) {
 	PurpleHMACCipherPrivate *priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
 
-	if(PURPLE_IS_CIPHER(priv->hash)) {
-		purple_cipher_reset_state(priv->hash);
-		purple_cipher_append(priv->hash, priv->ipad,
-								purple_cipher_get_block_size(priv->hash));
+	if(PURPLE_IS_HASH(priv->hash)) {
+		purple_hash_reset_state(priv->hash);
+		purple_hash_append(priv->hash, priv->ipad,
+								purple_hash_get_block_size(priv->hash));
 	}
 }
 
@@ -97,17 +97,17 @@ static void
 purple_hmac_cipher_set_iv(PurpleCipher *cipher, guchar *iv, size_t len) {
 	PurpleHMACCipherPrivate *priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
 
-	if(PURPLE_IS_CIPHER(priv->hash))
-		purple_cipher_set_iv(priv->hash, iv, len);
+	if(PURPLE_IS_HASH(priv->hash))
+		purple_hash_set_iv(priv->hash, iv, len);
 }
 
 static void
 purple_hmac_cipher_append(PurpleCipher *cipher, const guchar *d, size_t l) {
 	PurpleHMACCipherPrivate *priv = PURPLE_HMAC_CIPHER_GET_PRIVATE(cipher);
 
-	g_return_if_fail(PURPLE_IS_CIPHER(priv->hash));
+	g_return_if_fail(PURPLE_IS_HASH(priv->hash));
 
-	purple_cipher_append(priv->hash, d, l);
+	purple_hash_append(priv->hash, d, l);
 }
 
 static gboolean
@@ -118,17 +118,17 @@ purple_hmac_cipher_digest(PurpleCipher *
 	size_t hash_len, block_size;
 	gboolean result = FALSE;
 
-	g_return_val_if_fail(PURPLE_IS_CIPHER(priv->hash), FALSE);
+	g_return_val_if_fail(PURPLE_IS_HASH(priv->hash), FALSE);
 
-	hash_len = purple_cipher_get_digest_size(priv->hash);
+	hash_len = purple_hash_get_digest_size(priv->hash);
 	g_return_val_if_fail(hash_len > 0, FALSE);
 
-	block_size = purple_cipher_get_block_size(priv->hash);
+	block_size = purple_hash_get_block_size(priv->hash);
 	digest = g_malloc(hash_len);
 
 	/* get the digest of the data */
-	result = purple_cipher_digest(priv->hash, digest, hash_len);
-	purple_cipher_reset(priv->hash);
+	result = purple_hash_digest(priv->hash, digest, hash_len);
+	purple_hash_reset(priv->hash);
 
 	if(!result) {
 		g_free(digest);
@@ -137,11 +137,11 @@ purple_hmac_cipher_digest(PurpleCipher *
 	}
 
 	/* now append the opad and the digest from above */
-	purple_cipher_append(priv->hash, priv->opad, block_size);



More information about the Commits mailing list