1 /**
2  * Author......: See docs/credits.txt
3  * License.....: MIT
4  */
5 
6 #ifndef _TYPES_H
7 #define _TYPES_H
8 
9 #include "common.h"
10 
11 #include <stdio.h>
12 #include <stdint.h>
13 #include <stdbool.h>
14 #include <string.h>
15 #include <sys/types.h>
16 #include <sys/stat.h>
17 #include <sys/time.h>
18 #include <unistd.h>
19 #include <math.h>
20 
21 // workaround to get the rid of "redefinition of typedef 'Byte'" build warning
22 #if !defined (__APPLE__)
23 #include "zlib.h"
24 #endif
25 
26 #if !defined(__MACTYPES__)
27 #define __MACTYPES__
28 #include "ext_lzma.h"
29 #undef __MACTYPES__
30 #endif
31 // end of workaround
32 
33 #if defined (_WIN)
34 #define WINICONV_CONST
35 #endif
36 
37 #include <iconv.h>
38 
39 #if defined (_WIN)
40 #include <windows.h>
41 #if defined (_BASETSD_H)
42 #else
43 typedef UINT8  uint8_t;
44 typedef UINT16 uint16_t;
45 typedef UINT32 uint32_t;
46 typedef UINT64 uint64_t;
47 typedef INT8   int8_t;
48 typedef INT16  int16_t;
49 typedef INT32  int32_t;
50 typedef INT64  int64_t;
51 #endif
52 #endif // _WIN
53 
54 typedef int8_t  i8;
55 typedef int16_t i16;
56 typedef int32_t i32;
57 typedef int64_t i64;
58 
59 #include "inc_types.h"
60 
61 // there's no such thing in plain C, therefore all vector operation cannot work in this emu
62 // which is why VECT_SIZE is set to 1
63 
64 typedef uint32_t uint4;
65 
66 // timer
67 
68 #if defined (_WIN)
69 typedef LARGE_INTEGER     hc_timer_t;
70 #elif defined(__APPLE__) && defined(MISSING_CLOCK_GETTIME)
71 typedef struct timeval    hc_timer_t;
72 #else
73 typedef struct timespec   hc_timer_t;
74 #endif
75 
76 // thread
77 
78 #if defined (_POSIX)
79 #include <pthread.h>
80 #include <semaphore.h>
81 #endif
82 
83 #if defined (_WIN)
84 typedef HANDLE           hc_thread_t;
85 typedef CRITICAL_SECTION hc_thread_mutex_t;
86 typedef HANDLE           hc_thread_semaphore_t;
87 #else
88 typedef pthread_t        hc_thread_t;
89 typedef pthread_mutex_t  hc_thread_mutex_t;
90 typedef sem_t            hc_thread_semaphore_t;
91 #endif
92 
93 // enums
94 
95 typedef enum loglevel
96 {
97   LOGLEVEL_INFO    = 0,
98   LOGLEVEL_WARNING = 1,
99   LOGLEVEL_ERROR   = 2,
100   LOGLEVEL_ADVICE  = 3,
101 
102 } loglevel_t;
103 
104 typedef enum event_identifier
105 {
106   EVENT_AUTODETECT_FINISHED       = 0x00000100,
107   EVENT_AUTODETECT_STARTING       = 0x00000101,
108   EVENT_AUTOTUNE_FINISHED         = 0x00000000,
109   EVENT_AUTOTUNE_STARTING         = 0x00000001,
110   EVENT_BITMAP_INIT_POST          = 0x00000010,
111   EVENT_BITMAP_INIT_PRE           = 0x00000011,
112   EVENT_BITMAP_FINAL_OVERFLOW     = 0x00000012,
113   EVENT_CALCULATED_WORDS_BASE     = 0x00000020,
114   EVENT_CRACKER_FINISHED          = 0x00000030,
115   EVENT_CRACKER_HASH_CRACKED      = 0x00000031,
116   EVENT_CRACKER_STARTING          = 0x00000032,
117   EVENT_HASHCONFIG_PRE            = 0x00000040,
118   EVENT_HASHCONFIG_POST           = 0x00000041,
119   EVENT_HASHLIST_COUNT_LINES_POST = 0x00000050,
120   EVENT_HASHLIST_COUNT_LINES_PRE  = 0x00000051,
121   EVENT_HASHLIST_PARSE_HASH       = 0x00000052,
122   EVENT_HASHLIST_SORT_HASH_POST   = 0x00000053,
123   EVENT_HASHLIST_SORT_HASH_PRE    = 0x00000054,
124   EVENT_HASHLIST_SORT_SALT_POST   = 0x00000055,
125   EVENT_HASHLIST_SORT_SALT_PRE    = 0x00000056,
126   EVENT_HASHLIST_UNIQUE_HASH_POST = 0x00000057,
127   EVENT_HASHLIST_UNIQUE_HASH_PRE  = 0x00000058,
128   EVENT_INNERLOOP1_FINISHED       = 0x00000060,
129   EVENT_INNERLOOP1_STARTING       = 0x00000061,
130   EVENT_INNERLOOP2_FINISHED       = 0x00000070,
131   EVENT_INNERLOOP2_STARTING       = 0x00000071,
132   EVENT_LOG_ERROR                 = 0x00000080,
133   EVENT_LOG_INFO                  = 0x00000081,
134   EVENT_LOG_WARNING               = 0x00000082,
135   EVENT_LOG_ADVICE                = 0x00000083,
136   EVENT_MONITOR_RUNTIME_LIMIT     = 0x00000090,
137   EVENT_MONITOR_STATUS_REFRESH    = 0x00000091,
138   EVENT_MONITOR_TEMP_ABORT        = 0x00000092,
139   EVENT_MONITOR_THROTTLE1         = 0x00000093,
140   EVENT_MONITOR_THROTTLE2         = 0x00000094,
141   EVENT_MONITOR_THROTTLE3         = 0x00000095,
142   EVENT_MONITOR_PERFORMANCE_HINT  = 0x00000096,
143   EVENT_MONITOR_NOINPUT_HINT      = 0x00000097,
144   EVENT_MONITOR_NOINPUT_ABORT     = 0x00000098,
145   EVENT_BACKEND_SESSION_POST      = 0x000000a0,
146   EVENT_BACKEND_SESSION_PRE       = 0x000000a1,
147   EVENT_BACKEND_SESSION_HOSTMEM   = 0x000000a2,
148   EVENT_BACKEND_DEVICE_INIT_POST  = 0x000000a3,
149   EVENT_BACKEND_DEVICE_INIT_PRE   = 0x000000a4,
150   EVENT_OUTERLOOP_FINISHED        = 0x000000b0,
151   EVENT_OUTERLOOP_MAINSCREEN      = 0x000000b1,
152   EVENT_OUTERLOOP_STARTING        = 0x000000b2,
153   EVENT_POTFILE_ALL_CRACKED       = 0x000000c0,
154   EVENT_POTFILE_HASH_LEFT         = 0x000000c1,
155   EVENT_POTFILE_HASH_SHOW         = 0x000000c2,
156   EVENT_POTFILE_NUM_CRACKED       = 0x000000c3,
157   EVENT_POTFILE_REMOVE_PARSE_POST = 0x000000c4,
158   EVENT_POTFILE_REMOVE_PARSE_PRE  = 0x000000c5,
159   EVENT_SELFTEST_FINISHED         = 0x000000d0,
160   EVENT_SELFTEST_STARTING         = 0x000000d1,
161   EVENT_SET_KERNEL_POWER_FINAL    = 0x000000e0,
162   EVENT_WORDLIST_CACHE_GENERATE   = 0x000000f0,
163   EVENT_WORDLIST_CACHE_HIT        = 0x000000f1,
164 
165   // there will be much more event types soon
166 
167 } event_identifier_t;
168 
169 typedef enum amplifier_count
170 {
171   KERNEL_BFS                        = 1024,
172   KERNEL_COMBS                      = 1024,
173   KERNEL_RULES                      = 256,
174 
175 } amplifier_count_t;
176 
177 typedef enum vendor_id
178 {
179   VENDOR_ID_AMD           = (1U << 0),
180   VENDOR_ID_APPLE         = (1U << 1),
181   VENDOR_ID_INTEL_BEIGNET = (1U << 2),
182   VENDOR_ID_INTEL_SDK     = (1U << 3),
183   VENDOR_ID_MESA          = (1U << 4),
184   VENDOR_ID_NV            = (1U << 5),
185   VENDOR_ID_POCL          = (1U << 6),
186   VENDOR_ID_AMD_USE_INTEL = (1U << 7),
187   VENDOR_ID_AMD_USE_HIP   = (1U << 8),
188   VENDOR_ID_GENERIC       = (1U << 31)
189 
190 } vendor_id_t;
191 
192 typedef enum st_status_rc
193 {
194   ST_STATUS_PASSED        = 0,
195   ST_STATUS_FAILED        = 1,
196   ST_STATUS_IGNORED       = 2,
197 
198 } st_status_t;
199 
200 typedef enum status_rc
201 {
202   STATUS_INIT               = 0,
203   STATUS_AUTOTUNE           = 1,
204   STATUS_SELFTEST           = 2,
205   STATUS_RUNNING            = 3,
206   STATUS_PAUSED             = 4,
207   STATUS_EXHAUSTED          = 5,
208   STATUS_CRACKED            = 6,
209   STATUS_ABORTED            = 7,
210   STATUS_QUIT               = 8,
211   STATUS_BYPASS             = 9,
212   STATUS_ABORTED_CHECKPOINT = 10,
213   STATUS_ABORTED_RUNTIME    = 11,
214   STATUS_ERROR              = 13,
215   STATUS_ABORTED_FINISH     = 14,
216   STATUS_AUTODETECT         = 16,
217 
218 } status_rc_t;
219 
220 typedef enum wl_mode
221 {
222   WL_MODE_NONE  = 0,
223   WL_MODE_STDIN = 1,
224   WL_MODE_FILE  = 2,
225   WL_MODE_MASK  = 3
226 
227 } wl_mode_t;
228 
229 typedef enum hl_mode
230 {
231   HL_MODE_ARG         = 2,
232   HL_MODE_FILE_PLAIN  = 5,
233   HL_MODE_FILE_BINARY = 6,
234 
235 } hl_mode_t;
236 
237 typedef enum attack_mode
238 {
239   ATTACK_MODE_STRAIGHT  = 0,
240   ATTACK_MODE_COMBI     = 1,
241   ATTACK_MODE_TOGGLE    = 2,
242   ATTACK_MODE_BF        = 3,
243   ATTACK_MODE_PERM      = 4,
244   ATTACK_MODE_TABLE     = 5,
245   ATTACK_MODE_HYBRID1   = 6,
246   ATTACK_MODE_HYBRID2   = 7,
247   ATTACK_MODE_ASSOCIATION   = 9,
248   ATTACK_MODE_NONE      = 100
249 
250 } attack_mode_t;
251 
252 typedef enum attack_kern
253 {
254   ATTACK_KERN_STRAIGHT  = 0,
255   ATTACK_KERN_COMBI     = 1,
256   ATTACK_KERN_BF        = 3,
257   ATTACK_KERN_NONE      = 100
258 
259 } attack_kern_t;
260 
261 typedef enum kern_run
262 {
263   KERN_RUN_1      = 1000,
264   KERN_RUN_12     = 1500,
265   KERN_RUN_2P     = 1999,
266   KERN_RUN_2      = 2000,
267   KERN_RUN_2E     = 2001,
268   KERN_RUN_23     = 2500,
269   KERN_RUN_3      = 3000,
270   KERN_RUN_4      = 4000,
271   KERN_RUN_INIT2  = 5000,
272   KERN_RUN_LOOP2P = 5999,
273   KERN_RUN_LOOP2  = 6000,
274   KERN_RUN_AUX1   = 7001,
275   KERN_RUN_AUX2   = 7002,
276   KERN_RUN_AUX3   = 7003,
277   KERN_RUN_AUX4   = 7004,
278 
279 } kern_run_t;
280 
281 typedef enum kern_run_mp
282 {
283   KERN_RUN_MP   = 101,
284   KERN_RUN_MP_L = 102,
285   KERN_RUN_MP_R = 103
286 
287 } kern_run_mp_t;
288 
289 typedef enum rule_functions
290 {
291   RULE_OP_MANGLE_NOOP            = ':',
292   RULE_OP_MANGLE_LREST           = 'l',
293   RULE_OP_MANGLE_UREST           = 'u',
294   RULE_OP_MANGLE_LREST_UFIRST    = 'c',
295   RULE_OP_MANGLE_UREST_LFIRST    = 'C',
296   RULE_OP_MANGLE_TREST           = 't',
297   RULE_OP_MANGLE_TOGGLE_AT       = 'T',
298   RULE_OP_MANGLE_TOGGLE_AT_SEP   = '3',
299   RULE_OP_MANGLE_REVERSE         = 'r',
300   RULE_OP_MANGLE_DUPEWORD        = 'd',
301   RULE_OP_MANGLE_DUPEWORD_TIMES  = 'p',
302   RULE_OP_MANGLE_REFLECT         = 'f',
303   RULE_OP_MANGLE_ROTATE_LEFT     = '{',
304   RULE_OP_MANGLE_ROTATE_RIGHT    = '}',
305   RULE_OP_MANGLE_APPEND          = '$',
306   RULE_OP_MANGLE_PREPEND         = '^',
307   RULE_OP_MANGLE_DELETE_FIRST    = '[',
308   RULE_OP_MANGLE_DELETE_LAST     = ']',
309   RULE_OP_MANGLE_DELETE_AT       = 'D',
310   RULE_OP_MANGLE_EXTRACT         = 'x',
311   RULE_OP_MANGLE_OMIT            = 'O',
312   RULE_OP_MANGLE_INSERT          = 'i',
313   RULE_OP_MANGLE_OVERSTRIKE      = 'o',
314   RULE_OP_MANGLE_TRUNCATE_AT     = '\'',
315   RULE_OP_MANGLE_REPLACE         = 's',
316   RULE_OP_MANGLE_PURGECHAR       = '@',
317   RULE_OP_MANGLE_TOGGLECASE_REC  = 'a',
318   RULE_OP_MANGLE_DUPECHAR_FIRST  = 'z',
319   RULE_OP_MANGLE_DUPECHAR_LAST   = 'Z',
320   RULE_OP_MANGLE_DUPECHAR_ALL    = 'q',
321   RULE_OP_MANGLE_EXTRACT_MEMORY  = 'X',
322   RULE_OP_MANGLE_APPEND_MEMORY   = '4',
323   RULE_OP_MANGLE_PREPEND_MEMORY  = '6',
324   RULE_OP_MANGLE_TITLE_SEP       = 'e',
325 
326   RULE_OP_MEMORIZE_WORD          = 'M',
327 
328   RULE_OP_REJECT_LESS            = '<',
329   RULE_OP_REJECT_GREATER         = '>',
330   RULE_OP_REJECT_EQUAL           = '_',
331   RULE_OP_REJECT_CONTAIN         = '!',
332   RULE_OP_REJECT_NOT_CONTAIN     = '/',
333   RULE_OP_REJECT_EQUAL_FIRST     = '(',
334   RULE_OP_REJECT_EQUAL_LAST      = ')',
335   RULE_OP_REJECT_EQUAL_AT        = '=',
336   RULE_OP_REJECT_CONTAINS        = '%',
337   RULE_OP_REJECT_MEMORY          = 'Q',
338   RULE_LAST_REJECTED_SAVED_POS   = 'p',
339 
340   RULE_OP_MANGLE_SWITCH_FIRST    = 'k',
341   RULE_OP_MANGLE_SWITCH_LAST     = 'K',
342   RULE_OP_MANGLE_SWITCH_AT       = '*',
343   RULE_OP_MANGLE_CHR_SHIFTL      = 'L',
344   RULE_OP_MANGLE_CHR_SHIFTR      = 'R',
345   RULE_OP_MANGLE_CHR_INCR        = '+',
346   RULE_OP_MANGLE_CHR_DECR        = '-',
347   RULE_OP_MANGLE_REPLACE_NP1     = '.',
348   RULE_OP_MANGLE_REPLACE_NM1     = ',',
349   RULE_OP_MANGLE_DUPEBLOCK_FIRST = 'y',
350   RULE_OP_MANGLE_DUPEBLOCK_LAST  = 'Y',
351   RULE_OP_MANGLE_TITLE           = 'E',
352 
353 } rule_functions_t;
354 
355 typedef enum salt_type
356 {
357   SALT_TYPE_NONE     = 1,
358   SALT_TYPE_EMBEDDED = 2,
359   SALT_TYPE_GENERIC  = 3,
360   SALT_TYPE_VIRTUAL  = 5
361 
362 } salt_type_t;
363 
364 typedef enum opti_type
365 {
366   OPTI_TYPE_OPTIMIZED_KERNEL      = (1 <<  0),
367   OPTI_TYPE_ZERO_BYTE             = (1 <<  1),
368   OPTI_TYPE_PRECOMPUTE_INIT       = (1 <<  2),
369   OPTI_TYPE_MEET_IN_MIDDLE        = (1 <<  3),
370   OPTI_TYPE_EARLY_SKIP            = (1 <<  4),
371   OPTI_TYPE_NOT_SALTED            = (1 <<  5),
372   OPTI_TYPE_NOT_ITERATED          = (1 <<  6),
373   OPTI_TYPE_PREPENDED_SALT        = (1 <<  7),
374   OPTI_TYPE_APPENDED_SALT         = (1 <<  8),
375   OPTI_TYPE_SINGLE_HASH           = (1 <<  9),
376   OPTI_TYPE_SINGLE_SALT           = (1 << 10),
377   OPTI_TYPE_BRUTE_FORCE           = (1 << 11),
378   OPTI_TYPE_RAW_HASH              = (1 << 12),
379   OPTI_TYPE_SLOW_HASH_SIMD_INIT   = (1 << 13),
380   OPTI_TYPE_SLOW_HASH_SIMD_LOOP   = (1 << 14),
381   OPTI_TYPE_SLOW_HASH_SIMD_COMP   = (1 << 15),
382   OPTI_TYPE_USES_BITS_8           = (1 << 16),
383   OPTI_TYPE_USES_BITS_16          = (1 << 17),
384   OPTI_TYPE_USES_BITS_32          = (1 << 18),
385   OPTI_TYPE_USES_BITS_64          = (1 << 19),
386   OPTI_TYPE_REGISTER_LIMIT        = (1 << 20), // We'll limit the register count to 128
387   OPTI_TYPE_SLOW_HASH_SIMD_INIT2  = (1 << 21),
388   OPTI_TYPE_SLOW_HASH_SIMD_LOOP2  = (1 << 22),
389 
390 } opti_type_t;
391 
392 typedef enum opts_type
393 {
394   OPTS_TYPE_PT_UTF16LE        = (1ULL <<  0),
395   OPTS_TYPE_PT_UTF16BE        = (1ULL <<  1),
396   OPTS_TYPE_PT_UPPER          = (1ULL <<  2),
397   OPTS_TYPE_PT_LOWER          = (1ULL <<  3),
398   OPTS_TYPE_PT_ADD01          = (1ULL <<  4),
399   OPTS_TYPE_PT_ADD02          = (1ULL <<  5),
400   OPTS_TYPE_PT_ADD80          = (1ULL <<  6),
401   OPTS_TYPE_PT_ADDBITS14      = (1ULL <<  7),
402   OPTS_TYPE_PT_ADDBITS15      = (1ULL <<  8),
403   OPTS_TYPE_PT_GENERATE_LE    = (1ULL <<  9),
404   OPTS_TYPE_PT_GENERATE_BE    = (1ULL << 10),
405   OPTS_TYPE_PT_NEVERCRACK     = (1ULL << 11), // if we want all possible results
406   OPTS_TYPE_PT_ALWAYS_ASCII   = (1ULL << 12),
407   OPTS_TYPE_PT_ALWAYS_HEXIFY  = (1ULL << 13),
408   OPTS_TYPE_PT_LM             = (1ULL << 14), // special handling: all lower, 7 max, ...
409   OPTS_TYPE_PT_HEX            = (1ULL << 15), // input wordlist (and masks!) are always in hex
410   OPTS_TYPE_ST_UTF16LE        = (1ULL << 16),
411   OPTS_TYPE_ST_UTF16BE        = (1ULL << 17),
412   OPTS_TYPE_ST_UPPER          = (1ULL << 18),
413   OPTS_TYPE_ST_LOWER          = (1ULL << 19),
414   OPTS_TYPE_ST_ADD01          = (1ULL << 20),
415   OPTS_TYPE_ST_ADD02          = (1ULL << 21),
416   OPTS_TYPE_ST_ADD80          = (1ULL << 22),
417   OPTS_TYPE_ST_ADDBITS14      = (1ULL << 23),
418   OPTS_TYPE_ST_ADDBITS15      = (1ULL << 24),
419   OPTS_TYPE_ST_HEX            = (1ULL << 25),
420   OPTS_TYPE_ST_BASE64         = (1ULL << 26),
421   OPTS_TYPE_HASH_COPY         = (1ULL << 28),
422   OPTS_TYPE_HASH_SPLIT        = (1ULL << 29),
423   OPTS_TYPE_LOOP_PREPARE      = (1ULL << 30), // a kernel which is called each time before _loop kernel started.
424                                               // like a hook12 kernel but without extra buffers.
425   OPTS_TYPE_LOOP_EXTENDED     = (1ULL << 31), // a kernel which is called each time normal _loop kernel finished.
426                                               // but unlike a hook kernel this kernel is called for every _loop iteration offset
427   OPTS_TYPE_HOOK12            = (1ULL << 32),
428   OPTS_TYPE_HOOK23            = (1ULL << 33),
429   OPTS_TYPE_INIT2             = (1ULL << 34),
430   OPTS_TYPE_LOOP2_PREPARE     = (1ULL << 35), // same as OPTS_TYPE_LOOP_PREPARE but for loop2 kernel
431   OPTS_TYPE_LOOP2             = (1ULL << 36),
432   OPTS_TYPE_AUX1              = (1ULL << 37),
433   OPTS_TYPE_AUX2              = (1ULL << 38),
434   OPTS_TYPE_AUX3              = (1ULL << 39),
435   OPTS_TYPE_AUX4              = (1ULL << 40),
436   OPTS_TYPE_BINARY_HASHFILE   = (1ULL << 41),
437   OPTS_TYPE_BINARY_HASHFILE_OPTIONAL
438                               = (1ULL << 42), // this allows us to not enforce the use of a binary file. requires OPTS_TYPE_BINARY_HASHFILE set to be effective.
439   OPTS_TYPE_PT_ADD06          = (1ULL << 43),
440   OPTS_TYPE_KEYBOARD_MAPPING  = (1ULL << 44),
441   OPTS_TYPE_DEEP_COMP_KERNEL  = (1ULL << 45), // if we have to iterate through each hash inside the comp kernel, for example if each hash has to be decrypted separately
442   OPTS_TYPE_TM_KERNEL         = (1ULL << 46),
443   OPTS_TYPE_SUGGEST_KG        = (1ULL << 47), // suggest keep guessing for modules the user maybe wants to use --keep-guessing
444   OPTS_TYPE_COPY_TMPS         = (1ULL << 48), // if we want to use data from tmps buffer (for example get the PMK in WPA)
445   OPTS_TYPE_POTFILE_NOPASS    = (1ULL << 49), // sometimes the password should not be printed to potfile
446   OPTS_TYPE_DYNAMIC_SHARED    = (1ULL << 50), // use dynamic shared memory (note: needs special kernel changes)
447   OPTS_TYPE_SELF_TEST_DISABLE = (1ULL << 51), // some algos use JiT in combinations with a salt or create too much startup time
448   OPTS_TYPE_MP_MULTI_DISABLE  = (1ULL << 52), // do not multiply the kernel-accel with the multiprocessor count per device to allow more fine-tuned workload settings
449   OPTS_TYPE_NATIVE_THREADS    = (1ULL << 53), // forces "native" thread count: CPU=1, GPU-Intel=8, GPU-AMD=64 (wavefront), GPU-NV=32 (warps)
450   OPTS_TYPE_MAXIMUM_THREADS   = (1ULL << 54), // disable else branch in pre-compilation thread count optimization setting
451   OPTS_TYPE_POST_AMP_UTF16LE  = (1ULL << 55), // run the utf8 to utf16le conversion kernel after they have been processed from amplifiers
452   OPTS_TYPE_AUTODETECT_DISABLE
453                               = (1ULL << 56), // skip autodetect engine
454 
455 } opts_type_t;
456 
457 typedef enum dgst_size
458 {
459   DGST_SIZE_4_2  = (2  * sizeof (u32)), // 8
460   DGST_SIZE_4_4  = (4  * sizeof (u32)), // 16 !!!
461   DGST_SIZE_4_5  = (5  * sizeof (u32)), // 20
462   DGST_SIZE_4_6  = (6  * sizeof (u32)), // 24
463   DGST_SIZE_4_7  = (7  * sizeof (u32)), // 28
464   DGST_SIZE_4_8  = (8  * sizeof (u32)), // 32
465   DGST_SIZE_4_16 = (16 * sizeof (u32)), // 64 !!!
466   DGST_SIZE_4_32 = (32 * sizeof (u32)), // 128 !!!
467   DGST_SIZE_4_64 = (64 * sizeof (u32)), // 256
468   DGST_SIZE_8_2  = (2  * sizeof (u64)), // 16 !!!
469   DGST_SIZE_8_4  = (4  * sizeof (u64)), // 32 !!!
470   DGST_SIZE_8_6  = (6  * sizeof (u64)), // 48 !!!
471   DGST_SIZE_8_8  = (8  * sizeof (u64)), // 64 !!!
472   DGST_SIZE_8_16 = (16 * sizeof (u64)), // 128 !!!
473   DGST_SIZE_8_25 = (25 * sizeof (u64))  // 200
474 
475 } dgst_size_t;
476 
477 typedef enum attack_exec
478 {
479   ATTACK_EXEC_OUTSIDE_KERNEL = 10,
480   ATTACK_EXEC_INSIDE_KERNEL  = 11
481 
482 } attack_exec_t;
483 
484 typedef enum hlfmt_name
485 {
486   HLFMT_HASHCAT  = 0,
487   HLFMT_PWDUMP   = 1,
488   HLFMT_PASSWD   = 2,
489   HLFMT_SHADOW   = 3,
490   HLFMT_DCC      = 4,
491   HLFMT_DCC2     = 5,
492   HLFMT_NETNTLM1 = 7,
493   HLFMT_NETNTLM2 = 8,
494   HLFMT_NSLDAP   = 9,
495   HLFMT_NSLDAPS  = 10
496 
497 } hlfmt_name_t;
498 
499 typedef enum pwdump_column
500 {
501   PWDUMP_COLUMN_INVALID   = -1,
502   PWDUMP_COLUMN_USERNAME  = 0,
503   PWDUMP_COLUMN_UID       = 1,
504   PWDUMP_COLUMN_LM_HASH   = 2,
505   PWDUMP_COLUMN_NTLM_HASH = 3,
506   PWDUMP_COLUMN_COMMENT   = 4,
507   PWDUMP_COLUMN_HOMEDIR   = 5,
508 
509 } pwdump_column_t;
510 
511 typedef enum outfile_fmt
512 {
513   OUTFILE_FMT_HASH      = (1 << 0),
514   OUTFILE_FMT_PLAIN     = (1 << 1),
515   OUTFILE_FMT_HEXPLAIN  = (1 << 2),
516   OUTFILE_FMT_CRACKPOS  = (1 << 3),
517   OUTFILE_FMT_TIME_ABS  = (1 << 4),
518   OUTFILE_FMT_TIME_REL  = (1 << 5)
519 
520 } outfile_fmt_t;
521 
522 typedef enum parser_rc
523 {
524   PARSER_OK                   = 0,
525   PARSER_COMMENT              = -1,
526   PARSER_GLOBAL_ZERO          = -2,
527   PARSER_GLOBAL_LENGTH        = -3,
528   PARSER_HASH_LENGTH          = -4,
529   PARSER_HASH_VALUE           = -5,
530   PARSER_SALT_LENGTH          = -6,
531   PARSER_SALT_VALUE           = -7,
532   PARSER_SALT_ITERATION       = -8,
533   PARSER_SEPARATOR_UNMATCHED  = -9,
534   PARSER_SIGNATURE_UNMATCHED  = -10,
535   PARSER_HCCAPX_FILE_SIZE     = -11,
536   PARSER_HCCAPX_EAPOL_LEN     = -12,
537   PARSER_PSAFE2_FILE_SIZE     = -13,
538   PARSER_PSAFE3_FILE_SIZE     = -14,
539   PARSER_TC_FILE_SIZE         = -15,
540   PARSER_VC_FILE_SIZE         = -16,
541   PARSER_SIP_AUTH_DIRECTIVE   = -17,
542   PARSER_HASH_FILE            = -18,
543   PARSER_HASH_ENCODING        = -19,
544   PARSER_SALT_ENCODING        = -20,
545   PARSER_LUKS_FILE_SIZE       = -21,
546   PARSER_LUKS_MAGIC           = -22,
547   PARSER_LUKS_VERSION         = -23,
548   PARSER_LUKS_CIPHER_TYPE     = -24,
549   PARSER_LUKS_CIPHER_MODE     = -25,
550   PARSER_LUKS_HASH_TYPE       = -26,
551   PARSER_LUKS_KEY_SIZE        = -27,
552   PARSER_LUKS_KEY_DISABLED    = -28,
553   PARSER_LUKS_KEY_STRIPES     = -29,
554   PARSER_LUKS_HASH_CIPHER     = -30,
555   PARSER_HCCAPX_SIGNATURE     = -31,
556   PARSER_HCCAPX_VERSION       = -32,
557   PARSER_HCCAPX_MESSAGE_PAIR  = -33,
558   PARSER_TOKEN_ENCODING       = -34,
559   PARSER_TOKEN_LENGTH         = -35,
560   PARSER_INSUFFICIENT_ENTROPY = -36,
561   PARSER_PKZIP_CT_UNMATCHED   = -37,
562   PARSER_KEY_SIZE             = -38,
563   PARSER_BLOCK_SIZE           = -39,
564   PARSER_CIPHER               = -40,
565   PARSER_FILE_SIZE            = -41,
566   PARSER_IV_LENGTH            = -42,
567   PARSER_CT_LENGTH            = -43,
568   PARSER_CRYPTOAPI_KERNELTYPE = -44,
569   PARSER_CRYPTOAPI_KEYSIZE    = -45,
570   PARSER_HAVE_ERRNO           = -100,
571   PARSER_UNKNOWN_ERROR        = -255
572 
573 } parser_rc_t;
574 
575 typedef enum guess_mode
576 {
577   GUESS_MODE_NONE                       = 0,
578   GUESS_MODE_STRAIGHT_FILE              = 1,
579   GUESS_MODE_STRAIGHT_FILE_RULES_FILE   = 2,
580   GUESS_MODE_STRAIGHT_FILE_RULES_GEN    = 3,
581   GUESS_MODE_STRAIGHT_STDIN             = 4,
582   GUESS_MODE_STRAIGHT_STDIN_RULES_FILE  = 5,
583   GUESS_MODE_STRAIGHT_STDIN_RULES_GEN   = 6,
584   GUESS_MODE_COMBINATOR_BASE_LEFT       = 7,
585   GUESS_MODE_COMBINATOR_BASE_RIGHT      = 8,
586   GUESS_MODE_MASK                       = 9,
587   GUESS_MODE_MASK_CS                    = 10,
588   GUESS_MODE_HYBRID1                    = 11,
589   GUESS_MODE_HYBRID1_CS                 = 12,
590   GUESS_MODE_HYBRID2                    = 13,
591   GUESS_MODE_HYBRID2_CS                 = 14,
592 
593 } guess_mode_t;
594 
595 typedef enum progress_mode
596 {
597   PROGRESS_MODE_NONE              = 0,
598   PROGRESS_MODE_KEYSPACE_KNOWN    = 1,
599   PROGRESS_MODE_KEYSPACE_UNKNOWN  = 2,
600 
601 } progress_mode_t;
602 
603 typedef enum user_options_defaults
604 {
605   ADVICE_DISABLE           = false,
606   ATTACK_MODE              = ATTACK_MODE_STRAIGHT,
607   AUTODETECT               = false,
608   BENCHMARK_ALL            = false,
609   BENCHMARK                = false,
610   BITMAP_MAX               = 18,
611   BITMAP_MIN               = 16,
612   #ifdef WITH_BRAIN
613   BRAIN_CLIENT             = false,
614   BRAIN_CLIENT_FEATURES    = 2,
615   BRAIN_PORT               = 6863,
616   BRAIN_SERVER             = false,
617   BRAIN_SESSION            = 0,
618   #endif
619   DEBUG_MODE               = 0,
620   DEPRECATED_CHECK_DISABLE = false,
621   FORCE                    = false,
622   HWMON_DISABLE            = false,
623   #if defined (__APPLE__)
624   HWMON_TEMP_ABORT         = 100,
625   #else
626   HWMON_TEMP_ABORT         = 90,
627   #endif
628   HASH_INFO                = false,
629   HASH_MODE                = 0,
630   HCCAPX_MESSAGE_PAIR      = 0,
631   HEX_CHARSET              = false,
632   HEX_SALT                 = false,
633   HEX_WORDLIST             = false,
634   HOOK_THREADS             = 0,
635   IDENTIFY                 = false,
636   INCREMENT                = false,
637   INCREMENT_MAX            = PW_MAX,
638   INCREMENT_MIN            = 1,
639   KEEP_GUESSING            = false,
640   KERNEL_ACCEL             = 0,
641   KERNEL_LOOPS             = 0,
642   KERNEL_THREADS           = 0,
643   KEYSPACE                 = false,
644   LEFT                     = false,
645   LIMIT                    = 0,
646   LOGFILE_DISABLE          = false,
647   LOOPBACK                 = false,
648   MACHINE_READABLE         = false,
649   MARKOV_CLASSIC           = false,
650   MARKOV_DISABLE           = false,
651   MARKOV_INVERSE           = false,
652   MARKOV_THRESHOLD         = 0,
653   NONCE_ERROR_CORRECTIONS  = 8,
654   BACKEND_IGNORE_CUDA      = false,
655   BACKEND_IGNORE_HIP       = false,
656   BACKEND_IGNORE_OPENCL    = false,
657   BACKEND_INFO             = false,
658   BACKEND_VECTOR_WIDTH     = 0,
659   OPTIMIZED_KERNEL_ENABLE  = false,
660   MULTIPLY_ACCEL_DISABLE   = false,
661   OUTFILE_AUTOHEX          = true,
662   OUTFILE_CHECK_TIMER      = 5,
663   OUTFILE_FORMAT           = 3,
664   POTFILE_DISABLE          = false,
665   PROGRESS_ONLY            = false,
666   QUIET                    = false,
667   REMOVE                   = false,
668   REMOVE_TIMER             = 60,
669   RESTORE_DISABLE          = false,
670   RESTORE                  = false,
671   RESTORE_TIMER            = 60,
672   RP_GEN                   = 0,
673   RP_GEN_FUNC_MAX          = 4,
674   RP_GEN_FUNC_MIN          = 1,
675   RP_GEN_SEED              = 0,
676   RUNTIME                  = 0,
677   SCRYPT_TMTO              = 0,
678   SEGMENT_SIZE             = 33554432,
679   SELF_TEST_DISABLE        = false,
680   SHOW                     = false,
681   SKIP                     = 0,
682   SLOW_CANDIDATES          = false,
683   SPEED_ONLY               = false,
684   SPIN_DAMP                = 0,
685   STATUS                   = false,
686   STATUS_JSON              = false,
687   STATUS_TIMER             = 10,
688   STDIN_TIMEOUT_ABORT      = 120,
689   STDOUT_FLAG              = false,
690   USAGE                    = false,
691   USERNAME                 = false,
692   VERSION                  = false,
693   VERACRYPT_PIM_START      = 485,
694   VERACRYPT_PIM_STOP       = 485,
695   WORDLIST_AUTOHEX_DISABLE = false,
696   WORKLOAD_PROFILE         = 2,
697 
698 } user_options_defaults_t;
699 
700 typedef enum user_options_map
701 {
702   IDX_ADVICE_DISABLE            = 0xff00,
703   IDX_ATTACK_MODE               = 'a',
704   IDX_BACKEND_DEVICES           = 'd',
705   IDX_BACKEND_IGNORE_CUDA       = 0xff01,
706   IDX_BACKEND_IGNORE_HIP        = 0xff02,
707   IDX_BACKEND_IGNORE_OPENCL     = 0xff03,
708   IDX_BACKEND_INFO              = 'I',
709   IDX_BACKEND_VECTOR_WIDTH      = 0xff04,
710   IDX_BENCHMARK_ALL             = 0xff05,
711   IDX_BENCHMARK                 = 'b',
712   IDX_BITMAP_MAX                = 0xff06,
713   IDX_BITMAP_MIN                = 0xff07,
714   #ifdef WITH_BRAIN
715   IDX_BRAIN_CLIENT              = 'z',
716   IDX_BRAIN_CLIENT_FEATURES     = 0xff08,
717   IDX_BRAIN_HOST                = 0xff09,
718   IDX_BRAIN_PASSWORD            = 0xff0a,
719   IDX_BRAIN_PORT                = 0xff0b,
720   IDX_BRAIN_SERVER              = 0xff0c,
721   IDX_BRAIN_SERVER_TIMER        = 0xff0d,
722   IDX_BRAIN_SESSION             = 0xff0e,
723   IDX_BRAIN_SESSION_WHITELIST   = 0xff0f,
724   #endif
725   IDX_CPU_AFFINITY              = 0xff10,
726   IDX_CUSTOM_CHARSET_1          = '1',
727   IDX_CUSTOM_CHARSET_2          = '2',
728   IDX_CUSTOM_CHARSET_3          = '3',
729   IDX_CUSTOM_CHARSET_4          = '4',
730   IDX_DEBUG_FILE                = 0xff11,
731   IDX_DEBUG_MODE                = 0xff12,
732   IDX_DEPRECATED_CHECK_DISABLE  = 0xff13,
733   IDX_ENCODING_FROM             = 0xff14,
734   IDX_ENCODING_TO               = 0xff15,
735   IDX_HASH_INFO                 = 0xff16,
736   IDX_FORCE                     = 0xff17,
737   IDX_HWMON_DISABLE             = 0xff18,
738   IDX_HWMON_TEMP_ABORT          = 0xff19,
739   IDX_HASH_MODE                 = 'm',
740   IDX_HCCAPX_MESSAGE_PAIR       = 0xff1a,
741   IDX_HELP                      = 'h',
742   IDX_HEX_CHARSET               = 0xff1b,
743   IDX_HEX_SALT                  = 0xff1c,
744   IDX_HEX_WORDLIST              = 0xff1d,
745   IDX_HOOK_THREADS              = 0xff1e,
746   IDX_IDENTIFY                  = 0xff1f,
747   IDX_INCREMENT                 = 'i',
748   IDX_INCREMENT_MAX             = 0xff20,
749   IDX_INCREMENT_MIN             = 0xff21,
750   IDX_INDUCTION_DIR             = 0xff22,
751   IDX_KEEP_GUESSING             = 0xff23,
752   IDX_KERNEL_ACCEL              = 'n',
753   IDX_KERNEL_LOOPS              = 'u',
754   IDX_KERNEL_THREADS            = 'T',
755   IDX_KEYBOARD_LAYOUT_MAPPING   = 0xff24,
756   IDX_KEYSPACE                  = 0xff25,
757   IDX_LEFT                      = 0xff26,
758   IDX_LIMIT                     = 'l',
759   IDX_LOGFILE_DISABLE           = 0xff27,
760   IDX_LOOPBACK                  = 0xff28,
761   IDX_MACHINE_READABLE          = 0xff29,
762   IDX_MARKOV_CLASSIC            = 0xff2a,
763   IDX_MARKOV_DISABLE            = 0xff2b,
764   IDX_MARKOV_HCSTAT2            = 0xff2c,
765   IDX_MARKOV_INVERSE            = 0xff2d,
766   IDX_MARKOV_THRESHOLD          = 't',
767   IDX_NONCE_ERROR_CORRECTIONS   = 0xff2e,
768   IDX_OPENCL_DEVICE_TYPES       = 'D',
769   IDX_OPTIMIZED_KERNEL_ENABLE   = 'O',
770   IDX_MULTIPLY_ACCEL_DISABLE    = 'M',
771   IDX_OUTFILE_AUTOHEX_DISABLE   = 0xff2f,
772   IDX_OUTFILE_CHECK_DIR         = 0xff30,
773   IDX_OUTFILE_CHECK_TIMER       = 0xff31,
774   IDX_OUTFILE_FORMAT            = 0xff32,
775   IDX_OUTFILE                   = 'o',
776   IDX_POTFILE_DISABLE           = 0xff33,
777   IDX_POTFILE_PATH              = 0xff34,
778   IDX_PROGRESS_ONLY             = 0xff35,
779   IDX_QUIET                     = 0xff36,
780   IDX_REMOVE                    = 0xff37,
781   IDX_REMOVE_TIMER              = 0xff38,
782   IDX_RESTORE                   = 0xff39,
783   IDX_RESTORE_DISABLE           = 0xff3a,
784   IDX_RESTORE_FILE_PATH         = 0xff3b,
785   IDX_RP_FILE                   = 'r',
786   IDX_RP_GEN_FUNC_MAX           = 0xff3c,
787   IDX_RP_GEN_FUNC_MIN           = 0xff3d,
788   IDX_RP_GEN_FUNC_SEL           = 0xff3e,
789   IDX_RP_GEN                    = 'g',
790   IDX_RP_GEN_SEED               = 0xff3f,
791   IDX_RULE_BUF_L                = 'j',
792   IDX_RULE_BUF_R                = 'k',
793   IDX_RUNTIME                   = 0xff40,
794   IDX_SCRYPT_TMTO               = 0xff41,
795   IDX_SEGMENT_SIZE              = 'c',
796   IDX_SELF_TEST_DISABLE         = 0xff42,
797   IDX_SEPARATOR                 = 'p',
798   IDX_SESSION                   = 0xff43,
799   IDX_SHOW                      = 0xff44,
800   IDX_SKIP                      = 's',
801   IDX_SLOW_CANDIDATES           = 'S',
802   IDX_SPEED_ONLY                = 0xff45,
803   IDX_SPIN_DAMP                 = 0xff46,
804   IDX_STATUS                    = 0xff47,
805   IDX_STATUS_JSON               = 0xff48,
806   IDX_STATUS_TIMER              = 0xff49,
807   IDX_STDOUT_FLAG               = 0xff4a,
808   IDX_STDIN_TIMEOUT_ABORT       = 0xff4b,
809   IDX_TRUECRYPT_KEYFILES        = 0xff4c,
810   IDX_USERNAME                  = 0xff4d,
811   IDX_VERACRYPT_KEYFILES        = 0xff4e,
812   IDX_VERACRYPT_PIM_START       = 0xff4f,
813   IDX_VERACRYPT_PIM_STOP        = 0xff50,
814   IDX_VERSION_LOWER             = 'v',
815   IDX_VERSION                   = 'V',
816   IDX_WORDLIST_AUTOHEX_DISABLE  = 0xff51,
817   IDX_WORKLOAD_PROFILE          = 'w',
818 
819 } user_options_map_t;
820 
821 typedef enum token_attr
822 {
823   TOKEN_ATTR_FIXED_LENGTH       = 1 <<  0,
824   TOKEN_ATTR_SEPARATOR_FARTHEST = 1 <<  1,
825   TOKEN_ATTR_OPTIONAL_ROUNDS    = 1 <<  2,
826   TOKEN_ATTR_VERIFY_SIGNATURE   = 1 <<  3,
827   TOKEN_ATTR_VERIFY_LENGTH      = 1 <<  4,
828   TOKEN_ATTR_VERIFY_DIGIT       = 1 <<  5,
829   TOKEN_ATTR_VERIFY_FLOAT       = 1 <<  6,
830   TOKEN_ATTR_VERIFY_HEX         = 1 <<  7,
831   TOKEN_ATTR_VERIFY_BASE64A     = 1 <<  8,
832   TOKEN_ATTR_VERIFY_BASE64B     = 1 <<  9,
833   TOKEN_ATTR_VERIFY_BASE64C     = 1 << 10,
834 
835 } token_attr_t;
836 
837 #ifdef WITH_BRAIN
838 typedef enum brain_link_status
839 {
840   BRAIN_LINK_STATUS_CONNECTED   = 1 << 0,
841   BRAIN_LINK_STATUS_RECEIVING   = 1 << 1,
842   BRAIN_LINK_STATUS_SENDING     = 1 << 2,
843 
844 } brain_link_status_t;
845 #endif
846 
847 #ifdef _WIN
848 typedef HMODULE hc_dynlib_t;
849 typedef FARPROC hc_dynfunc_t;
850 #else
851 typedef void * hc_dynlib_t;
852 typedef void * hc_dynfunc_t;
853 #endif
854 
855 /**
856  * structs
857  */
858 
859 typedef struct user
860 {
861   char *user_name;
862   u32   user_len;
863 
864 } user_t;
865 
866 typedef enum split_origin
867 {
868   SPLIT_ORIGIN_NONE   = 0,
869   SPLIT_ORIGIN_LEFT   = 1,
870   SPLIT_ORIGIN_RIGHT  = 2,
871 
872 } split_origin_t;
873 
874 typedef struct split
875 {
876   // some hashes, like lm, are split. this id point to the other hash of the group
877 
878   int split_group;
879   int split_neighbor;
880   int split_origin;
881 
882 } split_t;
883 
884 typedef struct hashinfo
885 {
886   user_t  *user;
887   char    *orighash;
888   split_t *split;
889 
890 } hashinfo_t;
891 
892 typedef struct hash
893 {
894   void       *digest;
895   salt_t     *salt;
896   void       *esalt;
897   void       *hook_salt; // additional salt info only used by the hook (host)
898   int         cracked;
899   hashinfo_t *hash_info;
900   char       *pw_buf;
901   int         pw_len;
902   u64         orig_line_pos;
903 
904 } hash_t;
905 
906 typedef struct outfile_data
907 {
908   char      *file_name;
909   off_t      seek;
910   time_t     ctime;
911 
912 } outfile_data_t;
913 
914 typedef struct logfile_ctx
915 {
916   bool  enabled;
917 
918   char *logfile;
919   char *topid;
920   char *subid;
921 
922 } logfile_ctx_t;
923 
924 typedef struct hashes
925 {
926   const char  *hashfile;
927 
928   u32          hashlist_mode;
929   u32          hashlist_format;
930 
931   u32          digests_cnt;
932   u32          digests_done;
933   u32          digests_saved;
934 
935   void        *digests_buf;
936   u32         *digests_shown;
937 
938   u32          salts_cnt;
939   u32          salts_done;
940 
941   salt_t      *salts_buf;
942   u32         *salts_shown;
943 
944   void        *esalts_buf;
945 
946   void        *hook_salts_buf;
947 
948   u32          hashes_cnt_orig;
949   u32          hashes_cnt;
950   hash_t      *hashes_buf;
951 
952   hashinfo_t **hash_info;
953 
954   u8          *out_buf; // allocates [HCBUFSIZ_LARGE];
955   u8          *tmp_buf; // allocates [HCBUFSIZ_LARGE];
956 
957   // selftest buffers
958 
959   void        *st_digests_buf;
960   salt_t      *st_salts_buf;
961   void        *st_esalts_buf;
962   void        *st_hook_salts_buf;
963 
964 } hashes_t;
965 
966 typedef struct hashconfig
967 {
968   char  separator;
969 
970   int   hash_mode;
971   u32   salt_type;
972   u32   attack_exec;
973   u32   kern_type;
974   u32   dgst_size;
975   u32   opti_type;
976   u64   opts_type;
977   u32   dgst_pos0;
978   u32   dgst_pos1;
979   u32   dgst_pos2;
980   u32   dgst_pos3;
981 
982   bool  is_salted;
983 
984   bool  has_pure_kernel;
985   bool  has_optimized_kernel;
986 
987   // sizes have to be size_t
988 
989   u64   esalt_size;
990   u64   hook_extra_param_size;
991   u64   hook_salt_size;
992   u64   tmp_size;
993   u64   hook_size;
994 
995   // password length limit
996 
997   u32   pw_min;
998   u32   pw_max;
999 
1000   // salt length limit (generic hashes)
1001 
1002   u32   salt_min;
1003   u32   salt_max;
1004 
1005   // hash count limit
1006 
1007   u32   hashes_count_min;
1008   u32   hashes_count_max;
1009 
1010   //  int (*parse_func) (u8 *, u32, hash_t *, struct hashconfig *);
1011 
1012   const char *st_hash;
1013   const char *st_pass;
1014 
1015   u32         hash_category;
1016   const char *hash_name;
1017 
1018   const char *benchmark_mask;
1019 
1020   u32 kernel_accel_min;
1021   u32 kernel_accel_max;
1022   u32 kernel_loops_min;
1023   u32 kernel_loops_max;
1024   u32 kernel_threads_min;
1025   u32 kernel_threads_max;
1026 
1027   u32 forced_outfile_format;
1028 
1029   bool dictstat_disable;
1030   bool hlfmt_disable;
1031   bool warmup_disable;
1032   bool outfile_check_disable;
1033   bool outfile_check_nocomp;
1034   bool potfile_disable;
1035   bool potfile_keep_all_hashes;
1036   bool forced_jit_compile;
1037 
1038   u32 pwdump_column;
1039 } hashconfig_t;
1040 
1041 typedef struct pw_pre
1042 {
1043   u32 pw_buf[64];
1044   u32 pw_len;
1045 
1046   u32 base_buf[64];
1047   u32 base_len;
1048 
1049   u32 rule_idx;
1050 
1051 } pw_pre_t;
1052 
1053 typedef struct cpt
1054 {
1055   u32       cracked;
1056   time_t    timestamp;
1057 
1058 } cpt_t;
1059 
1060 #define LINK_SPEED_COUNT 10000
1061 
1062 typedef struct link_speed
1063 {
1064   hc_timer_t timer[LINK_SPEED_COUNT];
1065   ssize_t    bytes[LINK_SPEED_COUNT];
1066   int        pos;
1067 
1068 } link_speed_t;
1069 
1070 // file handling
1071 
1072 typedef struct xzfile xzfile_t;
1073 
1074 typedef struct hc_fp
1075 {
1076   int         fd;
1077 
1078   FILE       *pfp; // plain fp
1079   gzFile      gfp; //  gzip fp
1080   unzFile     ufp; //   zip fp
1081   xzfile_t   *xfp; //    xz fp
1082 
1083   int         bom_size;
1084 
1085   const char *mode;
1086   const char *path;
1087 
1088 } HCFILE;
1089 
1090 #include "ext_nvrtc.h"
1091 #include "ext_hiprtc.h"
1092 
1093 #include "ext_cuda.h"
1094 #include "ext_hip.h"
1095 #include "ext_OpenCL.h"
1096 
1097 typedef struct hc_device_param
1098 {
1099   int     device_id;
1100 
1101   // this occurs if the same device (pci address) is used by multiple backend API
1102   int     device_id_alias_cnt;
1103   int     device_id_alias_buf[DEVICES_MAX];
1104 
1105   u8      pcie_domain;
1106   u8      pcie_bus;
1107   u8      pcie_device;
1108   u8      pcie_function;
1109 
1110   bool    skipped;              // permanent
1111   bool    skipped_warning;      // iteration
1112 
1113   u32     device_processors;
1114   u64     device_maxmem_alloc;
1115   u64     device_global_mem;
1116   u64     device_available_mem;
1117   int     device_host_unified_memory;
1118   u32     device_maxclock_frequency;
1119   size_t  device_maxworkgroup_size;
1120   u64     device_local_mem_size;
1121   int     device_local_mem_type;
1122   char   *device_name;
1123 
1124   int     sm_major;
1125   int     sm_minor;
1126   u32     kernel_exec_timeout;
1127 
1128   u32     kernel_preferred_wgs_multiple;
1129 
1130   st_status_t st_status;
1131 
1132   int     vector_width;
1133 
1134   u32     kernel_wgs1;
1135   u32     kernel_wgs12;
1136   u32     kernel_wgs2p;
1137   u32     kernel_wgs2;
1138   u32     kernel_wgs2e;
1139   u32     kernel_wgs23;
1140   u32     kernel_wgs3;
1141   u32     kernel_wgs4;
1142   u32     kernel_wgs_init2;
1143   u32     kernel_wgs_loop2p;
1144   u32     kernel_wgs_loop2;
1145   u32     kernel_wgs_mp;
1146   u32     kernel_wgs_mp_l;
1147   u32     kernel_wgs_mp_r;
1148   u32     kernel_wgs_amp;
1149   u32     kernel_wgs_tm;
1150   u32     kernel_wgs_memset;
1151   u32     kernel_wgs_bzero;
1152   u32     kernel_wgs_atinit;
1153   u32     kernel_wgs_utf8toutf16le;
1154   u32     kernel_wgs_decompress;
1155   u32     kernel_wgs_aux1;
1156   u32     kernel_wgs_aux2;
1157   u32     kernel_wgs_aux3;
1158   u32     kernel_wgs_aux4;
1159 
1160   u32     kernel_preferred_wgs_multiple1;
1161   u32     kernel_preferred_wgs_multiple12;
1162   u32     kernel_preferred_wgs_multiple2p;
1163   u32     kernel_preferred_wgs_multiple2;
1164   u32     kernel_preferred_wgs_multiple2e;
1165   u32     kernel_preferred_wgs_multiple23;
1166   u32     kernel_preferred_wgs_multiple3;
1167   u32     kernel_preferred_wgs_multiple4;
1168   u32     kernel_preferred_wgs_multiple_init2;
1169   u32     kernel_preferred_wgs_multiple_loop2p;
1170   u32     kernel_preferred_wgs_multiple_loop2;
1171   u32     kernel_preferred_wgs_multiple_mp;
1172   u32     kernel_preferred_wgs_multiple_mp_l;
1173   u32     kernel_preferred_wgs_multiple_mp_r;
1174   u32     kernel_preferred_wgs_multiple_amp;
1175   u32     kernel_preferred_wgs_multiple_tm;
1176   u32     kernel_preferred_wgs_multiple_memset;
1177   u32     kernel_preferred_wgs_multiple_bzero;
1178   u32     kernel_preferred_wgs_multiple_atinit;
1179   u32     kernel_preferred_wgs_multiple_utf8toutf16le;
1180   u32     kernel_preferred_wgs_multiple_decompress;
1181   u32     kernel_preferred_wgs_multiple_aux1;
1182   u32     kernel_preferred_wgs_multiple_aux2;
1183   u32     kernel_preferred_wgs_multiple_aux3;
1184   u32     kernel_preferred_wgs_multiple_aux4;
1185 
1186   u64     kernel_local_mem_size1;
1187   u64     kernel_local_mem_size12;
1188   u64     kernel_local_mem_size2p;
1189   u64     kernel_local_mem_size2;
1190   u64     kernel_local_mem_size2e;
1191   u64     kernel_local_mem_size23;
1192   u64     kernel_local_mem_size3;
1193   u64     kernel_local_mem_size4;
1194   u64     kernel_local_mem_size_init2;
1195   u64     kernel_local_mem_size_loop2p;
1196   u64     kernel_local_mem_size_loop2;
1197   u64     kernel_local_mem_size_mp;
1198   u64     kernel_local_mem_size_mp_l;
1199   u64     kernel_local_mem_size_mp_r;
1200   u64     kernel_local_mem_size_amp;
1201   u64     kernel_local_mem_size_tm;
1202   u64     kernel_local_mem_size_memset;
1203   u64     kernel_local_mem_size_bzero;
1204   u64     kernel_local_mem_size_atinit;
1205   u64     kernel_local_mem_size_utf8toutf16le;
1206   u64     kernel_local_mem_size_decompress;
1207   u64     kernel_local_mem_size_aux1;
1208   u64     kernel_local_mem_size_aux2;
1209   u64     kernel_local_mem_size_aux3;
1210   u64     kernel_local_mem_size_aux4;
1211 
1212   u64     kernel_dynamic_local_mem_size1;
1213   u64     kernel_dynamic_local_mem_size12;
1214   u64     kernel_dynamic_local_mem_size2p;
1215   u64     kernel_dynamic_local_mem_size2;
1216   u64     kernel_dynamic_local_mem_size2e;
1217   u64     kernel_dynamic_local_mem_size23;
1218   u64     kernel_dynamic_local_mem_size3;
1219   u64     kernel_dynamic_local_mem_size4;
1220   u64     kernel_dynamic_local_mem_size_init2;
1221   u64     kernel_dynamic_local_mem_size_loop2p;
1222   u64     kernel_dynamic_local_mem_size_loop2;
1223   u64     kernel_dynamic_local_mem_size_mp;
1224   u64     kernel_dynamic_local_mem_size_mp_l;
1225   u64     kernel_dynamic_local_mem_size_mp_r;
1226   u64     kernel_dynamic_local_mem_size_amp;
1227   u64     kernel_dynamic_local_mem_size_tm;
1228   u64     kernel_dynamic_local_mem_size_memset;
1229   u64     kernel_dynamic_local_mem_size_bzero;
1230   u64     kernel_dynamic_local_mem_size_atinit;
1231   u64     kernel_dynamic_local_mem_size_utf8toutf16le;
1232   u64     kernel_dynamic_local_mem_size_decompress;
1233   u64     kernel_dynamic_local_mem_size_aux1;
1234   u64     kernel_dynamic_local_mem_size_aux2;
1235   u64     kernel_dynamic_local_mem_size_aux3;
1236   u64     kernel_dynamic_local_mem_size_aux4;
1237 
1238   u32     kernel_accel;
1239   u32     kernel_accel_prev;
1240   u32     kernel_accel_min;
1241   u32     kernel_accel_max;
1242   u32     kernel_loops;
1243   u32     kernel_loops_prev;
1244   u32     kernel_loops_min;
1245   u32     kernel_loops_max;
1246   u32     kernel_loops_min_sav; // the _sav are required because each -i iteration
1247   u32     kernel_loops_max_sav; // needs to recalculate the kernel_loops_min/max based on the current amplifier count
1248   u32     kernel_threads;
1249   u32     kernel_threads_prev;
1250   u32     kernel_threads_min;
1251   u32     kernel_threads_max;
1252 
1253   u64     kernel_power;
1254   u64     hardware_power;
1255 
1256   u64  size_pws;
1257   u64  size_pws_amp;
1258   u64  size_pws_comp;
1259   u64  size_pws_idx;
1260   u64  size_pws_pre;
1261   u64  size_pws_base;
1262   u64  size_tmps;
1263   u64  size_hooks;
1264   u64  size_bfs;
1265   u64  size_combs;
1266   u64  size_rules;
1267   u64  size_rules_c;
1268   u64  size_root_css;
1269   u64  size_markov_css;
1270   u64  size_digests;
1271   u64  size_salts;
1272   u64  size_esalts;
1273   u64  size_shown;
1274   u64  size_results;
1275   u64  size_plains;
1276   u64  size_st_digests;
1277   u64  size_st_salts;
1278   u64  size_st_esalts;
1279   u64  size_tm;
1280 
1281   u64  extra_buffer_size;
1282 
1283   #ifdef WITH_BRAIN
1284   u64  size_brain_link_in;
1285   u64  size_brain_link_out;
1286 
1287   int           brain_link_client_fd;
1288   link_speed_t  brain_link_recv_speed;
1289   link_speed_t  brain_link_send_speed;
1290   bool          brain_link_recv_active;
1291   bool          brain_link_send_active;
1292   u64           brain_link_recv_bytes;
1293   u64           brain_link_send_bytes;
1294   u8           *brain_link_in_buf;
1295   u32          *brain_link_out_buf;
1296   #endif
1297 
1298   char     *scratch_buf;
1299 
1300   HCFILE    combs_fp;
1301   pw_t     *combs_buf;
1302 
1303   void     *hooks_buf;
1304 
1305   pw_idx_t *pws_idx;
1306   u32      *pws_comp;
1307   u64       pws_cnt;
1308 
1309   pw_pre_t *pws_pre_buf;  // for slow candidates
1310   u64       pws_pre_cnt;
1311 
1312   pw_pre_t *pws_base_buf; // for debug mode
1313   u64       pws_base_cnt;
1314 
1315   u64     words_off;
1316   u64     words_done;
1317 
1318   u64     outerloop_pos;
1319   u64     outerloop_left;
1320   double  outerloop_msec;
1321   double  outerloop_multi;
1322 
1323   u32     innerloop_pos;
1324   u32     innerloop_left;
1325 
1326   u32     exec_pos;
1327   double  exec_msec[EXEC_CACHE];
1328 
1329   // workaround cpu spinning
1330 
1331   double  exec_us_prev1[EXPECTED_ITERATIONS];
1332   double  exec_us_prev2p[EXPECTED_ITERATIONS];
1333   double  exec_us_prev2[EXPECTED_ITERATIONS];
1334   double  exec_us_prev2e[EXPECTED_ITERATIONS];
1335   double  exec_us_prev3[EXPECTED_ITERATIONS];
1336   double  exec_us_prev4[EXPECTED_ITERATIONS];
1337   double  exec_us_prev_init2[EXPECTED_ITERATIONS];
1338   double  exec_us_prev_loop2p[EXPECTED_ITERATIONS];
1339   double  exec_us_prev_loop2[EXPECTED_ITERATIONS];
1340   double  exec_us_prev_aux1[EXPECTED_ITERATIONS];
1341   double  exec_us_prev_aux2[EXPECTED_ITERATIONS];
1342   double  exec_us_prev_aux3[EXPECTED_ITERATIONS];
1343   double  exec_us_prev_aux4[EXPECTED_ITERATIONS];
1344 
1345   // this is "current" speed
1346 
1347   u32     speed_pos;
1348   u64     speed_cnt[SPEED_CACHE];
1349   double  speed_msec[SPEED_CACHE];
1350   bool    speed_only_finish;
1351 
1352   hc_timer_t timer_speed;
1353 
1354   // Some more attributes
1355 
1356   bool    use_opencl12;
1357   bool    use_opencl20;
1358   bool    use_opencl21;
1359 
1360   // AMD
1361   bool    has_vadd;
1362   bool    has_vaddc;
1363   bool    has_vadd_co;
1364   bool    has_vaddc_co;
1365   bool    has_vsub;
1366   bool    has_vsubb;
1367   bool    has_vsub_co;
1368   bool    has_vsubb_co;
1369   bool    has_vadd3;
1370   bool    has_vbfe;
1371   bool    has_vperm;
1372 
1373   // NV
1374   bool    has_add;
1375   bool    has_addc;
1376   bool    has_sub;
1377   bool    has_subc;
1378   bool    has_bfe;
1379   bool    has_lop3;
1380   bool    has_mov64;
1381   bool    has_prmt;
1382 
1383   double  spin_damp;
1384 
1385   void   *kernel_params[PARAMCNT];
1386   void   *kernel_params_mp[PARAMCNT];
1387   void   *kernel_params_mp_r[PARAMCNT];
1388   void   *kernel_params_mp_l[PARAMCNT];
1389   void   *kernel_params_amp[PARAMCNT];
1390   void   *kernel_params_tm[PARAMCNT];
1391   void   *kernel_params_memset[PARAMCNT];
1392   void   *kernel_params_bzero[PARAMCNT];
1393   void   *kernel_params_atinit[PARAMCNT];
1394   void   *kernel_params_utf8toutf16le[PARAMCNT];
1395   void   *kernel_params_decompress[PARAMCNT];
1396 
1397   u32     kernel_params_buf32[PARAMCNT];
1398   u64     kernel_params_buf64[PARAMCNT];
1399 
1400   u32     kernel_params_mp_buf32[PARAMCNT];
1401   u64     kernel_params_mp_buf64[PARAMCNT];
1402 
1403   u32     kernel_params_mp_r_buf32[PARAMCNT];
1404   u64     kernel_params_mp_r_buf64[PARAMCNT];
1405 
1406   u32     kernel_params_mp_l_buf32[PARAMCNT];
1407   u64     kernel_params_mp_l_buf64[PARAMCNT];
1408 
1409   u32     kernel_params_amp_buf32[PARAMCNT];
1410   u64     kernel_params_amp_buf64[PARAMCNT];
1411 
1412   u32     kernel_params_memset_buf32[PARAMCNT];
1413   u64     kernel_params_memset_buf64[PARAMCNT];
1414 
1415   u32     kernel_params_bzero_buf32[PARAMCNT];
1416   u64     kernel_params_bzero_buf64[PARAMCNT];
1417 
1418   u32     kernel_params_atinit_buf32[PARAMCNT];
1419   u64     kernel_params_atinit_buf64[PARAMCNT];
1420 
1421   u32     kernel_params_utf8toutf16le_buf32[PARAMCNT];
1422   u64     kernel_params_utf8toutf16le_buf64[PARAMCNT];
1423 
1424   u32     kernel_params_decompress_buf32[PARAMCNT];
1425   u64     kernel_params_decompress_buf64[PARAMCNT];
1426 
1427   // API: cuda
1428 
1429   bool              is_cuda;
1430 
1431   int               cuda_warp_size;
1432 
1433   CUdevice          cuda_device;
1434   CUcontext         cuda_context;
1435   CUstream          cuda_stream;
1436 
1437   CUevent           cuda_event1;
1438   CUevent           cuda_event2;
1439   CUevent           cuda_event3;
1440 
1441   CUmodule          cuda_module;
1442   CUmodule          cuda_module_shared;
1443   CUmodule          cuda_module_mp;
1444   CUmodule          cuda_module_amp;
1445 
1446   CUfunction        cuda_function1;
1447   CUfunction        cuda_function12;
1448   CUfunction        cuda_function2p;
1449   CUfunction        cuda_function2;
1450   CUfunction        cuda_function2e;
1451   CUfunction        cuda_function23;
1452   CUfunction        cuda_function3;
1453   CUfunction        cuda_function4;
1454   CUfunction        cuda_function_init2;
1455   CUfunction        cuda_function_loop2p;
1456   CUfunction        cuda_function_loop2;
1457   CUfunction        cuda_function_mp;
1458   CUfunction        cuda_function_mp_l;
1459   CUfunction        cuda_function_mp_r;
1460   CUfunction        cuda_function_amp;
1461   CUfunction        cuda_function_tm;
1462   CUfunction        cuda_function_memset;
1463   CUfunction        cuda_function_bzero;
1464   CUfunction        cuda_function_atinit;
1465   CUfunction        cuda_function_utf8toutf16le;
1466   CUfunction        cuda_function_decompress;
1467   CUfunction        cuda_function_aux1;
1468   CUfunction        cuda_function_aux2;
1469   CUfunction        cuda_function_aux3;
1470   CUfunction        cuda_function_aux4;
1471 
1472   CUdeviceptr       cuda_d_pws_buf;
1473   CUdeviceptr       cuda_d_pws_amp_buf;
1474   CUdeviceptr       cuda_d_pws_comp_buf;
1475   CUdeviceptr       cuda_d_pws_idx;
1476   CUdeviceptr       cuda_d_rules;
1477   CUdeviceptr       cuda_d_rules_c;
1478   CUdeviceptr       cuda_d_combs;
1479   CUdeviceptr       cuda_d_combs_c;
1480   CUdeviceptr       cuda_d_bfs;
1481   CUdeviceptr       cuda_d_bfs_c;
1482   CUdeviceptr       cuda_d_tm_c;
1483   CUdeviceptr       cuda_d_bitmap_s1_a;
1484   CUdeviceptr       cuda_d_bitmap_s1_b;
1485   CUdeviceptr       cuda_d_bitmap_s1_c;
1486   CUdeviceptr       cuda_d_bitmap_s1_d;
1487   CUdeviceptr       cuda_d_bitmap_s2_a;
1488   CUdeviceptr       cuda_d_bitmap_s2_b;
1489   CUdeviceptr       cuda_d_bitmap_s2_c;
1490   CUdeviceptr       cuda_d_bitmap_s2_d;
1491   CUdeviceptr       cuda_d_plain_bufs;
1492   CUdeviceptr       cuda_d_digests_buf;
1493   CUdeviceptr       cuda_d_digests_shown;
1494   CUdeviceptr       cuda_d_salt_bufs;
1495   CUdeviceptr       cuda_d_esalt_bufs;
1496   CUdeviceptr       cuda_d_tmps;
1497   CUdeviceptr       cuda_d_hooks;
1498   CUdeviceptr       cuda_d_result;
1499   CUdeviceptr       cuda_d_extra0_buf;
1500   CUdeviceptr       cuda_d_extra1_buf;
1501   CUdeviceptr       cuda_d_extra2_buf;
1502   CUdeviceptr       cuda_d_extra3_buf;
1503   CUdeviceptr       cuda_d_root_css_buf;
1504   CUdeviceptr       cuda_d_markov_css_buf;
1505   CUdeviceptr       cuda_d_st_digests_buf;
1506   CUdeviceptr       cuda_d_st_salts_buf;
1507   CUdeviceptr       cuda_d_st_esalts_buf;
1508 
1509   // API: hip
1510 
1511   bool              is_hip;
1512 
1513   int               hip_warp_size;
1514 
1515   hipDevice_t       hip_device;
1516   hipCtx_t          hip_context;
1517   hipStream_t       hip_stream;
1518 
1519   hipEvent_t        hip_event1;
1520   hipEvent_t        hip_event2;
1521   hipEvent_t        hip_event3;
1522 
1523   hipModule_t       hip_module;
1524   hipModule_t       hip_module_shared;
1525   hipModule_t       hip_module_mp;
1526   hipModule_t       hip_module_amp;
1527 
1528   hipFunction_t     hip_function1;
1529   hipFunction_t     hip_function12;
1530   hipFunction_t     hip_function2p;
1531   hipFunction_t     hip_function2;
1532   hipFunction_t     hip_function2e;
1533   hipFunction_t     hip_function23;
1534   hipFunction_t     hip_function3;
1535   hipFunction_t     hip_function4;
1536   hipFunction_t     hip_function_init2;
1537   hipFunction_t     hip_function_loop2p;
1538   hipFunction_t     hip_function_loop2;
1539   hipFunction_t     hip_function_mp;
1540   hipFunction_t     hip_function_mp_l;
1541   hipFunction_t     hip_function_mp_r;
1542   hipFunction_t     hip_function_amp;
1543   hipFunction_t     hip_function_tm;
1544   hipFunction_t     hip_function_memset;
1545   hipFunction_t     hip_function_bzero;
1546   hipFunction_t     hip_function_atinit;
1547   hipFunction_t     hip_function_utf8toutf16le;
1548   hipFunction_t     hip_function_decompress;
1549   hipFunction_t     hip_function_aux1;
1550   hipFunction_t     hip_function_aux2;
1551   hipFunction_t     hip_function_aux3;
1552   hipFunction_t     hip_function_aux4;
1553 
1554   hipDeviceptr_t    hip_d_pws_buf;
1555   hipDeviceptr_t    hip_d_pws_amp_buf;
1556   hipDeviceptr_t    hip_d_pws_comp_buf;
1557   hipDeviceptr_t    hip_d_pws_idx;
1558   hipDeviceptr_t    hip_d_rules;
1559   hipDeviceptr_t    hip_d_rules_c;
1560   hipDeviceptr_t    hip_d_combs;
1561   hipDeviceptr_t    hip_d_combs_c;
1562   hipDeviceptr_t    hip_d_bfs;
1563   hipDeviceptr_t    hip_d_bfs_c;
1564   hipDeviceptr_t    hip_d_tm_c;
1565   hipDeviceptr_t    hip_d_bitmap_s1_a;
1566   hipDeviceptr_t    hip_d_bitmap_s1_b;
1567   hipDeviceptr_t    hip_d_bitmap_s1_c;
1568   hipDeviceptr_t    hip_d_bitmap_s1_d;
1569   hipDeviceptr_t    hip_d_bitmap_s2_a;
1570   hipDeviceptr_t    hip_d_bitmap_s2_b;
1571   hipDeviceptr_t    hip_d_bitmap_s2_c;
1572   hipDeviceptr_t    hip_d_bitmap_s2_d;
1573   hipDeviceptr_t    hip_d_plain_bufs;
1574   hipDeviceptr_t    hip_d_digests_buf;
1575   hipDeviceptr_t    hip_d_digests_shown;
1576   hipDeviceptr_t    hip_d_salt_bufs;
1577   hipDeviceptr_t    hip_d_esalt_bufs;
1578   hipDeviceptr_t    hip_d_tmps;
1579   hipDeviceptr_t    hip_d_hooks;
1580   hipDeviceptr_t    hip_d_result;
1581   hipDeviceptr_t    hip_d_extra0_buf;
1582   hipDeviceptr_t    hip_d_extra1_buf;
1583   hipDeviceptr_t    hip_d_extra2_buf;
1584   hipDeviceptr_t    hip_d_extra3_buf;
1585   hipDeviceptr_t    hip_d_root_css_buf;
1586   hipDeviceptr_t    hip_d_markov_css_buf;
1587   hipDeviceptr_t    hip_d_st_digests_buf;
1588   hipDeviceptr_t    hip_d_st_salts_buf;
1589   hipDeviceptr_t    hip_d_st_esalts_buf;
1590 
1591   // API: opencl
1592 
1593   bool              is_opencl;
1594 
1595   char             *opencl_driver_version;
1596   char             *opencl_device_vendor;
1597   char             *opencl_device_version;
1598   char             *opencl_device_c_version;
1599 
1600   cl_device_type    opencl_device_type;
1601   cl_uint           opencl_device_vendor_id;
1602   u32               opencl_platform_id;
1603   cl_uint           opencl_platform_vendor_id;
1604 
1605   cl_device_id      opencl_device;
1606   cl_context        opencl_context;
1607   cl_command_queue  opencl_command_queue;
1608 
1609   cl_program        opencl_program;
1610   cl_program        opencl_program_shared;
1611   cl_program        opencl_program_mp;
1612   cl_program        opencl_program_amp;
1613 
1614   cl_kernel         opencl_kernel1;
1615   cl_kernel         opencl_kernel12;
1616   cl_kernel         opencl_kernel2p;
1617   cl_kernel         opencl_kernel2;
1618   cl_kernel         opencl_kernel2e;
1619   cl_kernel         opencl_kernel23;
1620   cl_kernel         opencl_kernel3;
1621   cl_kernel         opencl_kernel4;
1622   cl_kernel         opencl_kernel_init2;
1623   cl_kernel         opencl_kernel_loop2p;
1624   cl_kernel         opencl_kernel_loop2;
1625   cl_kernel         opencl_kernel_mp;
1626   cl_kernel         opencl_kernel_mp_l;
1627   cl_kernel         opencl_kernel_mp_r;
1628   cl_kernel         opencl_kernel_amp;
1629   cl_kernel         opencl_kernel_tm;
1630   cl_kernel         opencl_kernel_memset;
1631   cl_kernel         opencl_kernel_bzero;
1632   cl_kernel         opencl_kernel_atinit;
1633   cl_kernel         opencl_kernel_utf8toutf16le;
1634   cl_kernel         opencl_kernel_decompress;
1635   cl_kernel         opencl_kernel_aux1;
1636   cl_kernel         opencl_kernel_aux2;
1637   cl_kernel         opencl_kernel_aux3;
1638   cl_kernel         opencl_kernel_aux4;
1639 
1640   cl_mem            opencl_d_pws_buf;
1641   cl_mem            opencl_d_pws_amp_buf;
1642   cl_mem            opencl_d_pws_comp_buf;
1643   cl_mem            opencl_d_pws_idx;
1644   cl_mem            opencl_d_rules;
1645   cl_mem            opencl_d_rules_c;
1646   cl_mem            opencl_d_combs;
1647   cl_mem            opencl_d_combs_c;
1648   cl_mem            opencl_d_bfs;
1649   cl_mem            opencl_d_bfs_c;
1650   cl_mem            opencl_d_tm_c;
1651   cl_mem            opencl_d_bitmap_s1_a;
1652   cl_mem            opencl_d_bitmap_s1_b;
1653   cl_mem            opencl_d_bitmap_s1_c;
1654   cl_mem            opencl_d_bitmap_s1_d;
1655   cl_mem            opencl_d_bitmap_s2_a;
1656   cl_mem            opencl_d_bitmap_s2_b;
1657   cl_mem            opencl_d_bitmap_s2_c;
1658   cl_mem            opencl_d_bitmap_s2_d;
1659   cl_mem            opencl_d_plain_bufs;
1660   cl_mem            opencl_d_digests_buf;
1661   cl_mem            opencl_d_digests_shown;
1662   cl_mem            opencl_d_salt_bufs;
1663   cl_mem            opencl_d_esalt_bufs;
1664   cl_mem            opencl_d_tmps;
1665   cl_mem            opencl_d_hooks;
1666   cl_mem            opencl_d_result;
1667   cl_mem            opencl_d_extra0_buf;
1668   cl_mem            opencl_d_extra1_buf;
1669   cl_mem            opencl_d_extra2_buf;
1670   cl_mem            opencl_d_extra3_buf;
1671   cl_mem            opencl_d_root_css_buf;
1672   cl_mem            opencl_d_markov_css_buf;
1673   cl_mem            opencl_d_st_digests_buf;
1674   cl_mem            opencl_d_st_salts_buf;
1675   cl_mem            opencl_d_st_esalts_buf;
1676 
1677 } hc_device_param_t;
1678 
1679 typedef struct backend_ctx
1680 {
1681   bool                enabled;
1682 
1683   void               *cuda;
1684   void               *hip;
1685   void               *ocl;
1686 
1687   void               *nvrtc;
1688   void               *hiprtc;
1689 
1690   int                 backend_device_from_cuda[DEVICES_MAX];                              // from cuda device index to backend device index
1691   int                 backend_device_from_hip[DEVICES_MAX];                               // from hip device index to backend device index
1692   int                 backend_device_from_opencl[DEVICES_MAX];                            // from opencl device index to backend device index
1693   int                 backend_device_from_opencl_platform[CL_PLATFORMS_MAX][DEVICES_MAX]; // from opencl device index to backend device index (by platform)
1694 
1695   int                 backend_devices_cnt;
1696   int                 backend_devices_active;
1697 
1698   int                 cuda_devices_cnt;
1699   int                 cuda_devices_active;
1700   int                 hip_devices_cnt;
1701   int                 hip_devices_active;
1702   int                 opencl_devices_cnt;
1703   int                 opencl_devices_active;
1704 
1705   u64                 backend_devices_filter;
1706 
1707   hc_device_param_t  *devices_param;
1708 
1709   u32                 hardware_power_all;
1710 
1711   u64                 kernel_power_all;
1712   u64                 kernel_power_final; // we save that so that all divisions are done from the same base
1713 
1714   double              target_msec;
1715 
1716   bool                need_adl;
1717   bool                need_nvml;
1718   bool                need_nvapi;
1719   bool                need_sysfs_amdgpu;
1720   bool                need_sysfs_cpu;
1721   bool                need_iokit;
1722 
1723   int                 comptime;
1724 
1725   int                 force_jit_compilation;
1726 
1727   // cuda
1728 
1729   int                 rc_cuda_init;
1730   int                 rc_nvrtc_init;
1731 
1732   int                 nvrtc_driver_version;
1733   int                 cuda_driver_version;
1734 
1735   // hip
1736 
1737   int                 rc_hip_init;
1738   int                 rc_hiprtc_init;
1739 
1740   int                 hip_runtimeVersion;
1741   int                 hip_driverVersion;
1742 
1743   // opencl
1744 
1745   cl_platform_id     *opencl_platforms;
1746   cl_uint             opencl_platforms_cnt;
1747   cl_device_id      **opencl_platforms_devices;
1748   cl_uint            *opencl_platforms_devices_cnt;
1749   char              **opencl_platforms_name;
1750   char              **opencl_platforms_vendor;
1751   cl_uint            *opencl_platforms_vendor_id;
1752   char              **opencl_platforms_version;
1753 
1754   cl_device_type      opencl_device_types_filter;
1755 
1756 } backend_ctx_t;
1757 
1758 typedef enum kernel_workload
1759 {
1760   KERNEL_ACCEL_MIN   = 1,
1761   KERNEL_ACCEL_MAX   = 1024,
1762   KERNEL_LOOPS_MIN   = 1,
1763   KERNEL_LOOPS_MAX   = 1024,
1764   KERNEL_THREADS_MIN = 1,
1765   KERNEL_THREADS_MAX = 1024,
1766 
1767 } kernel_workload_t;
1768 
1769 #include "ext_ADL.h"
1770 #include "ext_nvapi.h"
1771 #include "ext_nvml.h"
1772 #include "ext_sysfs_amdgpu.h"
1773 #include "ext_sysfs_cpu.h"
1774 #include "ext_iokit.h"
1775 
1776 typedef struct hm_attrs
1777 {
1778   HM_ADAPTER_ADL          adl;
1779   HM_ADAPTER_NVML         nvml;
1780   HM_ADAPTER_NVAPI        nvapi;
1781   HM_ADAPTER_SYSFS_AMDGPU sysfs_amdgpu;
1782   HM_ADAPTER_SYSFS_CPU    sysfs_cpu;
1783   HM_ADAPTER_IOKIT        iokit;
1784 
1785   int od_version;
1786 
1787   bool buslanes_get_supported;
1788   bool corespeed_get_supported;
1789   bool fanspeed_get_supported;
1790   bool fanpolicy_get_supported;
1791   bool memoryspeed_get_supported;
1792   bool temperature_get_supported;
1793   bool threshold_shutdown_get_supported;
1794   bool threshold_slowdown_get_supported;
1795   bool throttle_get_supported;
1796   bool utilization_get_supported;
1797 
1798 } hm_attrs_t;
1799 
1800 typedef struct hwmon_ctx
1801 {
1802   bool  enabled;
1803 
1804   void *hm_adl;
1805   void *hm_nvml;
1806   void *hm_nvapi;
1807   void *hm_sysfs_amdgpu;
1808   void *hm_sysfs_cpu;
1809   void *hm_iokit;
1810 
1811   hm_attrs_t *hm_device;
1812 
1813 } hwmon_ctx_t;
1814 
1815 #if defined (__APPLE__)
1816 typedef struct cpu_set
1817 {
1818   u32 count;
1819 
1820 } cpu_set_t;
1821 #endif
1822 
1823 typedef struct
1824 {
1825   char *buf;
1826   int   len;
1827 
1828 } string_sized_t;
1829 
1830 /* AES context.  */
1831 typedef struct aes_context
1832 {
1833   int bits;
1834 
1835   u32 rek[60];
1836   u32 rdk[60];
1837 
1838 } aes_context_t;
1839 
1840 typedef aes_context_t aes_ctx;
1841 
1842 typedef struct debugfile_ctx
1843 {
1844   HCFILE  fp;
1845 
1846   bool    enabled;
1847 
1848   char   *filename;
1849   u32     mode;
1850 
1851 } debugfile_ctx_t;
1852 
1853 typedef struct dictstat
1854 {
1855   u64 cnt;
1856 
1857   struct stat stat;
1858 
1859   char encoding_from[64];
1860   char encoding_to[64];
1861 
1862   u8 hash_filename[16];
1863 
1864 } dictstat_t;
1865 
1866 typedef struct hashdump
1867 {
1868   int version;
1869 
1870   hashes_t hashes;
1871 
1872 } hashdump_t;
1873 
1874 typedef struct dictstat_ctx
1875 {
1876   bool enabled;
1877 
1878   char *filename;
1879 
1880   dictstat_t *base;
1881 
1882   #if defined (_WIN)
1883   u32    cnt;
1884   #else
1885   size_t cnt;
1886   #endif
1887 
1888 } dictstat_ctx_t;
1889 
1890 typedef struct loopback_ctx
1891 {
1892   HCFILE  fp;
1893 
1894   bool    enabled;
1895   bool    unused;
1896 
1897   char   *filename;
1898 
1899 } loopback_ctx_t;
1900 
1901 typedef struct mf
1902 {
1903   char mf_buf[0x400];
1904   int  mf_len;
1905 
1906 } mf_t;
1907 
1908 typedef struct outfile_ctx
1909 {
1910   HCFILE  fp;
1911 
1912   u32     outfile_format;
1913   bool    outfile_autohex;
1914 
1915   char   *filename;
1916 
1917 } outfile_ctx_t;
1918 
1919 typedef struct pot
1920 {
1921   char     plain_buf[HCBUFSIZ_SMALL];
1922   int      plain_len;
1923 
1924   hash_t   hash;
1925 
1926 } pot_t;
1927 
1928 typedef struct potfile_ctx
1929 {
1930   HCFILE   fp;
1931 
1932   bool     enabled;
1933 
1934   char    *filename;
1935 
1936   u8      *out_buf; // allocates [HCBUFSIZ_LARGE];
1937   u8      *tmp_buf; // allocates [HCBUFSIZ_LARGE];
1938 
1939 } potfile_ctx_t;
1940 
1941 // this is a linked list structure of all the hashes with the same "key" (hash or hash + salt)
1942 
1943 typedef struct pot_hash_node
1944 {
1945   hash_t *hash_buf;
1946 
1947   struct pot_hash_node *next;
1948 
1949 } pot_hash_node_t;
1950 
1951 // Attention: this is only used when --show and --username are used together
1952 // there could be multiple entries for each identical hash+salt combination
1953 // (e.g. same hashes, but different user names... we want to print all of them!)
1954 // that is why we use a linked list here
1955 
1956 typedef struct pot_tree_entry
1957 {
1958   pot_hash_node_t *nodes; // head of the linked list (under the field "hash_buf" it contains the sorting keys)
1959 
1960   // the hashconfig is required to distinguish between salted and non-salted hashes and to make sure
1961   // we compare the correct dgst_pos0...dgst_pos3
1962 
1963   hashconfig_t *hashconfig;
1964 
1965 } pot_tree_entry_t;
1966 
1967 typedef struct pot_orig_line_entry
1968 {
1969   u8 *hash_buf;
1970   int hash_len;
1971   int line_pos;
1972 
1973 } pot_orig_line_entry_t;
1974 
1975 typedef struct restore_data
1976 {
1977   int  version;
1978   char cwd[256];
1979 
1980   u32  dicts_pos;
1981   u32  masks_pos;
1982 
1983   u64  words_cur;
1984 
1985   u32  argc;
1986   char **argv;
1987 
1988 } restore_data_t;
1989 
1990 typedef struct pidfile_data
1991 {
1992   u32 pid;
1993 
1994 } pidfile_data_t;
1995 
1996 typedef struct restore_ctx
1997 {
1998   bool    enabled;
1999 
2000   bool    restore_execute;
2001 
2002   int     argc;
2003   char  **argv;
2004 
2005   char   *eff_restore_file;
2006   char   *new_restore_file;
2007 
2008   restore_data_t *rd;
2009 
2010 } restore_ctx_t;
2011 
2012 typedef struct pidfile_ctx
2013 {
2014   u32   pid;
2015   char *filename;
2016 
2017   pidfile_data_t *pd;
2018 
2019   bool  pidfile_written;
2020 
2021 } pidfile_ctx_t;
2022 
2023 typedef struct out
2024 {
2025   HCFILE fp;
2026 
2027   char   buf[HCBUFSIZ_SMALL];
2028   int    len;
2029 
2030 } out_t;
2031 
2032 typedef struct tuning_db_alias
2033 {
2034   char *device_name;
2035   char *alias_name;
2036 
2037 } tuning_db_alias_t;
2038 
2039 typedef struct tuning_db_entry
2040 {
2041   const char *device_name;
2042   int         attack_mode;
2043   int         hash_mode;
2044   int         workload_profile;
2045   int         vector_width;
2046   int         kernel_accel;
2047   int         kernel_loops;
2048 
2049 } tuning_db_entry_t;
2050 
2051 typedef struct tuning_db
2052 {
2053   bool enabled;
2054 
2055   tuning_db_alias_t *alias_buf;
2056   int                alias_cnt;
2057   int                alias_alloc;
2058 
2059   tuning_db_entry_t *entry_buf;
2060   int                entry_cnt;
2061   int                entry_alloc;
2062 
2063 } tuning_db_t;
2064 
2065 typedef struct wl_data
2066 {
2067   bool enabled;
2068 
2069   char *buf;
2070   u64  incr;
2071   u64  avail;
2072   u64  cnt;
2073   u64  pos;
2074 
2075   bool    iconv_enabled;
2076   iconv_t iconv_ctx;
2077   char   *iconv_tmp;
2078 
2079   void (*func) (char *, u64, u64 *, u64 *);
2080 
2081 } wl_data_t;
2082 
2083 typedef struct user_options
2084 {
2085   const char  *hc_bin;
2086 
2087   int          hc_argc;
2088   char       **hc_argv;
2089 
2090   bool         attack_mode_chgd;
2091   bool         autodetect;
2092   #ifdef WITH_BRAIN
2093   bool         brain_host_chgd;
2094   bool         brain_port_chgd;
2095   bool         brain_password_chgd;
2096   bool         brain_server_timer_chgd;
2097   #endif
2098   bool         hash_mode_chgd;
2099   bool         hccapx_message_pair_chgd;
2100   bool         identify;
2101   bool         increment_max_chgd;
2102   bool         increment_min_chgd;
2103   bool         kernel_accel_chgd;
2104   bool         kernel_loops_chgd;
2105   bool         kernel_threads_chgd;
2106   bool         nonce_error_corrections_chgd;
2107   bool         spin_damp_chgd;
2108   bool         backend_vector_width_chgd;
2109   bool         outfile_format_chgd;
2110   bool         remove_timer_chgd;
2111   bool         rp_gen_seed_chgd;
2112   bool         runtime_chgd;
2113   bool         segment_size_chgd;
2114   bool         workload_profile_chgd;
2115   bool         skip_chgd;
2116   bool         limit_chgd;
2117   bool         scrypt_tmto_chgd;
2118   bool         separator_chgd;
2119 
2120   bool         advice_disable;
2121   bool         benchmark;
2122   bool         benchmark_all;
2123   #ifdef WITH_BRAIN
2124   bool         brain_client;
2125   bool         brain_server;
2126   #endif
2127   bool         force;
2128   bool         deprecated_check_disable;
2129   bool         hwmon_disable;
2130   bool         hash_info;
2131   bool         hex_charset;
2132   bool         hex_salt;
2133   bool         hex_wordlist;
2134   bool         increment;
2135   bool         keep_guessing;
2136   bool         keyspace;
2137   bool         left;
2138   bool         logfile_disable;
2139   bool         loopback;
2140   bool         machine_readable;
2141   bool         markov_classic;
2142   bool         markov_disable;
2143   bool         markov_inverse;
2144   bool         backend_ignore_cuda;
2145   bool         backend_ignore_hip;
2146   bool         backend_ignore_opencl;
2147   bool         backend_info;
2148   bool         optimized_kernel_enable;
2149   bool         multiply_accel_disable;
2150   bool         outfile_autohex;
2151   bool         potfile_disable;
2152   bool         progress_only;
2153   bool         quiet;
2154   bool         remove;
2155   bool         restore;
2156   bool         restore_disable;
2157   bool         self_test_disable;
2158   bool         show;
2159   bool         slow_candidates;
2160   bool         speed_only;
2161   bool         status;
2162   bool         status_json;
2163   bool         stdout_flag;
2164   bool         stdin_timeout_abort_chgd;
2165   bool         usage;
2166   bool         username;
2167   bool         veracrypt_pim_start_chgd;
2168   bool         veracrypt_pim_stop_chgd;
2169   bool         version;
2170   bool         wordlist_autohex_disable;
2171   #ifdef WITH_BRAIN
2172   char        *brain_host;
2173   char        *brain_password;
2174   char        *brain_session_whitelist;
2175   #endif
2176   char        *cpu_affinity;
2177   char        *custom_charset_4;
2178   char        *debug_file;
2179   char        *induction_dir;
2180   char        *keyboard_layout_mapping;
2181   char        *markov_hcstat2;
2182   char        *backend_devices;
2183   char        *opencl_device_types;
2184   char        *outfile;
2185   char        *outfile_check_dir;
2186   char        *potfile_path;
2187   char        *restore_file_path;
2188   char       **rp_files;
2189   char        *rp_gen_func_sel;
2190   char        *separator;
2191   char        *truecrypt_keyfiles;
2192   char        *veracrypt_keyfiles;
2193   const char  *custom_charset_1;
2194   const char  *custom_charset_2;
2195   const char  *custom_charset_3;
2196   const char  *encoding_from;
2197   const char  *encoding_to;
2198   const char  *rule_buf_l;
2199   const char  *rule_buf_r;
2200   const char  *session;
2201   u32          attack_mode;
2202   u32          bitmap_max;
2203   u32          bitmap_min;
2204   #ifdef WITH_BRAIN
2205   u32          brain_server_timer;
2206   u32          brain_client_features;
2207   u32          brain_port;
2208   u32          brain_session;
2209   u32          brain_attack;
2210   #endif
2211   u32          debug_mode;
2212   u32          hwmon_temp_abort;
2213   int          hash_mode;
2214   u32          hccapx_message_pair;
2215   u32          hook_threads;
2216   u32          increment_max;
2217   u32          increment_min;
2218   u32          kernel_accel;
2219   u32          kernel_loops;
2220   u32          kernel_threads;
2221   u32          markov_threshold;
2222   u32          nonce_error_corrections;
2223   u32          spin_damp;
2224   u32          backend_vector_width;
2225   u32          outfile_check_timer;
2226   u32          outfile_format;
2227   u32          remove_timer;
2228   u32          restore_timer;
2229   u32          rp_files_cnt;
2230   u32          rp_gen;
2231   u32          rp_gen_func_max;
2232   u32          rp_gen_func_min;
2233   u32          rp_gen_seed;
2234   u32          runtime;
2235   u32          scrypt_tmto;
2236   u32          segment_size;
2237   u32          status_timer;
2238   u32          stdin_timeout_abort;
2239   u32          veracrypt_pim_start;
2240   u32          veracrypt_pim_stop;
2241   u32          workload_profile;
2242   u64          limit;
2243   u64          skip;
2244 
2245 } user_options_t;
2246 
2247 typedef struct user_options_extra
2248 {
2249   u32 attack_kern;
2250 
2251   u32 rule_len_r;
2252   u32 rule_len_l;
2253 
2254   u32 wordlist_mode;
2255 
2256   char   separator;
2257 
2258   char  *hc_hash;   // can be filename or string
2259 
2260   int    hc_workc;  // can be 0 in bf-mode = default mask
2261   char **hc_workv;
2262 
2263 } user_options_extra_t;
2264 
2265 typedef struct brain_ctx
2266 {
2267   bool support;     // general brain support compiled in (server or client)
2268   bool enabled;     // brain support required by user request on command line
2269 
2270 } brain_ctx_t;
2271 
2272 typedef struct bitmap_ctx
2273 {
2274   bool enabled;
2275 
2276   u32   bitmap_bits;
2277   u32   bitmap_nums;
2278   u32   bitmap_size;
2279   u32   bitmap_mask;
2280   u32   bitmap_shift1;
2281   u32   bitmap_shift2;
2282 
2283   u32  *bitmap_s1_a;
2284   u32  *bitmap_s1_b;
2285   u32  *bitmap_s1_c;
2286   u32  *bitmap_s1_d;
2287   u32  *bitmap_s2_a;
2288   u32  *bitmap_s2_b;
2289   u32  *bitmap_s2_c;
2290   u32  *bitmap_s2_d;
2291 
2292 } bitmap_ctx_t;
2293 
2294 typedef struct folder_config
2295 {
2296   char *cwd;
2297   char *install_dir;
2298   char *profile_dir;
2299   char *cache_dir;
2300   char *session_dir;
2301   char *shared_dir;
2302   char *cpath_real;
2303 
2304 } folder_config_t;
2305 
2306 typedef struct induct_ctx
2307 {
2308   bool enabled;
2309 
2310   char *root_directory;
2311 
2312   char **induction_dictionaries;
2313   int    induction_dictionaries_cnt;
2314   int    induction_dictionaries_pos;
2315 
2316 } induct_ctx_t;
2317 
2318 typedef struct outcheck_ctx
2319 {
2320   bool enabled;
2321 
2322   char *root_directory;
2323 
2324 } outcheck_ctx_t;
2325 
2326 typedef struct straight_ctx
2327 {
2328   bool enabled;
2329 
2330   u32             kernel_rules_cnt;
2331   kernel_rule_t  *kernel_rules_buf;
2332 
2333   char **dicts;
2334   u32    dicts_pos;
2335   u32    dicts_cnt;
2336   u32    dicts_avail;
2337 
2338   char *dict;
2339 
2340 } straight_ctx_t;
2341 
2342 typedef struct combinator_ctx
2343 {
2344   bool enabled;
2345 
2346   char *dict1;
2347   char *dict2;
2348 
2349   u32 combs_mode;
2350   u64 combs_cnt;
2351 
2352 } combinator_ctx_t;
2353 
2354 typedef struct mask_ctx
2355 {
2356   bool   enabled;
2357 
2358   cs_t  *mp_sys;
2359   cs_t  *mp_usr;
2360 
2361   u64    bfs_cnt;
2362 
2363   cs_t  *css_buf;
2364   u32    css_cnt;
2365 
2366   hcstat_table_t *root_table_buf;
2367   hcstat_table_t *markov_table_buf;
2368 
2369   cs_t  *root_css_buf;
2370   cs_t  *markov_css_buf;
2371 
2372   bool   mask_from_file;
2373 
2374   char **masks;
2375   u32    masks_pos;
2376   u32    masks_cnt;
2377   u32    masks_avail;
2378 
2379   char  *mask;
2380 
2381   mf_t  *mfs;
2382 
2383 } mask_ctx_t;
2384 
2385 typedef struct cpt_ctx
2386 {
2387   bool enabled;
2388 
2389   cpt_t     *cpt_buf;
2390   int        cpt_pos;
2391   time_t     cpt_start;
2392   u64        cpt_total;
2393 
2394 } cpt_ctx_t;
2395 
2396 typedef struct device_info
2397 {
2398   bool    skipped_dev;
2399   bool    skipped_warning_dev;
2400   double  hashes_msec_dev;
2401   double  hashes_msec_dev_benchmark;
2402   double  exec_msec_dev;
2403   char   *speed_sec_dev;
2404   char   *guess_candidates_dev;
2405   #if defined(__APPLE__)
2406   char   *hwmon_fan_dev;
2407   #endif
2408   char   *hwmon_dev;
2409   int     corespeed_dev;
2410   int     memoryspeed_dev;
2411   double  runtime_msec_dev;
2412   u64     progress_dev;
2413   int     kernel_accel_dev;
2414   int     kernel_loops_dev;
2415   int     kernel_threads_dev;
2416   int     vector_width_dev;
2417   int     salt_pos_dev;
2418   int     innerloop_pos_dev;
2419   int     innerloop_left_dev;
2420   int     iteration_pos_dev;
2421   int     iteration_left_dev;
2422   #ifdef WITH_BRAIN
2423   int     brain_link_client_id_dev;
2424   int     brain_link_status_dev;
2425   char   *brain_link_recv_bytes_dev;
2426   char   *brain_link_send_bytes_dev;
2427   char   *brain_link_recv_bytes_sec_dev;
2428   char   *brain_link_send_bytes_sec_dev;
2429   double  brain_link_time_recv_dev;
2430   double  brain_link_time_send_dev;
2431   #endif
2432 
2433 } device_info_t;
2434 
2435 typedef struct hashcat_status
2436 {
2437   char       *hash_target;
2438   char       *hash_name;
2439   int         guess_mode;
2440   char       *guess_base;
2441   int         guess_base_offset;
2442   int         guess_base_count;
2443   double      guess_base_percent;
2444   char       *guess_mod;
2445   int         guess_mod_offset;
2446   int         guess_mod_count;
2447   double      guess_mod_percent;
2448   char       *guess_charset;
2449   int         guess_mask_length;
2450   char       *session;
2451   #ifdef WITH_BRAIN
2452   int         brain_session;
2453   int         brain_attack;
2454   char       *brain_rx_all;
2455   char       *brain_tx_all;
2456   #endif
2457   const char *status_string;
2458   int         status_number;
2459   char       *time_estimated_absolute;
2460   char       *time_estimated_relative;
2461   char       *time_started_absolute;
2462   char       *time_started_relative;
2463   double      msec_paused;
2464   double      msec_running;
2465   double      msec_real;
2466   int         digests_cnt;
2467   int         digests_done;
2468   double      digests_percent;
2469   int         salts_cnt;
2470   int         salts_done;
2471   double      salts_percent;
2472   int         progress_mode;
2473   double      progress_finished_percent;
2474   u64         progress_cur;
2475   u64         progress_cur_relative_skip;
2476   u64         progress_done;
2477   u64         progress_end;
2478   u64         progress_end_relative_skip;
2479   u64         progress_ignore;
2480   u64         progress_rejected;
2481   double      progress_rejected_percent;
2482   u64         progress_restored;
2483   u64         progress_skip;
2484   u64         restore_point;
2485   u64         restore_total;
2486   double      restore_percent;
2487   int         cpt_cur_min;
2488   int         cpt_cur_hour;
2489   int         cpt_cur_day;
2490   double      cpt_avg_min;
2491   double      cpt_avg_hour;
2492   double      cpt_avg_day;
2493   char       *cpt;
2494 
2495   device_info_t device_info_buf[DEVICES_MAX];
2496   int           device_info_cnt;
2497   int           device_info_active;
2498 
2499   double  hashes_msec_all;
2500   double  exec_msec_all;
2501   char   *speed_sec_all;
2502 
2503 } hashcat_status_t;
2504 
2505 typedef struct status_ctx
2506 {
2507   /**
2508    * main status
2509    */
2510 
2511   bool accessible;
2512 
2513   u32  devices_status;
2514 
2515   /**
2516    * full (final) status snapshot
2517    */
2518 
2519   hashcat_status_t *hashcat_status_final;
2520 
2521   /**
2522    * thread control
2523    */
2524 
2525   bool run_main_level1;
2526   bool run_main_level2;
2527   bool run_main_level3;
2528   bool run_thread_level1;
2529   bool run_thread_level2;
2530 
2531   bool shutdown_inner;
2532   bool shutdown_outer;
2533 
2534   bool checkpoint_shutdown;
2535   bool finish_shutdown;
2536 
2537   hc_thread_mutex_t mux_dispatcher;
2538   hc_thread_mutex_t mux_counter;
2539   hc_thread_mutex_t mux_hwmon;
2540   hc_thread_mutex_t mux_display;
2541 
2542   /**
2543    * workload
2544    */
2545 
2546   u64  words_off;               // used by dispatcher; get_work () as offset; attention: needs to be redone on in restore case!
2547   u64  words_cur;               // used by dispatcher; the different to words_cur_next is that this counter guarantees that the work from zero to this counter has been actually computed
2548                                 // has been finished actually, can be used for restore point therefore
2549   u64  words_base;              // the unamplified max keyspace
2550   u64  words_cnt;               // the amplified max keyspace
2551 
2552   /**
2553    * progress
2554    */
2555 
2556   u64 *words_progress_done;     // progress number of words done     per salt
2557   u64 *words_progress_rejected; // progress number of words rejected per salt
2558   u64 *words_progress_restored; // progress number of words restored per salt
2559 
2560   /**
2561    * timer
2562    */
2563 
2564   time_t runtime_start;
2565   time_t runtime_stop;
2566 
2567   hc_timer_t timer_running;     // timer on current dict
2568   hc_timer_t timer_paused;      // timer on current dict
2569 
2570   double  msec_paused;          // timer on current dict
2571 
2572   /**
2573    * read timeouts
2574    */
2575 
2576   u32  stdin_read_timeout_cnt;
2577 
2578 } status_ctx_t;
2579 
2580 typedef struct hashcat_user
2581 {
2582   // use this for context specific data
2583   // see main.c as how this example is used
2584 
2585   int          outer_threads_cnt;
2586   hc_thread_t *outer_threads;
2587 
2588 } hashcat_user_t;
2589 
2590 typedef struct cache_hit
2591 {
2592   const char *dictfile;
2593 
2594   struct stat stat;
2595 
2596   u64 cached_cnt;
2597   u64 keyspace;
2598 
2599 } cache_hit_t;
2600 
2601 typedef struct cache_generate
2602 {
2603   const char *dictfile;
2604 
2605   double percent;
2606 
2607   u64 comp;
2608   u64 cnt;
2609   u64 cnt2;
2610 
2611   time_t runtime;
2612 
2613 } cache_generate_t;
2614 
2615 typedef struct hashlist_parse
2616 {
2617   u64 hashes_cnt;
2618   u64 hashes_avail;
2619 
2620 } hashlist_parse_t;
2621 
2622 #define MAX_OLD_EVENTS 10
2623 
2624 typedef struct event_ctx
2625 {
2626   char   old_buf[MAX_OLD_EVENTS][HCBUFSIZ_SMALL];
2627   size_t old_len[MAX_OLD_EVENTS];
2628   int    old_cnt;
2629 
2630   char   msg_buf[HCBUFSIZ_SMALL];
2631   size_t msg_len;
2632   bool   msg_newline;
2633 
2634   size_t prev_len;
2635 
2636   hc_thread_mutex_t mux_event;
2637 
2638 } event_ctx_t;
2639 
2640 #define MODULE_DEFAULT (void *) -1
2641 
2642 typedef void (*MODULE_INIT) (void *);
2643 
2644 typedef struct module_ctx
2645 {
2646   size_t      module_context_size;
2647   int         module_interface_version;
2648 
2649   hc_dynlib_t module_handle;
2650 
2651   MODULE_INIT module_init;
2652 
2653   void      **hook_extra_params; // free for module to use (for instance: library handles)
2654 
2655   u32         (*module_attack_exec)             (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2656   void       *(*module_benchmark_esalt)         (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2657   void       *(*module_benchmark_hook_salt)     (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2658   const char *(*module_benchmark_mask)          (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2659   salt_t     *(*module_benchmark_salt)          (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2660   const char *(*module_deprecated_notice)       (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2661   u32         (*module_dgst_pos0)               (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2662   u32         (*module_dgst_pos1)               (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2663   u32         (*module_dgst_pos2)               (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2664   u32         (*module_dgst_pos3)               (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2665   u32         (*module_dgst_size)               (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2666   bool        (*module_dictstat_disable)        (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2667   u64         (*module_esalt_size)              (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2668   const char *(*module_extra_tuningdb_block)    (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2669   u32         (*module_forced_outfile_format)   (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2670   u32         (*module_hash_category)           (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2671   const char *(*module_hash_name)               (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2672   int         (*module_hash_mode)               (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2673   u32         (*module_hashes_count_min)        (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2674   u32         (*module_hashes_count_max)        (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2675   bool        (*module_hlfmt_disable)           (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2676   u64         (*module_hook_salt_size)          (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2677   u64         (*module_hook_size)               (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2678   u32         (*module_kernel_accel_min)        (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2679   u32         (*module_kernel_accel_max)        (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2680   u32         (*module_kernel_loops_min)        (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2681   u32         (*module_kernel_loops_max)        (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2682   u32         (*module_kernel_threads_min)      (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2683   u32         (*module_kernel_threads_max)      (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2684   u64         (*module_kern_type)               (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2685   u32         (*module_opti_type)               (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2686   u64         (*module_opts_type)               (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2687   bool        (*module_outfile_check_disable)   (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2688   bool        (*module_outfile_check_nocomp)    (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2689   bool        (*module_potfile_disable)         (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2690   bool        (*module_potfile_keep_all_hashes) (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2691   u32         (*module_pwdump_column)           (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2692   u32         (*module_pw_min)                  (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2693   u32         (*module_pw_max)                  (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2694   u32         (*module_salt_min)                (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2695   u32         (*module_salt_max)                (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2696   u32         (*module_salt_type)               (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2697   char        (*module_separator)               (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2698   const char *(*module_st_hash)                 (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2699   const char *(*module_st_pass)                 (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2700   u64         (*module_tmp_size)                (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2701   bool        (*module_warmup_disable)          (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2702 
2703   int         (*module_hash_binary_count)       (const hashes_t *);
2704   int         (*module_hash_binary_parse)       (const hashconfig_t *, const user_options_t *, const user_options_extra_t *, hashes_t *);
2705   int         (*module_hash_binary_save)        (const hashes_t *, const u32, const u32, char **);
2706 
2707   int         (*module_hash_decode_potfile)     (const hashconfig_t *,       void *,       salt_t *,       void *,       void *,       hashinfo_t *, const char *, const int, void *);
2708   int         (*module_hash_decode_zero_hash)   (const hashconfig_t *,       void *,       salt_t *,       void *,       void *,       hashinfo_t *);
2709   int         (*module_hash_decode)             (const hashconfig_t *,       void *,       salt_t *,       void *,       void *,       hashinfo_t *, const char *, const int);
2710   int         (*module_hash_encode_potfile)     (const hashconfig_t *, const void *, const salt_t *, const void *, const void *, const hashinfo_t *,       char *,       int, const void *);
2711   int         (*module_hash_encode_status)      (const hashconfig_t *, const void *, const salt_t *, const void *, const void *, const hashinfo_t *,       char *,       int);
2712   int         (*module_hash_encode)             (const hashconfig_t *, const void *, const salt_t *, const void *, const void *, const hashinfo_t *,       char *,       int);
2713 
2714   u64         (*module_kern_type_dynamic)       (const hashconfig_t *, const void *, const salt_t *, const void *, const void *, const hashinfo_t *);
2715   u64         (*module_extra_buffer_size)       (const hashconfig_t *, const user_options_t *, const user_options_extra_t *, const hashes_t *, const hc_device_param_t *);
2716   u64         (*module_extra_tmp_size)          (const hashconfig_t *, const user_options_t *, const user_options_extra_t *, const hashes_t *);
2717   char       *(*module_jit_build_options)       (const hashconfig_t *, const user_options_t *, const user_options_extra_t *, const hashes_t *, const hc_device_param_t *);
2718   bool        (*module_jit_cache_disable)       (const hashconfig_t *, const user_options_t *, const user_options_extra_t *, const hashes_t *, const hc_device_param_t *);
2719   u32         (*module_deep_comp_kernel)        (const hashes_t *, const u32, const u32);
2720   int         (*module_hash_init_selftest)      (const hashconfig_t *, hash_t *);
2721 
2722   u64         (*module_hook_extra_param_size)   (const hashconfig_t *, const user_options_t *, const user_options_extra_t *);
2723   bool        (*module_hook_extra_param_init)   (const hashconfig_t *, const user_options_t *, const user_options_extra_t *, const folder_config_t *, const backend_ctx_t *, void *);
2724   bool        (*module_hook_extra_param_term)   (const hashconfig_t *, const user_options_t *, const user_options_extra_t *, const folder_config_t *, const backend_ctx_t *, void *);
2725 
2726   void        (*module_hook12)                  (hc_device_param_t *, const void *, const void *, const u32, const u64);
2727   void        (*module_hook23)                  (hc_device_param_t *, const void *, const void *, const u32, const u64);
2728 
2729   int         (*module_build_plain_postprocess) (const hashconfig_t *, const hashes_t *, const void *, const u32 *, const size_t, const int, u32 *, const size_t);
2730 
2731   bool        (*module_unstable_warning)        (const hashconfig_t *, const user_options_t *, const user_options_extra_t *, const hc_device_param_t *);
2732 
2733   bool        (*module_potfile_custom_check)    (const hashconfig_t *, const hash_t *, const hash_t *, const void *);
2734 
2735 } module_ctx_t;
2736 
2737 typedef struct hashcat_ctx
2738 {
2739   brain_ctx_t           *brain_ctx;
2740   bitmap_ctx_t          *bitmap_ctx;
2741   combinator_ctx_t      *combinator_ctx;
2742   cpt_ctx_t             *cpt_ctx;
2743   debugfile_ctx_t       *debugfile_ctx;
2744   dictstat_ctx_t        *dictstat_ctx;
2745   event_ctx_t           *event_ctx;
2746   folder_config_t       *folder_config;
2747   hashcat_user_t        *hashcat_user;
2748   hashconfig_t          *hashconfig;
2749   hashes_t              *hashes;
2750   hwmon_ctx_t           *hwmon_ctx;
2751   induct_ctx_t          *induct_ctx;
2752   logfile_ctx_t         *logfile_ctx;
2753   loopback_ctx_t        *loopback_ctx;
2754   mask_ctx_t            *mask_ctx;
2755   module_ctx_t          *module_ctx;
2756   backend_ctx_t         *backend_ctx;
2757   outcheck_ctx_t        *outcheck_ctx;
2758   outfile_ctx_t         *outfile_ctx;
2759   pidfile_ctx_t         *pidfile_ctx;
2760   potfile_ctx_t         *potfile_ctx;
2761   restore_ctx_t         *restore_ctx;
2762   status_ctx_t          *status_ctx;
2763   straight_ctx_t        *straight_ctx;
2764   tuning_db_t           *tuning_db;
2765   user_options_extra_t  *user_options_extra;
2766   user_options_t        *user_options;
2767   wl_data_t             *wl_data;
2768 
2769   void (*event) (const u32, struct hashcat_ctx *, const void *, const size_t);
2770 
2771 } hashcat_ctx_t;
2772 
2773 typedef struct thread_param
2774 {
2775   u32 tid;
2776 
2777   hashcat_ctx_t *hashcat_ctx;
2778 
2779 } thread_param_t;
2780 
2781 typedef struct hook_thread_param
2782 {
2783   int tid;
2784   int tsz;
2785 
2786   module_ctx_t *module_ctx;
2787   status_ctx_t *status_ctx;
2788 
2789   hc_device_param_t *device_param;
2790 
2791   void *hook_extra_param;
2792   void *hook_salts_buf;
2793 
2794   u32 salt_pos;
2795   u64 pws_cnt;
2796 
2797 } hook_thread_param_t;
2798 
2799 #define MAX_TOKENS     128
2800 #define MAX_SIGNATURES 16
2801 
2802 typedef struct token
2803 {
2804   int token_cnt;
2805 
2806   int signatures_cnt;
2807   const char *signatures_buf[MAX_SIGNATURES];
2808 
2809   int sep[MAX_TOKENS];
2810 
2811   const u8 *buf[MAX_TOKENS];
2812   int len[MAX_TOKENS];
2813 
2814   int len_min[MAX_TOKENS];
2815   int len_max[MAX_TOKENS];
2816 
2817   int attr[MAX_TOKENS];
2818 
2819   const u8 *opt_buf;
2820   int opt_len;
2821 
2822 } token_t;
2823 
2824 /**
2825  * hash category is relevant in usage.c (--help screen)
2826  */
2827 
2828 typedef enum hash_category
2829 {
2830   HASH_CATEGORY_UNDEFINED               = 0,
2831   HASH_CATEGORY_RAW_HASH                = 1,
2832   HASH_CATEGORY_RAW_HASH_SALTED         = 2,
2833   HASH_CATEGORY_RAW_HASH_AUTHENTICATED  = 3,
2834   HASH_CATEGORY_RAW_CHECKSUM            = 4,
2835   HASH_CATEGORY_RAW_CIPHER_KPA          = 5,
2836   HASH_CATEGORY_GENERIC_KDF             = 6,
2837   HASH_CATEGORY_NETWORK_PROTOCOL        = 7,
2838   HASH_CATEGORY_OS                      = 8,
2839   HASH_CATEGORY_DATABASE_SERVER         = 9,
2840   HASH_CATEGORY_NETWORK_SERVER          = 10,
2841   HASH_CATEGORY_EAS                     = 11,
2842   HASH_CATEGORY_FDE                     = 12,
2843   HASH_CATEGORY_DOCUMENTS               = 13,
2844   HASH_CATEGORY_PASSWORD_MANAGER        = 14,
2845   HASH_CATEGORY_ARCHIVE                 = 15,
2846   HASH_CATEGORY_FORUM_SOFTWARE          = 16,
2847   HASH_CATEGORY_OTP                     = 17,
2848   HASH_CATEGORY_PLAIN                   = 18,
2849   HASH_CATEGORY_FRAMEWORK               = 19,
2850   HASH_CATEGORY_PRIVATE_KEY             = 20,
2851   HASH_CATEGORY_IMS                     = 21,
2852   HASH_CATEGORY_CRYPTOCURRENCY_WALLET   = 22,
2853   HASH_CATEGORY_FBE                     = 23
2854 } hash_category_t;
2855 
2856 // hash specific
2857 
2858 typedef aes_ctx AES_KEY;
2859 
2860 #endif // _TYPES_H
2861