Openwall GNU/*/Linux - a small security-enhanced Linux distro for servers
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Thu, 26 Sep 2013 21:59:37 +0200
From: magnum <john.magnum@...hmail.com>
To: john-dev@...ts.openwall.com
Subject: Re: External node distribution (call for help)

On 2013-09-26 04:30, Solar Designer wrote:
> On Thu, Sep 26, 2013 at 04:14:19AM +0200, magnum wrote:
>> I mean, can I assume that I am at
>> the start of a full "their_words" block after resuming?
>
> In an equivalent of the "if" branch that you extracted the above comment
> from, yes.
>
>> How/why is that?
>> I can't see why that would be a safe assumption. A fix_state() seems to
>> happen right before a clear_keys and if "we" are several nodes (as in
>> -node:1-7/10) that could be in the middle of my_words.
>
> The "We assume ..." comment is located inside an "if".  The special case
> that you mention here is the "else" after that "if".  That case is
> handled as well, and you may handle it in a similar fashion in external
> mode.

Right, thanks! There was some odd race condition in my head. I tried to 
get rid of a proper "seq" but then I realized I had to keep it anyway in 
order to maintain session file compatibility in both directions. This 
also means wrapping is not an issue.

I'm applying it to bleeding now. Here's a patch against core, pretty 
clean and fairly well tested[tm]. Feel free to use it - you wrote the 
better part of it %-)

magnum


>From 3e07602cdc709efa55cf04aff5100a369f69e70c Mon Sep 17 00:00:00 2001
From: magnum <john.magnum@...hmail.com>
Date: Thu, 26 Sep 2013 12:33:21 +0200
Subject: [PATCH] External mode node distribution: Avoid modulo operation.

---
 src/external.c | 33 ++++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/src/external.c b/src/external.c
index cf1b395..8fce6a3 100644
--- a/src/external.c
+++ b/src/external.c
@@ -227,6 +227,7 @@ void do_external_crack(struct db_main *db)
 {
 	unsigned char *internal;
 	c_int *external;
+	int my_words, their_words;
 
 	log_event("Proceeding with external mode: %.100s", ext_mode);
 
@@ -245,20 +246,38 @@ void do_external_crack(struct db_main *db)
 
 	crk_init(db, fix_state, NULL);
 
+	my_words = options.node_max - options.node_min + 1;
+	their_words = options.node_min - 1;
+
+	if (seq) {
+/* Restored session.  seq is right after a word we've actually used. */
+		int for_node = seq % options.node_count + 1;
+		if (for_node < options.node_min ||
+		        for_node > options.node_max) {
+/* We assume that seq is at the beginning of other nodes' block */
+			their_words = options.node_count - my_words;
+		} else {
+			my_words = options.node_max - for_node + 1;
+			their_words = 0;
+		}
+	}
+
 	do {
 		c_execute_fast(f_generate);
 		if (!ext_word[0])
 			break;
 
-/*
- * The skipping of other nodes' candidate passwords can be optimized, such as
- * to avoid the modulo division like it's done for dist_words in wordlist.c.
- */
 		if (options.node_count) {
-			int for_node = seq++ % options.node_count + 1;
-			if (for_node < options.node_min ||
-			    for_node > options.node_max)
+			seq++;
+			if (their_words) {
+				their_words--;
 				continue;
+			}
+			if (--my_words == 0) {
+				my_words =
+					options.node_max - options.node_min + 1;
+				their_words = options.node_count - my_words;
+			}
 		}
 
 		if (f_filter) {
-- 
1.8.1.2


Powered by blists - more mailing lists

Your e-mail address:

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