Skip to content

Commit

Permalink
work-in-progress:mask mode internal candidate gen
Browse files Browse the repository at this point in the history
  • Loading branch information
sayan1an committed Jan 17, 2015
1 parent 4e26eac commit 7553d25
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 46 deletions.
18 changes: 15 additions & 3 deletions src/mask.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "unicode.h"
#include "encoding_data.h"
#include "memdbg.h"
#include "mask_device.h"
#include "mask_ext.h"

static parsed_ctx parsed_mask;
static cpu_mask_context cpu_mask_ctx, rec_ctx;
Expand Down Expand Up @@ -1022,6 +1022,11 @@ static void save_restore(cpu_mask_context *cpu_mask_ctx, int range_idx, int ch)
static void truncate_mask(cpu_mask_context *cpu_mask_ctx, int range_idx)
{
int i;
if (range_idx < mask_max_skip_loc && mask_max_skip_loc != -1) {
fprintf(stderr, "Format internal ranges cannot be truncated!\n");
fprintf(stderr, "Use a bigger key length or non-gpu format.\n");
error();
}

cpu_mask_ctx->ranges[range_idx].next = MAX_NUM_MASK_PLHDR;

Expand Down Expand Up @@ -1690,13 +1695,18 @@ void mask_init(struct db_main *db, char *unprocessed_mask)
#endif
init_cpu_mask(mask, &parsed_mask, &cpu_mask_ctx, db);

calc_combination(5);
mask_calc_combination(&cpu_mask_ctx);

fprintf(stderr, "MASK_FMT_INT_PLHDRs:");
for (i = 0; i < MASK_FMT_INT_PLHDR && mask_skip_ranges; i++)
fprintf(stderr, "%d ", mask_skip_ranges[i]);
fprintf(stderr, "\n");

/*
* Warning: NULL to be replaced by an array containing information
* regarding GPU portion of mask.
*/
skip_position(&cpu_mask_ctx, NULL);
skip_position(&cpu_mask_ctx, mask_skip_ranges);

/* If running hybrid (stacked), we let the parent mode distribute */
if (options.node_count && !(options.flags & FLG_MASK_STACKED))
Expand Down Expand Up @@ -1725,6 +1735,8 @@ void mask_done()
{
MEM_FREE(template_key);
MEM_FREE(template_key_offsets);
if (!mask_skip_ranges)
MEM_FREE(mask_skip_ranges);

if (!(options.flags & FLG_MASK_STACKED)) {
if (parsed_mask.parse_ok &&
Expand Down
40 changes: 0 additions & 40 deletions src/mask_device.c

This file was deleted.

69 changes: 69 additions & 0 deletions src/mask_ext.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* This file is part of John the Ripper password cracker,
* Copyright (c) 2014 by Sayantan Datta
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted.
*
* There's ABSOLUTELY NO WARRANTY, express or implied.
*/

#include "mask_ext.h"
#include "memory.h"

int *mask_skip_ranges = NULL;
int mask_max_skip_loc = -1;
int mask_int_cand_target = 0;

static void combination_util(int *, int, int, int, int,
cpu_mask_context *, int *);

void mask_calc_combination(cpu_mask_context *ptr) {
int *data, i, n;
int delta_to_target = 0x7fffffff;
if (!mask_int_cand_target) return;

n = ptr->count;
data = (int*) malloc(n * sizeof(int));
mask_skip_ranges = (int*) malloc (MASK_FMT_INT_PLHDR * sizeof(int));

for (i = 0; i < MASK_FMT_INT_PLHDR; i++)
mask_skip_ranges[i] = -1;

/* Fix the maximum number of ranges that can be calculated on GPU to 3 */
for (i = 1; i <= MASK_FMT_INT_PLHDR; i++)
combination_util(data, 0, n - 1, 0, i, ptr,
&delta_to_target);

MEM_FREE(data);
}

static void combination_util(int *data, int start, int end, int index,
int r, cpu_mask_context *ptr, int *delta) {
int i;

if (index == r) {
int tmp = 1;
for (i = 0; i < r; i++)
tmp *= ptr->ranges[data[i]].count;

tmp -= mask_int_cand_target;
tmp = tmp < 0 ? -tmp : tmp;

if (tmp < *delta) {
for (i = 0; i < r; i++)
mask_skip_ranges[i] = data[i];

mask_max_skip_loc = mask_skip_ranges[i-1];
*delta = tmp;
}

return;
}

for (i = start; i <= end && end - i + 1 >= r - index; i++) {
data[index] = i;
combination_util(data, i + 1, end, index + 1,
r, ptr, delta);
}
}
13 changes: 10 additions & 3 deletions src/mask_device.h → src/mask_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@
* There's ABSOLUTELY NO WARRANTY, express or implied.
*/

#ifndef _JOHN_MASK_DEVICE_H
#define _JOHN_MASK_DEVICE_H
#ifndef _JOHN_MASK_EXT_H
#define _JOHN_MASK_EXT_H

extern void calc_combination(int n);
#include "mask.h"

#define MASK_FMT_INT_PLHDR 3

extern void mask_calc_combination(cpu_mask_context *);
extern int *mask_skip_ranges;
extern int mask_max_skip_loc;
extern int mask_int_cand_target;

#endif

0 comments on commit 7553d25

Please sign in to comment.