From bb14caa05aa31fe00302a1abb2657dbca95f4e01 Mon Sep 17 00:00:00 2001
From: magnum <magnum>
Date: Mon, 7 Nov 2011 02:00:08 +0100
Subject: [PATCH 4/6] All salt_hash functions use params.h macros for size

---
 src/PO_fmt_plug.c       |    6 +++---
 src/XSHA512_fmt.c       |    2 +-
 src/XSHA_fmt_plug.c     |    2 +-
 src/dynamic_fmt.c       |    4 ++--
 src/hmailserver_fmt.c   |    8 ++++----
 src/md4_gen_fmt_plug.c  |   10 +++++-----
 src/sha1_gen_fmt_plug.c |   10 +++++-----
 7 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/src/PO_fmt_plug.c b/src/PO_fmt_plug.c
index aab104d..a513b67 100644
--- a/src/PO_fmt_plug.c
+++ b/src/PO_fmt_plug.c
@@ -132,9 +132,9 @@ static int get_hash_4(int index)
 
 static int salt_hash(void *salt)
 {
-	return
-		((int)atoi64[ARCH_INDEX(((char *)salt)[0])] |
-		((int)atoi64[ARCH_INDEX(((char *)salt)[1])] << 6)) & 0x3FF;
+	return	((int)atoi16[ARCH_INDEX(((char *)salt)[0])] |
+		((int)atoi16[ARCH_INDEX(((char *)salt)[1])] << 4) |
+		((int)atoi16[ARCH_INDEX(((char *)salt)[2])] << 8)) & (SALT_HASH_SIZE - 1);
 }
 
 static void set_key(char *key, int index)
diff --git a/src/XSHA512_fmt.c b/src/XSHA512_fmt.c
index fbac232..2993a4a 100644
--- a/src/XSHA512_fmt.c
+++ b/src/XSHA512_fmt.c
@@ -182,7 +182,7 @@ static int get_hash_4(int index)
 
 static int salt_hash(void *salt)
 {
-	return *(ARCH_WORD_32 *)salt & 0x3FF;
+	return *(ARCH_WORD_32 *)salt & (SALT_HASH_SIZE - 1);
 }
 
 static void set_salt(void *salt)
diff --git a/src/XSHA_fmt_plug.c b/src/XSHA_fmt_plug.c
index c4450b1..de0ff66 100644
--- a/src/XSHA_fmt_plug.c
+++ b/src/XSHA_fmt_plug.c
@@ -143,7 +143,7 @@ static int get_hash_4(int index)
 
 static int salt_hash(void *salt)
 {
-	return *(ARCH_WORD_32 *)salt & 0x3FF;
+	return *(ARCH_WORD_32 *)salt & (SALT_HASH_SIZE - 1);
 }
 
 static void set_salt(void *salt)
diff --git a/src/dynamic_fmt.c b/src/dynamic_fmt.c
index 6fa355f..8bc6f82 100644
--- a/src/dynamic_fmt.c
+++ b/src/dynamic_fmt.c
@@ -1637,8 +1637,8 @@ static int salt_hash(void *salt)
 	if (!salt || *((char*)salt) == 0)
 		return 0;
 	x = ((ARCH_WORD_32)(ARCH_INDEX(((unsigned char *)salt)[0])-' '));
-	y = (((ARCH_WORD_32)(ARCH_INDEX(((unsigned char *)salt)[1])-' ')<<4));
-	return (x+y) & 0x3FF;
+	y = (((ARCH_WORD_32)(ARCH_INDEX(((unsigned char *)salt)[1])-' ')<<6));
+	return (x+y) & (SALT_HASH_SIZE - 1);
 }
 
 /*********************************************************************************
diff --git a/src/hmailserver_fmt.c b/src/hmailserver_fmt.c
index f58ae60..cb117cb 100644
--- a/src/hmailserver_fmt.c
+++ b/src/hmailserver_fmt.c
@@ -163,10 +163,10 @@ static int get_hash_4(int index)
 
 static int salt_hash(void *salt)
 {
-    int x, y;
-    x = ((ARCH_WORD_32)(ARCH_INDEX(((unsigned char *)salt)[0])-' '));
-    y = (((ARCH_WORD_32)(ARCH_INDEX(((unsigned char *)salt)[1])-' ')<<4));
-    return (x+y) & 0x3FF;
+	return (((ARCH_WORD_32)(ARCH_INDEX(((unsigned char *)salt)[0])-' ')) +
+	    ((ARCH_WORD_32)(ARCH_INDEX(((unsigned char *)salt)[1])-' ')<<4) +
+	    ((ARCH_WORD_32)(ARCH_INDEX(((unsigned char *)salt)[2])-' ')<<8))
+	    & (SALT_HASH_SIZE - 1);
 }
 
 static void set_salt(void *salt)
diff --git a/src/md4_gen_fmt_plug.c b/src/md4_gen_fmt_plug.c
index bb23a31..9a374ba 100644
--- a/src/md4_gen_fmt_plug.c
+++ b/src/md4_gen_fmt_plug.c
@@ -151,14 +151,14 @@ static int salt_hash(void *salt)
 	while (*p) {
 		hash <<= 1;
 		hash += (unsigned char)*p++;
-		if (hash >> 10) {
-			hash ^= hash >> 10;
-			hash &= 0x3FF;
+		if (hash >> SALT_HASH_LOG) {
+			hash ^= hash >> SALT_HASH_LOG;
+			hash &= (SALT_HASH_SIZE - 1);
 		}
 	}
 
-	hash ^= hash >> 10;
-	hash &= 0x3FF;
+	hash ^= hash >> SALT_HASH_LOG;
+	hash &= (SALT_HASH_SIZE - 1);
 
 	return hash;
 }
diff --git a/src/sha1_gen_fmt_plug.c b/src/sha1_gen_fmt_plug.c
index 746920a..63872ea 100644
--- a/src/sha1_gen_fmt_plug.c
+++ b/src/sha1_gen_fmt_plug.c
@@ -151,14 +151,14 @@ static int salt_hash(void *salt)
 	while (*p) {
 		hash <<= 1;
 		hash += (unsigned char)*p++;
-		if (hash >> 10) {
-			hash ^= hash >> 10;
-			hash &= 0x3FF;
+		if (hash >> SALT_HASH_LOG) {
+			hash ^= hash >> SALT_HASH_LOG;
+			hash &= (SALT_HASH_SIZE - 1);
 		}
 	}
 
-	hash ^= hash >> 10;
-	hash &= 0x3FF;
+	hash ^= hash >> SALT_HASH_LOG;
+	hash &= (SALT_HASH_SIZE - 1);
 
 	return hash;
 }
-- 
1.7.5.4

