Openwall GNU/*/Linux - a small security-enhanced Linux distro for servers
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sun, 20 Sep 2015 07:46:14 +0300
From: Solar Designer <solar@...nwall.com>
To: john-dev@...ts.openwall.com
Subject: Re: current large hash file speeds and bottlenecks (was: ldr_split_line() performance regression)

On Sat, Sep 19, 2015 at 01:02:19AM +0300, Solar Designer wrote:
> I am still not entirely happy with the performance, but I think it's now
> acceptable:
> 
> [solar@...er run]$ time ./john -form=raw-md5 -show 29m.txt | tail -2
> 
> 1709703 password hashes cracked, 27302555 left
> 
> real    0m14.284s
> user    0m13.883s
> sys     0m0.456s

Here's further speedup for --show:

real    0m12.012s
user    0m11.607s
sys     0m0.449s

BTW, these are with:

$ wc -l john.pot 
3963455 john.pot

Patch attached.

Alexander

diff --git a/src/loader.c b/src/loader.c
index b55439e..388474f 100644
--- a/src/loader.c
+++ b/src/loader.c
@@ -177,10 +177,8 @@ void ldr_init_database(struct db_main *db, struct db_options *db_options)
 	if (db_options->flags & DB_CRACKED) {
 		db->salt_hash = NULL;
 
-		db->cracked_hash = mem_alloc(
-			CRACKED_HASH_SIZE * sizeof(struct db_cracked *));
-		memset(db->cracked_hash, 0,
-			CRACKED_HASH_SIZE * sizeof(struct db_cracked *));
+		db->cracked_hash = mem_calloc(
+			CRACKED_HASH_SIZE, sizeof(struct db_cracked *));
 	} else {
 		db->salt_hash = mem_alloc(
 			SALT_HASH_SIZE * sizeof(struct db_salt *));
@@ -1574,28 +1572,52 @@ void ldr_fix_database(struct db_main *db)
 
 static int ldr_cracked_hash(char *ciphertext)
 {
-	unsigned int hash = 0;
-	char *p = ciphertext;
+	unsigned int hash, extra;
+	unsigned char *p = (unsigned char *)ciphertext;
+
+	hash = p[0] | 0x20; /* ASCII case insensitive */
+	if (!hash)
+		goto out;
+	extra = p[1] | 0x20;
+	if (!extra)
+#if CRACKED_HASH_SIZE >= 0x100
+		goto out;
+#else
+		goto out_and;
+#endif
 
+	p += 2;
 	while (*p) {
-		hash <<= 1;
-		hash += (unsigned char)*p++ | 0x20; /* ASCII case insensitive */
-#if CRACKED_HASH_LOG <= 12
-		if (hash >> (2 * CRACKED_HASH_LOG - 1)) {
+		hash <<= 3; extra <<= 2;
+		hash += p[0] | 0x20;
+		if (!p[1]) break;
+		extra += p[1] | 0x20;
+		p += 2;
+		if (hash & 0xe0000000) {
 			hash ^= hash >> CRACKED_HASH_LOG;
+			extra ^= extra >> CRACKED_HASH_LOG;
 			hash &= CRACKED_HASH_SIZE - 1;
 		}
-#else
-		if (hash & 0xff000000U) {
-			hash ^= hash >> 13;
-			hash &= 0xffffffU;
-		}
-#endif
 	}
 
+	hash -= extra;
+	hash ^= extra << (CRACKED_HASH_LOG / 2);
+
 	hash ^= hash >> CRACKED_HASH_LOG;
+
+#if CRACKED_HASH_LOG <= 15
+	hash ^= hash >> (2 * CRACKED_HASH_LOG);
+#endif
+#if CRACKED_HASH_LOG <= 10
+	hash ^= hash >> (3 * CRACKED_HASH_LOG);
+#endif
+
+#if CRACKED_HASH_SIZE < 0x100
+out_and:
+#endif
 	hash &= CRACKED_HASH_SIZE - 1;
 
+out:
 	return hash;
 }
 

Powered by blists - more mailing lists

Your e-mail address:

Powered by Openwall GNU/*/Linux - Powered by OpenVZ