From 555a47a3f4c109a2e9b0c79a47efa477533c9b2f Mon Sep 17 00:00:00 2001
From: magnum <magnum>
Date: Tue, 11 Oct 2011 10:22:46 +0200
Subject: [PATCH] Crc32, IBP2, SybaseASE, Oracle11 hash functions

---
 src/IPB2_fmt_plug.c     |   79 +++++++++++++++++++++++++++++++++++++++-------
 src/SybaseASE_fmt.c     |    7 +++-
 src/crc32_fmt_plug.c    |    7 +++-
 src/oracle11_fmt_plug.c |    7 +++-
 4 files changed, 85 insertions(+), 15 deletions(-)

diff --git a/src/IPB2_fmt_plug.c b/src/IPB2_fmt_plug.c
index cabb47a..492f473 100644
--- a/src/IPB2_fmt_plug.c
+++ b/src/IPB2_fmt_plug.c
@@ -88,7 +88,7 @@ static MD5_CTX ctx;
 static char saved_key[PLAINTEXT_LENGTH + 1];
 static int saved_key_len;
 static char workspace[MD5_HEX_SIZE * 2];
-static char output[MD5_BINARY_SIZE];
+static ARCH_WORD_32 output[MD5_BINARY_SIZE / sizeof(ARCH_WORD_32)];
 
 static int ipb2_valid(char *ciphertext, struct fmt_main *pFmt)
 {
@@ -208,6 +208,61 @@ static int ipb2_cmp_exact(char *source, int index)
 	return 1;
 }
 
+static int binary_hash_0(void *binary)
+{
+	return *(ARCH_WORD_32*)binary & 0xF;
+}
+
+static int binary_hash_1(void *binary)
+{
+	return *(ARCH_WORD_32*)binary & 0xFF;
+}
+
+static int binary_hash_2(void *binary)
+{
+	return *(ARCH_WORD_32*)binary & 0xFFF;
+}
+
+static int binary_hash_3(void *binary)
+{
+	return *(ARCH_WORD_32*)binary & 0xFFFF;
+}
+
+static int binary_hash_4(void *binary)
+{
+	return *(ARCH_WORD_32*)binary & 0xFFFFF;
+}
+
+static int get_hash_0(int index)
+{
+	return *output & 0xF;
+}
+
+static int get_hash_1(int index)
+{
+	return *output & 0xFF;
+}
+
+static int get_hash_2(int index)
+{
+	return *output & 0xFFF;
+}
+
+static int get_hash_3(int index)
+{
+	return *output & 0xFFFF;
+}
+
+static int get_hash_4(int index)
+{
+	return *output & 0xFFFFF;
+}
+
+static int salt_hash(void *salt)
+{
+	return *(ARCH_WORD_32*)salt & (SALT_HASH_SIZE - 1);
+}
+
 struct fmt_main fmt_IPB2 = {
 	{
 		FORMAT_LABEL,
@@ -231,24 +286,24 @@ struct fmt_main fmt_IPB2 = {
 		ipb2_binary,
 		ipb2_salt,
 		{
-			fmt_default_binary_hash,
-			fmt_default_binary_hash,
-			fmt_default_binary_hash,
-			fmt_default_binary_hash,
-			fmt_default_binary_hash
+			binary_hash_0,
+			binary_hash_1,
+			binary_hash_2,
+			binary_hash_3,
+			binary_hash_4
 		},
-		fmt_default_salt_hash,
+		salt_hash,
 		ipb2_set_salt,
 		ipb2_set_key,
 		ipb2_get_key,
 		fmt_default_clear_keys,
 		ipb2_crypt_all,
 		{
-			fmt_default_get_hash,
-			fmt_default_get_hash,
-			fmt_default_get_hash,
-			fmt_default_get_hash,
-			fmt_default_get_hash
+			get_hash_0,
+			get_hash_1,
+			get_hash_2,
+			get_hash_3,
+			get_hash_4
 		},
 		ipb2_cmp_all,
 		ipb2_cmp_all,
diff --git a/src/SybaseASE_fmt.c b/src/SybaseASE_fmt.c
index ba8bc46..bfd0620 100644
--- a/src/SybaseASE_fmt.c
+++ b/src/SybaseASE_fmt.c
@@ -234,6 +234,11 @@ static int cmp_exact(char *source, int index)
     return 1;
 }
 
+static int salt_hash(void *salt)
+{
+	return *(ARCH_WORD_32*)salt & (SALT_HASH_SIZE - 1);
+}
+
 struct fmt_main fmt_SybaseASE = {
     {
         FORMAT_LABEL,
@@ -262,7 +267,7 @@ struct fmt_main fmt_SybaseASE = {
             binary_hash_3,
             binary_hash_4
         },
-        fmt_default_salt_hash, // XXX: slow loading
+        salt_hash,
         set_salt,
         set_key,
         get_key,
diff --git a/src/crc32_fmt_plug.c b/src/crc32_fmt_plug.c
index 62fa2cb..a2a5979 100644
--- a/src/crc32_fmt_plug.c
+++ b/src/crc32_fmt_plug.c
@@ -172,6 +172,11 @@ static int cmp_exact(char *source, int index)
 	return 1;
 }
 
+static int salt_hash(void *salt)
+{
+	return *(ARCH_WORD_32*)salt & (SALT_HASH_SIZE - 1);
+}
+
 struct fmt_main fmt_crc32 = {
 	{
 		FORMAT_LABEL,
@@ -200,7 +205,7 @@ struct fmt_main fmt_crc32 = {
 			binary_hash_3,
 			binary_hash_4
 		},
-		fmt_default_salt_hash,
+		salt_hash,
 		set_salt,
 		set_key,
 		get_key,
diff --git a/src/oracle11_fmt_plug.c b/src/oracle11_fmt_plug.c
index c07a7ff..208e2e6 100644
--- a/src/oracle11_fmt_plug.c
+++ b/src/oracle11_fmt_plug.c
@@ -212,6 +212,11 @@ static int get_hash_4(int index)
   return crypt_out[0] & 0xFFFFF;
 }
 
+static int salt_hash(void *salt)
+{
+	return *(ARCH_WORD_32*)salt & (SALT_HASH_SIZE - 1);
+}
+
 struct fmt_main fmt_oracle11 = {
 	{
 		FORMAT_LABEL,
@@ -240,7 +245,7 @@ struct fmt_main fmt_oracle11 = {
 			binary_hash_3,
 			binary_hash_4
 		},
-		fmt_default_salt_hash,
+		salt_hash,
 		set_salt,
 		set_key,
 		get_key,
-- 
1.7.4.1

