diff --git a/include/filenames.h b/include/filenames.h new file mode 100644 index 000000000..167103da0 --- /dev/null +++ b/include/filenames.h @@ -0,0 +1,18 @@ +/** + * Author......: Jens Steube + * License.....: MIT + */ + +#ifndef _FILENAMES_H +#define _FILENAMES_H + +#include + +void generate_source_kernel_filename (const uint attack_exec, const uint attack_kern, const uint kern_type, char *shared_dir, char *source_file); +void generate_cached_kernel_filename (const uint attack_exec, const uint attack_kern, const uint kern_type, char *profile_dir, const char *device_name_chksum, char *cached_file); +void generate_source_kernel_mp_filename (const uint opti_type, const uint opts_type, char *shared_dir, char *source_file); +void generate_cached_kernel_mp_filename (const uint opti_type, const uint opts_type, char *profile_dir, const char *device_name_chksum, char *cached_file); +void generate_source_kernel_amp_filename (const uint attack_kern, char *shared_dir, char *source_file); +void generate_cached_kernel_amp_filename (const uint attack_kern, char *profile_dir, const char *device_name_chksum, char *cached_file); + +#endif // _FILENAMES_H diff --git a/include/opencl.h b/include/opencl.h index f5925b42e..8857e5986 100644 --- a/include/opencl.h +++ b/include/opencl.h @@ -226,3 +226,4 @@ void writeProgramBin (char *dst, u8 *binary, size_t binary_size); double get_avg_exec_time (hc_device_param_t *device_param, const int last_num_entries); +int gidd_to_pw_t (hc_device_param_t *device_param, const u64 gidd, pw_t *pw); diff --git a/include/stdout.h b/include/stdout.h new file mode 100644 index 000000000..2dc0b1754 --- /dev/null +++ b/include/stdout.h @@ -0,0 +1,36 @@ +/** + * Author......: Jens Steube + * License.....: MIT + */ + +#ifndef _STDOUT_H +#define _STDOUT_H + +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined (_POSIX) +#include +#include +#endif // _POSIX + +#define STDOUT_FLAG 0 + +typedef struct +{ + FILE *fp; + + char buf[BUFSIZ]; + int len; + +} out_t; + +void process_stdout (hc_device_param_t *device_param, const uint pws_cnt); + +#endif // _STDOUT_H diff --git a/src/Makefile b/src/Makefile index 8cfa2eee6..d4aa860a1 100644 --- a/src/Makefile +++ b/src/Makefile @@ -166,7 +166,7 @@ LFLAGS_CROSS_WIN := -lpsapi ## Objects ## -NATIVE_OBJS := obj/filenames.NATIVE.o obj/hlfmt.NATIVE.o obj/status.NATIVE.o obj/restore.NATIVE.o obj/bitmap.NATIVE.o obj/opencl.NATIVE.o obj/affinity.NATIVE.o obj/filehandling.NATIVE.o obj/tuningdb.NATIVE.o obj/locking.NATIVE.o obj/folder.NATIVE.o obj/bitops.NATIVE.o obj/convert.NATIVE.o obj/cpu_aes.NATIVE.o obj/cpu_crc32.NATIVE.o obj/cpu_des.NATIVE.o obj/cpu_md5.NATIVE.o obj/cpu_sha1.NATIVE.o obj/cpu_sha256.NATIVE.o obj/data.NATIVE.o obj/ext_OpenCL.NATIVE.o obj/hwmon.NATIVE.o obj/interface.NATIVE.o obj/logfile.NATIVE.o obj/logging.NATIVE.o obj/memory.NATIVE.o obj/mpsp.NATIVE.o obj/rp_cpu.NATIVE.o obj/rp_kernel_on_cpu.NATIVE.o obj/shared.NATIVE.o obj/terminal.NATIVE.o obj/usage.NATIVE.o +NATIVE_OBJS := obj/stdout.NATIVE.o obj/filenames.NATIVE.o obj/hlfmt.NATIVE.o obj/status.NATIVE.o obj/restore.NATIVE.o obj/bitmap.NATIVE.o obj/opencl.NATIVE.o obj/affinity.NATIVE.o obj/filehandling.NATIVE.o obj/tuningdb.NATIVE.o obj/locking.NATIVE.o obj/folder.NATIVE.o obj/bitops.NATIVE.o obj/convert.NATIVE.o obj/cpu_aes.NATIVE.o obj/cpu_crc32.NATIVE.o obj/cpu_des.NATIVE.o obj/cpu_md5.NATIVE.o obj/cpu_sha1.NATIVE.o obj/cpu_sha256.NATIVE.o obj/data.NATIVE.o obj/ext_OpenCL.NATIVE.o obj/hwmon.NATIVE.o obj/interface.NATIVE.o obj/logfile.NATIVE.o obj/logging.NATIVE.o obj/memory.NATIVE.o obj/mpsp.NATIVE.o obj/rp_cpu.NATIVE.o obj/rp_kernel_on_cpu.NATIVE.o obj/shared.NATIVE.o obj/terminal.NATIVE.o obj/usage.NATIVE.o ifeq ($(UNAME),Linux) NATIVE_OBJS += obj/ext_ADL.NATIVE.o @@ -175,8 +175,8 @@ NATIVE_OBJS += obj/ext_nvml.NATIVE.o NATIVE_OBJS += obj/ext_xnvctrl.NATIVE.o endif -LINUX_32_OBJS := obj/filenames.LINUX.32.o obj/hlfmt.LINUX.32.o obj/status.LINUX.32.o obj/restore.LINUX.32.o obj/bitmap.LINUX.32.o obj/opencl.LINUX.32.o obj/affinity.LINUX.32.o obj/filehandling.LINUX.32.o obj/tuningdb.LINUX.32.o obj/locking.LINUX.32.o obj/folder.LINUX.32.o obj/bitops.LINUX.32.o obj/convert.LINUX.32.o obj/cpu_aes.LINUX.32.o obj/cpu_crc32.LINUX.32.o obj/cpu_des.LINUX.32.o obj/cpu_md5.LINUX.32.o obj/cpu_sha1.LINUX.32.o obj/cpu_sha256.LINUX.32.o obj/data.LINUX.32.o obj/ext_ADL.LINUX.32.o obj/ext_nvapi.LINUX.32.o obj/ext_nvml.LINUX.32.o obj/ext_OpenCL.LINUX.32.o obj/ext_xnvctrl.LINUX.32.o obj/hwmon.LINUX.32.o obj/interface.LINUX.32.o obj/logfile.LINUX.32.o obj/logging.LINUX.32.o obj/memory.LINUX.32.o obj/mpsp.LINUX.32.o obj/rp_cpu.LINUX.32.o obj/rp_kernel_on_cpu.LINUX.32.o obj/shared.LINUX.32.o obj/terminal.LINUX.32.o obj/usage.LINUX.32.o -LINUX_64_OBJS := obj/filenames.LINUX.64.o obj/hlfmt.LINUX.64.o obj/status.LINUX.64.o obj/restore.LINUX.64.o obj/bitmap.LINUX.64.o obj/opencl.LINUX.64.o obj/affinity.LINUX.64.o obj/filehandling.LINUX.64.o obj/tuningdb.LINUX.64.o obj/locking.LINUX.64.o obj/folder.LINUX.64.o obj/bitops.LINUX.64.o obj/convert.LINUX.64.o obj/cpu_aes.LINUX.64.o obj/cpu_crc32.LINUX.64.o obj/cpu_des.LINUX.64.o obj/cpu_md5.LINUX.64.o obj/cpu_sha1.LINUX.64.o obj/cpu_sha256.LINUX.64.o obj/data.LINUX.64.o obj/ext_ADL.LINUX.64.o obj/ext_nvapi.LINUX.64.o obj/ext_nvml.LINUX.64.o obj/ext_OpenCL.LINUX.64.o obj/ext_xnvctrl.LINUX.64.o obj/hwmon.LINUX.64.o obj/interface.LINUX.64.o obj/logfile.LINUX.64.o obj/logging.LINUX.64.o obj/memory.LINUX.64.o obj/mpsp.LINUX.64.o obj/rp_cpu.LINUX.64.o obj/rp_kernel_on_cpu.LINUX.64.o obj/shared.LINUX.64.o obj/terminal.LINUX.64.o obj/usage.LINUX.64.o +LINUX_32_OBJS := obj/stdout.LINUX.32.o obj/filenames.LINUX.32.o obj/hlfmt.LINUX.32.o obj/status.LINUX.32.o obj/restore.LINUX.32.o obj/bitmap.LINUX.32.o obj/opencl.LINUX.32.o obj/affinity.LINUX.32.o obj/filehandling.LINUX.32.o obj/tuningdb.LINUX.32.o obj/locking.LINUX.32.o obj/folder.LINUX.32.o obj/bitops.LINUX.32.o obj/convert.LINUX.32.o obj/cpu_aes.LINUX.32.o obj/cpu_crc32.LINUX.32.o obj/cpu_des.LINUX.32.o obj/cpu_md5.LINUX.32.o obj/cpu_sha1.LINUX.32.o obj/cpu_sha256.LINUX.32.o obj/data.LINUX.32.o obj/ext_ADL.LINUX.32.o obj/ext_nvapi.LINUX.32.o obj/ext_nvml.LINUX.32.o obj/ext_OpenCL.LINUX.32.o obj/ext_xnvctrl.LINUX.32.o obj/hwmon.LINUX.32.o obj/interface.LINUX.32.o obj/logfile.LINUX.32.o obj/logging.LINUX.32.o obj/memory.LINUX.32.o obj/mpsp.LINUX.32.o obj/rp_cpu.LINUX.32.o obj/rp_kernel_on_cpu.LINUX.32.o obj/shared.LINUX.32.o obj/terminal.LINUX.32.o obj/usage.LINUX.32.o +LINUX_64_OBJS := obj/stdout.LINUX.64.o obj/filenames.LINUX.64.o obj/hlfmt.LINUX.64.o obj/status.LINUX.64.o obj/restore.LINUX.64.o obj/bitmap.LINUX.64.o obj/opencl.LINUX.64.o obj/affinity.LINUX.64.o obj/filehandling.LINUX.64.o obj/tuningdb.LINUX.64.o obj/locking.LINUX.64.o obj/folder.LINUX.64.o obj/bitops.LINUX.64.o obj/convert.LINUX.64.o obj/cpu_aes.LINUX.64.o obj/cpu_crc32.LINUX.64.o obj/cpu_des.LINUX.64.o obj/cpu_md5.LINUX.64.o obj/cpu_sha1.LINUX.64.o obj/cpu_sha256.LINUX.64.o obj/data.LINUX.64.o obj/ext_ADL.LINUX.64.o obj/ext_nvapi.LINUX.64.o obj/ext_nvml.LINUX.64.o obj/ext_OpenCL.LINUX.64.o obj/ext_xnvctrl.LINUX.64.o obj/hwmon.LINUX.64.o obj/interface.LINUX.64.o obj/logfile.LINUX.64.o obj/logging.LINUX.64.o obj/memory.LINUX.64.o obj/mpsp.LINUX.64.o obj/rp_cpu.LINUX.64.o obj/rp_kernel_on_cpu.LINUX.64.o obj/shared.LINUX.64.o obj/terminal.LINUX.64.o obj/usage.LINUX.64.o # Windows CRT file globbing: @@ -186,8 +186,8 @@ CRT_GLOB_INCLUDE_FOLDER := $(dir $(lastword $(MAKEFILE_LIST))) include $(CRT_GLOB_INCLUDE_FOLDER)/win_file_globbing.mk -WIN_32_OBJS := obj/filenames.WIN.32.o obj/hlfmt.WIN.32.o obj/status.WIN.32.o obj/restore.WIN.32.o obj/bitmap.WIN.32.o obj/opencl.WIN.32.o obj/affinity.WIN.32.o obj/filehandling.WIN.32.o obj/tuningdb.WIN.32.o obj/locking.WIN.32.o obj/folder.WIN.32.o obj/bitops.WIN.32.o obj/convert.WIN.32.o obj/cpu_aes.WIN.32.o obj/cpu_crc32.WIN.32.o obj/cpu_des.WIN.32.o obj/cpu_md5.WIN.32.o obj/cpu_sha1.WIN.32.o obj/cpu_sha256.WIN.32.o obj/data.WIN.32.o obj/ext_ADL.WIN.32.o obj/ext_nvapi.WIN.32.o obj/ext_nvml.WIN.32.o obj/ext_OpenCL.WIN.32.o obj/ext_xnvctrl.WIN.32.o obj/hwmon.WIN.32.o obj/interface.WIN.32.o obj/logfile.WIN.32.o obj/logging.WIN.32.o obj/memory.WIN.32.o obj/mpsp.WIN.32.o obj/rp_cpu.WIN.32.o obj/rp_kernel_on_cpu.WIN.32.o obj/shared.WIN.32.o obj/terminal.WIN.32.o obj/usage.WIN.32.o $(CRT_GLOB_32) -WIN_64_OBJS := obj/filenames.WIN.64.o obj/hlfmt.WIN.64.o obj/status.WIN.64.o obj/restore.WIN.64.o obj/bitmap.WIN.64.o obj/opencl.WIN.64.o obj/affinity.WIN.64.o obj/filehandling.WIN.64.o obj/tuningdb.WIN.64.o obj/locking.WIN.64.o obj/folder.WIN.64.o obj/bitops.WIN.64.o obj/convert.WIN.64.o obj/cpu_aes.WIN.64.o obj/cpu_crc32.WIN.64.o obj/cpu_des.WIN.64.o obj/cpu_md5.WIN.64.o obj/cpu_sha1.WIN.64.o obj/cpu_sha256.WIN.64.o obj/data.WIN.64.o obj/ext_ADL.WIN.64.o obj/ext_nvapi.WIN.64.o obj/ext_nvml.WIN.64.o obj/ext_OpenCL.WIN.64.o obj/ext_xnvctrl.WIN.64.o obj/hwmon.WIN.64.o obj/interface.WIN.64.o obj/logfile.WIN.64.o obj/logging.WIN.64.o obj/memory.WIN.64.o obj/mpsp.WIN.64.o obj/rp_cpu.WIN.64.o obj/rp_kernel_on_cpu.WIN.64.o obj/shared.WIN.64.o obj/terminal.WIN.64.o obj/usage.WIN.64.o $(CRT_GLOB_64) +WIN_32_OBJS := obj/stdout.WIN.32.o obj/filenames.WIN.32.o obj/hlfmt.WIN.32.o obj/status.WIN.32.o obj/restore.WIN.32.o obj/bitmap.WIN.32.o obj/opencl.WIN.32.o obj/affinity.WIN.32.o obj/filehandling.WIN.32.o obj/tuningdb.WIN.32.o obj/locking.WIN.32.o obj/folder.WIN.32.o obj/bitops.WIN.32.o obj/convert.WIN.32.o obj/cpu_aes.WIN.32.o obj/cpu_crc32.WIN.32.o obj/cpu_des.WIN.32.o obj/cpu_md5.WIN.32.o obj/cpu_sha1.WIN.32.o obj/cpu_sha256.WIN.32.o obj/data.WIN.32.o obj/ext_ADL.WIN.32.o obj/ext_nvapi.WIN.32.o obj/ext_nvml.WIN.32.o obj/ext_OpenCL.WIN.32.o obj/ext_xnvctrl.WIN.32.o obj/hwmon.WIN.32.o obj/interface.WIN.32.o obj/logfile.WIN.32.o obj/logging.WIN.32.o obj/memory.WIN.32.o obj/mpsp.WIN.32.o obj/rp_cpu.WIN.32.o obj/rp_kernel_on_cpu.WIN.32.o obj/shared.WIN.32.o obj/terminal.WIN.32.o obj/usage.WIN.32.o $(CRT_GLOB_32) +WIN_64_OBJS := obj/stdout.WIN.64.o obj/filenames.WIN.64.o obj/hlfmt.WIN.64.o obj/status.WIN.64.o obj/restore.WIN.64.o obj/bitmap.WIN.64.o obj/opencl.WIN.64.o obj/affinity.WIN.64.o obj/filehandling.WIN.64.o obj/tuningdb.WIN.64.o obj/locking.WIN.64.o obj/folder.WIN.64.o obj/bitops.WIN.64.o obj/convert.WIN.64.o obj/cpu_aes.WIN.64.o obj/cpu_crc32.WIN.64.o obj/cpu_des.WIN.64.o obj/cpu_md5.WIN.64.o obj/cpu_sha1.WIN.64.o obj/cpu_sha256.WIN.64.o obj/data.WIN.64.o obj/ext_ADL.WIN.64.o obj/ext_nvapi.WIN.64.o obj/ext_nvml.WIN.64.o obj/ext_OpenCL.WIN.64.o obj/ext_xnvctrl.WIN.64.o obj/hwmon.WIN.64.o obj/interface.WIN.64.o obj/logfile.WIN.64.o obj/logging.WIN.64.o obj/memory.WIN.64.o obj/mpsp.WIN.64.o obj/rp_cpu.WIN.64.o obj/rp_kernel_on_cpu.WIN.64.o obj/shared.WIN.64.o obj/terminal.WIN.64.o obj/usage.WIN.64.o $(CRT_GLOB_64) ## ## Targets: Global diff --git a/src/filenames.c b/src/filenames.c new file mode 100644 index 000000000..0f69f6a1e --- /dev/null +++ b/src/filenames.c @@ -0,0 +1,75 @@ +/** + * Author......: Jens Steube + * License.....: MIT + */ + +#include "common.h" +#include "types_int.h" +#include "types.h" +#include "filenames.h" + +void generate_source_kernel_filename (const uint attack_exec, const uint attack_kern, const uint kern_type, char *shared_dir, char *source_file) +{ + if (attack_exec == ATTACK_EXEC_INSIDE_KERNEL) + { + if (attack_kern == ATTACK_KERN_STRAIGHT) + snprintf (source_file, 255, "%s/OpenCL/m%05d_a0.cl", shared_dir, (int) kern_type); + else if (attack_kern == ATTACK_KERN_COMBI) + snprintf (source_file, 255, "%s/OpenCL/m%05d_a1.cl", shared_dir, (int) kern_type); + else if (attack_kern == ATTACK_KERN_BF) + snprintf (source_file, 255, "%s/OpenCL/m%05d_a3.cl", shared_dir, (int) kern_type); + } + else + snprintf (source_file, 255, "%s/OpenCL/m%05d.cl", shared_dir, (int) kern_type); +} + +void generate_cached_kernel_filename (const uint attack_exec, const uint attack_kern, const uint kern_type, char *profile_dir, const char *device_name_chksum, char *cached_file) +{ + if (attack_exec == ATTACK_EXEC_INSIDE_KERNEL) + { + if (attack_kern == ATTACK_KERN_STRAIGHT) + snprintf (cached_file, 255, "%s/kernels/m%05d_a0.%s.kernel", profile_dir, (int) kern_type, device_name_chksum); + else if (attack_kern == ATTACK_KERN_COMBI) + snprintf (cached_file, 255, "%s/kernels/m%05d_a1.%s.kernel", profile_dir, (int) kern_type, device_name_chksum); + else if (attack_kern == ATTACK_KERN_BF) + snprintf (cached_file, 255, "%s/kernels/m%05d_a3.%s.kernel", profile_dir, (int) kern_type, device_name_chksum); + } + else + { + snprintf (cached_file, 255, "%s/kernels/m%05d.%s.kernel", profile_dir, (int) kern_type, device_name_chksum); + } +} + +void generate_source_kernel_mp_filename (const uint opti_type, const uint opts_type, char *shared_dir, char *source_file) +{ + if ((opti_type & OPTI_TYPE_BRUTE_FORCE) && (opts_type & OPTS_TYPE_PT_GENERATE_BE)) + { + snprintf (source_file, 255, "%s/OpenCL/markov_be.cl", shared_dir); + } + else + { + snprintf (source_file, 255, "%s/OpenCL/markov_le.cl", shared_dir); + } +} + +void generate_cached_kernel_mp_filename (const uint opti_type, const uint opts_type, char *profile_dir, const char *device_name_chksum, char *cached_file) +{ + if ((opti_type & OPTI_TYPE_BRUTE_FORCE) && (opts_type & OPTS_TYPE_PT_GENERATE_BE)) + { + snprintf (cached_file, 255, "%s/kernels/markov_be.%s.kernel", profile_dir, device_name_chksum); + } + else + { + snprintf (cached_file, 255, "%s/kernels/markov_le.%s.kernel", profile_dir, device_name_chksum); + } +} + +void generate_source_kernel_amp_filename (const uint attack_kern, char *shared_dir, char *source_file) +{ + snprintf (source_file, 255, "%s/OpenCL/amp_a%d.cl", shared_dir, attack_kern); +} + +void generate_cached_kernel_amp_filename (const uint attack_kern, char *profile_dir, const char *device_name_chksum, char *cached_file) +{ + snprintf (cached_file, 255, "%s/kernels/amp_a%d.%s.kernel", profile_dir, attack_kern, device_name_chksum); +} diff --git a/src/hashcat.c b/src/hashcat.c index 3a23b274e..8f95c797e 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -67,6 +67,7 @@ #include "status.h" #include "hlfmt.h" #include "filenames.h" +#include "stdout.h" extern hc_global_data_t data; @@ -91,7 +92,6 @@ static double TARGET_MS_PROFILE[4] = { 2, 12, 96, 480 }; #define MARKOV_DISABLE 0 #define MARKOV_CLASSIC 0 #define BENCHMARK 0 -#define STDOUT_FLAG 0 #define MACHINE_READABLE 0 #define LOOPBACK 0 @@ -1437,20 +1437,6 @@ static void clear_prompt () fflush (stdout); } -static int gidd_to_pw_t (hc_device_param_t *device_param, const u64 gidd, pw_t *pw) -{ - cl_int CL_err = hc_clEnqueueReadBuffer (data.ocl, device_param->command_queue, device_param->d_pws_buf, CL_TRUE, gidd * sizeof (pw_t), sizeof (pw_t), pw, 0, NULL, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clEnqueueReadBuffer(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - return 0; -} - static void check_hash (hc_device_param_t *device_param, plain_t *plain) { char *outfile = data.outfile; @@ -1903,236 +1889,6 @@ static int check_cracked (hc_device_param_t *device_param, const uint salt_pos) return 0; } -// stolen from princeprocessor ;) - -typedef struct -{ - FILE *fp; - - char buf[BUFSIZ]; - int len; - -} out_t; - -static void out_flush (out_t *out) -{ - fwrite (out->buf, 1, out->len, out->fp); - - out->len = 0; -} - -static void out_push (out_t *out, const u8 *pw_buf, const int pw_len) -{ - char *ptr = out->buf + out->len; - - memcpy (ptr, pw_buf, pw_len); - - ptr[pw_len] = '\n'; - - out->len += pw_len + 1; - - if (out->len >= BUFSIZ - 100) - { - out_flush (out); - } -} - -static void process_stdout (hc_device_param_t *device_param, const uint pws_cnt) -{ - out_t out; - - out.fp = stdout; - - if (data.outfile != NULL) - { - if ((out.fp = fopen (data.outfile, "ab")) != NULL) - { - lock_file (out.fp); - } - else - { - log_error ("ERROR: %s: %s", data.outfile, strerror (errno)); - - out.fp = stdout; - } - } - - out.len = 0; - - uint plain_buf[16] = { 0 }; - - u8 *plain_ptr = (u8 *) plain_buf; - - uint plain_len = 0; - - const uint il_cnt = device_param->kernel_params_buf32[30]; // ugly, i know - - if (data.attack_mode == ATTACK_MODE_STRAIGHT) - { - pw_t pw; - - for (uint gidvid = 0; gidvid < pws_cnt; gidvid++) - { - gidd_to_pw_t (device_param, gidvid, &pw); - - const uint pos = device_param->innerloop_pos; - - for (uint il_pos = 0; il_pos < il_cnt; il_pos++) - { - for (int i = 0; i < 8; i++) - { - plain_buf[i] = pw.i[i]; - } - - plain_len = pw.pw_len; - - plain_len = apply_rules (data.kernel_rules_buf[pos + il_pos].cmds, &plain_buf[0], &plain_buf[4], plain_len); - - if (plain_len > data.pw_max) plain_len = data.pw_max; - - out_push (&out, plain_ptr, plain_len); - } - } - } - else if (data.attack_mode == ATTACK_MODE_COMBI) - { - pw_t pw; - - for (uint gidvid = 0; gidvid < pws_cnt; gidvid++) - { - gidd_to_pw_t (device_param, gidvid, &pw); - - for (uint il_pos = 0; il_pos < il_cnt; il_pos++) - { - for (int i = 0; i < 8; i++) - { - plain_buf[i] = pw.i[i]; - } - - plain_len = pw.pw_len; - - char *comb_buf = (char *) device_param->combs_buf[il_pos].i; - uint comb_len = device_param->combs_buf[il_pos].pw_len; - - if (data.combs_mode == COMBINATOR_MODE_BASE_LEFT) - { - memcpy (plain_ptr + plain_len, comb_buf, comb_len); - } - else - { - memmove (plain_ptr + comb_len, plain_ptr, plain_len); - - memcpy (plain_ptr, comb_buf, comb_len); - } - - plain_len += comb_len; - - if (data.pw_max != PW_DICTMAX1) - { - if (plain_len > data.pw_max) plain_len = data.pw_max; - } - - out_push (&out, plain_ptr, plain_len); - } - } - } - else if (data.attack_mode == ATTACK_MODE_BF) - { - for (uint gidvid = 0; gidvid < pws_cnt; gidvid++) - { - for (uint il_pos = 0; il_pos < il_cnt; il_pos++) - { - u64 l_off = device_param->kernel_params_mp_l_buf64[3] + gidvid; - u64 r_off = device_param->kernel_params_mp_r_buf64[3] + il_pos; - - uint l_start = device_param->kernel_params_mp_l_buf32[5]; - uint r_start = device_param->kernel_params_mp_r_buf32[5]; - - uint l_stop = device_param->kernel_params_mp_l_buf32[4]; - uint r_stop = device_param->kernel_params_mp_r_buf32[4]; - - sp_exec (l_off, (char *) plain_ptr + l_start, data.root_css_buf, data.markov_css_buf, l_start, l_start + l_stop); - sp_exec (r_off, (char *) plain_ptr + r_start, data.root_css_buf, data.markov_css_buf, r_start, r_start + r_stop); - - plain_len = data.css_cnt; - - out_push (&out, plain_ptr, plain_len); - } - } - } - else if (data.attack_mode == ATTACK_MODE_HYBRID1) - { - pw_t pw; - - for (uint gidvid = 0; gidvid < pws_cnt; gidvid++) - { - gidd_to_pw_t (device_param, gidvid, &pw); - - for (uint il_pos = 0; il_pos < il_cnt; il_pos++) - { - for (int i = 0; i < 8; i++) - { - plain_buf[i] = pw.i[i]; - } - - plain_len = pw.pw_len; - - u64 off = device_param->kernel_params_mp_buf64[3] + il_pos; - - uint start = 0; - uint stop = device_param->kernel_params_mp_buf32[4]; - - sp_exec (off, (char *) plain_ptr + plain_len, data.root_css_buf, data.markov_css_buf, start, start + stop); - - plain_len += start + stop; - - out_push (&out, plain_ptr, plain_len); - } - } - } - else if (data.attack_mode == ATTACK_MODE_HYBRID2) - { - pw_t pw; - - for (uint gidvid = 0; gidvid < pws_cnt; gidvid++) - { - gidd_to_pw_t (device_param, gidvid, &pw); - - for (uint il_pos = 0; il_pos < il_cnt; il_pos++) - { - for (int i = 0; i < 8; i++) - { - plain_buf[i] = pw.i[i]; - } - - plain_len = pw.pw_len; - - u64 off = device_param->kernel_params_mp_buf64[3] + il_pos; - - uint start = 0; - uint stop = device_param->kernel_params_mp_buf32[4]; - - memmove (plain_ptr + stop, plain_ptr, plain_len); - - sp_exec (off, (char *) plain_ptr, data.root_css_buf, data.markov_css_buf, start, start + stop); - - plain_len += start + stop; - - out_push (&out, plain_ptr, plain_len); - } - } - } - - out_flush (&out); - - if (out.fp != stdout) - { - unlock_file (out.fp); - - fclose (out.fp); - } -} - static void save_hash () { char *hashfile = data.hashfile; diff --git a/src/opencl.c b/src/opencl.c index 05b4c1052..4b2e88a4f 100644 --- a/src/opencl.c +++ b/src/opencl.c @@ -12,8 +12,20 @@ #include "logging.h" #include "locking.h" #include "ext_OpenCL.h" +#include "ext_ADL.h" +#include "ext_nvapi.h" +#include "ext_nvml.h" +#include "ext_xnvctrl.h" +#include "rp_cpu.h" #include "timer.h" #include "opencl.h" +#include "shared.h" +#include "hwmon.h" +#include "mpsp.h" +#include "restore.h" +#include "data.h" + +extern hc_global_data_t data; uint setup_opencl_platforms_filter (char *opencl_platforms) { @@ -207,3 +219,17 @@ double get_avg_exec_time (hc_device_param_t *device_param, const int last_num_en return exec_ms_sum / exec_ms_cnt; } + +int gidd_to_pw_t (hc_device_param_t *device_param, const u64 gidd, pw_t *pw) +{ + cl_int CL_err = hc_clEnqueueReadBuffer (data.ocl, device_param->command_queue, device_param->d_pws_buf, CL_TRUE, gidd * sizeof (pw_t), sizeof (pw_t), pw, 0, NULL, NULL); + + if (CL_err != CL_SUCCESS) + { + log_error ("ERROR: clEnqueueReadBuffer(): %s\n", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} diff --git a/src/stdout.c b/src/stdout.c new file mode 100644 index 000000000..b81170369 --- /dev/null +++ b/src/stdout.c @@ -0,0 +1,251 @@ +/** + * Author......: Jens Steube + * License.....: MIT + */ + +#include "common.h" +#include "types_int.h" +#include "types.h" +#include "timer.h" +#include "memory.h" +#include "convert.h" +#include "logging.h" +#include "logfile.h" +#include "ext_OpenCL.h" +#include "ext_ADL.h" +#include "ext_nvapi.h" +#include "ext_nvml.h" +#include "ext_xnvctrl.h" +#include "opencl.h" +#include "thread.h" +#include "locking.h" +#include "rp_cpu.h" +#include "rp_kernel_on_cpu.h" +#include "interface.h" +#include "shared.h" +#include "hwmon.h" +#include "mpsp.h" +#include "restore.h" +#include "data.h" +#include "stdout.h" + +extern hc_global_data_t data; + +static void out_flush (out_t *out) +{ + fwrite (out->buf, 1, out->len, out->fp); + + out->len = 0; +} + +static void out_push (out_t *out, const u8 *pw_buf, const int pw_len) +{ + char *ptr = out->buf + out->len; + + memcpy (ptr, pw_buf, pw_len); + + ptr[pw_len] = '\n'; + + out->len += pw_len + 1; + + if (out->len >= BUFSIZ - 100) + { + out_flush (out); + } +} + +void process_stdout (hc_device_param_t *device_param, const uint pws_cnt) +{ + out_t out; + + out.fp = stdout; + + if (data.outfile != NULL) + { + if ((out.fp = fopen (data.outfile, "ab")) != NULL) + { + lock_file (out.fp); + } + else + { + log_error ("ERROR: %s: %s", data.outfile, strerror (errno)); + + out.fp = stdout; + } + } + + out.len = 0; + + uint plain_buf[16] = { 0 }; + + u8 *plain_ptr = (u8 *) plain_buf; + + uint plain_len = 0; + + const uint il_cnt = device_param->kernel_params_buf32[30]; // ugly, i know + + if (data.attack_mode == ATTACK_MODE_STRAIGHT) + { + pw_t pw; + + for (uint gidvid = 0; gidvid < pws_cnt; gidvid++) + { + gidd_to_pw_t (device_param, gidvid, &pw); + + const uint pos = device_param->innerloop_pos; + + for (uint il_pos = 0; il_pos < il_cnt; il_pos++) + { + for (int i = 0; i < 8; i++) + { + plain_buf[i] = pw.i[i]; + } + + plain_len = pw.pw_len; + + plain_len = apply_rules (data.kernel_rules_buf[pos + il_pos].cmds, &plain_buf[0], &plain_buf[4], plain_len); + + if (plain_len > data.pw_max) plain_len = data.pw_max; + + out_push (&out, plain_ptr, plain_len); + } + } + } + else if (data.attack_mode == ATTACK_MODE_COMBI) + { + pw_t pw; + + for (uint gidvid = 0; gidvid < pws_cnt; gidvid++) + { + gidd_to_pw_t (device_param, gidvid, &pw); + + for (uint il_pos = 0; il_pos < il_cnt; il_pos++) + { + for (int i = 0; i < 8; i++) + { + plain_buf[i] = pw.i[i]; + } + + plain_len = pw.pw_len; + + char *comb_buf = (char *) device_param->combs_buf[il_pos].i; + uint comb_len = device_param->combs_buf[il_pos].pw_len; + + if (data.combs_mode == COMBINATOR_MODE_BASE_LEFT) + { + memcpy (plain_ptr + plain_len, comb_buf, comb_len); + } + else + { + memmove (plain_ptr + comb_len, plain_ptr, plain_len); + + memcpy (plain_ptr, comb_buf, comb_len); + } + + plain_len += comb_len; + + if (data.pw_max != PW_DICTMAX1) + { + if (plain_len > data.pw_max) plain_len = data.pw_max; + } + + out_push (&out, plain_ptr, plain_len); + } + } + } + else if (data.attack_mode == ATTACK_MODE_BF) + { + for (uint gidvid = 0; gidvid < pws_cnt; gidvid++) + { + for (uint il_pos = 0; il_pos < il_cnt; il_pos++) + { + u64 l_off = device_param->kernel_params_mp_l_buf64[3] + gidvid; + u64 r_off = device_param->kernel_params_mp_r_buf64[3] + il_pos; + + uint l_start = device_param->kernel_params_mp_l_buf32[5]; + uint r_start = device_param->kernel_params_mp_r_buf32[5]; + + uint l_stop = device_param->kernel_params_mp_l_buf32[4]; + uint r_stop = device_param->kernel_params_mp_r_buf32[4]; + + sp_exec (l_off, (char *) plain_ptr + l_start, data.root_css_buf, data.markov_css_buf, l_start, l_start + l_stop); + sp_exec (r_off, (char *) plain_ptr + r_start, data.root_css_buf, data.markov_css_buf, r_start, r_start + r_stop); + + plain_len = data.css_cnt; + + out_push (&out, plain_ptr, plain_len); + } + } + } + else if (data.attack_mode == ATTACK_MODE_HYBRID1) + { + pw_t pw; + + for (uint gidvid = 0; gidvid < pws_cnt; gidvid++) + { + gidd_to_pw_t (device_param, gidvid, &pw); + + for (uint il_pos = 0; il_pos < il_cnt; il_pos++) + { + for (int i = 0; i < 8; i++) + { + plain_buf[i] = pw.i[i]; + } + + plain_len = pw.pw_len; + + u64 off = device_param->kernel_params_mp_buf64[3] + il_pos; + + uint start = 0; + uint stop = device_param->kernel_params_mp_buf32[4]; + + sp_exec (off, (char *) plain_ptr + plain_len, data.root_css_buf, data.markov_css_buf, start, start + stop); + + plain_len += start + stop; + + out_push (&out, plain_ptr, plain_len); + } + } + } + else if (data.attack_mode == ATTACK_MODE_HYBRID2) + { + pw_t pw; + + for (uint gidvid = 0; gidvid < pws_cnt; gidvid++) + { + gidd_to_pw_t (device_param, gidvid, &pw); + + for (uint il_pos = 0; il_pos < il_cnt; il_pos++) + { + for (int i = 0; i < 8; i++) + { + plain_buf[i] = pw.i[i]; + } + + plain_len = pw.pw_len; + + u64 off = device_param->kernel_params_mp_buf64[3] + il_pos; + + uint start = 0; + uint stop = device_param->kernel_params_mp_buf32[4]; + + memmove (plain_ptr + stop, plain_ptr, plain_len); + + sp_exec (off, (char *) plain_ptr, data.root_css_buf, data.markov_css_buf, start, start + stop); + + plain_len += start + stop; + + out_push (&out, plain_ptr, plain_len); + } + } + } + + out_flush (&out); + + if (out.fp != stdout) + { + unlock_file (out.fp); + + fclose (out.fp); + } +}