Skip to content

Commit 3eebc4e

Browse files
committed
Merge pull request #36 from magnumripper/master
Vary hash size depending on length, for more effective use of memory.
2 parents e196a5a + c44aa13 commit 3eebc4e

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/pp.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
#define CASE_PERMUTE 0
3434
#define DUPE_CHECK 1
3535

36-
#define DUPE_HASH_LOG 23
37-
3836
#define VERSION_BIN 20
3937

4038
#define ALLOC_NEW_ELEMS 0x40000
@@ -88,6 +86,7 @@ typedef struct
8886
u32 alloc;
8987

9088
u32 *hash;
89+
u32 hash_mask;
9190

9291
uniq_data_t *data;
9392

@@ -154,6 +153,15 @@ static u64 DEF_WORDLEN_DIST[DEF_WORDLEN_DIST_CNT] =
154153
13
155154
};
156155

156+
/* Losely based on rockyou-with-dupes */
157+
static const u32 DEF_HASH_LOG_SIZE[33] =
158+
{ 0,
159+
8, 12, 16, 20, 24, 24, 24, 24,
160+
24, 24, 23, 22, 21, 20, 19, 18,
161+
17, 16, 16, 16, 16, 16, 16, 16,
162+
16, 16, 16, 16, 16, 16, 16, 16
163+
};
164+
157165
static const char *USAGE_MINI[] =
158166
{
159167
"Usage: %s [options] < wordlist",
@@ -575,7 +583,7 @@ static char *add_elem (db_entry_t *db_entry, char *input_buf, int input_len)
575583
return (char *) elem_buf->buf;
576584
}
577585

578-
static u32 input_hash (char *input_buf, int input_len)
586+
static u32 input_hash (char *input_buf, int input_len, const int hash_mask)
579587
{
580588
u32 h = 0;
581589

@@ -584,17 +592,15 @@ static u32 input_hash (char *input_buf, int input_len)
584592
h = (h * 33) + input_buf[i];
585593
}
586594

587-
#define HASH_MASK ((1 << DUPE_HASH_LOG) - 1)
588-
589-
return h & HASH_MASK;
595+
return h & hash_mask;
590596
}
591597

592598
static void add_uniq (db_entry_t *db_entry, char *input_buf, int input_len)
593599
{
594-
const u32 h = input_hash (input_buf, input_len);
595-
596600
uniq_t *uniq = db_entry->uniq;
597601

602+
const u32 h = input_hash (input_buf, input_len, uniq->hash_mask);
603+
598604
u32 cur = uniq->hash[h];
599605

600606
u32 prev = cur;
@@ -834,11 +840,12 @@ int main (int argc, char *argv[])
834840
{
835841
db_entry_t *db_entry = &db_entries[pw_len];
836842

837-
const u32 hash_size = 1 << DUPE_HASH_LOG;
843+
const u32 hash_size = 1 << DEF_HASH_LOG_SIZE[pw_len];
838844
const u32 hash_alloc = ALLOC_NEW_DUPES;
839845

840846
uniq_t *uniq = mem_alloc (sizeof (uniq_t));
841847

848+
uniq->hash_mask = hash_size - 1;
842849
uniq->data = mem_alloc (hash_alloc * sizeof (uniq_data_t));
843850
uniq->hash = mem_alloc (hash_size * sizeof (u32));
844851
uniq->index = 0;

0 commit comments

Comments
 (0)