1 /* 2 * This file is part of John the Ripper password cracker, 3 * Copyright (c) 2013-2018 by magnum 4 * Copyright (c) 2014 by Sayantan Datta 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted. 8 * 9 * There's ABSOLUTELY NO WARRANTY, express or implied. 10 */ 11 12 /* 13 * Mask mode cracker. 14 */ 15 16 #ifndef _JOHN_MASK_H 17 #define _JOHN_MASK_H 18 19 #include "loader.h" 20 21 // See also opencl_mask.h. 22 #define MASK_FMT_INT_PLHDR 4 23 24 // Maximum number of placeholders in a mask. 25 #define MAX_NUM_MASK_PLHDR 125 26 27 //#define MASK_DEBUG 28 29 typedef struct { 30 /* store locations of op braces in mask */ 31 int stack_op_br[MAX_NUM_MASK_PLHDR + 1]; 32 /* store locations of cl braces in mask */ 33 int stack_cl_br[MAX_NUM_MASK_PLHDR + 1]; 34 /* store locations of valid ? in mask */ 35 int stack_qtn[MAX_NUM_MASK_PLHDR + 1]; 36 } mask_parsed_ctx; 37 38 /* Range of characters for a placeholder in the mask */ 39 /* Rearranging the structure could affect performance */ 40 typedef struct { 41 /* Characters in the range */ 42 unsigned char chars[0xFF]; 43 /* next active range */ 44 unsigned char next; 45 /* current postion in chars[] while iterating */ 46 unsigned char iter; 47 /* Number of characters in the range */ 48 unsigned char count; 49 /* 50 * Set to zero when the characters in the range are not consecutive, 51 * otherwise start is set to the minimum value in range. Minimum 52 * value cannot be a null character which has a value zero. 53 */ 54 unsigned char start; 55 /* Base postion of the characters in key */ 56 int pos; 57 /* offset when a key is inserted from other mode */ 58 int offset; 59 } mask_range; 60 61 /* Processed mask structure for password generation on CPU */ 62 typedef struct { 63 /* Set of mask placeholders for generating password */ 64 mask_range ranges[MAX_NUM_MASK_PLHDR + 1]; 65 /* Positions in mask for iteration on CPU */ 66 int active_positions[MAX_NUM_MASK_PLHDR + 1]; 67 /* Postion of the first active range */ 68 int ps1; 69 /* Total number of placeholders, cpu + gpu */ 70 int count; 71 /* Number of placeholders active for iteration on CPU */ 72 int cpu_count; 73 /* offset at which mask starts in the key */ 74 int offset; 75 } mask_cpu_context; 76 77 /* 78 * Initialize mask mode cracker. 79 */ 80 extern void mask_init(struct db_main *db, char *unprocessed_mask); 81 82 /* 83 * Initialize cracker database. 84 */ 85 extern void mask_crk_init(struct db_main *db); 86 87 /* 88 * Runs the mask mode cracker. 89 */ 90 extern int do_mask_crack(const char *key); 91 92 extern void mask_done(void); 93 extern void mask_destroy(void); 94 95 /* 96 * These are exported for stacked modes (eg. hybrid mask) 97 */ 98 extern void mask_fix_state(void); 99 extern void mask_save_state(FILE *file); 100 extern int mask_restore_state(FILE *file); 101 102 /* Evaluate mask_add_len from a given mask string without calling mask_init */ 103 extern int mask_calc_len(const char *mask); 104 105 /* 106 * Total number of candidates (per node) to begin with. Remains unchanged 107 * throughout one call to do_mask_crack but may vary with hybrid parent key 108 * length. The number includes the part that is processed on GPU, and is 109 * used as a multiplier in native mask mode's and parent modes' get_progress(). 110 */ 111 extern uint64_t mask_tot_cand; 112 113 /* Hybrid mask's contribution to key length. Eg. for bc?l?d?w this will be 4. */ 114 extern int mask_add_len; 115 116 /* Number of ?w in hybrid mask */ 117 extern int mask_num_qw; 118 119 /* Number of times parent mode called hybrid mask. */ 120 extern uint64_t mask_parent_keys; 121 122 /* Current length when pure mask mode iterates over lengths */ 123 extern int mask_cur_len; 124 125 /* Incremental mask iteration started at this length (contrary to options) */ 126 extern int mask_iter_warn; 127 128 /* Mask mode is incrementing mask length */ 129 extern int mask_increments_len; 130 131 #endif 132