1 /**
2 * Author......: See docs/credits.txt
3 * License.....: MIT
4 */
5
6 #include "common.h"
7 #include "types.h"
8 #include "memory.h"
9 #include "locking.h"
10 #include "thread.h"
11 #include "timer.h"
12 #include "tuningdb.h"
13 #include "rp.h"
14 #include "rp_cpu.h"
15 #include "mpsp.h"
16 #include "convert.h"
17 #include "stdout.h"
18 #include "filehandling.h"
19 #include "wordlist.h"
20 #include "shared.h"
21 #include "hashes.h"
22 #include "emu_inc_hash_md5.h"
23 #include "event.h"
24 #include "dynloader.h"
25 #include "backend.h"
26 #include "terminal.h"
27
28 #if defined (__linux__)
29 static const char *const dri_card0_path = "/dev/dri/card0";
30
31 static const char *const drm_card0_vendor_path = "/sys/class/drm/card0/device/vendor";
32 static const char *const drm_card0_driver_path = "/sys/class/drm/card0/device/driver";
33 #endif
34
35 static const u32 full01 = 0x01010101;
36 static const u32 full06 = 0x06060606;
37 static const u32 full80 = 0x80808080;
38
39 static double TARGET_MSEC_PROFILE[4] = { 2, 12, 96, 480 };
40
41 HC_ALIGN(16)
42 static const u32 bzeros[4] = { 0, 0, 0, 0 };
43
44 /* forward declarations */
45 static void rebuild_pws_compressed_append (hc_device_param_t *device_param, const u64 pws_cnt, const u8 chr);
46
is_same_device(const hc_device_param_t * src,const hc_device_param_t * dst)47 static bool is_same_device (const hc_device_param_t *src, const hc_device_param_t *dst)
48 {
49 // First check by PCI address
50
51 if (src->pcie_domain != dst->pcie_domain) return false; // PCI domain not available on OpenCL
52 if (src->pcie_bus != dst->pcie_bus) return false;
53 if (src->pcie_device != dst->pcie_device) return false;
54 if (src->pcie_function != dst->pcie_function) return false;
55
56 // macOS still can't distinguish the devices by PCIe bus:
57
58 if (src->device_processors != dst->device_processors) return false;
59
60 // CUDA can't have aliases
61
62 if ((src->is_cuda == true) && (dst->is_cuda == true)) return false;
63
64 // HIP can't have aliases
65
66 if ((src->is_hip == true) && (dst->is_hip == true)) return false;
67
68 // But OpenCL can have aliases
69
70 if ((src->is_opencl == true) && (dst->is_opencl == true))
71 {
72 // Intel CPU and embedded GPU would survive up to here!
73
74 if (src->opencl_device_type != dst->opencl_device_type) return false;
75
76 // There should be no aliases on the same opencl platform
77
78 if (src->opencl_platform_id == dst->opencl_platform_id) return false;
79 }
80
81 return true;
82 }
83
backend_ctx_find_alias_devices(hashcat_ctx_t * hashcat_ctx)84 static int backend_ctx_find_alias_devices (hashcat_ctx_t *hashcat_ctx)
85 {
86 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
87
88 // first identify all aliases
89
90 for (int backend_devices_cnt_src = 0; backend_devices_cnt_src < backend_ctx->backend_devices_cnt; backend_devices_cnt_src++)
91 {
92 hc_device_param_t *device_param_src = &backend_ctx->devices_param[backend_devices_cnt_src];
93
94 for (int backend_devices_cnt_dst = backend_devices_cnt_src + 1; backend_devices_cnt_dst < backend_ctx->backend_devices_cnt; backend_devices_cnt_dst++)
95 {
96 hc_device_param_t *device_param_dst = &backend_ctx->devices_param[backend_devices_cnt_dst];
97
98 if (is_same_device (device_param_src, device_param_dst) == false) continue;
99
100 device_param_src->device_id_alias_buf[device_param_src->device_id_alias_cnt] = device_param_dst->device_id;
101 device_param_src->device_id_alias_cnt++;
102
103 device_param_dst->device_id_alias_buf[device_param_dst->device_id_alias_cnt] = device_param_src->device_id;
104 device_param_dst->device_id_alias_cnt++;
105 }
106 }
107
108 // find the alias to skip
109
110 for (int backend_devices_pos = 0; backend_devices_pos < backend_ctx->backend_devices_cnt; backend_devices_pos++)
111 {
112 hc_device_param_t *backend_device = &backend_ctx->devices_param[backend_devices_pos];
113
114 if (backend_device->skipped == true) continue;
115
116 if (backend_device->skipped_warning == true) continue;
117
118 for (int device_id_alias_pos = 0; device_id_alias_pos < backend_device->device_id_alias_cnt; device_id_alias_pos++)
119 {
120 const int alias_pos = backend_device->device_id_alias_buf[device_id_alias_pos];
121
122 hc_device_param_t *alias_device = &backend_ctx->devices_param[alias_pos];
123
124 if (alias_device->skipped == true) continue;
125
126 if (alias_device->skipped_warning == true) continue;
127
128 // this lets CUDA devices survive over OpenCL
129
130 if (alias_device->is_cuda == true) continue;
131
132 // this lets HIP devices survive over OpenCL
133
134 if (alias_device->is_hip == true) continue;
135
136 // this lets native OpenCL runtime survive over generic OpenCL runtime
137
138 if (alias_device->opencl_device_type & CL_DEVICE_TYPE_CPU)
139 {
140 if (alias_device->opencl_platform_vendor_id == alias_device->opencl_device_vendor_id) continue;
141 }
142
143 alias_device->skipped = true;
144
145 backend_ctx->opencl_devices_active--;
146
147 backend_ctx->backend_devices_active--;
148
149 // show a warning for specifically listed devices if they are an alias
150
151 if (backend_ctx->backend_devices_filter != (u64) -1)
152 {
153 if (backend_ctx->backend_devices_filter & (1ULL << alias_device->device_id))
154 {
155 event_log_warning (hashcat_ctx, "The device #%d specifically listed was skipped because it is an alias of device #%d", alias_device->device_id + 1, backend_device->device_id + 1);
156 event_log_warning (hashcat_ctx, NULL);
157 }
158 }
159 }
160 }
161
162 return -1;
163 }
164
is_same_device_type(const hc_device_param_t * src,const hc_device_param_t * dst)165 static bool is_same_device_type (const hc_device_param_t *src, const hc_device_param_t *dst)
166 {
167 if (src->is_cuda != dst->is_cuda) return false;
168 if (src->is_hip != dst->is_hip) return false;
169 if (src->is_opencl != dst->is_opencl) return false;
170
171 if (strcmp (src->device_name, dst->device_name) != 0) return false;
172
173 if (src->is_opencl == true)
174 {
175 if (strcmp (src->opencl_device_vendor, dst->opencl_device_vendor) != 0) return false;
176 if (strcmp (src->opencl_device_version, dst->opencl_device_version) != 0) return false;
177 if (strcmp (src->opencl_driver_version, dst->opencl_driver_version) != 0) return false;
178 }
179
180 if (src->device_processors != dst->device_processors) return false;
181 if (src->device_maxclock_frequency != dst->device_maxclock_frequency) return false;
182 if (src->device_maxworkgroup_size != dst->device_maxworkgroup_size) return false;
183
184 // memory size can be different, depending on which gpu has a monitor connected
185 // if (src->device_maxmem_alloc != dst->device_maxmem_alloc) return false;
186 // if (src->device_global_mem != dst->device_global_mem) return false;
187
188 if (src->sm_major != dst->sm_major) return false;
189 if (src->sm_minor != dst->sm_minor) return false;
190
191 if (src->kernel_exec_timeout != dst->kernel_exec_timeout) return false;
192
193 return true;
194 }
195
ocl_check_dri(MAYBE_UNUSED hashcat_ctx_t * hashcat_ctx)196 static int ocl_check_dri (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx)
197 {
198 #if defined (__linux__)
199
200 // This check makes sense only if we're not root
201
202 const uid_t uid = getuid ();
203
204 if (uid == 0) return 0;
205
206 // No GPU available! That's fine, so we don't need to check if we have access to it.
207
208 if (hc_path_exist (dri_card0_path) == false) return 0;
209
210 // Now we need to check if this an AMD vendor, because this is when the problems start
211
212 FILE *fd_drm = fopen (drm_card0_vendor_path, "rb");
213
214 if (fd_drm == NULL) return 0;
215
216 u32 vendor = 0;
217
218 if (fscanf (fd_drm, "0x%x", &vendor) != 1)
219 {
220 fclose (fd_drm);
221
222 return 0;
223 }
224
225 fclose (fd_drm);
226
227 if (vendor != 4098) return 0;
228
229 // Now the problem is only with AMDGPU-PRO, not with oldschool AMD driver
230
231 char buf[HCBUFSIZ_TINY] = { 0 };
232
233 const ssize_t len = readlink (drm_card0_driver_path, buf, HCBUFSIZ_TINY - 1);
234
235 if (len == -1) return 0;
236
237 buf[len] = 0;
238
239 if (strstr (buf, "amdgpu") == NULL) return 0;
240
241 // Now do the real check
242
243 FILE *fd_dri = fopen (dri_card0_path, "rb");
244
245 if (fd_dri == NULL)
246 {
247 event_log_error (hashcat_ctx, "Cannot access %s: %m.", dri_card0_path);
248
249 event_log_warning (hashcat_ctx, "This causes some drivers to crash when OpenCL is used!");
250 event_log_warning (hashcat_ctx, "Adding your user to the \"video\" group usually fixes this problem:");
251 event_log_warning (hashcat_ctx, "$ sudo usermod -a -G video $LOGNAME");
252 event_log_warning (hashcat_ctx, NULL);
253
254 return -1;
255 }
256
257 fclose (fd_dri);
258
259 #endif // __linux__
260
261 return 0;
262 }
263
setup_backend_devices_filter(hashcat_ctx_t * hashcat_ctx,const char * backend_devices,u64 * out)264 static bool setup_backend_devices_filter (hashcat_ctx_t *hashcat_ctx, const char *backend_devices, u64 *out)
265 {
266 u64 backend_devices_filter = 0;
267
268 if (backend_devices)
269 {
270 char *devices = hcstrdup (backend_devices);
271
272 if (devices == NULL) return false;
273
274 char *saveptr = NULL;
275
276 char *next = strtok_r (devices, ",", &saveptr);
277
278 do
279 {
280 const int backend_device_id = (const int) strtol (next, NULL, 10);
281
282 if ((backend_device_id <= 0) || (backend_device_id >= 64))
283 {
284 event_log_error (hashcat_ctx, "Invalid device_id %d specified.", backend_device_id);
285
286 hcfree (devices);
287
288 return false;
289 }
290
291 backend_devices_filter |= 1ULL << (backend_device_id - 1);
292
293 } while ((next = strtok_r ((char *) NULL, ",", &saveptr)) != NULL);
294
295 hcfree (devices);
296 }
297 else
298 {
299 backend_devices_filter = -1ULL;
300 }
301
302 *out = backend_devices_filter;
303
304 return true;
305 }
306
setup_opencl_device_types_filter(hashcat_ctx_t * hashcat_ctx,const char * opencl_device_types,cl_device_type * out)307 static bool setup_opencl_device_types_filter (hashcat_ctx_t *hashcat_ctx, const char *opencl_device_types, cl_device_type *out)
308 {
309 cl_device_type opencl_device_types_filter = 0;
310
311 if (opencl_device_types)
312 {
313 char *device_types = hcstrdup (opencl_device_types);
314
315 if (device_types == NULL) return false;
316
317 char *saveptr = NULL;
318
319 char *next = strtok_r (device_types, ",", &saveptr);
320
321 do
322 {
323 const int device_type = (const int) strtol (next, NULL, 10);
324
325 if (device_type < 1 || device_type > 3)
326 {
327 event_log_error (hashcat_ctx, "Invalid OpenCL device-type %d specified.", device_type);
328
329 hcfree (device_types);
330
331 return false;
332 }
333
334 opencl_device_types_filter |= 1U << device_type;
335
336 } while ((next = strtok_r (NULL, ",", &saveptr)) != NULL);
337
338 hcfree (device_types);
339 }
340 else
341 {
342 #if defined (__APPLE__)
343
344 // For apple use CPU only, because GPU drivers are not reliable
345 // The user can explicitly enable GPU by setting -D2
346
347 //opencl_device_types_filter = CL_DEVICE_TYPE_ALL & ~CL_DEVICE_TYPE_GPU;
348 opencl_device_types_filter = CL_DEVICE_TYPE_CPU;
349
350 #else
351
352 // Do not use CPU by default, this often reduces GPU performance because
353 // the CPU is too busy to handle GPU synchronization
354 // Do not use FPGA/other by default, this is a rare case and we expect the users to enable this manually.
355 // this is needed since Intel One API started to add FPGA emulated OpenCL device by default and it's just annoying.
356
357 //opencl_device_types_filter = CL_DEVICE_TYPE_ALL & ~CL_DEVICE_TYPE_CPU;
358 opencl_device_types_filter = CL_DEVICE_TYPE_GPU;
359
360 #endif
361 }
362
363 *out = opencl_device_types_filter;
364
365 return true;
366 }
367
368 /*
369 static bool cuda_test_instruction (hashcat_ctx_t *hashcat_ctx, const int sm_major, const int sm_minor, const char *kernel_buf)
370 {
371 nvrtcProgram program;
372
373 if (hc_nvrtcCreateProgram (hashcat_ctx, &program, kernel_buf, "test_instruction", 0, NULL, NULL) == -1) return false;
374
375 char *nvrtc_options[4];
376
377 nvrtc_options[0] = "--restrict";
378 nvrtc_options[1] = "--gpu-architecture";
379
380 hc_asprintf (&nvrtc_options[2], "compute_%d%d", sm_major, sm_minor);
381
382 nvrtc_options[3] = NULL;
383
384 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
385
386 NVRTC_PTR *nvrtc = (NVRTC_PTR *) backend_ctx->nvrtc;
387
388 const nvrtcResult NVRTC_err = nvrtc->nvrtcCompileProgram (program, 3, (const char * const *) nvrtc_options);
389
390 hcfree (nvrtc_options[2]);
391
392 size_t build_log_size = 0;
393
394 hc_nvrtcGetProgramLogSize (hashcat_ctx, program, &build_log_size);
395
396 if (NVRTC_err != NVRTC_SUCCESS)
397 {
398 char *build_log = (char *) hcmalloc (build_log_size + 1);
399
400 if (hc_nvrtcGetProgramLog (hashcat_ctx, program, build_log) == -1) return false;
401
402 puts (build_log);
403
404 hcfree (build_log);
405
406 hc_nvrtcDestroyProgram (hashcat_ctx, &program);
407
408 return false;
409 }
410
411 size_t binary_size;
412
413 if (hc_nvrtcGetPTXSize (hashcat_ctx, program, &binary_size) == -1) return false;
414
415 char *binary = (char *) hcmalloc (binary_size);
416
417 if (hc_nvrtcGetPTX (hashcat_ctx, program, binary) == -1)
418 {
419 hcfree (binary);
420
421 return false;
422 }
423
424 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
425
426 CUmodule cuda_module;
427
428 const CUresult CU_err = cuda->cuModuleLoadDataEx (&cuda_module, binary, 0, NULL, NULL);
429
430 if (CU_err != CUDA_SUCCESS)
431 {
432 hcfree (binary);
433
434 return false;
435 }
436
437 hcfree (binary);
438
439 if (hc_cuModuleUnload (hashcat_ctx, cuda_module) == -1) return false;
440
441 if (hc_nvrtcDestroyProgram (hashcat_ctx, &program) == -1) return false;
442
443 return true;
444 }
445 */
446
opencl_test_instruction(hashcat_ctx_t * hashcat_ctx,cl_context context,cl_device_id device,const char * kernel_buf)447 static bool opencl_test_instruction (hashcat_ctx_t *hashcat_ctx, cl_context context, cl_device_id device, const char *kernel_buf)
448 {
449 cl_program program;
450
451 if (hc_clCreateProgramWithSource (hashcat_ctx, context, 1, &kernel_buf, NULL, &program) == -1) return false;
452
453 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
454
455 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
456
457
458 #ifndef DEBUG
459 const int fd_stderr = fileno (stderr);
460 const int stderr_bak = dup (fd_stderr);
461 #ifdef _WIN
462 const int tmp = open ("NUL", O_WRONLY);
463 #else
464 const int tmp = open ("/dev/null", O_WRONLY);
465 #endif
466 dup2 (tmp, fd_stderr);
467 close (tmp);
468 #endif
469
470 const int CL_rc = ocl->clBuildProgram (program, 1, &device, NULL, NULL, NULL);
471
472 #ifndef DEBUG
473 dup2 (stderr_bak, fd_stderr);
474 close (stderr_bak);
475 #endif
476
477 if (CL_rc != CL_SUCCESS)
478 {
479 #if defined (DEBUG)
480
481 event_log_error (hashcat_ctx, "clBuildProgram(): %s", val2cstr_cl (CL_rc));
482
483 size_t build_log_size = 0;
484
485 hc_clGetProgramBuildInfo (hashcat_ctx, program, device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size);
486
487 char *build_log = (char *) hcmalloc (build_log_size + 1);
488
489 hc_clGetProgramBuildInfo (hashcat_ctx, program, device, CL_PROGRAM_BUILD_LOG, build_log_size, build_log, NULL);
490
491 build_log[build_log_size] = 0;
492
493 puts (build_log);
494
495 hcfree (build_log);
496
497 #endif
498
499 hc_clReleaseProgram (hashcat_ctx, program);
500
501 return false;
502 }
503
504 if (hc_clReleaseProgram (hashcat_ctx, program) == -1) return false;
505
506 return true;
507 }
508
read_kernel_binary(hashcat_ctx_t * hashcat_ctx,const char * kernel_file,size_t * kernel_lengths,char ** kernel_sources)509 static bool read_kernel_binary (hashcat_ctx_t *hashcat_ctx, const char *kernel_file, size_t *kernel_lengths, char **kernel_sources)
510 {
511 HCFILE fp;
512
513 if (hc_fopen (&fp, kernel_file, "rb") == true)
514 {
515 struct stat st;
516
517 if (stat (kernel_file, &st))
518 {
519 hc_fclose (&fp);
520
521 return false;
522 }
523
524 const size_t klen = st.st_size;
525
526 char *buf = (char *) hcmalloc (klen + 1);
527
528 size_t num_read = hc_fread (buf, sizeof (char), klen, &fp);
529
530 hc_fclose (&fp);
531
532 if (num_read != klen)
533 {
534 event_log_error (hashcat_ctx, "%s: %s", kernel_file, strerror (errno));
535
536 hcfree (buf);
537
538 return false;
539 }
540
541 buf[klen] = 0;
542
543 kernel_lengths[0] = klen;
544
545 kernel_sources[0] = buf;
546 }
547 else
548 {
549 event_log_error (hashcat_ctx, "%s: %s", kernel_file, strerror (errno));
550
551 return false;
552 }
553
554 return true;
555 }
556
write_kernel_binary(hashcat_ctx_t * hashcat_ctx,const char * kernel_file,char * binary,size_t binary_size)557 static bool write_kernel_binary (hashcat_ctx_t *hashcat_ctx, const char *kernel_file, char *binary, size_t binary_size)
558 {
559 if (binary_size > 0)
560 {
561 HCFILE fp;
562
563 if (hc_fopen (&fp, kernel_file, "wb") == false)
564 {
565 event_log_error (hashcat_ctx, "%s: %s", kernel_file, strerror (errno));
566
567 return false;
568 }
569
570 if (hc_lockfile (&fp) == -1)
571 {
572 hc_fclose (&fp);
573
574 event_log_error (hashcat_ctx, "%s: %s", kernel_file, strerror (errno));
575
576 return false;
577 }
578
579 hc_fwrite (binary, sizeof (char), binary_size, &fp);
580
581 hc_fflush (&fp);
582
583 if (hc_unlockfile (&fp) == -1)
584 {
585 hc_fclose (&fp);
586
587 event_log_error (hashcat_ctx, "%s: %s", kernel_file, strerror (errno));
588
589 return false;
590 }
591
592 hc_fclose (&fp);
593 }
594
595 return true;
596 }
597
generate_source_kernel_filename(const bool slow_candidates,const u32 attack_exec,const u32 attack_kern,const u32 kern_type,const u32 opti_type,char * shared_dir,char * source_file)598 void generate_source_kernel_filename (const bool slow_candidates, const u32 attack_exec, const u32 attack_kern, const u32 kern_type, const u32 opti_type, char *shared_dir, char *source_file)
599 {
600 if (opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
601 {
602 if (attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
603 {
604 if (slow_candidates == true)
605 {
606 snprintf (source_file, 255, "%s/OpenCL/m%05d_a0-optimized.cl", shared_dir, (int) kern_type);
607 }
608 else
609 {
610 if (attack_kern == ATTACK_KERN_STRAIGHT)
611 snprintf (source_file, 255, "%s/OpenCL/m%05d_a0-optimized.cl", shared_dir, (int) kern_type);
612 else if (attack_kern == ATTACK_KERN_COMBI)
613 snprintf (source_file, 255, "%s/OpenCL/m%05d_a1-optimized.cl", shared_dir, (int) kern_type);
614 else if (attack_kern == ATTACK_KERN_BF)
615 snprintf (source_file, 255, "%s/OpenCL/m%05d_a3-optimized.cl", shared_dir, (int) kern_type);
616 else if (attack_kern == ATTACK_KERN_NONE)
617 snprintf (source_file, 255, "%s/OpenCL/m%05d_a0-optimized.cl", shared_dir, (int) kern_type);
618 }
619 }
620 else
621 {
622 snprintf (source_file, 255, "%s/OpenCL/m%05d-optimized.cl", shared_dir, (int) kern_type);
623 }
624 }
625 else
626 {
627 if (attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
628 {
629 if (slow_candidates == true)
630 {
631 snprintf (source_file, 255, "%s/OpenCL/m%05d_a0-pure.cl", shared_dir, (int) kern_type);
632 }
633 else
634 {
635 if (attack_kern == ATTACK_KERN_STRAIGHT)
636 snprintf (source_file, 255, "%s/OpenCL/m%05d_a0-pure.cl", shared_dir, (int) kern_type);
637 else if (attack_kern == ATTACK_KERN_COMBI)
638 snprintf (source_file, 255, "%s/OpenCL/m%05d_a1-pure.cl", shared_dir, (int) kern_type);
639 else if (attack_kern == ATTACK_KERN_BF)
640 snprintf (source_file, 255, "%s/OpenCL/m%05d_a3-pure.cl", shared_dir, (int) kern_type);
641 else if (attack_kern == ATTACK_KERN_NONE)
642 snprintf (source_file, 255, "%s/OpenCL/m%05d_a0-pure.cl", shared_dir, (int) kern_type);
643 }
644 }
645 else
646 {
647 snprintf (source_file, 255, "%s/OpenCL/m%05d-pure.cl", shared_dir, (int) kern_type);
648 }
649 }
650 }
651
generate_cached_kernel_filename(const bool slow_candidates,const u32 attack_exec,const u32 attack_kern,const u32 kern_type,const u32 opti_type,char * cache_dir,const char * device_name_chksum,char * cached_file)652 void generate_cached_kernel_filename (const bool slow_candidates, const u32 attack_exec, const u32 attack_kern, const u32 kern_type, const u32 opti_type, char *cache_dir, const char *device_name_chksum, char *cached_file)
653 {
654 if (opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
655 {
656 if (attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
657 {
658 if (slow_candidates == true)
659 {
660 snprintf (cached_file, 255, "%s/kernels/m%05d_a0-optimized.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
661 }
662 else
663 {
664 if (attack_kern == ATTACK_KERN_STRAIGHT)
665 snprintf (cached_file, 255, "%s/kernels/m%05d_a0-optimized.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
666 else if (attack_kern == ATTACK_KERN_COMBI)
667 snprintf (cached_file, 255, "%s/kernels/m%05d_a1-optimized.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
668 else if (attack_kern == ATTACK_KERN_BF)
669 snprintf (cached_file, 255, "%s/kernels/m%05d_a3-optimized.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
670 else if (attack_kern == ATTACK_KERN_NONE)
671 snprintf (cached_file, 255, "%s/kernels/m%05d_a0-optimized.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
672 }
673 }
674 else
675 {
676 snprintf (cached_file, 255, "%s/kernels/m%05d-optimized.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
677 }
678 }
679 else
680 {
681 if (attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
682 {
683 if (slow_candidates == true)
684 {
685 snprintf (cached_file, 255, "%s/kernels/m%05d_a0-pure.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
686 }
687 else
688 {
689 if (attack_kern == ATTACK_KERN_STRAIGHT)
690 snprintf (cached_file, 255, "%s/kernels/m%05d_a0-pure.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
691 else if (attack_kern == ATTACK_KERN_COMBI)
692 snprintf (cached_file, 255, "%s/kernels/m%05d_a1-pure.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
693 else if (attack_kern == ATTACK_KERN_BF)
694 snprintf (cached_file, 255, "%s/kernels/m%05d_a3-pure.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
695 else if (attack_kern == ATTACK_KERN_NONE)
696 snprintf (cached_file, 255, "%s/kernels/m%05d_a0-pure.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
697 }
698 }
699 else
700 {
701 snprintf (cached_file, 255, "%s/kernels/m%05d-pure.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
702 }
703 }
704 }
705
generate_source_kernel_shared_filename(char * shared_dir,char * source_file)706 void generate_source_kernel_shared_filename (char *shared_dir, char *source_file)
707 {
708 snprintf (source_file, 255, "%s/OpenCL/shared.cl", shared_dir);
709 }
710
generate_cached_kernel_shared_filename(char * cache_dir,const char * device_name_chksum_amp_mp,char * cached_file)711 void generate_cached_kernel_shared_filename (char *cache_dir, const char *device_name_chksum_amp_mp, char *cached_file)
712 {
713 snprintf (cached_file, 255, "%s/kernels/shared.%s.kernel", cache_dir, device_name_chksum_amp_mp);
714 }
715
generate_source_kernel_mp_filename(const u32 opti_type,const u64 opts_type,char * shared_dir,char * source_file)716 void generate_source_kernel_mp_filename (const u32 opti_type, const u64 opts_type, char *shared_dir, char *source_file)
717 {
718 if ((opti_type & OPTI_TYPE_BRUTE_FORCE) && (opts_type & OPTS_TYPE_PT_GENERATE_BE))
719 {
720 snprintf (source_file, 255, "%s/OpenCL/markov_be.cl", shared_dir);
721 }
722 else
723 {
724 snprintf (source_file, 255, "%s/OpenCL/markov_le.cl", shared_dir);
725 }
726 }
727
generate_cached_kernel_mp_filename(const u32 opti_type,const u64 opts_type,char * cache_dir,const char * device_name_chksum_amp_mp,char * cached_file)728 void generate_cached_kernel_mp_filename (const u32 opti_type, const u64 opts_type, char *cache_dir, const char *device_name_chksum_amp_mp, char *cached_file)
729 {
730 if ((opti_type & OPTI_TYPE_BRUTE_FORCE) && (opts_type & OPTS_TYPE_PT_GENERATE_BE))
731 {
732 snprintf (cached_file, 255, "%s/kernels/markov_be.%s.kernel", cache_dir, device_name_chksum_amp_mp);
733 }
734 else
735 {
736 snprintf (cached_file, 255, "%s/kernels/markov_le.%s.kernel", cache_dir, device_name_chksum_amp_mp);
737 }
738 }
739
generate_source_kernel_amp_filename(const u32 attack_kern,char * shared_dir,char * source_file)740 void generate_source_kernel_amp_filename (const u32 attack_kern, char *shared_dir, char *source_file)
741 {
742 snprintf (source_file, 255, "%s/OpenCL/amp_a%u.cl", shared_dir, attack_kern);
743 }
744
generate_cached_kernel_amp_filename(const u32 attack_kern,char * cache_dir,const char * device_name_chksum_amp_mp,char * cached_file)745 void generate_cached_kernel_amp_filename (const u32 attack_kern, char *cache_dir, const char *device_name_chksum_amp_mp, char *cached_file)
746 {
747 snprintf (cached_file, 255, "%s/kernels/amp_a%u.%s.kernel", cache_dir, attack_kern, device_name_chksum_amp_mp);
748 }
749
750 // NVRTC
751
nvrtc_init(hashcat_ctx_t * hashcat_ctx)752 int nvrtc_init (hashcat_ctx_t *hashcat_ctx)
753 {
754 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
755
756 NVRTC_PTR *nvrtc = (NVRTC_PTR *) backend_ctx->nvrtc;
757
758 memset (nvrtc, 0, sizeof (NVRTC_PTR));
759
760 #if defined (_WIN)
761 nvrtc->lib = hc_dlopen ("nvrtc.dll");
762
763 if (nvrtc->lib == NULL)
764 {
765 // super annoying: nvidia is using the CUDA version in nvrtc???.dll filename!
766 // however, the cuda version string comes from nvcuda.dll which is from nvidia driver, but
767 // the driver version and the installed CUDA toolkit version can be different, so it cannot be used as a reference.
768 // brute force to the rescue
769
770 char dllname[100];
771
772 for (int major = 20; major >= 9; major--) // older than 3.x do not ship _v2 functions anyway
773 // older than 7.x does not support sm 5.x
774 // older than 8.x does not have documentation archive online, no way to check if nvrtc support whatever we need
775 // older than 9.x is just a theoretical limit since we define 9.0 as the minimum required version
776 {
777 for (int minor = 20; minor >= 0; minor--)
778 {
779 snprintf (dllname, sizeof (dllname), "nvrtc64_%d%d.dll", major, minor);
780
781 nvrtc->lib = hc_dlopen (dllname);
782
783 if (nvrtc->lib) break;
784
785 snprintf (dllname, sizeof (dllname), "nvrtc64_%d%d_0.dll", major, minor);
786
787 nvrtc->lib = hc_dlopen (dllname);
788
789 if (nvrtc->lib) break;
790 }
791
792 if (nvrtc->lib) break;
793 }
794 }
795 #elif defined (__APPLE__)
796 nvrtc->lib = hc_dlopen ("nvrtc.dylib");
797 #elif defined (__CYGWIN__)
798 nvrtc->lib = hc_dlopen ("nvrtc.dll");
799 #else
800 nvrtc->lib = hc_dlopen ("libnvrtc.so");
801
802 if (nvrtc->lib == NULL) nvrtc->lib = hc_dlopen ("libnvrtc.so.1");
803 #endif
804
805 if (nvrtc->lib == NULL) return -1;
806
807 HC_LOAD_FUNC (nvrtc, nvrtcAddNameExpression, NVRTC_NVRTCADDNAMEEXPRESSION, NVRTC, 1);
808 HC_LOAD_FUNC (nvrtc, nvrtcCompileProgram, NVRTC_NVRTCCOMPILEPROGRAM, NVRTC, 1);
809 HC_LOAD_FUNC (nvrtc, nvrtcCreateProgram, NVRTC_NVRTCCREATEPROGRAM, NVRTC, 1);
810 HC_LOAD_FUNC (nvrtc, nvrtcDestroyProgram, NVRTC_NVRTCDESTROYPROGRAM, NVRTC, 1);
811 HC_LOAD_FUNC (nvrtc, nvrtcGetLoweredName, NVRTC_NVRTCGETLOWEREDNAME, NVRTC, 1);
812 HC_LOAD_FUNC (nvrtc, nvrtcGetPTX, NVRTC_NVRTCGETPTX, NVRTC, 1);
813 HC_LOAD_FUNC (nvrtc, nvrtcGetPTXSize, NVRTC_NVRTCGETPTXSIZE, NVRTC, 1);
814 HC_LOAD_FUNC (nvrtc, nvrtcGetProgramLog, NVRTC_NVRTCGETPROGRAMLOG, NVRTC, 1);
815 HC_LOAD_FUNC (nvrtc, nvrtcGetProgramLogSize, NVRTC_NVRTCGETPROGRAMLOGSIZE, NVRTC, 1);
816 HC_LOAD_FUNC (nvrtc, nvrtcGetErrorString, NVRTC_NVRTCGETERRORSTRING, NVRTC, 1);
817 HC_LOAD_FUNC (nvrtc, nvrtcVersion, NVRTC_NVRTCVERSION, NVRTC, 1);
818
819 return 0;
820 }
821
nvrtc_close(hashcat_ctx_t * hashcat_ctx)822 void nvrtc_close (hashcat_ctx_t *hashcat_ctx)
823 {
824 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
825
826 NVRTC_PTR *nvrtc = (NVRTC_PTR *) backend_ctx->nvrtc;
827
828 if (nvrtc)
829 {
830 if (nvrtc->lib)
831 {
832 hc_dlclose (nvrtc->lib);
833 }
834
835 hcfree (backend_ctx->nvrtc);
836
837 backend_ctx->nvrtc = NULL;
838 }
839 }
840
hc_nvrtcCreateProgram(hashcat_ctx_t * hashcat_ctx,nvrtcProgram * prog,const char * src,const char * name,int numHeaders,const char * const * headers,const char * const * includeNames)841 int hc_nvrtcCreateProgram (hashcat_ctx_t *hashcat_ctx, nvrtcProgram *prog, const char *src, const char *name, int numHeaders, const char * const *headers, const char * const *includeNames)
842 {
843 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
844
845 NVRTC_PTR *nvrtc = (NVRTC_PTR *) backend_ctx->nvrtc;
846
847 const nvrtcResult NVRTC_err = nvrtc->nvrtcCreateProgram (prog, src, name, numHeaders, headers, includeNames);
848
849 if (NVRTC_err != NVRTC_SUCCESS)
850 {
851 event_log_error (hashcat_ctx, "nvrtcCreateProgram(): %s", nvrtc->nvrtcGetErrorString (NVRTC_err));
852
853 return -1;
854 }
855
856 return 0;
857 }
858
hc_nvrtcDestroyProgram(hashcat_ctx_t * hashcat_ctx,nvrtcProgram * prog)859 int hc_nvrtcDestroyProgram (hashcat_ctx_t *hashcat_ctx, nvrtcProgram *prog)
860 {
861 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
862
863 NVRTC_PTR *nvrtc = (NVRTC_PTR *) backend_ctx->nvrtc;
864
865 const nvrtcResult NVRTC_err = nvrtc->nvrtcDestroyProgram (prog);
866
867 if (NVRTC_err != NVRTC_SUCCESS)
868 {
869 event_log_error (hashcat_ctx, "nvrtcDestroyProgram(): %s", nvrtc->nvrtcGetErrorString (NVRTC_err));
870
871 return -1;
872 }
873
874 return 0;
875 }
876
hc_nvrtcCompileProgram(hashcat_ctx_t * hashcat_ctx,nvrtcProgram prog,int numOptions,const char * const * options)877 int hc_nvrtcCompileProgram (hashcat_ctx_t *hashcat_ctx, nvrtcProgram prog, int numOptions, const char * const *options)
878 {
879 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
880
881 NVRTC_PTR *nvrtc = (NVRTC_PTR *) backend_ctx->nvrtc;
882
883 const nvrtcResult NVRTC_err = nvrtc->nvrtcCompileProgram (prog, numOptions, options);
884
885 if (NVRTC_err != NVRTC_SUCCESS)
886 {
887 event_log_error (hashcat_ctx, "nvrtcCompileProgram(): %s", nvrtc->nvrtcGetErrorString (NVRTC_err));
888
889 return -1;
890 }
891
892 return 0;
893 }
894
hc_nvrtcGetProgramLogSize(hashcat_ctx_t * hashcat_ctx,nvrtcProgram prog,size_t * logSizeRet)895 int hc_nvrtcGetProgramLogSize (hashcat_ctx_t *hashcat_ctx, nvrtcProgram prog, size_t *logSizeRet)
896 {
897 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
898
899 NVRTC_PTR *nvrtc = (NVRTC_PTR *) backend_ctx->nvrtc;
900
901 const nvrtcResult NVRTC_err = nvrtc->nvrtcGetProgramLogSize (prog, logSizeRet);
902
903 if (NVRTC_err != NVRTC_SUCCESS)
904 {
905 event_log_error (hashcat_ctx, "nvrtcGetProgramLogSize(): %s", nvrtc->nvrtcGetErrorString (NVRTC_err));
906
907 return -1;
908 }
909
910 return 0;
911 }
912
hc_nvrtcGetProgramLog(hashcat_ctx_t * hashcat_ctx,nvrtcProgram prog,char * log)913 int hc_nvrtcGetProgramLog (hashcat_ctx_t *hashcat_ctx, nvrtcProgram prog, char *log)
914 {
915 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
916
917 NVRTC_PTR *nvrtc = (NVRTC_PTR *) backend_ctx->nvrtc;
918
919 const nvrtcResult NVRTC_err = nvrtc->nvrtcGetProgramLog (prog, log);
920
921 if (NVRTC_err != NVRTC_SUCCESS)
922 {
923 event_log_error (hashcat_ctx, "nvrtcGetProgramLog(): %s", nvrtc->nvrtcGetErrorString (NVRTC_err));
924
925 return -1;
926 }
927
928 return 0;
929 }
930
hc_nvrtcGetPTXSize(hashcat_ctx_t * hashcat_ctx,nvrtcProgram prog,size_t * ptxSizeRet)931 int hc_nvrtcGetPTXSize (hashcat_ctx_t *hashcat_ctx, nvrtcProgram prog, size_t *ptxSizeRet)
932 {
933 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
934
935 NVRTC_PTR *nvrtc = (NVRTC_PTR *) backend_ctx->nvrtc;
936
937 const nvrtcResult NVRTC_err = nvrtc->nvrtcGetPTXSize (prog, ptxSizeRet);
938
939 if (NVRTC_err != NVRTC_SUCCESS)
940 {
941 event_log_error (hashcat_ctx, "nvrtcGetPTXSize(): %s", nvrtc->nvrtcGetErrorString (NVRTC_err));
942
943 return -1;
944 }
945
946 return 0;
947 }
948
hc_nvrtcGetPTX(hashcat_ctx_t * hashcat_ctx,nvrtcProgram prog,char * ptx)949 int hc_nvrtcGetPTX (hashcat_ctx_t *hashcat_ctx, nvrtcProgram prog, char *ptx)
950 {
951 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
952
953 NVRTC_PTR *nvrtc = (NVRTC_PTR *) backend_ctx->nvrtc;
954
955 const nvrtcResult NVRTC_err = nvrtc->nvrtcGetPTX (prog, ptx);
956
957 if (NVRTC_err != NVRTC_SUCCESS)
958 {
959 event_log_error (hashcat_ctx, "nvrtcGetPTX(): %s", nvrtc->nvrtcGetErrorString (NVRTC_err));
960
961 return -1;
962 }
963
964 return 0;
965 }
966
hc_nvrtcVersion(hashcat_ctx_t * hashcat_ctx,int * major,int * minor)967 int hc_nvrtcVersion (hashcat_ctx_t *hashcat_ctx, int *major, int *minor)
968 {
969 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
970
971 NVRTC_PTR *nvrtc = (NVRTC_PTR *) backend_ctx->nvrtc;
972
973 const nvrtcResult NVRTC_err = nvrtc->nvrtcVersion (major, minor);
974
975 if (NVRTC_err != NVRTC_SUCCESS)
976 {
977 event_log_error (hashcat_ctx, "nvrtcVersion(): %s", nvrtc->nvrtcGetErrorString (NVRTC_err));
978
979 return -1;
980 }
981
982 return 0;
983 }
984
985 // HIPRTC
986
hiprtc_init(hashcat_ctx_t * hashcat_ctx)987 int hiprtc_init (hashcat_ctx_t *hashcat_ctx)
988 {
989 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
990
991 HIPRTC_PTR *hiprtc = (HIPRTC_PTR *) backend_ctx->hiprtc;
992
993 memset (hiprtc, 0, sizeof (HIPRTC_PTR));
994
995 #if defined (_WIN)
996 hiprtc->lib = hc_dlopen ("amdhip64.dll");
997 #elif defined (__APPLE__)
998 hiprtc->lib = hc_dlopen ("fixme.dylib");
999 #elif defined (__CYGWIN__)
1000 hiprtc->lib = hc_dlopen ("amdhip64.dll");
1001 #else
1002 hiprtc->lib = hc_dlopen ("libamdhip64.so");
1003
1004 if (hiprtc->lib == NULL) hiprtc->lib = hc_dlopen ("libamdhip64.so.4");
1005 #endif
1006
1007 if (hiprtc->lib == NULL) return -1;
1008
1009 HC_LOAD_FUNC (hiprtc, hiprtcAddNameExpression, HIPRTC_HIPRTCADDNAMEEXPRESSION, HIPRTC, 1);
1010 HC_LOAD_FUNC (hiprtc, hiprtcCompileProgram, HIPRTC_HIPRTCCOMPILEPROGRAM, HIPRTC, 1);
1011 HC_LOAD_FUNC (hiprtc, hiprtcCreateProgram, HIPRTC_HIPRTCCREATEPROGRAM, HIPRTC, 1);
1012 HC_LOAD_FUNC (hiprtc, hiprtcDestroyProgram, HIPRTC_HIPRTCDESTROYPROGRAM, HIPRTC, 1);
1013 HC_LOAD_FUNC (hiprtc, hiprtcGetLoweredName, HIPRTC_HIPRTCGETLOWEREDNAME, HIPRTC, 1);
1014 HC_LOAD_FUNC (hiprtc, hiprtcGetCode, HIPRTC_HIPRTCGETCODE, HIPRTC, 1);
1015 HC_LOAD_FUNC (hiprtc, hiprtcGetCodeSize, HIPRTC_HIPRTCGETCODESIZE, HIPRTC, 1);
1016 HC_LOAD_FUNC (hiprtc, hiprtcGetProgramLog, HIPRTC_HIPRTCGETPROGRAMLOG, HIPRTC, 1);
1017 HC_LOAD_FUNC (hiprtc, hiprtcGetProgramLogSize, HIPRTC_HIPRTCGETPROGRAMLOGSIZE, HIPRTC, 1);
1018 HC_LOAD_FUNC (hiprtc, hiprtcGetErrorString, HIPRTC_HIPRTCGETERRORSTRING, HIPRTC, 1);
1019
1020 return 0;
1021 }
1022
hiprtc_close(hashcat_ctx_t * hashcat_ctx)1023 void hiprtc_close (hashcat_ctx_t *hashcat_ctx)
1024 {
1025 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1026
1027 HIPRTC_PTR *hiprtc = (HIPRTC_PTR *) backend_ctx->hiprtc;
1028
1029 if (hiprtc)
1030 {
1031 if (hiprtc->lib)
1032 {
1033 hc_dlclose (hiprtc->lib);
1034 }
1035
1036 hcfree (backend_ctx->hiprtc);
1037
1038 backend_ctx->hiprtc = NULL;
1039 }
1040 }
1041
hc_hiprtcCreateProgram(hashcat_ctx_t * hashcat_ctx,hiprtcProgram * prog,const char * src,const char * name,int numHeaders,const char * const * headers,const char * const * includeNames)1042 int hc_hiprtcCreateProgram (hashcat_ctx_t *hashcat_ctx, hiprtcProgram *prog, const char *src, const char *name, int numHeaders, const char * const *headers, const char * const *includeNames)
1043 {
1044 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1045
1046 HIPRTC_PTR *hiprtc = (HIPRTC_PTR *) backend_ctx->hiprtc;
1047
1048 const hiprtcResult HIPRTC_err = hiprtc->hiprtcCreateProgram (prog, src, name, numHeaders, headers, includeNames);
1049
1050 if (HIPRTC_err != HIPRTC_SUCCESS)
1051 {
1052 event_log_error (hashcat_ctx, "hiprtcCreateProgram(): %s", hiprtc->hiprtcGetErrorString (HIPRTC_err));
1053
1054 return -1;
1055 }
1056
1057 return 0;
1058 }
1059
hc_hiprtcDestroyProgram(hashcat_ctx_t * hashcat_ctx,hiprtcProgram * prog)1060 int hc_hiprtcDestroyProgram (hashcat_ctx_t *hashcat_ctx, hiprtcProgram *prog)
1061 {
1062 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1063
1064 HIPRTC_PTR *hiprtc = (HIPRTC_PTR *) backend_ctx->hiprtc;
1065
1066 const hiprtcResult HIPRTC_err = hiprtc->hiprtcDestroyProgram (prog);
1067
1068 if (HIPRTC_err != HIPRTC_SUCCESS)
1069 {
1070 event_log_error (hashcat_ctx, "hiprtcDestroyProgram(): %s", hiprtc->hiprtcGetErrorString (HIPRTC_err));
1071
1072 return -1;
1073 }
1074
1075 return 0;
1076 }
1077
hc_hiprtcCompileProgram(hashcat_ctx_t * hashcat_ctx,hiprtcProgram prog,int numOptions,const char * const * options)1078 int hc_hiprtcCompileProgram (hashcat_ctx_t *hashcat_ctx, hiprtcProgram prog, int numOptions, const char * const *options)
1079 {
1080 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1081
1082 HIPRTC_PTR *hiprtc = (HIPRTC_PTR *) backend_ctx->hiprtc;
1083
1084 const hiprtcResult HIPRTC_err = hiprtc->hiprtcCompileProgram (prog, numOptions, options);
1085
1086 if (HIPRTC_err != HIPRTC_SUCCESS)
1087 {
1088 event_log_error (hashcat_ctx, "hiprtcCompileProgram(): %s", hiprtc->hiprtcGetErrorString (HIPRTC_err));
1089
1090 return -1;
1091 }
1092
1093 return 0;
1094 }
1095
hc_hiprtcGetProgramLogSize(hashcat_ctx_t * hashcat_ctx,hiprtcProgram prog,size_t * logSizeRet)1096 int hc_hiprtcGetProgramLogSize (hashcat_ctx_t *hashcat_ctx, hiprtcProgram prog, size_t *logSizeRet)
1097 {
1098 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1099
1100 HIPRTC_PTR *hiprtc = (HIPRTC_PTR *) backend_ctx->hiprtc;
1101
1102 const hiprtcResult HIPRTC_err = hiprtc->hiprtcGetProgramLogSize (prog, logSizeRet);
1103
1104 if (HIPRTC_err != HIPRTC_SUCCESS)
1105 {
1106 event_log_error (hashcat_ctx, "hiprtcGetProgramLogSize(): %s", hiprtc->hiprtcGetErrorString (HIPRTC_err));
1107
1108 return -1;
1109 }
1110
1111 return 0;
1112 }
1113
hc_hiprtcGetProgramLog(hashcat_ctx_t * hashcat_ctx,hiprtcProgram prog,char * log)1114 int hc_hiprtcGetProgramLog (hashcat_ctx_t *hashcat_ctx, hiprtcProgram prog, char *log)
1115 {
1116 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1117
1118 HIPRTC_PTR *hiprtc = (HIPRTC_PTR *) backend_ctx->hiprtc;
1119
1120 const hiprtcResult HIPRTC_err = hiprtc->hiprtcGetProgramLog (prog, log);
1121
1122 if (HIPRTC_err != HIPRTC_SUCCESS)
1123 {
1124 event_log_error (hashcat_ctx, "hiprtcGetProgramLog(): %s", hiprtc->hiprtcGetErrorString (HIPRTC_err));
1125
1126 return -1;
1127 }
1128
1129 return 0;
1130 }
1131
hc_hiprtcGetCodeSize(hashcat_ctx_t * hashcat_ctx,hiprtcProgram prog,size_t * codeSizeRet)1132 int hc_hiprtcGetCodeSize (hashcat_ctx_t *hashcat_ctx, hiprtcProgram prog, size_t *codeSizeRet)
1133 {
1134 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1135
1136 HIPRTC_PTR *hiprtc = (HIPRTC_PTR *) backend_ctx->hiprtc;
1137
1138 const hiprtcResult HIPRTC_err = hiprtc->hiprtcGetCodeSize (prog, codeSizeRet);
1139
1140 if (HIPRTC_err != HIPRTC_SUCCESS)
1141 {
1142 event_log_error (hashcat_ctx, "hiprtcGetCodeSize(): %s", hiprtc->hiprtcGetErrorString (HIPRTC_err));
1143
1144 return -1;
1145 }
1146
1147 return 0;
1148 }
1149
hc_hiprtcGetCode(hashcat_ctx_t * hashcat_ctx,hiprtcProgram prog,char * code)1150 int hc_hiprtcGetCode (hashcat_ctx_t *hashcat_ctx, hiprtcProgram prog, char *code)
1151 {
1152 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1153
1154 HIPRTC_PTR *hiprtc = (HIPRTC_PTR *) backend_ctx->hiprtc;
1155
1156 const hiprtcResult HIPRTC_err = hiprtc->hiprtcGetCode (prog, code);
1157
1158 if (HIPRTC_err != HIPRTC_SUCCESS)
1159 {
1160 event_log_error (hashcat_ctx, "hiprtcGetCode(): %s", hiprtc->hiprtcGetErrorString (HIPRTC_err));
1161
1162 return -1;
1163 }
1164
1165 return 0;
1166 }
1167
1168 // CUDA
1169
cuda_init(hashcat_ctx_t * hashcat_ctx)1170 int cuda_init (hashcat_ctx_t *hashcat_ctx)
1171 {
1172 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1173
1174 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
1175
1176 memset (cuda, 0, sizeof (CUDA_PTR));
1177
1178 #if defined (_WIN)
1179 cuda->lib = hc_dlopen ("nvcuda.dll");
1180 #elif defined (__APPLE__)
1181 cuda->lib = hc_dlopen ("nvcuda.dylib");
1182 #elif defined (__CYGWIN__)
1183 cuda->lib = hc_dlopen ("nvcuda.dll");
1184 #else
1185 cuda->lib = hc_dlopen ("libcuda.so");
1186
1187 if (cuda->lib == NULL) cuda->lib = hc_dlopen ("libcuda.so.1");
1188 #endif
1189
1190 if (cuda->lib == NULL) return -1;
1191
1192 #define HC_LOAD_FUNC_CUDA(ptr,name,cudaname,type,libname,noerr) \
1193 do { \
1194 ptr->name = (type) hc_dlsym ((ptr)->lib, #cudaname); \
1195 if ((noerr) != -1) { \
1196 if (!(ptr)->name) { \
1197 if ((noerr) == 1) { \
1198 event_log_error (hashcat_ctx, "%s is missing from %s shared library.", #name, #libname); \
1199 return -1; \
1200 } \
1201 if ((noerr) != 1) { \
1202 event_log_warning (hashcat_ctx, "%s is missing from %s shared library.", #name, #libname); \
1203 return 0; \
1204 } \
1205 } \
1206 } \
1207 } while (0)
1208
1209 // finding the right symbol is a PITA, because of the _v2 suffix
1210 // a good reference is cuda.h itself
1211 // this needs to be verified for each new cuda release
1212
1213 HC_LOAD_FUNC_CUDA (cuda, cuCtxCreate, cuCtxCreate_v2, CUDA_CUCTXCREATE, CUDA, 1);
1214 HC_LOAD_FUNC_CUDA (cuda, cuCtxDestroy, cuCtxDestroy_v2, CUDA_CUCTXDESTROY, CUDA, 1);
1215 HC_LOAD_FUNC_CUDA (cuda, cuCtxGetCacheConfig, cuCtxGetCacheConfig, CUDA_CUCTXGETCACHECONFIG, CUDA, 1);
1216 HC_LOAD_FUNC_CUDA (cuda, cuCtxGetCurrent, cuCtxGetCurrent, CUDA_CUCTXGETCURRENT, CUDA, 1);
1217 HC_LOAD_FUNC_CUDA (cuda, cuCtxGetSharedMemConfig, cuCtxGetSharedMemConfig, CUDA_CUCTXGETSHAREDMEMCONFIG, CUDA, 1);
1218 HC_LOAD_FUNC_CUDA (cuda, cuCtxPopCurrent, cuCtxPopCurrent_v2, CUDA_CUCTXPOPCURRENT, CUDA, 1);
1219 HC_LOAD_FUNC_CUDA (cuda, cuCtxPushCurrent, cuCtxPushCurrent_v2, CUDA_CUCTXPUSHCURRENT, CUDA, 1);
1220 HC_LOAD_FUNC_CUDA (cuda, cuCtxSetCacheConfig, cuCtxSetCacheConfig, CUDA_CUCTXSETCACHECONFIG, CUDA, 1);
1221 HC_LOAD_FUNC_CUDA (cuda, cuCtxSetCurrent, cuCtxSetCurrent, CUDA_CUCTXSETCURRENT, CUDA, 1);
1222 HC_LOAD_FUNC_CUDA (cuda, cuCtxSetSharedMemConfig, cuCtxSetSharedMemConfig, CUDA_CUCTXSETSHAREDMEMCONFIG, CUDA, 1);
1223 HC_LOAD_FUNC_CUDA (cuda, cuCtxSynchronize, cuCtxSynchronize, CUDA_CUCTXSYNCHRONIZE, CUDA, 1);
1224 HC_LOAD_FUNC_CUDA (cuda, cuDeviceGetAttribute, cuDeviceGetAttribute, CUDA_CUDEVICEGETATTRIBUTE, CUDA, 1);
1225 HC_LOAD_FUNC_CUDA (cuda, cuDeviceGetCount, cuDeviceGetCount, CUDA_CUDEVICEGETCOUNT, CUDA, 1);
1226 HC_LOAD_FUNC_CUDA (cuda, cuDeviceGet, cuDeviceGet, CUDA_CUDEVICEGET, CUDA, 1);
1227 HC_LOAD_FUNC_CUDA (cuda, cuDeviceGetName, cuDeviceGetName, CUDA_CUDEVICEGETNAME, CUDA, 1);
1228 HC_LOAD_FUNC_CUDA (cuda, cuDeviceTotalMem, cuDeviceTotalMem_v2, CUDA_CUDEVICETOTALMEM, CUDA, 1);
1229 HC_LOAD_FUNC_CUDA (cuda, cuDriverGetVersion, cuDriverGetVersion, CUDA_CUDRIVERGETVERSION, CUDA, 1);
1230 HC_LOAD_FUNC_CUDA (cuda, cuEventCreate, cuEventCreate, CUDA_CUEVENTCREATE, CUDA, 1);
1231 HC_LOAD_FUNC_CUDA (cuda, cuEventDestroy, cuEventDestroy_v2, CUDA_CUEVENTDESTROY, CUDA, 1);
1232 HC_LOAD_FUNC_CUDA (cuda, cuEventElapsedTime, cuEventElapsedTime, CUDA_CUEVENTELAPSEDTIME, CUDA, 1);
1233 HC_LOAD_FUNC_CUDA (cuda, cuEventQuery, cuEventQuery, CUDA_CUEVENTQUERY, CUDA, 1);
1234 HC_LOAD_FUNC_CUDA (cuda, cuEventRecord, cuEventRecord, CUDA_CUEVENTRECORD, CUDA, 1);
1235 HC_LOAD_FUNC_CUDA (cuda, cuEventSynchronize, cuEventSynchronize, CUDA_CUEVENTSYNCHRONIZE, CUDA, 1);
1236 HC_LOAD_FUNC_CUDA (cuda, cuFuncGetAttribute, cuFuncGetAttribute, CUDA_CUFUNCGETATTRIBUTE, CUDA, 1);
1237 HC_LOAD_FUNC_CUDA (cuda, cuFuncSetAttribute, cuFuncSetAttribute, CUDA_CUFUNCSETATTRIBUTE, CUDA, 1);
1238 HC_LOAD_FUNC_CUDA (cuda, cuFuncSetCacheConfig, cuFuncSetCacheConfig, CUDA_CUFUNCSETCACHECONFIG, CUDA, 1);
1239 HC_LOAD_FUNC_CUDA (cuda, cuFuncSetSharedMemConfig, cuFuncSetSharedMemConfig, CUDA_CUFUNCSETSHAREDMEMCONFIG, CUDA, 1);
1240 HC_LOAD_FUNC_CUDA (cuda, cuGetErrorName, cuGetErrorName, CUDA_CUGETERRORNAME, CUDA, 1);
1241 HC_LOAD_FUNC_CUDA (cuda, cuGetErrorString, cuGetErrorString, CUDA_CUGETERRORSTRING, CUDA, 1);
1242 HC_LOAD_FUNC_CUDA (cuda, cuInit, cuInit, CUDA_CUINIT, CUDA, 1);
1243 HC_LOAD_FUNC_CUDA (cuda, cuLaunchKernel, cuLaunchKernel, CUDA_CULAUNCHKERNEL, CUDA, 1);
1244 HC_LOAD_FUNC_CUDA (cuda, cuMemAlloc, cuMemAlloc_v2, CUDA_CUMEMALLOC, CUDA, 1);
1245 HC_LOAD_FUNC_CUDA (cuda, cuMemAllocHost, cuMemAllocHost_v2, CUDA_CUMEMALLOCHOST, CUDA, 1);
1246 HC_LOAD_FUNC_CUDA (cuda, cuMemcpyDtoDAsync, cuMemcpyDtoDAsync_v2, CUDA_CUMEMCPYDTODASYNC, CUDA, 1);
1247 HC_LOAD_FUNC_CUDA (cuda, cuMemcpyDtoHAsync, cuMemcpyDtoHAsync_v2, CUDA_CUMEMCPYDTOHASYNC, CUDA, 1);
1248 HC_LOAD_FUNC_CUDA (cuda, cuMemcpyHtoDAsync, cuMemcpyHtoDAsync_v2, CUDA_CUMEMCPYHTODASYNC, CUDA, 1);
1249 HC_LOAD_FUNC_CUDA (cuda, cuMemFree, cuMemFree_v2, CUDA_CUMEMFREE, CUDA, 1);
1250 HC_LOAD_FUNC_CUDA (cuda, cuMemFreeHost, cuMemFreeHost, CUDA_CUMEMFREEHOST, CUDA, 1);
1251 HC_LOAD_FUNC_CUDA (cuda, cuMemGetInfo, cuMemGetInfo_v2, CUDA_CUMEMGETINFO, CUDA, 1);
1252 HC_LOAD_FUNC_CUDA (cuda, cuMemsetD32Async, cuMemsetD32Async, CUDA_CUMEMSETD32ASYNC, CUDA, 1);
1253 HC_LOAD_FUNC_CUDA (cuda, cuMemsetD8Async, cuMemsetD8Async, CUDA_CUMEMSETD8ASYNC, CUDA, 1);
1254 HC_LOAD_FUNC_CUDA (cuda, cuModuleGetFunction, cuModuleGetFunction, CUDA_CUMODULEGETFUNCTION, CUDA, 1);
1255 HC_LOAD_FUNC_CUDA (cuda, cuModuleGetGlobal, cuModuleGetGlobal_v2, CUDA_CUMODULEGETGLOBAL, CUDA, 1);
1256 HC_LOAD_FUNC_CUDA (cuda, cuModuleLoad, cuModuleLoad, CUDA_CUMODULELOAD, CUDA, 1);
1257 HC_LOAD_FUNC_CUDA (cuda, cuModuleLoadData, cuModuleLoadData, CUDA_CUMODULELOADDATA, CUDA, 1);
1258 HC_LOAD_FUNC_CUDA (cuda, cuModuleLoadDataEx, cuModuleLoadDataEx, CUDA_CUMODULELOADDATAEX, CUDA, 1);
1259 HC_LOAD_FUNC_CUDA (cuda, cuModuleUnload, cuModuleUnload, CUDA_CUMODULEUNLOAD, CUDA, 1);
1260 HC_LOAD_FUNC_CUDA (cuda, cuProfilerStart, cuProfilerStart, CUDA_CUPROFILERSTART, CUDA, 1);
1261 HC_LOAD_FUNC_CUDA (cuda, cuProfilerStop, cuProfilerStop, CUDA_CUPROFILERSTOP, CUDA, 1);
1262 HC_LOAD_FUNC_CUDA (cuda, cuStreamCreate, cuStreamCreate, CUDA_CUSTREAMCREATE, CUDA, 1);
1263 HC_LOAD_FUNC_CUDA (cuda, cuStreamDestroy, cuStreamDestroy_v2, CUDA_CUSTREAMDESTROY, CUDA, 1);
1264 HC_LOAD_FUNC_CUDA (cuda, cuStreamSynchronize, cuStreamSynchronize, CUDA_CUSTREAMSYNCHRONIZE, CUDA, 1);
1265 HC_LOAD_FUNC_CUDA (cuda, cuStreamWaitEvent, cuStreamWaitEvent, CUDA_CUSTREAMWAITEVENT, CUDA, 1);
1266 #if defined (WITH_CUBIN)
1267 HC_LOAD_FUNC_CUDA (cuda, cuLinkCreate, cuLinkCreate_v2, CUDA_CULINKCREATE, CUDA, 1);
1268 HC_LOAD_FUNC_CUDA (cuda, cuLinkAddData, cuLinkAddData_v2, CUDA_CULINKADDDATA, CUDA, 1);
1269 HC_LOAD_FUNC_CUDA (cuda, cuLinkDestroy, cuLinkDestroy, CUDA_CULINKDESTROY, CUDA, 1);
1270 HC_LOAD_FUNC_CUDA (cuda, cuLinkComplete, cuLinkComplete, CUDA_CULINKCOMPLETE, CUDA, 1);
1271 #endif
1272
1273 return 0;
1274 }
1275
cuda_close(hashcat_ctx_t * hashcat_ctx)1276 void cuda_close (hashcat_ctx_t *hashcat_ctx)
1277 {
1278 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1279
1280 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
1281
1282 if (cuda)
1283 {
1284 if (cuda->lib)
1285 {
1286 hc_dlclose (cuda->lib);
1287 }
1288
1289 hcfree (backend_ctx->cuda);
1290
1291 backend_ctx->cuda = NULL;
1292 }
1293 }
1294
hc_cuInit(hashcat_ctx_t * hashcat_ctx,unsigned int Flags)1295 int hc_cuInit (hashcat_ctx_t *hashcat_ctx, unsigned int Flags)
1296 {
1297 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1298
1299 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
1300
1301 const CUresult CU_err = cuda->cuInit (Flags);
1302
1303 if (CU_err != CUDA_SUCCESS)
1304 {
1305 const char *pStr = NULL;
1306
1307 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
1308 {
1309 event_log_error (hashcat_ctx, "cuInit(): %s", pStr);
1310 }
1311 else
1312 {
1313 event_log_error (hashcat_ctx, "cuInit(): %d", CU_err);
1314 }
1315
1316 return -1;
1317 }
1318
1319 return 0;
1320 }
1321
hc_cuDeviceGetAttribute(hashcat_ctx_t * hashcat_ctx,int * pi,CUdevice_attribute attrib,CUdevice dev)1322 int hc_cuDeviceGetAttribute (hashcat_ctx_t *hashcat_ctx, int *pi, CUdevice_attribute attrib, CUdevice dev)
1323 {
1324 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1325
1326 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
1327
1328 const CUresult CU_err = cuda->cuDeviceGetAttribute (pi, attrib, dev);
1329
1330 if (CU_err != CUDA_SUCCESS)
1331 {
1332 const char *pStr = NULL;
1333
1334 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
1335 {
1336 event_log_error (hashcat_ctx, "cuDeviceGetAttribute(): %s", pStr);
1337 }
1338 else
1339 {
1340 event_log_error (hashcat_ctx, "cuDeviceGetAttribute(): %d", CU_err);
1341 }
1342
1343 return -1;
1344 }
1345
1346 return 0;
1347 }
1348
hc_cuDeviceGetCount(hashcat_ctx_t * hashcat_ctx,int * count)1349 int hc_cuDeviceGetCount (hashcat_ctx_t *hashcat_ctx, int *count)
1350 {
1351 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1352
1353 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
1354
1355 const CUresult CU_err = cuda->cuDeviceGetCount (count);
1356
1357 if (CU_err != CUDA_SUCCESS)
1358 {
1359 const char *pStr = NULL;
1360
1361 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
1362 {
1363 event_log_error (hashcat_ctx, "cuDeviceGetCount(): %s", pStr);
1364 }
1365 else
1366 {
1367 event_log_error (hashcat_ctx, "cuDeviceGetCount(): %d", CU_err);
1368 }
1369
1370 return -1;
1371 }
1372
1373 return 0;
1374 }
1375
hc_cuDeviceGet(hashcat_ctx_t * hashcat_ctx,CUdevice * device,int ordinal)1376 int hc_cuDeviceGet (hashcat_ctx_t *hashcat_ctx, CUdevice* device, int ordinal)
1377 {
1378 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1379
1380 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
1381
1382 const CUresult CU_err = cuda->cuDeviceGet (device, ordinal);
1383
1384 if (CU_err != CUDA_SUCCESS)
1385 {
1386 const char *pStr = NULL;
1387
1388 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
1389 {
1390 event_log_error (hashcat_ctx, "cuDeviceGet(): %s", pStr);
1391 }
1392 else
1393 {
1394 event_log_error (hashcat_ctx, "cuDeviceGet(): %d", CU_err);
1395 }
1396
1397 return -1;
1398 }
1399
1400 return 0;
1401 }
1402
hc_cuDeviceGetName(hashcat_ctx_t * hashcat_ctx,char * name,int len,CUdevice dev)1403 int hc_cuDeviceGetName (hashcat_ctx_t *hashcat_ctx, char *name, int len, CUdevice dev)
1404 {
1405 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1406
1407 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
1408
1409 const CUresult CU_err = cuda->cuDeviceGetName (name, len, dev);
1410
1411 if (CU_err != CUDA_SUCCESS)
1412 {
1413 const char *pStr = NULL;
1414
1415 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
1416 {
1417 event_log_error (hashcat_ctx, "cuDeviceGetName(): %s", pStr);
1418 }
1419 else
1420 {
1421 event_log_error (hashcat_ctx, "cuDeviceGetName(): %d", CU_err);
1422 }
1423
1424 return -1;
1425 }
1426
1427 return 0;
1428 }
1429
hc_cuDeviceTotalMem(hashcat_ctx_t * hashcat_ctx,size_t * bytes,CUdevice dev)1430 int hc_cuDeviceTotalMem (hashcat_ctx_t *hashcat_ctx, size_t *bytes, CUdevice dev)
1431 {
1432 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1433
1434 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
1435
1436 const CUresult CU_err = cuda->cuDeviceTotalMem (bytes, dev);
1437
1438 if (CU_err != CUDA_SUCCESS)
1439 {
1440 const char *pStr = NULL;
1441
1442 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
1443 {
1444 event_log_error (hashcat_ctx, "cuDeviceTotalMem(): %s", pStr);
1445 }
1446 else
1447 {
1448 event_log_error (hashcat_ctx, "cuDeviceTotalMem(): %d", CU_err);
1449 }
1450
1451 return -1;
1452 }
1453
1454 return 0;
1455 }
1456
hc_cuDriverGetVersion(hashcat_ctx_t * hashcat_ctx,int * driverVersion)1457 int hc_cuDriverGetVersion (hashcat_ctx_t *hashcat_ctx, int *driverVersion)
1458 {
1459 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1460
1461 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
1462
1463 const CUresult CU_err = cuda->cuDriverGetVersion (driverVersion);
1464
1465 if (CU_err != CUDA_SUCCESS)
1466 {
1467 const char *pStr = NULL;
1468
1469 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
1470 {
1471 event_log_error (hashcat_ctx, "cuDriverGetVersion(): %s", pStr);
1472 }
1473 else
1474 {
1475 event_log_error (hashcat_ctx, "cuDriverGetVersion(): %d", CU_err);
1476 }
1477
1478 return -1;
1479 }
1480
1481 return 0;
1482 }
1483
hc_cuCtxCreate(hashcat_ctx_t * hashcat_ctx,CUcontext * pctx,unsigned int flags,CUdevice dev)1484 int hc_cuCtxCreate (hashcat_ctx_t *hashcat_ctx, CUcontext *pctx, unsigned int flags, CUdevice dev)
1485 {
1486 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1487
1488 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
1489
1490 const CUresult CU_err = cuda->cuCtxCreate (pctx, flags, dev);
1491
1492 if (CU_err != CUDA_SUCCESS)
1493 {
1494 const char *pStr = NULL;
1495
1496 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
1497 {
1498 event_log_error (hashcat_ctx, "cuCtxCreate(): %s", pStr);
1499 }
1500 else
1501 {
1502 event_log_error (hashcat_ctx, "cuCtxCreate(): %d", CU_err);
1503 }
1504
1505 return -1;
1506 }
1507
1508 return 0;
1509 }
1510
hc_cuCtxDestroy(hashcat_ctx_t * hashcat_ctx,CUcontext ctx)1511 int hc_cuCtxDestroy (hashcat_ctx_t *hashcat_ctx, CUcontext ctx)
1512 {
1513 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1514
1515 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
1516
1517 const CUresult CU_err = cuda->cuCtxDestroy (ctx);
1518
1519 if (CU_err != CUDA_SUCCESS)
1520 {
1521 const char *pStr = NULL;
1522
1523 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
1524 {
1525 event_log_error (hashcat_ctx, "cuCtxDestroy(): %s", pStr);
1526 }
1527 else
1528 {
1529 event_log_error (hashcat_ctx, "cuCtxDestroy(): %d", CU_err);
1530 }
1531
1532 return -1;
1533 }
1534
1535 return 0;
1536 }
1537
hc_cuModuleLoadDataEx(hashcat_ctx_t * hashcat_ctx,CUmodule * module,const void * image,unsigned int numOptions,CUjit_option * options,void ** optionValues)1538 int hc_cuModuleLoadDataEx (hashcat_ctx_t *hashcat_ctx, CUmodule *module, const void *image, unsigned int numOptions, CUjit_option *options, void **optionValues)
1539 {
1540 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1541
1542 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
1543
1544 const CUresult CU_err = cuda->cuModuleLoadDataEx (module, image, numOptions, options, optionValues);
1545
1546 if (CU_err != CUDA_SUCCESS)
1547 {
1548 const char *pStr = NULL;
1549
1550 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
1551 {
1552 event_log_error (hashcat_ctx, "cuModuleLoadDataEx(): %s", pStr);
1553 }
1554 else
1555 {
1556 event_log_error (hashcat_ctx, "cuModuleLoadDataEx(): %d", CU_err);
1557 }
1558
1559 return -1;
1560 }
1561
1562 return 0;
1563 }
1564
hc_cuModuleUnload(hashcat_ctx_t * hashcat_ctx,CUmodule hmod)1565 int hc_cuModuleUnload (hashcat_ctx_t *hashcat_ctx, CUmodule hmod)
1566 {
1567 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1568
1569 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
1570
1571 const CUresult CU_err = cuda->cuModuleUnload (hmod);
1572
1573 if (CU_err != CUDA_SUCCESS)
1574 {
1575 const char *pStr = NULL;
1576
1577 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
1578 {
1579 event_log_error (hashcat_ctx, "cuModuleUnload(): %s", pStr);
1580 }
1581 else
1582 {
1583 event_log_error (hashcat_ctx, "cuModuleUnload(): %d", CU_err);
1584 }
1585
1586 return -1;
1587 }
1588
1589 return 0;
1590 }
1591
hc_cuCtxSetCurrent(hashcat_ctx_t * hashcat_ctx,CUcontext ctx)1592 int hc_cuCtxSetCurrent (hashcat_ctx_t *hashcat_ctx, CUcontext ctx)
1593 {
1594 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1595
1596 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
1597
1598 const CUresult CU_err = cuda->cuCtxSetCurrent (ctx);
1599
1600 if (CU_err != CUDA_SUCCESS)
1601 {
1602 const char *pStr = NULL;
1603
1604 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
1605 {
1606 event_log_error (hashcat_ctx, "cuCtxSetCurrent(): %s", pStr);
1607 }
1608 else
1609 {
1610 event_log_error (hashcat_ctx, "cuCtxSetCurrent(): %d", CU_err);
1611 }
1612
1613 return -1;
1614 }
1615
1616 return 0;
1617 }
1618
hc_cuMemAlloc(hashcat_ctx_t * hashcat_ctx,CUdeviceptr * dptr,size_t bytesize)1619 int hc_cuMemAlloc (hashcat_ctx_t *hashcat_ctx, CUdeviceptr *dptr, size_t bytesize)
1620 {
1621 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1622
1623 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
1624
1625 const CUresult CU_err = cuda->cuMemAlloc (dptr, bytesize);
1626
1627 if (CU_err != CUDA_SUCCESS)
1628 {
1629 const char *pStr = NULL;
1630
1631 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
1632 {
1633 event_log_error (hashcat_ctx, "cuMemAlloc(): %s", pStr);
1634 }
1635 else
1636 {
1637 event_log_error (hashcat_ctx, "cuMemAlloc(): %d", CU_err);
1638 }
1639
1640 return -1;
1641 }
1642
1643 return 0;
1644 }
1645
hc_cuMemFree(hashcat_ctx_t * hashcat_ctx,CUdeviceptr dptr)1646 int hc_cuMemFree (hashcat_ctx_t *hashcat_ctx, CUdeviceptr dptr)
1647 {
1648 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1649
1650 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
1651
1652 const CUresult CU_err = cuda->cuMemFree (dptr);
1653
1654 if (CU_err != CUDA_SUCCESS)
1655 {
1656 const char *pStr = NULL;
1657
1658 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
1659 {
1660 event_log_error (hashcat_ctx, "cuMemFree(): %s", pStr);
1661 }
1662 else
1663 {
1664 event_log_error (hashcat_ctx, "cuMemFree(): %d", CU_err);
1665 }
1666
1667 return -1;
1668 }
1669
1670 return 0;
1671 }
1672
hc_cuMemcpyDtoHAsync(hashcat_ctx_t * hashcat_ctx,void * dstHost,CUdeviceptr srcDevice,size_t ByteCount,CUstream hStream)1673 int hc_cuMemcpyDtoHAsync (hashcat_ctx_t *hashcat_ctx, void *dstHost, CUdeviceptr srcDevice, size_t ByteCount, CUstream hStream)
1674 {
1675 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1676
1677 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
1678
1679 const CUresult CU_err = cuda->cuMemcpyDtoHAsync (dstHost, srcDevice, ByteCount, hStream);
1680
1681 if (CU_err != CUDA_SUCCESS)
1682 {
1683 const char *pStr = NULL;
1684
1685 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
1686 {
1687 event_log_error (hashcat_ctx, "cuMemcpyDtoHAsync(): %s", pStr);
1688 }
1689 else
1690 {
1691 event_log_error (hashcat_ctx, "cuMemcpyDtoHAsync(): %d", CU_err);
1692 }
1693
1694 return -1;
1695 }
1696
1697 return 0;
1698 }
1699
hc_cuMemcpyDtoDAsync(hashcat_ctx_t * hashcat_ctx,CUdeviceptr dstDevice,CUdeviceptr srcDevice,size_t ByteCount,CUstream hStream)1700 int hc_cuMemcpyDtoDAsync (hashcat_ctx_t *hashcat_ctx, CUdeviceptr dstDevice, CUdeviceptr srcDevice, size_t ByteCount, CUstream hStream)
1701 {
1702 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1703
1704 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
1705
1706 const CUresult CU_err = cuda->cuMemcpyDtoDAsync (dstDevice, srcDevice, ByteCount, hStream);
1707
1708 if (CU_err != CUDA_SUCCESS)
1709 {
1710 const char *pStr = NULL;
1711
1712 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
1713 {
1714 event_log_error (hashcat_ctx, "cuMemcpyDtoDAsync(): %s", pStr);
1715 }
1716 else
1717 {
1718 event_log_error (hashcat_ctx, "cuMemcpyDtoDAsync(): %d", CU_err);
1719 }
1720
1721 return -1;
1722 }
1723
1724 return 0;
1725 }
1726
hc_cuMemcpyHtoDAsync(hashcat_ctx_t * hashcat_ctx,CUdeviceptr dstDevice,const void * srcHost,size_t ByteCount,CUstream hStream)1727 int hc_cuMemcpyHtoDAsync (hashcat_ctx_t *hashcat_ctx, CUdeviceptr dstDevice, const void *srcHost, size_t ByteCount, CUstream hStream)
1728 {
1729 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1730
1731 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
1732
1733 const CUresult CU_err = cuda->cuMemcpyHtoDAsync (dstDevice, srcHost, ByteCount, hStream);
1734
1735 if (CU_err != CUDA_SUCCESS)
1736 {
1737 const char *pStr = NULL;
1738
1739 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
1740 {
1741 event_log_error (hashcat_ctx, "cuMemcpyHtoDAsync(): %s", pStr);
1742 }
1743 else
1744 {
1745 event_log_error (hashcat_ctx, "cuMemcpyHtoDAsync(): %d", CU_err);
1746 }
1747
1748 return -1;
1749 }
1750
1751 return 0;
1752 }
1753
hc_cuMemsetD32Async(hashcat_ctx_t * hashcat_ctx,CUdeviceptr dstDevice,unsigned int ui,size_t N,CUstream hStream)1754 int hc_cuMemsetD32Async (hashcat_ctx_t *hashcat_ctx, CUdeviceptr dstDevice, unsigned int ui, size_t N, CUstream hStream)
1755 {
1756 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1757
1758 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
1759
1760 const CUresult CU_err = cuda->cuMemsetD32Async (dstDevice, ui, N, hStream);
1761
1762 if (CU_err != CUDA_SUCCESS)
1763 {
1764 const char *pStr = NULL;
1765
1766 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
1767 {
1768 event_log_error (hashcat_ctx, "cuMemsetD32Async(): %s", pStr);
1769 }
1770 else
1771 {
1772 event_log_error (hashcat_ctx, "cuMemsetD32Async(): %d", CU_err);
1773 }
1774
1775 return -1;
1776 }
1777
1778 return 0;
1779 }
1780
hc_cuMemsetD8Async(hashcat_ctx_t * hashcat_ctx,CUdeviceptr dstDevice,unsigned char uc,size_t N,CUstream hStream)1781 int hc_cuMemsetD8Async (hashcat_ctx_t *hashcat_ctx, CUdeviceptr dstDevice, unsigned char uc, size_t N, CUstream hStream)
1782 {
1783 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1784
1785 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
1786
1787 const CUresult CU_err = cuda->cuMemsetD8Async (dstDevice, uc, N, hStream);
1788
1789 if (CU_err != CUDA_SUCCESS)
1790 {
1791 const char *pStr = NULL;
1792
1793 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
1794 {
1795 event_log_error (hashcat_ctx, "cuMemsetD8Async(): %s", pStr);
1796 }
1797 else
1798 {
1799 event_log_error (hashcat_ctx, "cuMemsetD8Async(): %d", CU_err);
1800 }
1801
1802 return -1;
1803 }
1804
1805 return 0;
1806 }
1807
hc_cuModuleGetFunction(hashcat_ctx_t * hashcat_ctx,CUfunction * hfunc,CUmodule hmod,const char * name)1808 int hc_cuModuleGetFunction (hashcat_ctx_t *hashcat_ctx, CUfunction *hfunc, CUmodule hmod, const char *name)
1809 {
1810 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1811
1812 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
1813
1814 const CUresult CU_err = cuda->cuModuleGetFunction (hfunc, hmod, name);
1815
1816 if (CU_err != CUDA_SUCCESS)
1817 {
1818 const char *pStr = NULL;
1819
1820 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
1821 {
1822 event_log_error (hashcat_ctx, "cuModuleGetFunction(): %s", pStr);
1823 }
1824 else
1825 {
1826 event_log_error (hashcat_ctx, "cuModuleGetFunction(): %d", CU_err);
1827 }
1828
1829 return -1;
1830 }
1831
1832 return 0;
1833 }
1834
hc_cuModuleGetGlobal(hashcat_ctx_t * hashcat_ctx,CUdeviceptr * dptr,size_t * bytes,CUmodule hmod,const char * name)1835 int hc_cuModuleGetGlobal (hashcat_ctx_t *hashcat_ctx, CUdeviceptr *dptr, size_t *bytes, CUmodule hmod, const char *name)
1836 {
1837 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1838
1839 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
1840
1841 const CUresult CU_err = cuda->cuModuleGetGlobal (dptr, bytes, hmod, name);
1842
1843 if (CU_err != CUDA_SUCCESS)
1844 {
1845 const char *pStr = NULL;
1846
1847 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
1848 {
1849 event_log_error (hashcat_ctx, "cuModuleGetGlobal(): %s", pStr);
1850 }
1851 else
1852 {
1853 event_log_error (hashcat_ctx, "cuModuleGetGlobal(): %d", CU_err);
1854 }
1855
1856 return -1;
1857 }
1858
1859 return 0;
1860 }
1861
hc_cuMemGetInfo(hashcat_ctx_t * hashcat_ctx,size_t * free,size_t * total)1862 int hc_cuMemGetInfo (hashcat_ctx_t *hashcat_ctx, size_t *free, size_t *total)
1863 {
1864 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1865
1866 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
1867
1868 const CUresult CU_err = cuda->cuMemGetInfo (free, total);
1869
1870 if (CU_err != CUDA_SUCCESS)
1871 {
1872 const char *pStr = NULL;
1873
1874 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
1875 {
1876 event_log_error (hashcat_ctx, "cuMemGetInfo(): %s", pStr);
1877 }
1878 else
1879 {
1880 event_log_error (hashcat_ctx, "cuMemGetInfo(): %d", CU_err);
1881 }
1882
1883 return -1;
1884 }
1885
1886 return 0;
1887 }
1888
hc_cuFuncGetAttribute(hashcat_ctx_t * hashcat_ctx,int * pi,CUfunction_attribute attrib,CUfunction hfunc)1889 int hc_cuFuncGetAttribute (hashcat_ctx_t *hashcat_ctx, int *pi, CUfunction_attribute attrib, CUfunction hfunc)
1890 {
1891 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1892
1893 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
1894
1895 const CUresult CU_err = cuda->cuFuncGetAttribute (pi, attrib, hfunc);
1896
1897 if (CU_err != CUDA_SUCCESS)
1898 {
1899 const char *pStr = NULL;
1900
1901 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
1902 {
1903 event_log_error (hashcat_ctx, "cuFuncGetAttribute(): %s", pStr);
1904 }
1905 else
1906 {
1907 event_log_error (hashcat_ctx, "cuFuncGetAttribute(): %d", CU_err);
1908 }
1909
1910 return -1;
1911 }
1912
1913 return 0;
1914 }
1915
hc_cuFuncSetAttribute(hashcat_ctx_t * hashcat_ctx,CUfunction hfunc,CUfunction_attribute attrib,int value)1916 int hc_cuFuncSetAttribute (hashcat_ctx_t *hashcat_ctx, CUfunction hfunc, CUfunction_attribute attrib, int value)
1917 {
1918 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1919
1920 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
1921
1922 const CUresult CU_err = cuda->cuFuncSetAttribute (hfunc, attrib, value);
1923
1924 if (CU_err != CUDA_SUCCESS)
1925 {
1926 const char *pStr = NULL;
1927
1928 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
1929 {
1930 event_log_error (hashcat_ctx, "cuFuncSetAttribute(): %s", pStr);
1931 }
1932 else
1933 {
1934 event_log_error (hashcat_ctx, "cuFuncSetAttribute(): %d", CU_err);
1935 }
1936
1937 return -1;
1938 }
1939
1940 return 0;
1941 }
1942
hc_cuStreamCreate(hashcat_ctx_t * hashcat_ctx,CUstream * phStream,unsigned int Flags)1943 int hc_cuStreamCreate (hashcat_ctx_t *hashcat_ctx, CUstream *phStream, unsigned int Flags)
1944 {
1945 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1946
1947 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
1948
1949 const CUresult CU_err = cuda->cuStreamCreate (phStream, Flags);
1950
1951 if (CU_err != CUDA_SUCCESS)
1952 {
1953 const char *pStr = NULL;
1954
1955 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
1956 {
1957 event_log_error (hashcat_ctx, "cuStreamCreate(): %s", pStr);
1958 }
1959 else
1960 {
1961 event_log_error (hashcat_ctx, "cuStreamCreate(): %d", CU_err);
1962 }
1963
1964 return -1;
1965 }
1966
1967 return 0;
1968 }
1969
hc_cuStreamDestroy(hashcat_ctx_t * hashcat_ctx,CUstream hStream)1970 int hc_cuStreamDestroy (hashcat_ctx_t *hashcat_ctx, CUstream hStream)
1971 {
1972 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1973
1974 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
1975
1976 const CUresult CU_err = cuda->cuStreamDestroy (hStream);
1977
1978 if (CU_err != CUDA_SUCCESS)
1979 {
1980 const char *pStr = NULL;
1981
1982 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
1983 {
1984 event_log_error (hashcat_ctx, "cuStreamDestroy(): %s", pStr);
1985 }
1986 else
1987 {
1988 event_log_error (hashcat_ctx, "cuStreamDestroy(): %d", CU_err);
1989 }
1990
1991 return -1;
1992 }
1993
1994 return 0;
1995 }
1996
hc_cuStreamSynchronize(hashcat_ctx_t * hashcat_ctx,CUstream hStream)1997 int hc_cuStreamSynchronize (hashcat_ctx_t *hashcat_ctx, CUstream hStream)
1998 {
1999 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2000
2001 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
2002
2003 const CUresult CU_err = cuda->cuStreamSynchronize (hStream);
2004
2005 if (CU_err != CUDA_SUCCESS)
2006 {
2007 const char *pStr = NULL;
2008
2009 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
2010 {
2011 event_log_error (hashcat_ctx, "cuStreamSynchronize(): %s", pStr);
2012 }
2013 else
2014 {
2015 event_log_error (hashcat_ctx, "cuStreamSynchronize(): %d", CU_err);
2016 }
2017
2018 return -1;
2019 }
2020
2021 return 0;
2022 }
2023
hc_cuLaunchKernel(hashcat_ctx_t * hashcat_ctx,CUfunction f,unsigned int gridDimX,unsigned int gridDimY,unsigned int gridDimZ,unsigned int blockDimX,unsigned int blockDimY,unsigned int blockDimZ,unsigned int sharedMemBytes,CUstream hStream,void ** kernelParams,void ** extra)2024 int hc_cuLaunchKernel (hashcat_ctx_t *hashcat_ctx, CUfunction f, unsigned int gridDimX, unsigned int gridDimY, unsigned int gridDimZ, unsigned int blockDimX, unsigned int blockDimY, unsigned int blockDimZ, unsigned int sharedMemBytes, CUstream hStream, void **kernelParams, void **extra)
2025 {
2026 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2027
2028 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
2029
2030 const CUresult CU_err = cuda->cuLaunchKernel (f, gridDimX, gridDimY, gridDimZ, blockDimX, blockDimY, blockDimZ, sharedMemBytes, hStream, kernelParams, extra);
2031
2032 if (CU_err != CUDA_SUCCESS)
2033 {
2034 const char *pStr = NULL;
2035
2036 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
2037 {
2038 event_log_error (hashcat_ctx, "cuLaunchKernel(): %s", pStr);
2039 }
2040 else
2041 {
2042 event_log_error (hashcat_ctx, "cuLaunchKernel(): %d", CU_err);
2043 }
2044
2045 return -1;
2046 }
2047
2048 return 0;
2049 }
2050
hc_cuCtxSynchronize(hashcat_ctx_t * hashcat_ctx)2051 int hc_cuCtxSynchronize (hashcat_ctx_t *hashcat_ctx)
2052 {
2053 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2054
2055 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
2056
2057 const CUresult CU_err = cuda->cuCtxSynchronize ();
2058
2059 if (CU_err != CUDA_SUCCESS)
2060 {
2061 const char *pStr = NULL;
2062
2063 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
2064 {
2065 event_log_error (hashcat_ctx, "cuCtxSynchronize(): %s", pStr);
2066 }
2067 else
2068 {
2069 event_log_error (hashcat_ctx, "cuCtxSynchronize(): %d", CU_err);
2070 }
2071
2072 return -1;
2073 }
2074
2075 return 0;
2076 }
2077
hc_cuEventCreate(hashcat_ctx_t * hashcat_ctx,CUevent * phEvent,unsigned int Flags)2078 int hc_cuEventCreate (hashcat_ctx_t *hashcat_ctx, CUevent *phEvent, unsigned int Flags)
2079 {
2080 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2081
2082 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
2083
2084 const CUresult CU_err = cuda->cuEventCreate (phEvent, Flags);
2085
2086 if (CU_err != CUDA_SUCCESS)
2087 {
2088 const char *pStr = NULL;
2089
2090 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
2091 {
2092 event_log_error (hashcat_ctx, "cuEventCreate(): %s", pStr);
2093 }
2094 else
2095 {
2096 event_log_error (hashcat_ctx, "cuEventCreate(): %d", CU_err);
2097 }
2098
2099 return -1;
2100 }
2101
2102 return 0;
2103 }
2104
hc_cuEventDestroy(hashcat_ctx_t * hashcat_ctx,CUevent hEvent)2105 int hc_cuEventDestroy (hashcat_ctx_t *hashcat_ctx, CUevent hEvent)
2106 {
2107 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2108
2109 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
2110
2111 const CUresult CU_err = cuda->cuEventDestroy (hEvent);
2112
2113 if (CU_err != CUDA_SUCCESS)
2114 {
2115 const char *pStr = NULL;
2116
2117 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
2118 {
2119 event_log_error (hashcat_ctx, "cuEventDestroy(): %s", pStr);
2120 }
2121 else
2122 {
2123 event_log_error (hashcat_ctx, "cuEventDestroy(): %d", CU_err);
2124 }
2125
2126 return -1;
2127 }
2128
2129 return 0;
2130 }
2131
hc_cuEventElapsedTime(hashcat_ctx_t * hashcat_ctx,float * pMilliseconds,CUevent hStart,CUevent hEnd)2132 int hc_cuEventElapsedTime (hashcat_ctx_t *hashcat_ctx, float *pMilliseconds, CUevent hStart, CUevent hEnd)
2133 {
2134 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2135
2136 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
2137
2138 const CUresult CU_err = cuda->cuEventElapsedTime (pMilliseconds, hStart, hEnd);
2139
2140 if (CU_err != CUDA_SUCCESS)
2141 {
2142 const char *pStr = NULL;
2143
2144 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
2145 {
2146 event_log_error (hashcat_ctx, "cuEventElapsedTime(): %s", pStr);
2147 }
2148 else
2149 {
2150 event_log_error (hashcat_ctx, "cuEventElapsedTime(): %d", CU_err);
2151 }
2152
2153 return -1;
2154 }
2155
2156 return 0;
2157 }
2158
hc_cuEventQuery(hashcat_ctx_t * hashcat_ctx,CUevent hEvent)2159 int hc_cuEventQuery (hashcat_ctx_t *hashcat_ctx, CUevent hEvent)
2160 {
2161 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2162
2163 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
2164
2165 const CUresult CU_err = cuda->cuEventQuery (hEvent);
2166
2167 if (CU_err != CUDA_SUCCESS)
2168 {
2169 const char *pStr = NULL;
2170
2171 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
2172 {
2173 event_log_error (hashcat_ctx, "cuEventQuery(): %s", pStr);
2174 }
2175 else
2176 {
2177 event_log_error (hashcat_ctx, "cuEventQuery(): %d", CU_err);
2178 }
2179
2180 return -1;
2181 }
2182
2183 return 0;
2184 }
2185
hc_cuEventRecord(hashcat_ctx_t * hashcat_ctx,CUevent hEvent,CUstream hStream)2186 int hc_cuEventRecord (hashcat_ctx_t *hashcat_ctx, CUevent hEvent, CUstream hStream)
2187 {
2188 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2189
2190 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
2191
2192 const CUresult CU_err = cuda->cuEventRecord (hEvent, hStream);
2193
2194 if (CU_err != CUDA_SUCCESS)
2195 {
2196 const char *pStr = NULL;
2197
2198 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
2199 {
2200 event_log_error (hashcat_ctx, "cuEventRecord(): %s", pStr);
2201 }
2202 else
2203 {
2204 event_log_error (hashcat_ctx, "cuEventRecord(): %d", CU_err);
2205 }
2206
2207 return -1;
2208 }
2209
2210 return 0;
2211 }
2212
hc_cuEventSynchronize(hashcat_ctx_t * hashcat_ctx,CUevent hEvent)2213 int hc_cuEventSynchronize (hashcat_ctx_t *hashcat_ctx, CUevent hEvent)
2214 {
2215 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2216
2217 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
2218
2219 const CUresult CU_err = cuda->cuEventSynchronize (hEvent);
2220
2221 if (CU_err != CUDA_SUCCESS)
2222 {
2223 const char *pStr = NULL;
2224
2225 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
2226 {
2227 event_log_error (hashcat_ctx, "cuEventSynchronize(): %s", pStr);
2228 }
2229 else
2230 {
2231 event_log_error (hashcat_ctx, "cuEventSynchronize(): %d", CU_err);
2232 }
2233
2234 return -1;
2235 }
2236
2237 return 0;
2238 }
2239
hc_cuCtxSetCacheConfig(hashcat_ctx_t * hashcat_ctx,CUfunc_cache config)2240 int hc_cuCtxSetCacheConfig (hashcat_ctx_t *hashcat_ctx, CUfunc_cache config)
2241 {
2242 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2243
2244 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
2245
2246 const CUresult CU_err = cuda->cuCtxSetCacheConfig (config);
2247
2248 if (CU_err != CUDA_SUCCESS)
2249 {
2250 const char *pStr = NULL;
2251
2252 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
2253 {
2254 event_log_error (hashcat_ctx, "cuCtxSetCacheConfig(): %s", pStr);
2255 }
2256 else
2257 {
2258 event_log_error (hashcat_ctx, "cuCtxSetCacheConfig(): %d", CU_err);
2259 }
2260
2261 return -1;
2262 }
2263
2264 return 0;
2265 }
2266
hc_cuCtxPushCurrent(hashcat_ctx_t * hashcat_ctx,CUcontext ctx)2267 int hc_cuCtxPushCurrent (hashcat_ctx_t *hashcat_ctx, CUcontext ctx)
2268 {
2269 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2270
2271 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
2272
2273 const CUresult CU_err = cuda->cuCtxPushCurrent (ctx);
2274
2275 if (CU_err != CUDA_SUCCESS)
2276 {
2277 const char *pStr = NULL;
2278
2279 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
2280 {
2281 event_log_error (hashcat_ctx, "cuCtxPushCurrent(): %s", pStr);
2282 }
2283 else
2284 {
2285 event_log_error (hashcat_ctx, "cuCtxPushCurrent(): %d", CU_err);
2286 }
2287
2288 return -1;
2289 }
2290
2291 return 0;
2292 }
2293
hc_cuCtxPopCurrent(hashcat_ctx_t * hashcat_ctx,CUcontext * pctx)2294 int hc_cuCtxPopCurrent (hashcat_ctx_t *hashcat_ctx, CUcontext *pctx)
2295 {
2296 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2297
2298 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
2299
2300 const CUresult CU_err = cuda->cuCtxPopCurrent (pctx);
2301
2302 if (CU_err != CUDA_SUCCESS)
2303 {
2304 const char *pStr = NULL;
2305
2306 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
2307 {
2308 event_log_error (hashcat_ctx, "cuCtxPopCurrent(): %s", pStr);
2309 }
2310 else
2311 {
2312 event_log_error (hashcat_ctx, "cuCtxPopCurrent(): %d", CU_err);
2313 }
2314
2315 return -1;
2316 }
2317
2318 return 0;
2319 }
2320
hc_cuLinkCreate(hashcat_ctx_t * hashcat_ctx,unsigned int numOptions,CUjit_option * options,void ** optionValues,CUlinkState * stateOut)2321 int hc_cuLinkCreate (hashcat_ctx_t *hashcat_ctx, unsigned int numOptions, CUjit_option *options, void **optionValues, CUlinkState *stateOut)
2322 {
2323 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2324
2325 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
2326
2327 const CUresult CU_err = cuda->cuLinkCreate (numOptions, options, optionValues, stateOut);
2328
2329 if (CU_err != CUDA_SUCCESS)
2330 {
2331 const char *pStr = NULL;
2332
2333 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
2334 {
2335 event_log_error (hashcat_ctx, "cuLinkCreate(): %s", pStr);
2336 }
2337 else
2338 {
2339 event_log_error (hashcat_ctx, "cuLinkCreate(): %d", CU_err);
2340 }
2341
2342 return -1;
2343 }
2344
2345 return 0;
2346 }
2347
hc_cuLinkAddData(hashcat_ctx_t * hashcat_ctx,CUlinkState state,CUjitInputType type,void * data,size_t size,const char * name,unsigned int numOptions,CUjit_option * options,void ** optionValues)2348 int hc_cuLinkAddData (hashcat_ctx_t *hashcat_ctx, CUlinkState state, CUjitInputType type, void *data, size_t size, const char *name, unsigned int numOptions, CUjit_option *options, void **optionValues)
2349 {
2350 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2351
2352 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
2353
2354 const CUresult CU_err = cuda->cuLinkAddData (state, type, data, size, name, numOptions, options, optionValues);
2355
2356 if (CU_err != CUDA_SUCCESS)
2357 {
2358 const char *pStr = NULL;
2359
2360 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
2361 {
2362 event_log_error (hashcat_ctx, "cuLinkAddData(): %s", pStr);
2363 }
2364 else
2365 {
2366 event_log_error (hashcat_ctx, "cuLinkAddData(): %d", CU_err);
2367 }
2368
2369 return -1;
2370 }
2371
2372 return 0;
2373 }
2374
hc_cuLinkDestroy(hashcat_ctx_t * hashcat_ctx,CUlinkState state)2375 int hc_cuLinkDestroy (hashcat_ctx_t *hashcat_ctx, CUlinkState state)
2376 {
2377 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2378
2379 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
2380
2381 const CUresult CU_err = cuda->cuLinkDestroy (state);
2382
2383 if (CU_err != CUDA_SUCCESS)
2384 {
2385 const char *pStr = NULL;
2386
2387 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
2388 {
2389 event_log_error (hashcat_ctx, "cuLinkDestroy(): %s", pStr);
2390 }
2391 else
2392 {
2393 event_log_error (hashcat_ctx, "cuLinkDestroy(): %d", CU_err);
2394 }
2395
2396 return -1;
2397 }
2398
2399 return 0;
2400 }
2401
hc_cuLinkComplete(hashcat_ctx_t * hashcat_ctx,CUlinkState state,void ** cubinOut,size_t * sizeOut)2402 int hc_cuLinkComplete (hashcat_ctx_t *hashcat_ctx, CUlinkState state, void **cubinOut, size_t *sizeOut)
2403 {
2404 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2405
2406 CUDA_PTR *cuda = (CUDA_PTR *) backend_ctx->cuda;
2407
2408 const CUresult CU_err = cuda->cuLinkComplete (state, cubinOut, sizeOut);
2409
2410 if (CU_err != CUDA_SUCCESS)
2411 {
2412 const char *pStr = NULL;
2413
2414 if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS)
2415 {
2416 event_log_error (hashcat_ctx, "cuLinkComplete(): %s", pStr);
2417 }
2418 else
2419 {
2420 event_log_error (hashcat_ctx, "cuLinkComplete(): %d", CU_err);
2421 }
2422
2423 return -1;
2424 }
2425
2426 return 0;
2427 }
2428
2429 // HIP
2430
hip_init(hashcat_ctx_t * hashcat_ctx)2431 int hip_init (hashcat_ctx_t *hashcat_ctx)
2432 {
2433 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2434
2435 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
2436
2437 memset (hip, 0, sizeof (HIP_PTR));
2438
2439 #if defined (_WIN)
2440 hip->lib = hc_dlopen ("amdhip64.dll");
2441 #elif defined (__APPLE__)
2442 hip->lib = hc_dlopen ("fixme.dylib");
2443 #elif defined (__CYGWIN__)
2444 hip->lib = hc_dlopen ("amdhip64.dll");
2445 #else
2446 hip->lib = hc_dlopen ("libamdhip64.so");
2447 #endif
2448
2449 if (hip->lib == NULL) return -1;
2450
2451 // finding the right symbol is a PITA,
2452 #define HC_LOAD_FUNC_HIP(ptr,name,hipname,type,libname,noerr) \
2453 do { \
2454 ptr->name = (type) hc_dlsym ((ptr)->lib, #hipname); \
2455 if ((noerr) != -1) { \
2456 if (!(ptr)->name) { \
2457 if ((noerr) == 1) { \
2458 event_log_error (hashcat_ctx, "%s is missing from %s shared library.", #name, #libname); \
2459 return -1; \
2460 } \
2461 if ((noerr) != 1) { \
2462 event_log_warning (hashcat_ctx, "%s is missing from %s shared library.", #name, #libname); \
2463 return 0; \
2464 } \
2465 } \
2466 } \
2467 } while (0)
2468
2469 // finding the right symbol is a PITA, because of the _v2 suffix
2470 // a good reference is cuda.h itself
2471 // this needs to be verified for each new cuda release
2472
2473 HC_LOAD_FUNC_HIP (hip, hipCtxCreate, hipCtxCreate, HIP_HIPCTXCREATE, HIP, 1);
2474 HC_LOAD_FUNC_HIP (hip, hipCtxDestroy, hipCtxDestroy, HIP_HIPCTXDESTROY, HIP, 1);
2475 HC_LOAD_FUNC_HIP (hip, hipCtxPopCurrent, hipCtxPopCurrent, HIP_HIPCTXPOPCURRENT, HIP, 1);
2476 HC_LOAD_FUNC_HIP (hip, hipCtxPushCurrent, hipCtxPushCurrent, HIP_HIPCTXPUSHCURRENT, HIP, 1);
2477 HC_LOAD_FUNC_HIP (hip, hipCtxSetCurrent, hipCtxSetCurrent, HIP_HIPCTXSETCURRENT, HIP, 1);
2478 HC_LOAD_FUNC_HIP (hip, hipCtxSynchronize, hipCtxSynchronize, HIP_HIPCTXSYNCHRONIZE, HIP, 1);
2479 HC_LOAD_FUNC_HIP (hip, hipDeviceGet, hipDeviceGet, HIP_HIPDEVICEGET, HIP, 1);
2480 HC_LOAD_FUNC_HIP (hip, hipDeviceGetAttribute, hipDeviceGetAttribute, HIP_HIPDEVICEGETATTRIBUTE, HIP, 1);
2481 HC_LOAD_FUNC_HIP (hip, hipDeviceGetCount, hipGetDeviceCount, HIP_HIPDEVICEGETCOUNT, HIP, 1);
2482 HC_LOAD_FUNC_HIP (hip, hipDeviceGetName, hipDeviceGetName, HIP_HIPDEVICEGETNAME, HIP, 1);
2483 HC_LOAD_FUNC_HIP (hip, hipDeviceTotalMem, hipDeviceTotalMem, HIP_HIPDEVICETOTALMEM, HIP, 1);
2484 HC_LOAD_FUNC_HIP (hip, hipDriverGetVersion, hipDriverGetVersion, HIP_HIPDRIVERGETVERSION, HIP, 1);
2485 HC_LOAD_FUNC_HIP (hip, hipEventCreate, hipEventCreateWithFlags, HIP_HIPEVENTCREATE, HIP, 1);
2486 HC_LOAD_FUNC_HIP (hip, hipEventDestroy, hipEventDestroy, HIP_HIPEVENTDESTROY, HIP, 1);
2487 HC_LOAD_FUNC_HIP (hip, hipEventElapsedTime, hipEventElapsedTime, HIP_HIPEVENTELAPSEDTIME, HIP, 1);
2488 HC_LOAD_FUNC_HIP (hip, hipEventRecord, hipEventRecord, HIP_HIPEVENTRECORD, HIP, 1);
2489 HC_LOAD_FUNC_HIP (hip, hipEventSynchronize, hipEventSynchronize, HIP_HIPEVENTSYNCHRONIZE, HIP, 1);
2490 HC_LOAD_FUNC_HIP (hip, hipFuncGetAttribute, hipFuncGetAttribute, HIP_HIPFUNCGETATTRIBUTE, HIP, 1);
2491 HC_LOAD_FUNC_HIP (hip, hipGetErrorName, hipGetErrorName, HIP_HIPGETERRORNAME, HIP, 1);
2492 HC_LOAD_FUNC_HIP (hip, hipGetErrorString, hipGetErrorString, HIP_HIPGETERRORSTRING, HIP, 1);
2493 HC_LOAD_FUNC_HIP (hip, hipInit, hipInit, HIP_HIPINIT, HIP, 1);
2494 HC_LOAD_FUNC_HIP (hip, hipLaunchKernel, hipModuleLaunchKernel, HIP_HIPLAUNCHKERNEL, HIP, 1);
2495 HC_LOAD_FUNC_HIP (hip, hipMemAlloc, hipMalloc, HIP_HIPMEMALLOC, HIP, 1);
2496 HC_LOAD_FUNC_HIP (hip, hipMemFree, hipFree, HIP_HIPMEMFREE, HIP, 1);
2497 HC_LOAD_FUNC_HIP (hip, hipMemGetInfo, hipMemGetInfo, HIP_HIPMEMGETINFO, HIP, 1);
2498 HC_LOAD_FUNC_HIP (hip, hipMemcpyDtoDAsync, hipMemcpyDtoDAsync, HIP_HIPMEMCPYDTODASYNC, HIP, 1);
2499 HC_LOAD_FUNC_HIP (hip, hipMemcpyDtoHAsync, hipMemcpyDtoHAsync, HIP_HIPMEMCPYDTOHASYNC, HIP, 1);
2500 HC_LOAD_FUNC_HIP (hip, hipMemcpyHtoDAsync, hipMemcpyHtoDAsync, HIP_HIPMEMCPYHTODASYNC, HIP, 1);
2501 HC_LOAD_FUNC_HIP (hip, hipMemsetD32Async, hipMemsetD32Async, HIP_HIPMEMSETD32ASYNC, HIP, 1);
2502 HC_LOAD_FUNC_HIP (hip, hipMemsetD8Async, hipMemsetD8Async, HIP_HIPMEMSETD8ASYNC, HIP, 1);
2503 HC_LOAD_FUNC_HIP (hip, hipMemcpyHtoDAsync, hipMemcpyHtoDAsync, HIP_HIPMEMCPYHTODASYNC, HIP, 1);
2504 HC_LOAD_FUNC_HIP (hip, hipModuleGetFunction, hipModuleGetFunction, HIP_HIPMODULEGETFUNCTION, HIP, 1);
2505 HC_LOAD_FUNC_HIP (hip, hipModuleGetGlobal, hipModuleGetGlobal, HIP_HIPMODULEGETGLOBAL, HIP, 1);
2506 HC_LOAD_FUNC_HIP (hip, hipModuleLoadDataEx, hipModuleLoadDataEx, HIP_HIPMODULELOADDATAEX, HIP, 1);
2507 HC_LOAD_FUNC_HIP (hip, hipModuleUnload, hipModuleUnload, HIP_HIPMODULEUNLOAD, HIP, 1);
2508 HC_LOAD_FUNC_HIP (hip, hipRuntimeGetVersion, hipRuntimeGetVersion, HIP_HIPRUNTIMEGETVERSION, HIP, 1);
2509 HC_LOAD_FUNC_HIP (hip, hipStreamCreate, hipStreamCreate, HIP_HIPSTREAMCREATE, HIP, 1);
2510 HC_LOAD_FUNC_HIP (hip, hipStreamDestroy, hipStreamDestroy, HIP_HIPSTREAMDESTROY, HIP, 1);
2511 HC_LOAD_FUNC_HIP (hip, hipStreamSynchronize, hipStreamSynchronize, HIP_HIPSTREAMSYNCHRONIZE, HIP, 1);
2512
2513 return 0;
2514 }
2515
hip_close(hashcat_ctx_t * hashcat_ctx)2516 void hip_close (hashcat_ctx_t *hashcat_ctx)
2517 {
2518 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2519
2520 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
2521
2522 if (hip)
2523 {
2524 if (hip->lib)
2525 {
2526 hc_dlclose (hip->lib);
2527 }
2528
2529 hcfree (backend_ctx->hip);
2530
2531 backend_ctx->hip = NULL;
2532 }
2533 }
2534
hc_hipCtxCreate(hashcat_ctx_t * hashcat_ctx,hipCtx_t * pctx,unsigned int flags,hipDevice_t dev)2535 int hc_hipCtxCreate (hashcat_ctx_t *hashcat_ctx, hipCtx_t *pctx, unsigned int flags, hipDevice_t dev)
2536 {
2537 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2538
2539 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
2540
2541 const hipError_t HIP_err = hip->hipCtxCreate (pctx, flags, dev);
2542
2543 if (HIP_err != hipSuccess)
2544 {
2545 const char *pStr = NULL;
2546
2547 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
2548 {
2549 event_log_error (hashcat_ctx, "hipCtxCreate(): %s", pStr);
2550 }
2551 else
2552 {
2553 event_log_error (hashcat_ctx, "hipCtxCreate(): %d", HIP_err);
2554 }
2555
2556 return -1;
2557 }
2558
2559 return 0;
2560 }
2561
hc_hipCtxDestroy(hashcat_ctx_t * hashcat_ctx,hipCtx_t ctx)2562 int hc_hipCtxDestroy (hashcat_ctx_t *hashcat_ctx, hipCtx_t ctx)
2563 {
2564 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2565
2566 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
2567
2568 const hipError_t HIP_err = hip->hipCtxDestroy (ctx);
2569
2570 if (HIP_err != hipSuccess)
2571 {
2572 const char *pStr = NULL;
2573
2574 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
2575 {
2576 event_log_error (hashcat_ctx, "hipCtxDestroy(): %s", pStr);
2577 }
2578 else
2579 {
2580 event_log_error (hashcat_ctx, "hipCtxDestroy(): %d", HIP_err);
2581 }
2582
2583 return -1;
2584 }
2585
2586 return 0;
2587 }
2588
hc_hipCtxPopCurrent(hashcat_ctx_t * hashcat_ctx,hipCtx_t * pctx)2589 int hc_hipCtxPopCurrent (hashcat_ctx_t *hashcat_ctx, hipCtx_t *pctx)
2590 {
2591 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2592
2593 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
2594
2595 const hipError_t HIP_err = hip->hipCtxPopCurrent (pctx);
2596
2597 if (HIP_err != hipSuccess)
2598 {
2599 const char *pStr = NULL;
2600
2601 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
2602 {
2603 event_log_error (hashcat_ctx, "hipCtxPopCurrent(): %s", pStr);
2604 }
2605 else
2606 {
2607 event_log_error (hashcat_ctx, "hipCtxPopCurrent(): %d", HIP_err);
2608 }
2609
2610 return -1;
2611 }
2612
2613 return 0;
2614 }
2615
hc_hipCtxPushCurrent(hashcat_ctx_t * hashcat_ctx,hipCtx_t ctx)2616 int hc_hipCtxPushCurrent (hashcat_ctx_t *hashcat_ctx, hipCtx_t ctx)
2617 {
2618 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2619
2620 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
2621
2622 const hipError_t HIP_err = hip->hipCtxPushCurrent (ctx);
2623
2624 if (HIP_err != hipSuccess)
2625 {
2626 const char *pStr = NULL;
2627
2628 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
2629 {
2630 event_log_error (hashcat_ctx, "hipCtxPushCurrent(): %s", pStr);
2631 }
2632 else
2633 {
2634 event_log_error (hashcat_ctx, "hipCtxPushCurrent(): %d", HIP_err);
2635 }
2636
2637 return -1;
2638 }
2639
2640 return 0;
2641 }
2642
hc_hipCtxSetCurrent(hashcat_ctx_t * hashcat_ctx,hipCtx_t ctx)2643 int hc_hipCtxSetCurrent (hashcat_ctx_t *hashcat_ctx, hipCtx_t ctx)
2644 {
2645 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2646
2647 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
2648
2649 const hipError_t HIP_err = hip->hipCtxSetCurrent (ctx);
2650
2651 if (HIP_err != hipSuccess)
2652 {
2653 const char *pStr = NULL;
2654
2655 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
2656 {
2657 event_log_error (hashcat_ctx, "hipCtxSetCurrent(): %s", pStr);
2658 }
2659 else
2660 {
2661 event_log_error (hashcat_ctx, "hipCtxSetCurrent(): %d", HIP_err);
2662 }
2663
2664 return -1;
2665 }
2666
2667 return 0;
2668 }
2669
hc_hipCtxSynchronize(hashcat_ctx_t * hashcat_ctx)2670 int hc_hipCtxSynchronize (hashcat_ctx_t *hashcat_ctx)
2671 {
2672 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2673
2674 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
2675
2676 const hipError_t HIP_err = hip->hipCtxSynchronize ();
2677
2678 if (HIP_err != hipSuccess)
2679 {
2680 const char *pStr = NULL;
2681
2682 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
2683 {
2684 event_log_error (hashcat_ctx, "hipCtxSynchronize(): %s", pStr);
2685 }
2686 else
2687 {
2688 event_log_error (hashcat_ctx, "hipCtxSynchronize(): %d", HIP_err);
2689 }
2690
2691 return -1;
2692 }
2693
2694 return 0;
2695 }
2696
hc_hipDeviceGet(hashcat_ctx_t * hashcat_ctx,hipDevice_t * device,int ordinal)2697 int hc_hipDeviceGet (hashcat_ctx_t *hashcat_ctx, hipDevice_t* device, int ordinal)
2698 {
2699 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2700
2701 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
2702
2703 const hipError_t HIP_err = hip->hipDeviceGet (device, ordinal);
2704
2705 if (HIP_err != hipSuccess)
2706 {
2707 const char *pStr = NULL;
2708
2709 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
2710 {
2711 event_log_error (hashcat_ctx, "hipDeviceGet(): %s", pStr);
2712 }
2713 else
2714 {
2715 event_log_error (hashcat_ctx, "hipDeviceGet(): %d", HIP_err);
2716 }
2717
2718 return -1;
2719 }
2720
2721 return 0;
2722 }
2723
hc_hipDeviceGetAttribute(hashcat_ctx_t * hashcat_ctx,int * pi,hipDeviceAttribute_t attrib,hipDevice_t dev)2724 int hc_hipDeviceGetAttribute (hashcat_ctx_t *hashcat_ctx, int *pi, hipDeviceAttribute_t attrib, hipDevice_t dev)
2725 {
2726 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2727
2728 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
2729
2730 const hipError_t HIP_err = hip->hipDeviceGetAttribute (pi, attrib, dev);
2731
2732 if (HIP_err != hipSuccess)
2733 {
2734 const char *pStr = NULL;
2735
2736 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
2737 {
2738 event_log_error (hashcat_ctx, "hipDeviceGetAttribute(): %s", pStr);
2739 }
2740 else
2741 {
2742 event_log_error (hashcat_ctx, "hipDeviceGetAttribute(): %d", HIP_err);
2743 }
2744
2745 return -1;
2746 }
2747
2748 return 0;
2749 }
2750
hc_hipDeviceGetCount(hashcat_ctx_t * hashcat_ctx,int * count)2751 int hc_hipDeviceGetCount (hashcat_ctx_t *hashcat_ctx, int *count)
2752 {
2753 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2754
2755 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
2756
2757 const hipError_t HIP_err = hip->hipDeviceGetCount (count);
2758
2759 if (HIP_err != hipSuccess)
2760 {
2761 const char *pStr = NULL;
2762
2763 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
2764 {
2765 event_log_error (hashcat_ctx, "hipDeviceGetCount(): %s", pStr);
2766 }
2767 else
2768 {
2769 event_log_error (hashcat_ctx, "hipDeviceGetCount(): %d", HIP_err);
2770 }
2771
2772 return -1;
2773 }
2774
2775 return 0;
2776 }
2777
hc_hipDeviceGetName(hashcat_ctx_t * hashcat_ctx,char * name,int len,hipDevice_t dev)2778 int hc_hipDeviceGetName (hashcat_ctx_t *hashcat_ctx, char *name, int len, hipDevice_t dev)
2779 {
2780 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2781
2782 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
2783
2784 const hipError_t HIP_err = hip->hipDeviceGetName (name, len, dev);
2785
2786 if (HIP_err != hipSuccess)
2787 {
2788 const char *pStr = NULL;
2789
2790 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
2791 {
2792 event_log_error (hashcat_ctx, "hipDeviceGetName(): %s", pStr);
2793 }
2794 else
2795 {
2796 event_log_error (hashcat_ctx, "hipDeviceGetName(): %d", HIP_err);
2797 }
2798
2799 return -1;
2800 }
2801
2802 return 0;
2803 }
2804
hc_hipDeviceTotalMem(hashcat_ctx_t * hashcat_ctx,size_t * bytes,hipDevice_t dev)2805 int hc_hipDeviceTotalMem (hashcat_ctx_t *hashcat_ctx, size_t *bytes, hipDevice_t dev)
2806 {
2807 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2808
2809 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
2810
2811 const hipError_t HIP_err = hip->hipDeviceTotalMem (bytes, dev);
2812
2813 if (HIP_err != hipSuccess)
2814 {
2815 const char *pStr = NULL;
2816
2817 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
2818 {
2819 event_log_error (hashcat_ctx, "hipDeviceTotalMem(): %s", pStr);
2820 }
2821 else
2822 {
2823 event_log_error (hashcat_ctx, "hipDeviceTotalMem(): %d", HIP_err);
2824 }
2825
2826 return -1;
2827 }
2828
2829 return 0;
2830 }
2831
hc_hipDriverGetVersion(hashcat_ctx_t * hashcat_ctx,int * driverVersion)2832 int hc_hipDriverGetVersion (hashcat_ctx_t *hashcat_ctx, int *driverVersion)
2833 {
2834 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2835
2836 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
2837
2838 const hipError_t HIP_err = hip->hipDriverGetVersion (driverVersion);
2839
2840 if (HIP_err != hipSuccess)
2841 {
2842 const char *pStr = NULL;
2843
2844 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
2845 {
2846 event_log_error (hashcat_ctx, "hipDriverGetVersion(): %s", pStr);
2847 }
2848 else
2849 {
2850 event_log_error (hashcat_ctx, "hipDriverGetVersion(): %d", HIP_err);
2851 }
2852
2853 return -1;
2854 }
2855
2856 return 0;
2857 }
2858
hc_hipEventCreate(hashcat_ctx_t * hashcat_ctx,hipEvent_t * phEvent,unsigned int Flags)2859 int hc_hipEventCreate (hashcat_ctx_t *hashcat_ctx, hipEvent_t *phEvent, unsigned int Flags)
2860 {
2861 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2862
2863 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
2864
2865 const hipError_t HIP_err = hip->hipEventCreate (phEvent, Flags);
2866
2867 if (HIP_err != hipSuccess)
2868 {
2869 const char *pStr = NULL;
2870
2871 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
2872 {
2873 event_log_error (hashcat_ctx, "hipEventCreate(): %s", pStr);
2874 }
2875 else
2876 {
2877 event_log_error (hashcat_ctx, "hipEventCreate(): %d", HIP_err);
2878 }
2879
2880 return -1;
2881 }
2882
2883 return 0;
2884 }
2885
hc_hipEventDestroy(hashcat_ctx_t * hashcat_ctx,hipEvent_t hEvent)2886 int hc_hipEventDestroy (hashcat_ctx_t *hashcat_ctx, hipEvent_t hEvent)
2887 {
2888 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2889
2890 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
2891
2892 const hipError_t HIP_err = hip->hipEventDestroy (hEvent);
2893
2894 if (HIP_err != hipSuccess)
2895 {
2896 const char *pStr = NULL;
2897
2898 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
2899 {
2900 event_log_error (hashcat_ctx, "hipEventDestroy(): %s", pStr);
2901 }
2902 else
2903 {
2904 event_log_error (hashcat_ctx, "hipEventDestroy(): %d", HIP_err);
2905 }
2906
2907 return -1;
2908 }
2909
2910 return 0;
2911 }
2912
hc_hipEventElapsedTime(hashcat_ctx_t * hashcat_ctx,float * pMilliseconds,hipEvent_t hStart,hipEvent_t hEnd)2913 int hc_hipEventElapsedTime (hashcat_ctx_t *hashcat_ctx, float *pMilliseconds, hipEvent_t hStart, hipEvent_t hEnd)
2914 {
2915 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2916
2917 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
2918
2919 const hipError_t HIP_err = hip->hipEventElapsedTime (pMilliseconds, hStart, hEnd);
2920
2921 if (HIP_err != hipSuccess)
2922 {
2923 const char *pStr = NULL;
2924
2925 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
2926 {
2927 event_log_error (hashcat_ctx, "hipEventElapsedTime(): %s", pStr);
2928 }
2929 else
2930 {
2931 event_log_error (hashcat_ctx, "hipEventElapsedTime(): %d", HIP_err);
2932 }
2933
2934 return -1;
2935 }
2936
2937 return 0;
2938 }
2939
hc_hipEventRecord(hashcat_ctx_t * hashcat_ctx,hipEvent_t hEvent,hipStream_t hStream)2940 int hc_hipEventRecord (hashcat_ctx_t *hashcat_ctx, hipEvent_t hEvent, hipStream_t hStream)
2941 {
2942 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2943
2944 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
2945
2946 const hipError_t HIP_err = hip->hipEventRecord (hEvent, hStream);
2947
2948 if (HIP_err != hipSuccess)
2949 {
2950 const char *pStr = NULL;
2951
2952 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
2953 {
2954 event_log_error (hashcat_ctx, "hipEventRecord(): %s", pStr);
2955 }
2956 else
2957 {
2958 event_log_error (hashcat_ctx, "hipEventRecord(): %d", HIP_err);
2959 }
2960
2961 return -1;
2962 }
2963
2964 return 0;
2965 }
2966
hc_hipEventSynchronize(hashcat_ctx_t * hashcat_ctx,hipEvent_t hEvent)2967 int hc_hipEventSynchronize (hashcat_ctx_t *hashcat_ctx, hipEvent_t hEvent)
2968 {
2969 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2970
2971 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
2972
2973 const hipError_t HIP_err = hip->hipEventSynchronize (hEvent);
2974
2975 if (HIP_err != hipSuccess)
2976 {
2977 const char *pStr = NULL;
2978
2979 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
2980 {
2981 event_log_error (hashcat_ctx, "hipEventSynchronize(): %s", pStr);
2982 }
2983 else
2984 {
2985 event_log_error (hashcat_ctx, "hipEventSynchronize(): %d", HIP_err);
2986 }
2987
2988 return -1;
2989 }
2990
2991 return 0;
2992 }
2993
hc_hipFuncGetAttribute(hashcat_ctx_t * hashcat_ctx,int * pi,hipFunction_attribute attrib,hipFunction_t hfunc)2994 int hc_hipFuncGetAttribute (hashcat_ctx_t *hashcat_ctx, int *pi, hipFunction_attribute attrib, hipFunction_t hfunc)
2995 {
2996 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2997
2998 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
2999
3000 const hipError_t HIP_err = hip->hipFuncGetAttribute (pi, attrib, hfunc);
3001
3002 if (HIP_err != hipSuccess)
3003 {
3004 const char *pStr = NULL;
3005
3006 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
3007 {
3008 event_log_error (hashcat_ctx, "hipFuncGetAttribute(): %s", pStr);
3009 }
3010 else
3011 {
3012 event_log_error (hashcat_ctx, "hipFuncGetAttribute(): %d", HIP_err);
3013 }
3014
3015 return -1;
3016 }
3017
3018 return 0;
3019 }
3020
hc_hipLaunchKernel(hashcat_ctx_t * hashcat_ctx,hipFunction_t f,unsigned int gridDimX,unsigned int gridDimY,unsigned int gridDimZ,unsigned int blockDimX,unsigned int blockDimY,unsigned int blockDimZ,unsigned int sharedMemBytes,hipStream_t hStream,void ** kernelParams,void ** extra)3021 int hc_hipLaunchKernel (hashcat_ctx_t *hashcat_ctx, hipFunction_t f, unsigned int gridDimX, unsigned int gridDimY, unsigned int gridDimZ, unsigned int blockDimX, unsigned int blockDimY, unsigned int blockDimZ, unsigned int sharedMemBytes, hipStream_t hStream, void **kernelParams, void **extra)
3022 {
3023 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3024
3025 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
3026
3027 const hipError_t HIP_err = hip->hipLaunchKernel (f, gridDimX, gridDimY, gridDimZ, blockDimX, blockDimY, blockDimZ, sharedMemBytes, hStream, kernelParams, extra);
3028
3029 if (HIP_err != hipSuccess)
3030 {
3031 const char *pStr = NULL;
3032
3033 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
3034 {
3035 event_log_error (hashcat_ctx, "hipLaunchKernel(): %s", pStr);
3036 }
3037 else
3038 {
3039 event_log_error (hashcat_ctx, "hipLaunchKernel(): %d", HIP_err);
3040 }
3041
3042 return -1;
3043 }
3044
3045 return 0;
3046 }
3047
hc_hipInit(hashcat_ctx_t * hashcat_ctx,unsigned int Flags)3048 int hc_hipInit (hashcat_ctx_t *hashcat_ctx, unsigned int Flags)
3049 {
3050 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3051
3052 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
3053
3054 const hipError_t HIP_err = hip->hipInit (Flags);
3055
3056 if (HIP_err != hipSuccess)
3057 {
3058 const char *pStr = NULL;
3059
3060 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
3061 {
3062 event_log_error (hashcat_ctx, "hipInit(): %s", pStr);
3063 }
3064 else
3065 {
3066 event_log_error (hashcat_ctx, "hipInit(): %d", HIP_err);
3067 }
3068
3069 return -1;
3070 }
3071
3072 return 0;
3073 }
3074
hc_hipMemAlloc(hashcat_ctx_t * hashcat_ctx,hipDeviceptr_t * dptr,size_t bytesize)3075 int hc_hipMemAlloc (hashcat_ctx_t *hashcat_ctx, hipDeviceptr_t *dptr, size_t bytesize)
3076 {
3077 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3078
3079 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
3080
3081 const hipError_t HIP_err = hip->hipMemAlloc (dptr, bytesize);
3082
3083 if (HIP_err != hipSuccess)
3084 {
3085 const char *pStr = NULL;
3086
3087 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
3088 {
3089 event_log_error (hashcat_ctx, "hipMemAlloc(): %s", pStr);
3090 }
3091 else
3092 {
3093 event_log_error (hashcat_ctx, "hipMemAlloc(): %d", HIP_err);
3094 }
3095
3096 return -1;
3097 }
3098
3099 return 0;
3100 }
3101
hc_hipMemFree(hashcat_ctx_t * hashcat_ctx,hipDeviceptr_t dptr)3102 int hc_hipMemFree (hashcat_ctx_t *hashcat_ctx, hipDeviceptr_t dptr)
3103 {
3104 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3105
3106 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
3107
3108 const hipError_t HIP_err = hip->hipMemFree (dptr);
3109
3110 if (HIP_err != hipSuccess)
3111 {
3112 const char *pStr = NULL;
3113
3114 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
3115 {
3116 event_log_error (hashcat_ctx, "hipMemFree(): %s", pStr);
3117 }
3118 else
3119 {
3120 event_log_error (hashcat_ctx, "hipMemFree(): %d", HIP_err);
3121 }
3122
3123 return -1;
3124 }
3125
3126 return 0;
3127 }
3128
hc_hipMemGetInfo(hashcat_ctx_t * hashcat_ctx,size_t * free,size_t * total)3129 int hc_hipMemGetInfo (hashcat_ctx_t *hashcat_ctx, size_t *free, size_t *total)
3130 {
3131 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3132
3133 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
3134
3135 const hipError_t HIP_err = hip->hipMemGetInfo (free, total);
3136
3137 if (HIP_err != hipSuccess)
3138 {
3139 const char *pStr = NULL;
3140
3141 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
3142 {
3143 event_log_error (hashcat_ctx, "hipMemGetInfo(): %s", pStr);
3144 }
3145 else
3146 {
3147 event_log_error (hashcat_ctx, "hipMemGetInfo(): %d", HIP_err);
3148 }
3149
3150 return -1;
3151 }
3152
3153 return 0;
3154 }
3155
hc_hipMemcpyDtoHAsync(hashcat_ctx_t * hashcat_ctx,void * dstHost,hipDeviceptr_t srcDevice,size_t ByteCount,hipStream_t hStream)3156 int hc_hipMemcpyDtoHAsync (hashcat_ctx_t *hashcat_ctx, void *dstHost, hipDeviceptr_t srcDevice, size_t ByteCount, hipStream_t hStream)
3157 {
3158 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3159
3160 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
3161
3162 const hipError_t HIP_err = hip->hipMemcpyDtoHAsync (dstHost, srcDevice, ByteCount, hStream);
3163
3164 if (HIP_err != hipSuccess)
3165 {
3166 const char *pStr = NULL;
3167
3168 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
3169 {
3170 event_log_error (hashcat_ctx, "hipMemcpyDtoHAsync(): %s", pStr);
3171 }
3172 else
3173 {
3174 event_log_error (hashcat_ctx, "hipMemcpyDtoHAsync(): %d", HIP_err);
3175 }
3176
3177 return -1;
3178 }
3179
3180 return 0;
3181 }
3182
hc_hipMemcpyDtoDAsync(hashcat_ctx_t * hashcat_ctx,hipDeviceptr_t dstDevice,hipDeviceptr_t srcDevice,size_t ByteCount,hipStream_t hStream)3183 int hc_hipMemcpyDtoDAsync (hashcat_ctx_t *hashcat_ctx, hipDeviceptr_t dstDevice, hipDeviceptr_t srcDevice, size_t ByteCount, hipStream_t hStream)
3184 {
3185 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3186
3187 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
3188
3189 const hipError_t HIP_err = hip->hipMemcpyDtoDAsync (dstDevice, srcDevice, ByteCount, hStream);
3190
3191 if (HIP_err != hipSuccess)
3192 {
3193 const char *pStr = NULL;
3194
3195 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
3196 {
3197 event_log_error (hashcat_ctx, "hipMemcpyDtoDAsync(): %s", pStr);
3198 }
3199 else
3200 {
3201 event_log_error (hashcat_ctx, "hipMemcpyDtoDAsync(): %d", HIP_err);
3202 }
3203
3204 return -1;
3205 }
3206
3207 return 0;
3208 }
3209
hc_hipMemcpyHtoDAsync(hashcat_ctx_t * hashcat_ctx,hipDeviceptr_t dstDevice,const void * srcHost,size_t ByteCount,hipStream_t hStream)3210 int hc_hipMemcpyHtoDAsync (hashcat_ctx_t *hashcat_ctx, hipDeviceptr_t dstDevice, const void *srcHost, size_t ByteCount, hipStream_t hStream)
3211 {
3212 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3213
3214 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
3215
3216 const hipError_t HIP_err = hip->hipMemcpyHtoDAsync (dstDevice, srcHost, ByteCount, hStream);
3217
3218 if (HIP_err != hipSuccess)
3219 {
3220 const char *pStr = NULL;
3221
3222 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
3223 {
3224 event_log_error (hashcat_ctx, "hipMemcpyHtoDAsync(): %s", pStr);
3225 }
3226 else
3227 {
3228 event_log_error (hashcat_ctx, "hipMemcpyHtoDAsync(): %d", HIP_err);
3229 }
3230
3231 return -1;
3232 }
3233
3234 return 0;
3235 }
3236
hc_hipMemsetD32Async(hashcat_ctx_t * hashcat_ctx,hipDeviceptr_t dstDevice,unsigned int ui,size_t N,hipStream_t hStream)3237 int hc_hipMemsetD32Async (hashcat_ctx_t *hashcat_ctx, hipDeviceptr_t dstDevice, unsigned int ui, size_t N, hipStream_t hStream)
3238 {
3239 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3240
3241 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
3242
3243 const hipError_t HIP_err = hip->hipMemsetD32Async (dstDevice, ui, N, hStream);
3244
3245 if (HIP_err != hipSuccess)
3246 {
3247 const char *pStr = NULL;
3248
3249 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
3250 {
3251 event_log_error (hashcat_ctx, "hipMemsetD32Async(): %s", pStr);
3252 }
3253 else
3254 {
3255 event_log_error (hashcat_ctx, "hipMemsetD32Async(): %d", HIP_err);
3256 }
3257
3258 return -1;
3259 }
3260
3261 return 0;
3262 }
3263
hc_hipMemsetD8Async(hashcat_ctx_t * hashcat_ctx,hipDeviceptr_t dstDevice,unsigned char uc,size_t N,hipStream_t hStream)3264 int hc_hipMemsetD8Async (hashcat_ctx_t *hashcat_ctx, hipDeviceptr_t dstDevice, unsigned char uc, size_t N, hipStream_t hStream)
3265 {
3266 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3267
3268 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
3269
3270 const hipError_t HIP_err = hip->hipMemsetD8Async (dstDevice, uc, N, hStream);
3271
3272 if (HIP_err != hipSuccess)
3273 {
3274 const char *pStr = NULL;
3275
3276 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
3277 {
3278 event_log_error (hashcat_ctx, "hipMemsetD8Async(): %s", pStr);
3279 }
3280 else
3281 {
3282 event_log_error (hashcat_ctx, "hipMemsetD8Async(): %d", HIP_err);
3283 }
3284
3285 return -1;
3286 }
3287
3288 return 0;
3289 }
3290
hc_hipModuleGetFunction(hashcat_ctx_t * hashcat_ctx,hipFunction_t * hfunc,hipModule_t hmod,const char * name)3291 int hc_hipModuleGetFunction (hashcat_ctx_t *hashcat_ctx, hipFunction_t *hfunc, hipModule_t hmod, const char *name)
3292 {
3293 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3294
3295 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
3296
3297 const hipError_t HIP_err = hip->hipModuleGetFunction (hfunc, hmod, name);
3298
3299 if (HIP_err != hipSuccess)
3300 {
3301 const char *pStr = NULL;
3302
3303 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
3304 {
3305 event_log_error (hashcat_ctx, "hipModuleGetFunction(): %s", pStr);
3306 }
3307 else
3308 {
3309 event_log_error (hashcat_ctx, "hipModuleGetFunction(): %d", HIP_err);
3310 }
3311
3312 return -1;
3313 }
3314
3315 return 0;
3316 }
3317
hc_hipModuleGetGlobal(hashcat_ctx_t * hashcat_ctx,hipDeviceptr_t * dptr,size_t * bytes,hipModule_t hmod,const char * name)3318 int hc_hipModuleGetGlobal (hashcat_ctx_t *hashcat_ctx, hipDeviceptr_t *dptr, size_t *bytes, hipModule_t hmod, const char *name)
3319 {
3320 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3321
3322 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
3323
3324 const hipError_t HIP_err = hip->hipModuleGetGlobal (dptr, bytes, hmod, name);
3325
3326 if (HIP_err != hipSuccess)
3327 {
3328 const char *pStr = NULL;
3329
3330 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
3331 {
3332 event_log_error (hashcat_ctx, "hipModuleGetGlobal(): %s", pStr);
3333 }
3334 else
3335 {
3336 event_log_error (hashcat_ctx, "hipModuleGetGlobal(): %d", HIP_err);
3337 }
3338
3339 return -1;
3340 }
3341
3342 return 0;
3343 }
3344
hc_hipModuleLoadDataEx(hashcat_ctx_t * hashcat_ctx,hipModule_t * module,const void * image,unsigned int numOptions,hipJitOption * options,void ** optionValues)3345 int hc_hipModuleLoadDataEx (hashcat_ctx_t *hashcat_ctx, hipModule_t *module, const void *image, unsigned int numOptions, hipJitOption *options, void **optionValues)
3346 {
3347 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3348
3349 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
3350
3351 const hipError_t HIP_err = hip->hipModuleLoadDataEx (module, image, numOptions, options, optionValues);
3352
3353 if (HIP_err != hipSuccess)
3354 {
3355 const char *pStr = NULL;
3356
3357 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
3358 {
3359 event_log_error (hashcat_ctx, "hipModuleLoadDataEx(): %s", pStr);
3360 }
3361 else
3362 {
3363 event_log_error (hashcat_ctx, "hipModuleLoadDataEx(): %d", HIP_err);
3364 }
3365
3366 return -1;
3367 }
3368
3369 return 0;
3370 }
3371
hc_hipModuleUnload(hashcat_ctx_t * hashcat_ctx,hipModule_t hmod)3372 int hc_hipModuleUnload (hashcat_ctx_t *hashcat_ctx, hipModule_t hmod)
3373 {
3374 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3375
3376 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
3377
3378 const hipError_t HIP_err = hip->hipModuleUnload (hmod);
3379
3380 if (HIP_err != hipSuccess)
3381 {
3382 const char *pStr = NULL;
3383
3384 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
3385 {
3386 event_log_error (hashcat_ctx, "hipModuleUnload(): %s", pStr);
3387 }
3388 else
3389 {
3390 event_log_error (hashcat_ctx, "hipModuleUnload(): %d", HIP_err);
3391 }
3392
3393 return -1;
3394 }
3395
3396 return 0;
3397 }
3398
hc_hipRuntimeGetVersion(hashcat_ctx_t * hashcat_ctx,int * runtimeVersion)3399 int hc_hipRuntimeGetVersion (hashcat_ctx_t *hashcat_ctx, int *runtimeVersion)
3400 {
3401 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3402
3403 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
3404
3405 const hipError_t HIP_err = hip->hipRuntimeGetVersion (runtimeVersion);
3406
3407 if (HIP_err != hipSuccess)
3408 {
3409 const char *pStr = NULL;
3410
3411 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
3412 {
3413 event_log_error (hashcat_ctx, "hipRuntimeGetVersion(): %s", pStr);
3414 }
3415 else
3416 {
3417 event_log_error (hashcat_ctx, "hipRuntimeGetVersion(): %d", HIP_err);
3418 }
3419
3420 return -1;
3421 }
3422
3423 return 0;
3424 }
3425
hc_hipStreamCreate(hashcat_ctx_t * hashcat_ctx,hipStream_t * phStream,unsigned int Flags)3426 int hc_hipStreamCreate (hashcat_ctx_t *hashcat_ctx, hipStream_t *phStream, unsigned int Flags)
3427 {
3428 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3429
3430 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
3431
3432 const hipError_t HIP_err = hip->hipStreamCreate (phStream, Flags);
3433
3434 if (HIP_err != hipSuccess)
3435 {
3436 const char *pStr = NULL;
3437
3438 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
3439 {
3440 event_log_error (hashcat_ctx, "hipStreamCreate(): %s", pStr);
3441 }
3442 else
3443 {
3444 event_log_error (hashcat_ctx, "hipStreamCreate(): %d", HIP_err);
3445 }
3446
3447 return -1;
3448 }
3449
3450 return 0;
3451 }
3452
hc_hipStreamDestroy(hashcat_ctx_t * hashcat_ctx,hipStream_t hStream)3453 int hc_hipStreamDestroy (hashcat_ctx_t *hashcat_ctx, hipStream_t hStream)
3454 {
3455 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3456
3457 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
3458
3459 const hipError_t HIP_err = hip->hipStreamDestroy (hStream);
3460
3461 if (HIP_err != hipSuccess)
3462 {
3463 const char *pStr = NULL;
3464
3465 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
3466 {
3467 event_log_error (hashcat_ctx, "hipStreamDestroy(): %s", pStr);
3468 }
3469 else
3470 {
3471 event_log_error (hashcat_ctx, "hipStreamDestroy(): %d", HIP_err);
3472 }
3473
3474 return -1;
3475 }
3476
3477 return 0;
3478 }
3479
hc_hipStreamSynchronize(hashcat_ctx_t * hashcat_ctx,hipStream_t hStream)3480 int hc_hipStreamSynchronize (hashcat_ctx_t *hashcat_ctx, hipStream_t hStream)
3481 {
3482 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3483
3484 HIP_PTR *hip = (HIP_PTR *) backend_ctx->hip;
3485
3486 const hipError_t HIP_err = hip->hipStreamSynchronize (hStream);
3487
3488 if (HIP_err != hipSuccess)
3489 {
3490 const char *pStr = NULL;
3491
3492 if (hip->hipGetErrorString (HIP_err, &pStr) == hipSuccess)
3493 {
3494 event_log_error (hashcat_ctx, "hipStreamSynchronize(): %s", pStr);
3495 }
3496 else
3497 {
3498 event_log_error (hashcat_ctx, "hipStreamSynchronize(): %d", HIP_err);
3499 }
3500
3501 return -1;
3502 }
3503
3504 return 0;
3505 }
3506
3507 // OpenCL
3508
ocl_init(hashcat_ctx_t * hashcat_ctx)3509 int ocl_init (hashcat_ctx_t *hashcat_ctx)
3510 {
3511 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3512
3513 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
3514
3515 memset (ocl, 0, sizeof (OCL_PTR));
3516
3517 #if defined (_WIN)
3518 ocl->lib = hc_dlopen ("OpenCL");
3519 #elif defined (__APPLE__)
3520 ocl->lib = hc_dlopen ("/System/Library/Frameworks/OpenCL.framework/OpenCL");
3521 #elif defined (__CYGWIN__)
3522 ocl->lib = hc_dlopen ("opencl.dll");
3523
3524 if (ocl->lib == NULL) ocl->lib = hc_dlopen ("cygOpenCL-1.dll");
3525 #else
3526 ocl->lib = hc_dlopen ("libOpenCL.so");
3527
3528 if (ocl->lib == NULL) ocl->lib = hc_dlopen ("libOpenCL.so.1");
3529 #endif
3530
3531 if (ocl->lib == NULL) return -1;
3532
3533 HC_LOAD_FUNC (ocl, clBuildProgram, OCL_CLBUILDPROGRAM, OpenCL, 1);
3534 HC_LOAD_FUNC (ocl, clCompileProgram, OCL_CLCOMPILEPROGRAM, OpenCL, 1);
3535 HC_LOAD_FUNC (ocl, clCreateBuffer, OCL_CLCREATEBUFFER, OpenCL, 1);
3536 HC_LOAD_FUNC (ocl, clCreateCommandQueue, OCL_CLCREATECOMMANDQUEUE, OpenCL, 1);
3537 HC_LOAD_FUNC (ocl, clCreateContext, OCL_CLCREATECONTEXT, OpenCL, 1);
3538 HC_LOAD_FUNC (ocl, clCreateKernel, OCL_CLCREATEKERNEL, OpenCL, 1);
3539 HC_LOAD_FUNC (ocl, clCreateProgramWithBinary, OCL_CLCREATEPROGRAMWITHBINARY, OpenCL, 1);
3540 HC_LOAD_FUNC (ocl, clCreateProgramWithSource, OCL_CLCREATEPROGRAMWITHSOURCE, OpenCL, 1);
3541 HC_LOAD_FUNC (ocl, clEnqueueCopyBuffer, OCL_CLENQUEUECOPYBUFFER, OpenCL, 1);
3542 HC_LOAD_FUNC (ocl, clEnqueueFillBuffer, OCL_CLENQUEUEFILLBUFFER, OpenCL, -1);
3543 HC_LOAD_FUNC (ocl, clEnqueueMapBuffer, OCL_CLENQUEUEMAPBUFFER, OpenCL, 1);
3544 HC_LOAD_FUNC (ocl, clEnqueueNDRangeKernel, OCL_CLENQUEUENDRANGEKERNEL, OpenCL, 1);
3545 HC_LOAD_FUNC (ocl, clEnqueueReadBuffer, OCL_CLENQUEUEREADBUFFER, OpenCL, 1);
3546 HC_LOAD_FUNC (ocl, clEnqueueUnmapMemObject, OCL_CLENQUEUEUNMAPMEMOBJECT, OpenCL, 1);
3547 HC_LOAD_FUNC (ocl, clEnqueueWriteBuffer, OCL_CLENQUEUEWRITEBUFFER, OpenCL, 1);
3548 HC_LOAD_FUNC (ocl, clFinish, OCL_CLFINISH, OpenCL, 1);
3549 HC_LOAD_FUNC (ocl, clFlush, OCL_CLFLUSH, OpenCL, 1);
3550 HC_LOAD_FUNC (ocl, clGetDeviceIDs, OCL_CLGETDEVICEIDS, OpenCL, 1);
3551 HC_LOAD_FUNC (ocl, clGetDeviceInfo, OCL_CLGETDEVICEINFO, OpenCL, 1);
3552 HC_LOAD_FUNC (ocl, clGetEventInfo, OCL_CLGETEVENTINFO, OpenCL, 1);
3553 HC_LOAD_FUNC (ocl, clGetKernelWorkGroupInfo, OCL_CLGETKERNELWORKGROUPINFO, OpenCL, 1);
3554 HC_LOAD_FUNC (ocl, clGetPlatformIDs, OCL_CLGETPLATFORMIDS, OpenCL, 1);
3555 HC_LOAD_FUNC (ocl, clGetPlatformInfo, OCL_CLGETPLATFORMINFO, OpenCL, 1);
3556 HC_LOAD_FUNC (ocl, clGetProgramBuildInfo, OCL_CLGETPROGRAMBUILDINFO, OpenCL, 1);
3557 HC_LOAD_FUNC (ocl, clGetProgramInfo, OCL_CLGETPROGRAMINFO, OpenCL, 1);
3558 HC_LOAD_FUNC (ocl, clLinkProgram, OCL_CLLINKPROGRAM, OpenCL, 1);
3559 HC_LOAD_FUNC (ocl, clReleaseCommandQueue, OCL_CLRELEASECOMMANDQUEUE, OpenCL, 1);
3560 HC_LOAD_FUNC (ocl, clReleaseContext, OCL_CLRELEASECONTEXT, OpenCL, 1);
3561 HC_LOAD_FUNC (ocl, clReleaseKernel, OCL_CLRELEASEKERNEL, OpenCL, 1);
3562 HC_LOAD_FUNC (ocl, clReleaseMemObject, OCL_CLRELEASEMEMOBJECT, OpenCL, 1);
3563 HC_LOAD_FUNC (ocl, clReleaseProgram, OCL_CLRELEASEPROGRAM, OpenCL, 1);
3564 HC_LOAD_FUNC (ocl, clSetKernelArg, OCL_CLSETKERNELARG, OpenCL, 1);
3565 HC_LOAD_FUNC (ocl, clWaitForEvents, OCL_CLWAITFOREVENTS, OpenCL, 1);
3566 HC_LOAD_FUNC (ocl, clGetEventProfilingInfo, OCL_CLGETEVENTPROFILINGINFO, OpenCL, 1);
3567 HC_LOAD_FUNC (ocl, clReleaseEvent, OCL_CLRELEASEEVENT, OpenCL, 1);
3568 //HC_LOAD_FUNC (ocl, clUnloadPlatformCompiler, OCL_CLUNLOADPLATFORMCOMPILER, OpenCL, 1);
3569
3570 return 0;
3571 }
3572
ocl_close(hashcat_ctx_t * hashcat_ctx)3573 void ocl_close (hashcat_ctx_t *hashcat_ctx)
3574 {
3575 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3576
3577 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
3578
3579 if (ocl)
3580 {
3581 if (ocl->lib)
3582 {
3583 hc_dlclose (ocl->lib);
3584 }
3585
3586 hcfree (backend_ctx->ocl);
3587
3588 backend_ctx->ocl = NULL;
3589 }
3590 }
3591
hc_clEnqueueNDRangeKernel(hashcat_ctx_t * hashcat_ctx,cl_command_queue command_queue,cl_kernel kernel,cl_uint work_dim,const size_t * global_work_offset,const size_t * global_work_size,const size_t * local_work_size,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)3592 int hc_clEnqueueNDRangeKernel (hashcat_ctx_t *hashcat_ctx, cl_command_queue command_queue, cl_kernel kernel, cl_uint work_dim, const size_t *global_work_offset, const size_t *global_work_size, const size_t *local_work_size, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event)
3593 {
3594 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3595
3596 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
3597
3598 const cl_int CL_err = ocl->clEnqueueNDRangeKernel (command_queue, kernel, work_dim, global_work_offset, global_work_size, local_work_size, num_events_in_wait_list, event_wait_list, event);
3599
3600 if (CL_err != CL_SUCCESS)
3601 {
3602 event_log_error (hashcat_ctx, "clEnqueueNDRangeKernel(): %s", val2cstr_cl (CL_err));
3603
3604 return -1;
3605 }
3606
3607 return 0;
3608 }
3609
hc_clGetEventInfo(hashcat_ctx_t * hashcat_ctx,cl_event event,cl_event_info param_name,size_t param_value_size,void * param_value,size_t * param_value_size_ret)3610 int hc_clGetEventInfo (hashcat_ctx_t *hashcat_ctx, cl_event event, cl_event_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret)
3611 {
3612 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3613
3614 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
3615
3616 const cl_int CL_err = ocl->clGetEventInfo (event, param_name, param_value_size, param_value, param_value_size_ret);
3617
3618 if (CL_err != CL_SUCCESS)
3619 {
3620 event_log_error (hashcat_ctx, "clGetEventInfo(): %s", val2cstr_cl (CL_err));
3621
3622 return -1;
3623 }
3624
3625 return 0;
3626 }
3627
hc_clFlush(hashcat_ctx_t * hashcat_ctx,cl_command_queue command_queue)3628 int hc_clFlush (hashcat_ctx_t *hashcat_ctx, cl_command_queue command_queue)
3629 {
3630 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3631
3632 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
3633
3634 const cl_int CL_err = ocl->clFlush (command_queue);
3635
3636 if (CL_err != CL_SUCCESS)
3637 {
3638 event_log_error (hashcat_ctx, "clFlush(): %s", val2cstr_cl (CL_err));
3639
3640 return -1;
3641 }
3642
3643 return 0;
3644 }
3645
hc_clFinish(hashcat_ctx_t * hashcat_ctx,cl_command_queue command_queue)3646 int hc_clFinish (hashcat_ctx_t *hashcat_ctx, cl_command_queue command_queue)
3647 {
3648 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3649
3650 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
3651
3652 const cl_int CL_err = ocl->clFinish (command_queue);
3653
3654 if (CL_err != CL_SUCCESS)
3655 {
3656 event_log_error (hashcat_ctx, "clFinish(): %s", val2cstr_cl (CL_err));
3657
3658 return -1;
3659 }
3660
3661 return 0;
3662 }
3663
hc_clSetKernelArg(hashcat_ctx_t * hashcat_ctx,cl_kernel kernel,cl_uint arg_index,size_t arg_size,const void * arg_value)3664 int hc_clSetKernelArg (hashcat_ctx_t *hashcat_ctx, cl_kernel kernel, cl_uint arg_index, size_t arg_size, const void *arg_value)
3665 {
3666 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3667
3668 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
3669
3670 const cl_int CL_err = ocl->clSetKernelArg (kernel, arg_index, arg_size, arg_value);
3671
3672 if (CL_err != CL_SUCCESS)
3673 {
3674 event_log_error (hashcat_ctx, "clSetKernelArg(): %s", val2cstr_cl (CL_err));
3675
3676 return -1;
3677 }
3678
3679 return 0;
3680 }
3681
hc_clEnqueueWriteBuffer(hashcat_ctx_t * hashcat_ctx,cl_command_queue command_queue,cl_mem buffer,cl_bool blocking_write,size_t offset,size_t size,const void * ptr,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)3682 int hc_clEnqueueWriteBuffer (hashcat_ctx_t *hashcat_ctx, cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_write, size_t offset, size_t size, const void *ptr, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event)
3683 {
3684 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3685
3686 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
3687
3688 const cl_int CL_err = ocl->clEnqueueWriteBuffer (command_queue, buffer, blocking_write, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
3689
3690 if (CL_err != CL_SUCCESS)
3691 {
3692 event_log_error (hashcat_ctx, "clEnqueueWriteBuffer(): %s", val2cstr_cl (CL_err));
3693
3694 return -1;
3695 }
3696
3697 return 0;
3698 }
3699
hc_clEnqueueCopyBuffer(hashcat_ctx_t * hashcat_ctx,cl_command_queue command_queue,cl_mem src_buffer,cl_mem dst_buffer,size_t src_offset,size_t dst_offset,size_t size,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)3700 int hc_clEnqueueCopyBuffer (hashcat_ctx_t *hashcat_ctx, cl_command_queue command_queue, cl_mem src_buffer, cl_mem dst_buffer, size_t src_offset, size_t dst_offset, size_t size, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event)
3701 {
3702 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3703
3704 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
3705
3706 const cl_int CL_err = ocl->clEnqueueCopyBuffer (command_queue, src_buffer, dst_buffer, src_offset, dst_offset, size, num_events_in_wait_list, event_wait_list, event);
3707
3708 if (CL_err != CL_SUCCESS)
3709 {
3710 event_log_error (hashcat_ctx, "clEnqueueCopyBuffer(): %s", val2cstr_cl (CL_err));
3711
3712 return -1;
3713 }
3714
3715 return 0;
3716 }
3717
hc_clEnqueueFillBuffer(hashcat_ctx_t * hashcat_ctx,cl_command_queue command_queue,cl_mem buffer,const void * pattern,size_t pattern_size,size_t offset,size_t size,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)3718 int hc_clEnqueueFillBuffer (hashcat_ctx_t *hashcat_ctx, cl_command_queue command_queue, cl_mem buffer, const void *pattern, size_t pattern_size, size_t offset, size_t size, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event)
3719 {
3720 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3721 const OCL_PTR *ocl = backend_ctx->ocl;
3722
3723 cl_int CL_err = ocl->clEnqueueFillBuffer (command_queue, buffer, pattern, pattern_size, offset, size, num_events_in_wait_list, event_wait_list, event);
3724
3725 if (CL_err != CL_SUCCESS)
3726 {
3727 event_log_error (hashcat_ctx, "clEnqueueFillBuffer(): %s", val2cstr_cl (CL_err));
3728
3729 return -1;
3730 }
3731
3732 return 0;
3733 }
3734
hc_clEnqueueReadBuffer(hashcat_ctx_t * hashcat_ctx,cl_command_queue command_queue,cl_mem buffer,cl_bool blocking_read,size_t offset,size_t size,void * ptr,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)3735 int hc_clEnqueueReadBuffer (hashcat_ctx_t *hashcat_ctx, cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_read, size_t offset, size_t size, void *ptr, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event)
3736 {
3737 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3738
3739 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
3740
3741 const cl_int CL_err = ocl->clEnqueueReadBuffer (command_queue, buffer, blocking_read, offset, size, ptr, num_events_in_wait_list, event_wait_list, event);
3742
3743 if (CL_err != CL_SUCCESS)
3744 {
3745 event_log_error (hashcat_ctx, "clEnqueueReadBuffer(): %s", val2cstr_cl (CL_err));
3746
3747 return -1;
3748 }
3749
3750 return 0;
3751 }
3752
hc_clGetPlatformIDs(hashcat_ctx_t * hashcat_ctx,cl_uint num_entries,cl_platform_id * platforms,cl_uint * num_platforms)3753 int hc_clGetPlatformIDs (hashcat_ctx_t *hashcat_ctx, cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms)
3754 {
3755 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3756
3757 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
3758
3759 const cl_int CL_err = ocl->clGetPlatformIDs (num_entries, platforms, num_platforms);
3760
3761 if (CL_err != CL_SUCCESS)
3762 {
3763 event_log_error (hashcat_ctx, "clGetPlatformIDs(): %s", val2cstr_cl (CL_err));
3764
3765 return -1;
3766 }
3767
3768 return 0;
3769 }
3770
hc_clGetPlatformInfo(hashcat_ctx_t * hashcat_ctx,cl_platform_id platform,cl_platform_info param_name,size_t param_value_size,void * param_value,size_t * param_value_size_ret)3771 int hc_clGetPlatformInfo (hashcat_ctx_t *hashcat_ctx, cl_platform_id platform, cl_platform_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret)
3772 {
3773 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3774
3775 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
3776
3777 const cl_int CL_err = ocl->clGetPlatformInfo (platform, param_name, param_value_size, param_value, param_value_size_ret);
3778
3779 if (CL_err != CL_SUCCESS)
3780 {
3781 event_log_error (hashcat_ctx, "clGetPlatformInfo(): %s", val2cstr_cl (CL_err));
3782
3783 return -1;
3784 }
3785
3786 return 0;
3787 }
3788
hc_clGetDeviceIDs(hashcat_ctx_t * hashcat_ctx,cl_platform_id platform,cl_device_type device_type,cl_uint num_entries,cl_device_id * devices,cl_uint * num_devices)3789 int hc_clGetDeviceIDs (hashcat_ctx_t *hashcat_ctx, cl_platform_id platform, cl_device_type device_type, cl_uint num_entries, cl_device_id *devices, cl_uint *num_devices)
3790 {
3791 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3792
3793 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
3794
3795 const cl_int CL_err = ocl->clGetDeviceIDs (platform, device_type, num_entries, devices, num_devices);
3796
3797 if (CL_err != CL_SUCCESS)
3798 {
3799 event_log_error (hashcat_ctx, "clGetDeviceIDs(): %s", val2cstr_cl (CL_err));
3800
3801 return -1;
3802 }
3803
3804 return 0;
3805 }
3806
hc_clGetDeviceInfo(hashcat_ctx_t * hashcat_ctx,cl_device_id device,cl_device_info param_name,size_t param_value_size,void * param_value,size_t * param_value_size_ret)3807 int hc_clGetDeviceInfo (hashcat_ctx_t *hashcat_ctx, cl_device_id device, cl_device_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret)
3808 {
3809 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3810
3811 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
3812
3813 const cl_int CL_err = ocl->clGetDeviceInfo (device, param_name, param_value_size, param_value, param_value_size_ret);
3814
3815 if (CL_err != CL_SUCCESS)
3816 {
3817 event_log_error (hashcat_ctx, "clGetDeviceInfo(): %s", val2cstr_cl (CL_err));
3818
3819 return -1;
3820 }
3821
3822 return 0;
3823 }
3824
hc_clCreateContext(hashcat_ctx_t * hashcat_ctx,const cl_context_properties * properties,cl_uint num_devices,const cl_device_id * devices,void (CL_CALLBACK * pfn_notify)(const char * errinfo,const void * private_info,size_t cb,void * user_data),void * user_data,cl_context * context)3825 int hc_clCreateContext (hashcat_ctx_t *hashcat_ctx, const cl_context_properties *properties, cl_uint num_devices, const cl_device_id *devices, void (CL_CALLBACK *pfn_notify) (const char *errinfo, const void *private_info, size_t cb, void *user_data), void *user_data, cl_context *context)
3826 {
3827 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3828
3829 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
3830
3831 cl_int CL_err;
3832
3833 *context = ocl->clCreateContext (properties, num_devices, devices, pfn_notify, user_data, &CL_err);
3834
3835 if (CL_err != CL_SUCCESS)
3836 {
3837 event_log_error (hashcat_ctx, "clCreateContext(): %s", val2cstr_cl (CL_err));
3838
3839 return -1;
3840 }
3841
3842 return 0;
3843 }
3844
hc_clCreateCommandQueue(hashcat_ctx_t * hashcat_ctx,cl_context context,cl_device_id device,cl_command_queue_properties properties,cl_command_queue * command_queue)3845 int hc_clCreateCommandQueue (hashcat_ctx_t *hashcat_ctx, cl_context context, cl_device_id device, cl_command_queue_properties properties, cl_command_queue *command_queue)
3846 {
3847 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3848
3849 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
3850
3851 cl_int CL_err;
3852
3853 *command_queue = ocl->clCreateCommandQueue (context, device, properties, &CL_err);
3854
3855 if (CL_err != CL_SUCCESS)
3856 {
3857 event_log_error (hashcat_ctx, "clCreateCommandQueue(): %s", val2cstr_cl (CL_err));
3858
3859 return -1;
3860 }
3861
3862 return 0;
3863 }
3864
hc_clCreateBuffer(hashcat_ctx_t * hashcat_ctx,cl_context context,cl_mem_flags flags,size_t size,void * host_ptr,cl_mem * mem)3865 int hc_clCreateBuffer (hashcat_ctx_t *hashcat_ctx, cl_context context, cl_mem_flags flags, size_t size, void *host_ptr, cl_mem *mem)
3866 {
3867 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3868
3869 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
3870
3871 cl_int CL_err;
3872
3873 *mem = ocl->clCreateBuffer (context, flags, size, host_ptr, &CL_err);
3874
3875 if (CL_err != CL_SUCCESS)
3876 {
3877 event_log_error (hashcat_ctx, "clCreateBuffer(): %s", val2cstr_cl (CL_err));
3878
3879 return -1;
3880 }
3881
3882 return 0;
3883 }
3884
hc_clCreateProgramWithSource(hashcat_ctx_t * hashcat_ctx,cl_context context,cl_uint count,const char ** strings,const size_t * lengths,cl_program * program)3885 int hc_clCreateProgramWithSource (hashcat_ctx_t *hashcat_ctx, cl_context context, cl_uint count, const char **strings, const size_t *lengths, cl_program *program)
3886 {
3887 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3888
3889 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
3890
3891 cl_int CL_err;
3892
3893 *program = ocl->clCreateProgramWithSource (context, count, strings, lengths, &CL_err);
3894
3895 if (CL_err != CL_SUCCESS)
3896 {
3897 event_log_error (hashcat_ctx, "clCreateProgramWithSource(): %s", val2cstr_cl (CL_err));
3898
3899 return -1;
3900 }
3901
3902 return 0;
3903 }
3904
hc_clCreateProgramWithBinary(hashcat_ctx_t * hashcat_ctx,cl_context context,cl_uint num_devices,const cl_device_id * device_list,const size_t * lengths,const unsigned char ** binaries,cl_int * binary_status,cl_program * program)3905 int hc_clCreateProgramWithBinary (hashcat_ctx_t *hashcat_ctx, cl_context context, cl_uint num_devices, const cl_device_id *device_list, const size_t *lengths, const unsigned char **binaries, cl_int *binary_status, cl_program *program)
3906 {
3907 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3908
3909 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
3910
3911 cl_int CL_err;
3912
3913 *program = ocl->clCreateProgramWithBinary (context, num_devices, device_list, lengths, binaries, binary_status, &CL_err);
3914
3915 if (CL_err != CL_SUCCESS)
3916 {
3917 event_log_error (hashcat_ctx, "clCreateProgramWithBinary(): %s", val2cstr_cl (CL_err));
3918
3919 return -1;
3920 }
3921
3922 return 0;
3923 }
3924
hc_clBuildProgram(hashcat_ctx_t * hashcat_ctx,cl_program program,cl_uint num_devices,const cl_device_id * device_list,const char * options,void (CL_CALLBACK * pfn_notify)(cl_program program,void * user_data),void * user_data)3925 int hc_clBuildProgram (hashcat_ctx_t *hashcat_ctx, cl_program program, cl_uint num_devices, const cl_device_id *device_list, const char *options, void (CL_CALLBACK *pfn_notify) (cl_program program, void *user_data), void *user_data)
3926 {
3927 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3928
3929 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
3930
3931 const cl_int CL_err = ocl->clBuildProgram (program, num_devices, device_list, options, pfn_notify, user_data);
3932
3933 if (CL_err != CL_SUCCESS)
3934 {
3935 event_log_error (hashcat_ctx, "clBuildProgram(): %s", val2cstr_cl (CL_err));
3936
3937 return -1;
3938 }
3939
3940 return 0;
3941 }
3942
hc_clCompileProgram(hashcat_ctx_t * hashcat_ctx,cl_program program,cl_uint num_devices,const cl_device_id * device_list,const char * options,cl_uint num_input_headers,const cl_program * input_headers,const char ** header_include_names,void (CL_CALLBACK * pfn_notify)(cl_program program,void * user_data),void * user_data)3943 int hc_clCompileProgram (hashcat_ctx_t *hashcat_ctx, cl_program program, cl_uint num_devices, const cl_device_id *device_list, const char *options, cl_uint num_input_headers, const cl_program *input_headers, const char **header_include_names, void (CL_CALLBACK *pfn_notify) (cl_program program, void *user_data), void *user_data)
3944 {
3945 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3946
3947 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
3948
3949 const cl_int CL_err = ocl->clCompileProgram (program, num_devices, device_list, options, num_input_headers, input_headers, header_include_names, pfn_notify, user_data);
3950
3951 if (CL_err != CL_SUCCESS)
3952 {
3953 event_log_error (hashcat_ctx, "clCompileProgram(): %s", val2cstr_cl (CL_err));
3954
3955 return -1;
3956 }
3957
3958 return 0;
3959 }
3960
hc_clLinkProgram(hashcat_ctx_t * hashcat_ctx,cl_context context,cl_uint num_devices,const cl_device_id * device_list,const char * options,cl_uint num_input_programs,const cl_program * input_programs,void (CL_CALLBACK * pfn_notify)(cl_program program,void * user_data),void * user_data,cl_program * program)3961 int hc_clLinkProgram (hashcat_ctx_t *hashcat_ctx, cl_context context, cl_uint num_devices, const cl_device_id *device_list, const char *options, cl_uint num_input_programs, const cl_program *input_programs, void (CL_CALLBACK *pfn_notify) (cl_program program, void *user_data), void *user_data, cl_program *program)
3962 {
3963 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3964
3965 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
3966
3967 cl_int CL_err;
3968
3969 *program = ocl->clLinkProgram (context, num_devices, device_list, options, num_input_programs, input_programs, pfn_notify, user_data, &CL_err);
3970
3971 if (CL_err != CL_SUCCESS)
3972 {
3973 event_log_error (hashcat_ctx, "clLinkProgram(): %s", val2cstr_cl (CL_err));
3974
3975 return -1;
3976 }
3977
3978 return 0;
3979 }
3980
hc_clCreateKernel(hashcat_ctx_t * hashcat_ctx,cl_program program,const char * kernel_name,cl_kernel * kernel)3981 int hc_clCreateKernel (hashcat_ctx_t *hashcat_ctx, cl_program program, const char *kernel_name, cl_kernel *kernel)
3982 {
3983 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
3984
3985 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
3986
3987 cl_int CL_err;
3988
3989 *kernel = ocl->clCreateKernel (program, kernel_name, &CL_err);
3990
3991 if (CL_err != CL_SUCCESS)
3992 {
3993 event_log_error (hashcat_ctx, "clCreateKernel(): %s", val2cstr_cl (CL_err));
3994
3995 return -1;
3996 }
3997
3998 return 0;
3999 }
4000
hc_clReleaseMemObject(hashcat_ctx_t * hashcat_ctx,cl_mem mem)4001 int hc_clReleaseMemObject (hashcat_ctx_t *hashcat_ctx, cl_mem mem)
4002 {
4003 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
4004
4005 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
4006
4007 const cl_int CL_err = ocl->clReleaseMemObject (mem);
4008
4009 if (CL_err != CL_SUCCESS)
4010 {
4011 event_log_error (hashcat_ctx, "clReleaseMemObject(): %s", val2cstr_cl (CL_err));
4012
4013 return -1;
4014 }
4015
4016 return 0;
4017 }
4018
hc_clReleaseKernel(hashcat_ctx_t * hashcat_ctx,cl_kernel kernel)4019 int hc_clReleaseKernel (hashcat_ctx_t *hashcat_ctx, cl_kernel kernel)
4020 {
4021 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
4022
4023 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
4024
4025 const cl_int CL_err = ocl->clReleaseKernel (kernel);
4026
4027 if (CL_err != CL_SUCCESS)
4028 {
4029 event_log_error (hashcat_ctx, "clReleaseKernel(): %s", val2cstr_cl (CL_err));
4030
4031 return -1;
4032 }
4033
4034 return 0;
4035 }
4036
hc_clReleaseProgram(hashcat_ctx_t * hashcat_ctx,cl_program program)4037 int hc_clReleaseProgram (hashcat_ctx_t *hashcat_ctx, cl_program program)
4038 {
4039 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
4040
4041 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
4042
4043 const cl_int CL_err = ocl->clReleaseProgram (program);
4044
4045 if (CL_err != CL_SUCCESS)
4046 {
4047 event_log_error (hashcat_ctx, "clReleaseProgram(): %s", val2cstr_cl (CL_err));
4048
4049 return -1;
4050 }
4051
4052 return 0;
4053 }
4054
hc_clReleaseCommandQueue(hashcat_ctx_t * hashcat_ctx,cl_command_queue command_queue)4055 int hc_clReleaseCommandQueue (hashcat_ctx_t *hashcat_ctx, cl_command_queue command_queue)
4056 {
4057 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
4058
4059 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
4060
4061 const cl_int CL_err = ocl->clReleaseCommandQueue (command_queue);
4062
4063 if (CL_err != CL_SUCCESS)
4064 {
4065 event_log_error (hashcat_ctx, "clReleaseCommandQueue(): %s", val2cstr_cl (CL_err));
4066
4067 return -1;
4068 }
4069
4070 return 0;
4071 }
4072
hc_clReleaseContext(hashcat_ctx_t * hashcat_ctx,cl_context context)4073 int hc_clReleaseContext (hashcat_ctx_t *hashcat_ctx, cl_context context)
4074 {
4075 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
4076
4077 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
4078
4079 const cl_int CL_err = ocl->clReleaseContext (context);
4080
4081 if (CL_err != CL_SUCCESS)
4082 {
4083 event_log_error (hashcat_ctx, "clReleaseContext(): %s", val2cstr_cl (CL_err));
4084
4085 return -1;
4086 }
4087
4088 return 0;
4089 }
4090
hc_clEnqueueMapBuffer(hashcat_ctx_t * hashcat_ctx,cl_command_queue command_queue,cl_mem buffer,cl_bool blocking_map,cl_map_flags map_flags,size_t offset,size_t size,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event,void ** buf)4091 int hc_clEnqueueMapBuffer (hashcat_ctx_t *hashcat_ctx, cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_map, cl_map_flags map_flags, size_t offset, size_t size, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event, void **buf)
4092 {
4093 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
4094
4095 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
4096
4097 cl_int CL_err;
4098
4099 *buf = ocl->clEnqueueMapBuffer (command_queue, buffer, blocking_map, map_flags, offset, size, num_events_in_wait_list, event_wait_list, event, &CL_err);
4100
4101 if (CL_err != CL_SUCCESS)
4102 {
4103 event_log_error (hashcat_ctx, "clEnqueueMapBuffer(): %s", val2cstr_cl (CL_err));
4104
4105 return -1;
4106 }
4107
4108 return 0;
4109 }
4110
hc_clEnqueueUnmapMemObject(hashcat_ctx_t * hashcat_ctx,cl_command_queue command_queue,cl_mem memobj,void * mapped_ptr,cl_uint num_events_in_wait_list,const cl_event * event_wait_list,cl_event * event)4111 int hc_clEnqueueUnmapMemObject (hashcat_ctx_t *hashcat_ctx, cl_command_queue command_queue, cl_mem memobj, void *mapped_ptr, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event)
4112 {
4113 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
4114
4115 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
4116
4117 const cl_int CL_err = ocl->clEnqueueUnmapMemObject (command_queue, memobj, mapped_ptr, num_events_in_wait_list, event_wait_list, event);
4118
4119 if (CL_err != CL_SUCCESS)
4120 {
4121 event_log_error (hashcat_ctx, "clEnqueueUnmapMemObject(): %s", val2cstr_cl (CL_err));
4122
4123 return -1;
4124 }
4125
4126 return 0;
4127 }
4128
hc_clGetKernelWorkGroupInfo(hashcat_ctx_t * hashcat_ctx,cl_kernel kernel,cl_device_id device,cl_kernel_work_group_info param_name,size_t param_value_size,void * param_value,size_t * param_value_size_ret)4129 int hc_clGetKernelWorkGroupInfo (hashcat_ctx_t *hashcat_ctx, cl_kernel kernel, cl_device_id device, cl_kernel_work_group_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret)
4130 {
4131 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
4132
4133 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
4134
4135 const cl_int CL_err = ocl->clGetKernelWorkGroupInfo (kernel, device, param_name, param_value_size, param_value, param_value_size_ret);
4136
4137 if (CL_err != CL_SUCCESS)
4138 {
4139 event_log_error (hashcat_ctx, "clGetKernelWorkGroupInfo(): %s", val2cstr_cl (CL_err));
4140
4141 return -1;
4142 }
4143
4144 return 0;
4145 }
4146
hc_clGetProgramBuildInfo(hashcat_ctx_t * hashcat_ctx,cl_program program,cl_device_id device,cl_program_build_info param_name,size_t param_value_size,void * param_value,size_t * param_value_size_ret)4147 int hc_clGetProgramBuildInfo (hashcat_ctx_t *hashcat_ctx, cl_program program, cl_device_id device, cl_program_build_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret)
4148 {
4149 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
4150
4151 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
4152
4153 const cl_int CL_err = ocl->clGetProgramBuildInfo (program, device, param_name, param_value_size, param_value, param_value_size_ret);
4154
4155 if (CL_err != CL_SUCCESS)
4156 {
4157 event_log_error (hashcat_ctx, "clGetProgramBuildInfo(): %s", val2cstr_cl (CL_err));
4158
4159 return -1;
4160 }
4161
4162 return 0;
4163 }
4164
hc_clGetProgramInfo(hashcat_ctx_t * hashcat_ctx,cl_program program,cl_program_info param_name,size_t param_value_size,void * param_value,size_t * param_value_size_ret)4165 int hc_clGetProgramInfo (hashcat_ctx_t *hashcat_ctx, cl_program program, cl_program_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret)
4166 {
4167 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
4168
4169 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
4170
4171 const cl_int CL_err = ocl->clGetProgramInfo (program, param_name, param_value_size, param_value, param_value_size_ret);
4172
4173 if (CL_err != CL_SUCCESS)
4174 {
4175 event_log_error (hashcat_ctx, "clGetProgramInfo(): %s", val2cstr_cl (CL_err));
4176
4177 return -1;
4178 }
4179
4180 return 0;
4181 }
4182
hc_clWaitForEvents(hashcat_ctx_t * hashcat_ctx,cl_uint num_events,const cl_event * event_list)4183 int hc_clWaitForEvents (hashcat_ctx_t *hashcat_ctx, cl_uint num_events, const cl_event *event_list)
4184 {
4185 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
4186
4187 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
4188
4189 const cl_int CL_err = ocl->clWaitForEvents (num_events, event_list);
4190
4191 if (CL_err != CL_SUCCESS)
4192 {
4193 event_log_error (hashcat_ctx, "clWaitForEvents(): %s", val2cstr_cl (CL_err));
4194
4195 return -1;
4196 }
4197
4198 return 0;
4199 }
4200
hc_clGetEventProfilingInfo(hashcat_ctx_t * hashcat_ctx,cl_event event,cl_profiling_info param_name,size_t param_value_size,void * param_value,size_t * param_value_size_ret)4201 int hc_clGetEventProfilingInfo (hashcat_ctx_t *hashcat_ctx, cl_event event, cl_profiling_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret)
4202 {
4203 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
4204
4205 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
4206
4207 const cl_int CL_err = ocl->clGetEventProfilingInfo (event, param_name, param_value_size, param_value, param_value_size_ret);
4208
4209 if (CL_err != CL_SUCCESS)
4210 {
4211 event_log_error (hashcat_ctx, "clGetEventProfilingInfo(): %s", val2cstr_cl (CL_err));
4212
4213 return -1;
4214 }
4215
4216 return 0;
4217 }
4218
hc_clReleaseEvent(hashcat_ctx_t * hashcat_ctx,cl_event event)4219 int hc_clReleaseEvent (hashcat_ctx_t *hashcat_ctx, cl_event event)
4220 {
4221 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
4222
4223 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
4224
4225 const cl_int CL_err = ocl->clReleaseEvent (event);
4226
4227 if (CL_err != CL_SUCCESS)
4228 {
4229 event_log_error (hashcat_ctx, "clReleaseEvent(): %s", val2cstr_cl (CL_err));
4230
4231 return -1;
4232 }
4233
4234 return 0;
4235 }
4236
4237 /*
4238 int hc_clUnloadPlatformCompiler (hashcat_ctx_t *hashcat_ctx, cl_platform_id platform)
4239 {
4240 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
4241
4242 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
4243
4244 const cl_int CL_err = ocl->clUnloadPlatformCompiler (platform);
4245
4246 if (CL_err != CL_SUCCESS)
4247 {
4248 event_log_error (hashcat_ctx, "clUnloadPlatformCompiler(): %s", val2cstr_cl (CL_err));
4249
4250 return -1;
4251 }
4252
4253 return 0;
4254 }
4255 */
4256
4257 // Backend
4258
gidd_to_pw_t(hashcat_ctx_t * hashcat_ctx,hc_device_param_t * device_param,const u64 gidd,pw_t * pw)4259 int gidd_to_pw_t (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u64 gidd, pw_t *pw)
4260 {
4261 pw_idx_t pw_idx;
4262
4263 pw_idx.off = 0;
4264 pw_idx.cnt = 0;
4265 pw_idx.len = 0;
4266
4267 if (device_param->is_cuda == true)
4268 {
4269 if (hc_cuCtxPushCurrent (hashcat_ctx, device_param->cuda_context) == -1) return -1;
4270
4271 if (hc_cuMemcpyDtoHAsync (hashcat_ctx, &pw_idx, device_param->cuda_d_pws_idx + (gidd * sizeof (pw_idx_t)), sizeof (pw_idx_t), device_param->cuda_stream) == -1) return -1;
4272
4273 if (hc_cuStreamSynchronize (hashcat_ctx, device_param->cuda_stream) == -1) return -1;
4274 }
4275
4276 if (device_param->is_hip == true)
4277 {
4278 if (hc_hipCtxPushCurrent (hashcat_ctx, device_param->hip_context) == -1) return -1;
4279
4280 if (hc_hipMemcpyDtoHAsync (hashcat_ctx, &pw_idx, device_param->hip_d_pws_idx + (gidd * sizeof (pw_idx_t)), sizeof (pw_idx_t), device_param->hip_stream) == -1) return -1;
4281
4282 if (hc_hipStreamSynchronize (hashcat_ctx, device_param->hip_stream) == -1) return -1;
4283 }
4284
4285 if (device_param->is_opencl == true)
4286 {
4287 /* blocking */
4288 if (hc_clEnqueueReadBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_pws_idx, CL_TRUE, gidd * sizeof (pw_idx_t), sizeof (pw_idx_t), &pw_idx, 0, NULL, NULL) == -1) return -1;
4289 }
4290
4291 const u32 off = pw_idx.off;
4292 const u32 cnt = pw_idx.cnt;
4293 const u32 len = pw_idx.len;
4294
4295 if (cnt > 0)
4296 {
4297 if (device_param->is_cuda == true)
4298 {
4299 if (hc_cuMemcpyDtoHAsync (hashcat_ctx, pw->i, device_param->cuda_d_pws_comp_buf + (off * sizeof (u32)), cnt * sizeof (u32), device_param->cuda_stream) == -1) return -1;
4300
4301 if (hc_cuStreamSynchronize (hashcat_ctx, device_param->cuda_stream) == -1) return -1;
4302 }
4303
4304 if (device_param->is_hip == true)
4305 {
4306 if (hc_hipMemcpyDtoHAsync (hashcat_ctx, pw->i, device_param->hip_d_pws_comp_buf + (off * sizeof (u32)), cnt * sizeof (u32), device_param->hip_stream) == -1) return -1;
4307
4308 if (hc_hipStreamSynchronize (hashcat_ctx, device_param->hip_stream) == -1) return -1;
4309 }
4310
4311 if (device_param->is_opencl == true)
4312 {
4313 /* blocking */
4314 if (hc_clEnqueueReadBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_pws_comp_buf, CL_TRUE, off * sizeof (u32), cnt * sizeof (u32), pw->i, 0, NULL, NULL) == -1) return -1;
4315 }
4316 }
4317
4318 for (u32 i = cnt; i < 64; i++)
4319 {
4320 pw->i[i] = 0;
4321 }
4322
4323 pw->pw_len = len;
4324
4325 if (device_param->is_cuda == true)
4326 {
4327 if (hc_cuCtxPopCurrent (hashcat_ctx, &device_param->cuda_context) == -1) return -1;
4328 }
4329
4330 if (device_param->is_hip == true)
4331 {
4332 if (hc_hipCtxPopCurrent (hashcat_ctx, &device_param->hip_context) == -1) return -1;
4333 }
4334
4335 return 0;
4336 }
4337
choose_kernel(hashcat_ctx_t * hashcat_ctx,hc_device_param_t * device_param,const u32 highest_pw_len,const u64 pws_pos,const u64 pws_cnt,const u32 fast_iteration,const u32 salt_pos)4338 int choose_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u32 highest_pw_len, const u64 pws_pos, const u64 pws_cnt, const u32 fast_iteration, const u32 salt_pos)
4339 {
4340 hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
4341 hashes_t *hashes = hashcat_ctx->hashes;
4342 module_ctx_t *module_ctx = hashcat_ctx->module_ctx;
4343 status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
4344 user_options_t *user_options = hashcat_ctx->user_options;
4345
4346 if (user_options->stdout_flag == true)
4347 {
4348 return process_stdout (hashcat_ctx, device_param, pws_cnt);
4349 }
4350
4351 if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
4352 {
4353 if (user_options->attack_mode == ATTACK_MODE_BF)
4354 {
4355 if (user_options->slow_candidates == true)
4356 {
4357 }
4358 else
4359 {
4360 if (hashconfig->opts_type & OPTS_TYPE_TM_KERNEL)
4361 {
4362 const u32 size_tm = device_param->size_tm;
4363
4364 if (device_param->is_cuda == true)
4365 {
4366 if (run_cuda_kernel_bzero (hashcat_ctx, device_param, device_param->cuda_d_tm_c, size_tm) == -1) return -1;
4367 }
4368
4369 if (device_param->is_hip == true)
4370 {
4371 if (run_hip_kernel_bzero (hashcat_ctx, device_param, device_param->hip_d_tm_c, size_tm) == -1) return -1;
4372 }
4373
4374 if (device_param->is_opencl == true)
4375 {
4376 if (run_opencl_kernel_bzero (hashcat_ctx, device_param, device_param->opencl_d_tm_c, size_tm) == -1) return -1;
4377 }
4378
4379 if (run_kernel_tm (hashcat_ctx, device_param) == -1) return -1;
4380
4381 if (device_param->is_cuda == true)
4382 {
4383 if (hc_cuMemcpyDtoDAsync (hashcat_ctx, device_param->cuda_d_bfs_c, device_param->cuda_d_tm_c, size_tm, device_param->cuda_stream) == -1) return -1;
4384 }
4385
4386 if (device_param->is_hip == true)
4387 {
4388 if (hc_hipMemcpyDtoDAsync (hashcat_ctx, device_param->hip_d_bfs_c, device_param->hip_d_tm_c, size_tm, device_param->hip_stream) == -1) return -1;
4389 }
4390
4391 if (device_param->is_opencl == true)
4392 {
4393 if (hc_clEnqueueCopyBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_tm_c, device_param->opencl_d_bfs_c, 0, 0, size_tm, 0, NULL, NULL) == -1) return -1;
4394
4395 if (hc_clFlush (hashcat_ctx, device_param->opencl_command_queue) == -1) return -1;
4396 }
4397 }
4398 }
4399 }
4400
4401 if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
4402 {
4403 // this is not perfectly right, only in case algorithm has to add 0x80 (most of the cases for fast optimized kernels)
4404
4405 if (highest_pw_len < 16)
4406 {
4407 if (run_kernel (hashcat_ctx, device_param, KERN_RUN_1, pws_pos, pws_cnt, true, fast_iteration) == -1) return -1;
4408 }
4409 else if (highest_pw_len < 32)
4410 {
4411 if (run_kernel (hashcat_ctx, device_param, KERN_RUN_2, pws_pos, pws_cnt, true, fast_iteration) == -1) return -1;
4412 }
4413 else
4414 {
4415 if (run_kernel (hashcat_ctx, device_param, KERN_RUN_3, pws_pos, pws_cnt, true, fast_iteration) == -1) return -1;
4416 }
4417 }
4418 else
4419 {
4420 if (run_kernel (hashcat_ctx, device_param, KERN_RUN_4, pws_pos, pws_cnt, true, fast_iteration) == -1) return -1;
4421 }
4422 }
4423 else
4424 {
4425 // innerloop prediction to get a speed estimation is hard, because we don't know in advance how much
4426 // time the different kernels take and if their weightnings are equally distributed.
4427 // - for instance, a regular _loop kernel is likely to be the slowest, but _loop2 kernel can also be slow.
4428 // in fact, _loop2 can be even slower (see iTunes backup >= 10.0).
4429 // - hooks can have a large influence depending on the OS.
4430 // spawning threads and memory allocations take a lot of time on windows (compared to linux).
4431 // - the kernel execution can take shortcuts based on intermediate values
4432 // while these intermediate valus depend on input values.
4433 // - if we meassure runtimes of different kernels to find out about their weightning
4434 // we need to call them with real input values otherwise we miss the shortcuts inside the kernel.
4435 // - the problem is that these real input values could crack the hash which makes the chaos perfect.
4436 //
4437 // so the innerloop prediction is not perfectly accurate, because we:
4438 //
4439 // 1. completely ignore hooks and the time they take.
4440 // 2. assume that the code in _loop and _loop2 is similar,
4441 // but we respect the different iteration counts in _loop and _loop2.
4442 // 3. ignore _comp kernel runtimes (probably irrelevant).
4443 //
4444 // as soon as the first restore checkpoint is reached the prediction is accurate.
4445 // also the closer it gets to that point.
4446
4447 if (true)
4448 {
4449 if (device_param->is_cuda == true)
4450 {
4451 if (hc_cuMemcpyDtoDAsync (hashcat_ctx, device_param->cuda_d_pws_buf, device_param->cuda_d_pws_amp_buf, pws_cnt * sizeof (pw_t), device_param->cuda_stream) == -1) return -1;
4452 }
4453
4454 if (device_param->is_hip == true)
4455 {
4456 if (hc_hipMemcpyDtoDAsync (hashcat_ctx, device_param->hip_d_pws_buf, device_param->hip_d_pws_amp_buf, pws_cnt * sizeof (pw_t), device_param->hip_stream) == -1) return -1;
4457 }
4458
4459 if (device_param->is_opencl == true)
4460 {
4461 if (hc_clEnqueueCopyBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_pws_amp_buf, device_param->opencl_d_pws_buf, 0, 0, pws_cnt * sizeof (pw_t), 0, NULL, NULL) == -1) return -1;
4462 }
4463
4464 if (user_options->slow_candidates == true)
4465 {
4466 }
4467 else
4468 {
4469 if (run_kernel_amp (hashcat_ctx, device_param, pws_cnt) == -1) return -1;
4470 }
4471
4472 if (hashconfig->opts_type & OPTS_TYPE_POST_AMP_UTF16LE)
4473 {
4474 if (device_param->is_cuda == true)
4475 {
4476 if (run_cuda_kernel_utf8toutf16le (hashcat_ctx, device_param, device_param->cuda_d_pws_buf, pws_cnt) == -1) return -1;
4477 }
4478
4479 if (device_param->is_hip == true)
4480 {
4481 if (run_hip_kernel_utf8toutf16le (hashcat_ctx, device_param, device_param->hip_d_pws_buf, pws_cnt) == -1) return -1;
4482 }
4483
4484 if (device_param->is_opencl == true)
4485 {
4486 if (run_opencl_kernel_utf8toutf16le (hashcat_ctx, device_param, device_param->opencl_d_pws_buf, pws_cnt) == -1) return -1;
4487 }
4488 }
4489
4490 if (run_kernel (hashcat_ctx, device_param, KERN_RUN_1, pws_pos, pws_cnt, false, 0) == -1) return -1;
4491
4492 if (hashconfig->opts_type & OPTS_TYPE_HOOK12)
4493 {
4494 if (run_kernel (hashcat_ctx, device_param, KERN_RUN_12, pws_pos, pws_cnt, false, 0) == -1) return -1;
4495
4496 if (device_param->is_cuda == true)
4497 {
4498 if (hc_cuMemcpyDtoHAsync (hashcat_ctx, device_param->hooks_buf, device_param->cuda_d_hooks, pws_cnt * hashconfig->hook_size, device_param->cuda_stream) == -1) return -1;
4499
4500 if (hc_cuStreamSynchronize (hashcat_ctx, device_param->cuda_stream) == -1) return -1;
4501 }
4502
4503 if (device_param->is_hip == true)
4504 {
4505 if (hc_hipMemcpyDtoHAsync (hashcat_ctx, device_param->hooks_buf, device_param->hip_d_hooks, pws_cnt * hashconfig->hook_size, device_param->hip_stream) == -1) return -1;
4506
4507 if (hc_hipStreamSynchronize (hashcat_ctx, device_param->hip_stream) == -1) return -1;
4508 }
4509
4510 if (device_param->is_opencl == true)
4511 {
4512 /* blocking */
4513 if (hc_clEnqueueReadBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_hooks, CL_TRUE, 0, pws_cnt * hashconfig->hook_size, device_param->hooks_buf, 0, NULL, NULL) == -1) return -1;
4514 }
4515
4516 const int hook_threads = (int) user_options->hook_threads;
4517
4518 hook_thread_param_t *hook_threads_param = (hook_thread_param_t *) hcmalloc (hook_threads * sizeof (hook_thread_param_t));
4519 hc_thread_t *c_threads = (hc_thread_t *) hcmalloc (hook_threads * sizeof (hc_thread_t));
4520
4521 for (int i = 0; i < hook_threads; i++)
4522 {
4523 hook_thread_param_t *hook_thread_param = hook_threads_param + i;
4524
4525 hook_thread_param->tid = i;
4526 hook_thread_param->tsz = hook_threads;
4527
4528 hook_thread_param->module_ctx = module_ctx;
4529 hook_thread_param->status_ctx = status_ctx;
4530
4531 hook_thread_param->device_param = device_param;
4532
4533 hook_thread_param->hook_extra_param = module_ctx->hook_extra_params[i];
4534 hook_thread_param->hook_salts_buf = hashes->hook_salts_buf;
4535
4536 hook_thread_param->salt_pos = salt_pos;
4537
4538 hook_thread_param->pws_cnt = pws_cnt;
4539
4540 hc_thread_create (c_threads[i], hook12_thread, hook_thread_param);
4541 }
4542
4543 hc_thread_wait (hook_threads, c_threads);
4544
4545 hcfree (c_threads);
4546 hcfree (hook_threads_param);
4547
4548 if (device_param->is_cuda == true)
4549 {
4550 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_hooks, device_param->hooks_buf, pws_cnt * hashconfig->hook_size, device_param->cuda_stream) == -1) return -1;
4551 }
4552
4553 if (device_param->is_hip == true)
4554 {
4555 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_hooks, device_param->hooks_buf, pws_cnt * hashconfig->hook_size, device_param->hip_stream) == -1) return -1;
4556 }
4557
4558 if (device_param->is_opencl == true)
4559 {
4560 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_hooks, CL_FALSE, 0, pws_cnt * hashconfig->hook_size, device_param->hooks_buf, 0, NULL, NULL) == -1) return -1;
4561 }
4562 }
4563 }
4564
4565 if (true)
4566 {
4567 const u32 salt_repeats = hashes->salts_buf[salt_pos].salt_repeats;
4568
4569 for (u32 salt_repeat = 0; salt_repeat <= salt_repeats; salt_repeat++)
4570 {
4571 device_param->kernel_params_buf32[34] = salt_repeat;
4572
4573 if (hashconfig->opts_type & OPTS_TYPE_LOOP_PREPARE)
4574 {
4575 if (run_kernel (hashcat_ctx, device_param, KERN_RUN_2P, pws_pos, pws_cnt, false, 0) == -1) return -1;
4576 }
4577
4578 if (true)
4579 {
4580 const u32 iter = hashes->salts_buf[salt_pos].salt_iter;
4581
4582 const u32 loop_step = device_param->kernel_loops;
4583
4584 for (u32 loop_pos = 0, slow_iteration = 0; loop_pos < iter; loop_pos += loop_step, slow_iteration++)
4585 {
4586 u32 loop_left = iter - loop_pos;
4587
4588 loop_left = MIN (loop_left, loop_step);
4589
4590 device_param->kernel_params_buf32[28] = loop_pos;
4591 device_param->kernel_params_buf32[29] = loop_left;
4592
4593 if (run_kernel (hashcat_ctx, device_param, KERN_RUN_2, pws_pos, pws_cnt, true, slow_iteration) == -1) return -1;
4594
4595 if (hashconfig->opts_type & OPTS_TYPE_LOOP_EXTENDED)
4596 {
4597 if (run_kernel (hashcat_ctx, device_param, KERN_RUN_2E, pws_pos, pws_cnt, true, slow_iteration) == -1) return -1;
4598 }
4599
4600 //bug?
4601 //while (status_ctx->run_thread_level2 == false) break;
4602 if (status_ctx->run_thread_level2 == false) break;
4603
4604 /**
4605 * speed
4606 */
4607
4608 const u32 iter1r = hashes->salts_buf[salt_pos].salt_iter * (salt_repeats + 1);
4609 const u32 iter2r = hashes->salts_buf[salt_pos].salt_iter2 * (salt_repeats + 1);
4610
4611 const double iter_part = (double) ((iter * salt_repeat) + loop_pos + loop_left) / (double) (iter1r + iter2r);
4612
4613 const u64 perf_sum_all = (u64) (pws_cnt * iter_part);
4614
4615 double speed_msec = hc_timer_get (device_param->timer_speed);
4616
4617 const u32 speed_pos = device_param->speed_pos;
4618
4619 device_param->speed_cnt[speed_pos] = perf_sum_all;
4620
4621 device_param->speed_msec[speed_pos] = speed_msec;
4622
4623 if (user_options->speed_only == true)
4624 {
4625 if (speed_msec > 4000)
4626 {
4627 device_param->outerloop_multi *= 1 / iter_part;
4628
4629 device_param->speed_pos = 1;
4630
4631 device_param->speed_only_finish = true;
4632
4633 return 0;
4634 }
4635 }
4636 }
4637
4638 if (hashconfig->opts_type & OPTS_TYPE_HOOK23)
4639 {
4640 if (run_kernel (hashcat_ctx, device_param, KERN_RUN_23, pws_pos, pws_cnt, false, 0) == -1) return -1;
4641
4642 if (device_param->is_cuda == true)
4643 {
4644 if (hc_cuMemcpyDtoHAsync (hashcat_ctx, device_param->hooks_buf, device_param->cuda_d_hooks, pws_cnt * hashconfig->hook_size, device_param->cuda_stream) == -1) return -1;
4645
4646 if (hc_cuStreamSynchronize (hashcat_ctx, device_param->cuda_stream) == -1) return -1;
4647 }
4648
4649 if (device_param->is_hip == true)
4650 {
4651 if (hc_hipMemcpyDtoHAsync (hashcat_ctx, device_param->hooks_buf, device_param->hip_d_hooks, pws_cnt * hashconfig->hook_size, device_param->hip_stream) == -1) return -1;
4652
4653 if (hc_hipStreamSynchronize (hashcat_ctx, device_param->hip_stream) == -1) return -1;
4654 }
4655
4656 if (device_param->is_opencl == true)
4657 {
4658 /* blocking */
4659 if (hc_clEnqueueReadBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_hooks, CL_TRUE, 0, pws_cnt * hashconfig->hook_size, device_param->hooks_buf, 0, NULL, NULL) == -1) return -1;
4660 }
4661
4662 const int hook_threads = (int) user_options->hook_threads;
4663
4664 hook_thread_param_t *hook_threads_param = (hook_thread_param_t *) hcmalloc (hook_threads * sizeof (hook_thread_param_t));
4665 hc_thread_t *c_threads = (hc_thread_t *) hcmalloc (hook_threads * sizeof (hc_thread_t));
4666
4667 for (int i = 0; i < hook_threads; i++)
4668 {
4669 hook_thread_param_t *hook_thread_param = hook_threads_param + i;
4670
4671 hook_thread_param->tid = i;
4672 hook_thread_param->tsz = hook_threads;
4673
4674 hook_thread_param->module_ctx = module_ctx;
4675 hook_thread_param->status_ctx = status_ctx;
4676
4677 hook_thread_param->device_param = device_param;
4678
4679 hook_thread_param->hook_extra_param = module_ctx->hook_extra_params[i];
4680 hook_thread_param->hook_salts_buf = hashes->hook_salts_buf;
4681
4682 hook_thread_param->salt_pos = salt_pos;
4683
4684 hook_thread_param->pws_cnt = pws_cnt;
4685
4686 hc_thread_create (c_threads[i], hook23_thread, hook_thread_param);
4687 }
4688
4689 hc_thread_wait (hook_threads, c_threads);
4690
4691 hcfree (c_threads);
4692 hcfree (hook_threads_param);
4693
4694 if (device_param->is_cuda == true)
4695 {
4696 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_hooks, device_param->hooks_buf, pws_cnt * hashconfig->hook_size, device_param->cuda_stream) == -1) return -1;
4697 }
4698
4699 if (device_param->is_hip == true)
4700 {
4701 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_hooks, device_param->hooks_buf, pws_cnt * hashconfig->hook_size, device_param->hip_stream) == -1) return -1;
4702 }
4703
4704 if (device_param->is_opencl == true)
4705 {
4706 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_hooks, CL_FALSE, 0, pws_cnt * hashconfig->hook_size, device_param->hooks_buf, 0, NULL, NULL) == -1) return -1;
4707 }
4708 }
4709 }
4710 }
4711 }
4712
4713 // note: they also do not influence the performance screen
4714 // in case you want to use this, this cane make sense only if your input data comes out of tmps[]
4715
4716 if (hashconfig->opts_type & OPTS_TYPE_INIT2)
4717 {
4718 if (run_kernel (hashcat_ctx, device_param, KERN_RUN_INIT2, pws_pos, pws_cnt, false, 0) == -1) return -1;
4719 }
4720
4721 if (true)
4722 {
4723 const u32 salt_repeats = hashes->salts_buf[salt_pos].salt_repeats;
4724
4725 for (u32 salt_repeat = 0; salt_repeat <= salt_repeats; salt_repeat++)
4726 {
4727 device_param->kernel_params_buf32[34] = salt_repeat;
4728
4729 if (hashconfig->opts_type & OPTS_TYPE_LOOP2_PREPARE)
4730 {
4731 if (run_kernel (hashcat_ctx, device_param, KERN_RUN_LOOP2P, pws_pos, pws_cnt, false, 0) == -1) return -1;
4732 }
4733
4734 if (hashconfig->opts_type & OPTS_TYPE_LOOP2)
4735 {
4736 u32 iter = hashes->salts_buf[salt_pos].salt_iter2;
4737
4738 u32 loop_step = device_param->kernel_loops;
4739
4740 for (u32 loop_pos = 0, slow_iteration = 0; loop_pos < iter; loop_pos += loop_step, slow_iteration++)
4741 {
4742 u32 loop_left = iter - loop_pos;
4743
4744 loop_left = MIN (loop_left, loop_step);
4745
4746 device_param->kernel_params_buf32[28] = loop_pos;
4747 device_param->kernel_params_buf32[29] = loop_left;
4748
4749 if (run_kernel (hashcat_ctx, device_param, KERN_RUN_LOOP2, pws_pos, pws_cnt, true, slow_iteration) == -1) return -1;
4750
4751 //bug?
4752 //while (status_ctx->run_thread_level2 == false) break;
4753 if (status_ctx->run_thread_level2 == false) break;
4754
4755 /**
4756 * speed
4757 */
4758
4759 const u32 iter1r = hashes->salts_buf[salt_pos].salt_iter * (salt_repeats + 1);
4760 const u32 iter2r = hashes->salts_buf[salt_pos].salt_iter2 * (salt_repeats + 1);
4761
4762 const double iter_part = (double) (iter1r + (iter * salt_repeat) + loop_pos + loop_left) / (double) (iter1r + iter2r);
4763
4764 const u64 perf_sum_all = (u64) (pws_cnt * iter_part);
4765
4766 double speed_msec = hc_timer_get (device_param->timer_speed);
4767
4768 const u32 speed_pos = device_param->speed_pos;
4769
4770 device_param->speed_cnt[speed_pos] = perf_sum_all;
4771
4772 device_param->speed_msec[speed_pos] = speed_msec;
4773 }
4774 }
4775 }
4776 }
4777
4778 if (true)
4779 {
4780 if (hashconfig->opts_type & OPTS_TYPE_DEEP_COMP_KERNEL)
4781 {
4782 const u32 loops_cnt = hashes->salts_buf[salt_pos].digests_cnt;
4783
4784 for (u32 loops_pos = 0; loops_pos < loops_cnt; loops_pos++)
4785 {
4786 device_param->kernel_params_buf32[28] = loops_pos;
4787 device_param->kernel_params_buf32[29] = loops_cnt;
4788
4789 const u32 deep_comp_kernel = module_ctx->module_deep_comp_kernel (hashes, salt_pos, loops_pos);
4790
4791 if (run_kernel (hashcat_ctx, device_param, deep_comp_kernel, pws_pos, pws_cnt, false, 0) == -1) return -1;
4792
4793 if (status_ctx->run_thread_level2 == false) break;
4794 }
4795 }
4796 else
4797 {
4798 if (run_kernel (hashcat_ctx, device_param, KERN_RUN_3, pws_pos, pws_cnt, false, 0) == -1) return -1;
4799 }
4800 }
4801
4802 /*
4803 * maybe we should add this zero of temporary buffers
4804 * however it drops the performance from 7055338 to 7010621
4805
4806 if (device_param->is_cuda == true)
4807 {
4808 if (run_cuda_kernel_bzero (hashcat_ctx, device_param, device_param->cuda_d_tmps, device_param->size_tmps) == -1) return -1;
4809 }
4810
4811 if (device_param->is_hip == true)
4812 {
4813 if (run_hip_kernel_bzero (hashcat_ctx, device_param, device_param->hip_d_tmps, device_param->size_tmps) == -1) return -1;
4814 }
4815
4816 if (device_param->is_opencl == true)
4817 {
4818 if (run_opencl_kernel_bzero (hashcat_ctx, device_param, device_param->opencl_d_tmps, device_param->size_tmps) == -1) return -1;
4819 }
4820 */
4821
4822 if ((hashconfig->opts_type & OPTS_TYPE_HOOK12) || (hashconfig->opts_type & OPTS_TYPE_HOOK23))
4823 {
4824 if (device_param->is_cuda == true)
4825 {
4826 if (run_cuda_kernel_bzero (hashcat_ctx, device_param, device_param->cuda_d_hooks, pws_cnt * hashconfig->hook_size) == -1) return -1;
4827 }
4828
4829 if (device_param->is_hip == true)
4830 {
4831 if (run_hip_kernel_bzero (hashcat_ctx, device_param, device_param->hip_d_hooks, pws_cnt * hashconfig->hook_size) == -1) return -1;
4832 }
4833
4834 if (device_param->is_opencl == true)
4835 {
4836 if (run_opencl_kernel_bzero (hashcat_ctx, device_param, device_param->opencl_d_hooks, pws_cnt * hashconfig->hook_size) == -1) return -1;
4837 }
4838 }
4839 }
4840
4841 return 0;
4842 }
4843
rebuild_pws_compressed_append(hc_device_param_t * device_param,const u64 pws_cnt,const u8 chr)4844 static void rebuild_pws_compressed_append (hc_device_param_t *device_param, const u64 pws_cnt, const u8 chr)
4845 {
4846 // this function is used if we have to modify the compressed pws buffer in order to
4847 // append some data to each password candidate
4848
4849 u32 *tmp_pws_comp = (u32 *) hcmalloc (device_param->size_pws_comp);
4850 pw_idx_t *tmp_pws_idx = (pw_idx_t *) hcmalloc (device_param->size_pws_idx);
4851
4852 for (u32 i = 0; i < pws_cnt; i++)
4853 {
4854 pw_idx_t *pw_idx_src = device_param->pws_idx + i;
4855 pw_idx_t *pw_idx_dst = tmp_pws_idx + i;
4856
4857 const u32 src_off = pw_idx_src->off;
4858 const u32 src_len = pw_idx_src->len;
4859
4860 u8 buf[256];
4861
4862 memcpy (buf, device_param->pws_comp + src_off, src_len);
4863
4864 buf[src_len] = chr;
4865
4866 const u32 dst_len = src_len + 1;
4867
4868 const u32 dst_pw_len4 = (dst_len + 3) & ~3; // round up to multiple of 4
4869
4870 const u32 dst_pw_len4_cnt = dst_pw_len4 / 4;
4871
4872 pw_idx_dst->cnt = dst_pw_len4_cnt;
4873 pw_idx_dst->len = src_len; // this is intenionally! src_len can not be dst_len, we dont want the kernel to think 0x80 is part of the password
4874
4875 u8 *dst = (u8 *) (tmp_pws_comp + pw_idx_dst->off);
4876
4877 memcpy (dst, buf, dst_len);
4878
4879 memset (dst + dst_len, 0, dst_pw_len4 - dst_len);
4880
4881 // prepare next element
4882
4883 pw_idx_t *pw_idx_dst_next = pw_idx_dst + 1;
4884
4885 pw_idx_dst_next->off = pw_idx_dst->off + pw_idx_dst->cnt;
4886 }
4887
4888 hcfree (device_param->pws_comp);
4889 hcfree (device_param->pws_idx);
4890
4891 device_param->pws_comp = tmp_pws_comp;
4892 device_param->pws_idx = tmp_pws_idx;
4893 }
4894
run_cuda_kernel_atinit(hashcat_ctx_t * hashcat_ctx,hc_device_param_t * device_param,CUdeviceptr buf,const u64 num)4895 int run_cuda_kernel_atinit (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, CUdeviceptr buf, const u64 num)
4896 {
4897 u64 num_elements = num;
4898
4899 device_param->kernel_params_atinit[0] = (void *) &buf;
4900 device_param->kernel_params_atinit_buf64[1] = num_elements;
4901
4902 const u64 kernel_threads = device_param->kernel_wgs_atinit;
4903
4904 num_elements = CEILDIV (num_elements, kernel_threads);
4905
4906 CUfunction function = device_param->cuda_function_atinit;
4907
4908 if (hc_cuLaunchKernel (hashcat_ctx, function, num_elements, 1, 1, kernel_threads, 1, 1, 0, device_param->cuda_stream, device_param->kernel_params_atinit, NULL) == -1) return -1;
4909
4910 return 0;
4911 }
4912
run_cuda_kernel_utf8toutf16le(hashcat_ctx_t * hashcat_ctx,hc_device_param_t * device_param,CUdeviceptr buf,const u64 num)4913 int run_cuda_kernel_utf8toutf16le (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, CUdeviceptr buf, const u64 num)
4914 {
4915 u64 num_elements = num;
4916
4917 device_param->kernel_params_utf8toutf16le[0] = (void *) &buf;
4918 device_param->kernel_params_utf8toutf16le_buf64[1] = num_elements;
4919
4920 const u64 kernel_threads = device_param->kernel_wgs_utf8toutf16le;
4921
4922 num_elements = CEILDIV (num_elements, kernel_threads);
4923
4924 CUfunction function = device_param->cuda_function_utf8toutf16le;
4925
4926 if (hc_cuLaunchKernel (hashcat_ctx, function, num_elements, 1, 1, kernel_threads, 1, 1, 0, device_param->cuda_stream, device_param->kernel_params_utf8toutf16le, NULL) == -1) return -1;
4927
4928 return 0;
4929 }
4930
run_cuda_kernel_memset(hashcat_ctx_t * hashcat_ctx,hc_device_param_t * device_param,CUdeviceptr buf,const u64 offset,const u8 value,const u64 size)4931 int run_cuda_kernel_memset (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, CUdeviceptr buf, const u64 offset, const u8 value, const u64 size)
4932 {
4933 return hc_cuMemsetD8Async (hashcat_ctx, buf + offset, value, size, device_param->cuda_stream);
4934 }
4935
run_cuda_kernel_memset32(hashcat_ctx_t * hashcat_ctx,hc_device_param_t * device_param,CUdeviceptr buf,const u64 offset,const u32 value,const u64 size)4936 int run_cuda_kernel_memset32 (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, CUdeviceptr buf, const u64 offset, const u32 value, const u64 size)
4937 {
4938 /* check that the size is multiple of element size */
4939 if (size % 4 != 0)
4940 {
4941 return CUDA_ERROR_INVALID_VALUE;
4942 }
4943
4944 return hc_cuMemsetD32Async (hashcat_ctx, buf + offset, value, size / 4, device_param->cuda_stream);
4945 }
4946
run_cuda_kernel_bzero(hashcat_ctx_t * hashcat_ctx,hc_device_param_t * device_param,CUdeviceptr buf,const u64 size)4947 int run_cuda_kernel_bzero (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, CUdeviceptr buf, const u64 size)
4948 {
4949 const u64 num16d = size / 16;
4950 const u64 num16m = size % 16;
4951
4952 if (num16d)
4953 {
4954 device_param->kernel_params_bzero[0] = (void *) &buf;
4955 device_param->kernel_params_bzero_buf64[1] = num16d;
4956
4957 const u64 kernel_threads = device_param->kernel_wgs_bzero;
4958
4959 u64 num_elements = CEILDIV (num16d, kernel_threads);
4960
4961 CUfunction function = device_param->cuda_function_bzero;
4962
4963 if (hc_cuLaunchKernel (hashcat_ctx, function, num_elements, 1, 1, kernel_threads, 1, 1, 0, device_param->cuda_stream, device_param->kernel_params_bzero, NULL) == -1) return -1;
4964 }
4965
4966 if (num16m)
4967 {
4968 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, buf + (num16d * 16), bzeros, num16m, device_param->cuda_stream) == -1) return -1;
4969 }
4970
4971 return 0;
4972 }
4973
run_hip_kernel_atinit(hashcat_ctx_t * hashcat_ctx,hc_device_param_t * device_param,hipDeviceptr_t buf,const u64 num)4974 int run_hip_kernel_atinit (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, hipDeviceptr_t buf, const u64 num)
4975 {
4976 u64 num_elements = num;
4977
4978 device_param->kernel_params_atinit[0] = (void *) &buf;
4979 device_param->kernel_params_atinit_buf64[1] = num_elements;
4980
4981 const u64 kernel_threads = device_param->kernel_wgs_atinit;
4982
4983 num_elements = CEILDIV (num_elements, kernel_threads);
4984
4985 hipFunction_t function = device_param->hip_function_atinit;
4986
4987 if (hc_hipLaunchKernel (hashcat_ctx, function, num_elements, 1, 1, kernel_threads, 1, 1, 0, device_param->hip_stream, device_param->kernel_params_atinit, NULL) == -1) return -1;
4988
4989 return 0;
4990 }
4991
run_hip_kernel_utf8toutf16le(hashcat_ctx_t * hashcat_ctx,hc_device_param_t * device_param,hipDeviceptr_t buf,const u64 num)4992 int run_hip_kernel_utf8toutf16le (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, hipDeviceptr_t buf, const u64 num)
4993 {
4994 u64 num_elements = num;
4995
4996 device_param->kernel_params_utf8toutf16le[0] = (void *) &buf;
4997 device_param->kernel_params_utf8toutf16le_buf64[1] = num_elements;
4998
4999 const u64 kernel_threads = device_param->kernel_wgs_utf8toutf16le;
5000
5001 num_elements = CEILDIV (num_elements, kernel_threads);
5002
5003 hipFunction_t function = device_param->hip_function_utf8toutf16le;
5004
5005 if (hc_hipLaunchKernel (hashcat_ctx, function, num_elements, 1, 1, kernel_threads, 1, 1, 0, device_param->hip_stream, device_param->kernel_params_utf8toutf16le, NULL) == -1) return -1;
5006
5007 return 0;
5008 }
5009
run_hip_kernel_memset(hashcat_ctx_t * hashcat_ctx,hc_device_param_t * device_param,hipDeviceptr_t buf,const u64 offset,const u8 value,const u64 size)5010 int run_hip_kernel_memset (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, hipDeviceptr_t buf, const u64 offset, const u8 value, const u64 size)
5011 {
5012 return hc_hipMemsetD8Async (hashcat_ctx, buf + offset, value, size, device_param->hip_stream);
5013 }
5014
run_hip_kernel_memset32(hashcat_ctx_t * hashcat_ctx,hc_device_param_t * device_param,hipDeviceptr_t buf,const u64 offset,const u32 value,const u64 size)5015 int run_hip_kernel_memset32 (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, hipDeviceptr_t buf, const u64 offset, const u32 value, const u64 size)
5016 {
5017 /* check that the size is multiple of element size */
5018 if (size % 4 != 0)
5019 {
5020 return hipErrorInvalidValue;
5021 }
5022
5023 return hc_hipMemsetD32Async (hashcat_ctx, buf + offset, value, size / 4, device_param->hip_stream);
5024 }
5025
run_hip_kernel_bzero(hashcat_ctx_t * hashcat_ctx,hc_device_param_t * device_param,hipDeviceptr_t buf,const u64 size)5026 int run_hip_kernel_bzero (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, hipDeviceptr_t buf, const u64 size)
5027 {
5028 const u64 num16d = size / 16;
5029 const u64 num16m = size % 16;
5030
5031 if (num16d)
5032 {
5033 device_param->kernel_params_bzero[0] = (void *) &buf;
5034 device_param->kernel_params_bzero_buf64[1] = num16d;
5035
5036 const u64 kernel_threads = device_param->kernel_wgs_bzero;
5037
5038 u64 num_elements = CEILDIV(num16d, kernel_threads);
5039
5040 hipFunction_t function = device_param->hip_function_bzero;
5041
5042 if (hc_hipLaunchKernel (hashcat_ctx, function, num_elements, 1, 1, kernel_threads, 1, 1, 0, device_param->hip_stream, device_param->kernel_params_bzero, NULL) == -1) return -1;
5043 }
5044
5045 if (num16m)
5046 {
5047 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, buf + (num16d * 16), bzeros, num16m, device_param->hip_stream) == -1) return -1;
5048 }
5049
5050 return 0;
5051 }
5052
run_opencl_kernel_atinit(hashcat_ctx_t * hashcat_ctx,hc_device_param_t * device_param,cl_mem buf,const u64 num)5053 int run_opencl_kernel_atinit (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, cl_mem buf, const u64 num)
5054 {
5055 u64 num_elements = num;
5056
5057 device_param->kernel_params_atinit_buf64[1] = num_elements;
5058
5059 const u64 kernel_threads = device_param->kernel_wgs_atinit;
5060
5061 num_elements = round_up_multiple_64 (num_elements, kernel_threads);
5062
5063 cl_kernel kernel = device_param->opencl_kernel_atinit;
5064
5065 const size_t global_work_size[3] = { num_elements, 1, 1 };
5066 const size_t local_work_size[3] = { kernel_threads, 1, 1 };
5067
5068 if (hc_clSetKernelArg (hashcat_ctx, kernel, 0, sizeof (cl_mem), (void *) &buf) == -1) return -1;
5069
5070 if (hc_clSetKernelArg (hashcat_ctx, kernel, 1, sizeof (cl_ulong), device_param->kernel_params_atinit[1]) == -1) return -1;
5071
5072 if (hc_clEnqueueNDRangeKernel (hashcat_ctx, device_param->opencl_command_queue, kernel, 1, NULL, global_work_size, local_work_size, 0, NULL, NULL) == -1) return -1;
5073
5074 return 0;
5075 }
5076
run_opencl_kernel_utf8toutf16le(hashcat_ctx_t * hashcat_ctx,hc_device_param_t * device_param,cl_mem buf,const u64 num)5077 int run_opencl_kernel_utf8toutf16le (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, cl_mem buf, const u64 num)
5078 {
5079 u64 num_elements = num;
5080
5081 device_param->kernel_params_utf8toutf16le_buf64[1] = num_elements;
5082
5083 const u64 kernel_threads = device_param->kernel_wgs_utf8toutf16le;
5084
5085 num_elements = round_up_multiple_64 (num_elements, kernel_threads);
5086
5087 cl_kernel kernel = device_param->opencl_kernel_utf8toutf16le;
5088
5089 const size_t global_work_size[3] = { num_elements, 1, 1 };
5090 const size_t local_work_size[3] = { kernel_threads, 1, 1 };
5091
5092 if (hc_clSetKernelArg (hashcat_ctx, kernel, 0, sizeof (cl_mem), (void *) &buf) == -1) return -1;
5093
5094 if (hc_clSetKernelArg (hashcat_ctx, kernel, 1, sizeof (cl_ulong), device_param->kernel_params_utf8toutf16le[1]) == -1) return -1;
5095
5096 if (hc_clEnqueueNDRangeKernel (hashcat_ctx, device_param->opencl_command_queue, kernel, 1, NULL, global_work_size, local_work_size, 0, NULL, NULL) == -1) return -1;
5097
5098 return 0;
5099 }
5100
run_opencl_kernel_memset(hashcat_ctx_t * hashcat_ctx,hc_device_param_t * device_param,cl_mem buf,const u64 offset,const u8 value,const u64 size)5101 int run_opencl_kernel_memset (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, cl_mem buf, const u64 offset, const u8 value, const u64 size)
5102 {
5103 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
5104 const OCL_PTR *ocl = backend_ctx->ocl;
5105
5106 int rc;
5107
5108 /* workaround if missing clEnqueueFillBuffer() */
5109 if (ocl->clEnqueueFillBuffer == NULL)
5110 {
5111 char *tmp = hcmalloc (size * sizeof (u8));
5112
5113 memset (tmp, value, size);
5114
5115 /* blocking */
5116 rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, buf, CL_TRUE, offset, size, tmp, 0, NULL, NULL);
5117
5118 hcfree (tmp);
5119 }
5120 else
5121 {
5122 rc = hc_clEnqueueFillBuffer (hashcat_ctx, device_param->opencl_command_queue, buf, &value, sizeof (u8), offset, size, 0, NULL, NULL);
5123 }
5124
5125 return rc;
5126 }
5127
run_opencl_kernel_memset32(hashcat_ctx_t * hashcat_ctx,hc_device_param_t * device_param,cl_mem buf,const u64 offset,const u32 value,const u64 size)5128 int run_opencl_kernel_memset32 (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, cl_mem buf, const u64 offset, const u32 value, const u64 size)
5129 {
5130 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
5131 const OCL_PTR *ocl = backend_ctx->ocl;
5132
5133 int rc;
5134
5135 /* workaround if missing clEnqueueFillBuffer() */
5136 if (ocl->clEnqueueFillBuffer == NULL)
5137 {
5138 const u64 N = size / 4;
5139
5140 /* check that the size is multiple of element size */
5141 if (size % 4 != 0)
5142 {
5143 return CL_INVALID_VALUE;
5144 }
5145
5146 u32 *tmp = (u32 *) hcmalloc (size);
5147
5148 for (u64 i = 0; i < N; i++)
5149 {
5150 tmp[i] = value;
5151 }
5152
5153 /* blocking */
5154 rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, buf, CL_TRUE, offset, size, tmp, 0, NULL, NULL);
5155
5156 hcfree (tmp);
5157 }
5158 else
5159 {
5160 rc = hc_clEnqueueFillBuffer (hashcat_ctx, device_param->opencl_command_queue, buf, &value, sizeof (u32), offset, size, 0, NULL, NULL);
5161 }
5162
5163 return rc;
5164 }
5165
run_opencl_kernel_bzero(hashcat_ctx_t * hashcat_ctx,hc_device_param_t * device_param,cl_mem buf,const u64 size)5166 int run_opencl_kernel_bzero (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, cl_mem buf, const u64 size)
5167 {
5168 const u64 num16d = size / 16;
5169 const u64 num16m = size % 16;
5170
5171 // with apple GPU clEnqueueWriteBuffer() return CL_INVALID_VALUE, workaround
5172
5173 if (device_param->opencl_platform_vendor_id == VENDOR_ID_APPLE && \
5174 (device_param->opencl_device_vendor_id == VENDOR_ID_INTEL_SDK || device_param->opencl_device_vendor_id == VENDOR_ID_APPLE) && \
5175 device_param->opencl_device_type & CL_DEVICE_TYPE_GPU)
5176 {
5177 return run_opencl_kernel_memset (hashcat_ctx, device_param, buf, 0, 0, size);
5178 }
5179
5180 if (num16d)
5181 {
5182 const u64 kernel_threads = device_param->kernel_wgs_bzero;
5183
5184 u64 num_elements = round_up_multiple_64(num16d, kernel_threads);
5185
5186 cl_kernel kernel = device_param->opencl_kernel_bzero;
5187
5188 if (hc_clSetKernelArg (hashcat_ctx, kernel, 0, sizeof(cl_mem), (void *) &buf) == -1) return -1;
5189 if (hc_clSetKernelArg (hashcat_ctx, kernel, 1, sizeof(cl_ulong), (void *) &num16d) == -1) return -1;
5190
5191 const size_t global_work_size[3] = { num_elements, 1, 1 };
5192 const size_t local_work_size[3] = { kernel_threads, 1, 1 };
5193
5194 if (hc_clEnqueueNDRangeKernel (hashcat_ctx, device_param->opencl_command_queue, kernel, 1, NULL, global_work_size, local_work_size, 0, NULL, NULL) == -1) return -1;
5195 }
5196
5197 if (num16m)
5198 {
5199 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, buf, CL_FALSE, num16d * 16, num16m, bzeros, 0, NULL, NULL) == -1) return -1;
5200 }
5201
5202 return 0;
5203 }
5204
run_kernel(hashcat_ctx_t * hashcat_ctx,hc_device_param_t * device_param,const u32 kern_run,const u64 pws_pos,const u64 num,const u32 event_update,const u32 iteration)5205 int run_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u32 kern_run, const u64 pws_pos, const u64 num, const u32 event_update, const u32 iteration)
5206 {
5207 const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
5208 const status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
5209
5210 u64 kernel_threads = 0;
5211 u64 dynamic_shared_mem = 0;
5212
5213 switch (kern_run)
5214 {
5215 case KERN_RUN_1:
5216 kernel_threads = device_param->kernel_wgs1;
5217 dynamic_shared_mem = device_param->kernel_dynamic_local_mem_size1;
5218 break;
5219 case KERN_RUN_12:
5220 kernel_threads = device_param->kernel_wgs12;
5221 dynamic_shared_mem = device_param->kernel_dynamic_local_mem_size12;
5222 break;
5223 case KERN_RUN_2P:
5224 kernel_threads = device_param->kernel_wgs2p;
5225 dynamic_shared_mem = device_param->kernel_dynamic_local_mem_size2p;
5226 break;
5227 case KERN_RUN_2:
5228 kernel_threads = device_param->kernel_wgs2;
5229 dynamic_shared_mem = device_param->kernel_dynamic_local_mem_size2;
5230 break;
5231 case KERN_RUN_2E:
5232 kernel_threads = device_param->kernel_wgs2e;
5233 dynamic_shared_mem = device_param->kernel_dynamic_local_mem_size2e;
5234 break;
5235 case KERN_RUN_23:
5236 kernel_threads = device_param->kernel_wgs23;
5237 dynamic_shared_mem = device_param->kernel_dynamic_local_mem_size23;
5238 break;
5239 case KERN_RUN_3:
5240 kernel_threads = device_param->kernel_wgs3;
5241 dynamic_shared_mem = device_param->kernel_dynamic_local_mem_size3;
5242 break;
5243 case KERN_RUN_4:
5244 kernel_threads = device_param->kernel_wgs4;
5245 dynamic_shared_mem = device_param->kernel_dynamic_local_mem_size4;
5246 break;
5247 case KERN_RUN_INIT2:
5248 kernel_threads = device_param->kernel_wgs_init2;
5249 dynamic_shared_mem = device_param->kernel_dynamic_local_mem_size_init2;
5250 break;
5251 case KERN_RUN_LOOP2P:
5252 kernel_threads = device_param->kernel_wgs_loop2p;
5253 dynamic_shared_mem = device_param->kernel_dynamic_local_mem_size_loop2p;
5254 break;
5255 case KERN_RUN_LOOP2:
5256 kernel_threads = device_param->kernel_wgs_loop2;
5257 dynamic_shared_mem = device_param->kernel_dynamic_local_mem_size_loop2;
5258 break;
5259 case KERN_RUN_AUX1:
5260 kernel_threads = device_param->kernel_wgs_aux1;
5261 dynamic_shared_mem = device_param->kernel_dynamic_local_mem_size_aux1;
5262 break;
5263 case KERN_RUN_AUX2:
5264 kernel_threads = device_param->kernel_wgs_aux2;
5265 dynamic_shared_mem = device_param->kernel_dynamic_local_mem_size_aux2;
5266 break;
5267 case KERN_RUN_AUX3:
5268 kernel_threads = device_param->kernel_wgs_aux3;
5269 dynamic_shared_mem = device_param->kernel_dynamic_local_mem_size_aux3;
5270 break;
5271 case KERN_RUN_AUX4:
5272 kernel_threads = device_param->kernel_wgs_aux4;
5273 dynamic_shared_mem = device_param->kernel_dynamic_local_mem_size_aux4;
5274 break;
5275 }
5276
5277 if ((hashconfig->opts_type & OPTS_TYPE_DYNAMIC_SHARED) == 0)
5278 {
5279 dynamic_shared_mem = 0;
5280 }
5281
5282 //if (device_param->is_cuda == true)
5283 //{
5284 //if ((device_param->kernel_dynamic_local_mem_size_memset % device_param->device_local_mem_size) == 0)
5285 //{
5286 // this is the case Compute Capability 7.5
5287 // there is also Compute Capability 7.0 which offers a larger dynamic local size access
5288 // however, if it's an exact multiple the driver can optimize this for us more efficient
5289
5290 //dynamic_shared_mem = 0;
5291 //}
5292 //}
5293
5294 kernel_threads = MIN (kernel_threads, device_param->kernel_threads);
5295
5296 device_param->kernel_params_buf64[35] = pws_pos;
5297 device_param->kernel_params_buf64[36] = num;
5298
5299 u64 num_elements = num;
5300
5301 if (device_param->is_cuda == true)
5302 {
5303 CUfunction cuda_function = NULL;
5304
5305 switch (kern_run)
5306 {
5307 case KERN_RUN_1: cuda_function = device_param->cuda_function1; break;
5308 case KERN_RUN_12: cuda_function = device_param->cuda_function12; break;
5309 case KERN_RUN_2P: cuda_function = device_param->cuda_function2p; break;
5310 case KERN_RUN_2: cuda_function = device_param->cuda_function2; break;
5311 case KERN_RUN_2E: cuda_function = device_param->cuda_function2e; break;
5312 case KERN_RUN_23: cuda_function = device_param->cuda_function23; break;
5313 case KERN_RUN_3: cuda_function = device_param->cuda_function3; break;
5314 case KERN_RUN_4: cuda_function = device_param->cuda_function4; break;
5315 case KERN_RUN_INIT2: cuda_function = device_param->cuda_function_init2; break;
5316 case KERN_RUN_LOOP2P: cuda_function = device_param->cuda_function_loop2p; break;
5317 case KERN_RUN_LOOP2: cuda_function = device_param->cuda_function_loop2; break;
5318 case KERN_RUN_AUX1: cuda_function = device_param->cuda_function_aux1; break;
5319 case KERN_RUN_AUX2: cuda_function = device_param->cuda_function_aux2; break;
5320 case KERN_RUN_AUX3: cuda_function = device_param->cuda_function_aux3; break;
5321 case KERN_RUN_AUX4: cuda_function = device_param->cuda_function_aux4; break;
5322 }
5323
5324 if (hc_cuFuncSetAttribute (hashcat_ctx, cuda_function, CU_FUNC_ATTRIBUTE_MAX_DYNAMIC_SHARED_SIZE_BYTES, dynamic_shared_mem) == -1) return -1;
5325
5326 if (kernel_threads == 0) kernel_threads = 1;
5327
5328 num_elements = CEILDIV (num_elements, kernel_threads);
5329
5330 if (kern_run == KERN_RUN_1)
5331 {
5332 if (hashconfig->opti_type & OPTI_TYPE_SLOW_HASH_SIMD_INIT)
5333 {
5334 num_elements = CEILDIV (num_elements, device_param->vector_width);
5335 }
5336 }
5337 else if (kern_run == KERN_RUN_2)
5338 {
5339 if (hashconfig->opti_type & OPTI_TYPE_SLOW_HASH_SIMD_LOOP)
5340 {
5341 num_elements = CEILDIV (num_elements, device_param->vector_width);
5342 }
5343 }
5344 else if (kern_run == KERN_RUN_3)
5345 {
5346 if (hashconfig->opti_type & OPTI_TYPE_SLOW_HASH_SIMD_COMP)
5347 {
5348 num_elements = CEILDIV (num_elements, device_param->vector_width);
5349 }
5350 }
5351 else if (kern_run == KERN_RUN_INIT2)
5352 {
5353 if (hashconfig->opti_type & OPTI_TYPE_SLOW_HASH_SIMD_INIT2)
5354 {
5355 num_elements = CEILDIV (num_elements, device_param->vector_width);
5356 }
5357 }
5358 else if (kern_run == KERN_RUN_LOOP2)
5359 {
5360 if (hashconfig->opti_type & OPTI_TYPE_SLOW_HASH_SIMD_LOOP2)
5361 {
5362 num_elements = CEILDIV (num_elements, device_param->vector_width);
5363 }
5364 }
5365
5366 if (hc_cuEventRecord (hashcat_ctx, device_param->cuda_event1, device_param->cuda_stream) == -1) return -1;
5367
5368 if (hc_cuLaunchKernel (hashcat_ctx, cuda_function, num_elements, 1, 1, kernel_threads, 1, 1, dynamic_shared_mem, device_param->cuda_stream, device_param->kernel_params, NULL) == -1) return -1;
5369
5370 if (hc_cuEventRecord (hashcat_ctx, device_param->cuda_event2, device_param->cuda_stream) == -1) return -1;
5371
5372 if (hc_cuEventSynchronize (hashcat_ctx, device_param->cuda_event2) == -1) return -1;
5373
5374 float exec_ms;
5375
5376 if (hc_cuEventElapsedTime (hashcat_ctx, &exec_ms, device_param->cuda_event1, device_param->cuda_event2) == -1) return -1;
5377
5378 if (event_update)
5379 {
5380 u32 exec_pos = device_param->exec_pos;
5381
5382 device_param->exec_msec[exec_pos] = exec_ms;
5383
5384 exec_pos++;
5385
5386 if (exec_pos == EXEC_CACHE)
5387 {
5388 exec_pos = 0;
5389 }
5390
5391 device_param->exec_pos = exec_pos;
5392 }
5393 }
5394
5395 if (device_param->is_hip == true)
5396 {
5397 hipFunction_t hip_function = NULL;
5398
5399 switch (kern_run)
5400 {
5401 case KERN_RUN_1: hip_function = device_param->hip_function1; break;
5402 case KERN_RUN_12: hip_function = device_param->hip_function12; break;
5403 case KERN_RUN_2P: hip_function = device_param->hip_function2p; break;
5404 case KERN_RUN_2: hip_function = device_param->hip_function2; break;
5405 case KERN_RUN_2E: hip_function = device_param->hip_function2e; break;
5406 case KERN_RUN_23: hip_function = device_param->hip_function23; break;
5407 case KERN_RUN_3: hip_function = device_param->hip_function3; break;
5408 case KERN_RUN_4: hip_function = device_param->hip_function4; break;
5409 case KERN_RUN_INIT2: hip_function = device_param->hip_function_init2; break;
5410 case KERN_RUN_LOOP2P: hip_function = device_param->hip_function_loop2p; break;
5411 case KERN_RUN_LOOP2: hip_function = device_param->hip_function_loop2; break;
5412 case KERN_RUN_AUX1: hip_function = device_param->hip_function_aux1; break;
5413 case KERN_RUN_AUX2: hip_function = device_param->hip_function_aux2; break;
5414 case KERN_RUN_AUX3: hip_function = device_param->hip_function_aux3; break;
5415 case KERN_RUN_AUX4: hip_function = device_param->hip_function_aux4; break;
5416 }
5417
5418 //if (hc_hipFuncSetAttribute (hashcat_ctx, hip_function, HIP_FUNC_ATTRIBUTE_MAX_DYNAMIC_SHARED_SIZE_BYTES, dynamic_shared_mem) == -1) return -1;
5419
5420 if (kernel_threads == 0) kernel_threads = 1;
5421
5422 num_elements = CEILDIV (num_elements, kernel_threads);
5423
5424 if (kern_run == KERN_RUN_1)
5425 {
5426 if (hashconfig->opti_type & OPTI_TYPE_SLOW_HASH_SIMD_INIT)
5427 {
5428 num_elements = CEILDIV (num_elements, device_param->vector_width);
5429 }
5430 }
5431 else if (kern_run == KERN_RUN_2)
5432 {
5433 if (hashconfig->opti_type & OPTI_TYPE_SLOW_HASH_SIMD_LOOP)
5434 {
5435 num_elements = CEILDIV (num_elements, device_param->vector_width);
5436 }
5437 }
5438 else if (kern_run == KERN_RUN_3)
5439 {
5440 if (hashconfig->opti_type & OPTI_TYPE_SLOW_HASH_SIMD_COMP)
5441 {
5442 num_elements = CEILDIV (num_elements, device_param->vector_width);
5443 }
5444 }
5445 else if (kern_run == KERN_RUN_INIT2)
5446 {
5447 if (hashconfig->opti_type & OPTI_TYPE_SLOW_HASH_SIMD_INIT2)
5448 {
5449 num_elements = CEILDIV (num_elements, device_param->vector_width);
5450 }
5451 }
5452 else if (kern_run == KERN_RUN_LOOP2)
5453 {
5454 if (hashconfig->opti_type & OPTI_TYPE_SLOW_HASH_SIMD_LOOP2)
5455 {
5456 num_elements = CEILDIV (num_elements, device_param->vector_width);
5457 }
5458 }
5459
5460 if (hc_hipEventRecord (hashcat_ctx, device_param->hip_event1, device_param->hip_stream) == -1) return -1;
5461
5462 if (hc_hipLaunchKernel (hashcat_ctx, hip_function, num_elements, 1, 1, kernel_threads, 1, 1, dynamic_shared_mem, device_param->hip_stream, device_param->kernel_params, NULL) == -1) return -1;
5463
5464 if (hc_hipEventRecord (hashcat_ctx, device_param->hip_event2, device_param->hip_stream) == -1) return -1;
5465
5466 if (hc_hipEventSynchronize (hashcat_ctx, device_param->hip_event2) == -1) return -1;
5467
5468 float exec_ms;
5469
5470 if (hc_hipEventElapsedTime (hashcat_ctx, &exec_ms, device_param->hip_event1, device_param->hip_event2) == -1) return -1;
5471
5472 if (event_update)
5473 {
5474 u32 exec_pos = device_param->exec_pos;
5475
5476 device_param->exec_msec[exec_pos] = exec_ms;
5477
5478 exec_pos++;
5479
5480 if (exec_pos == EXEC_CACHE)
5481 {
5482 exec_pos = 0;
5483 }
5484
5485 device_param->exec_pos = exec_pos;
5486 }
5487 }
5488
5489 if (device_param->is_opencl == true)
5490 {
5491 cl_kernel opencl_kernel = NULL;
5492
5493 switch (kern_run)
5494 {
5495 case KERN_RUN_1: opencl_kernel = device_param->opencl_kernel1; break;
5496 case KERN_RUN_12: opencl_kernel = device_param->opencl_kernel12; break;
5497 case KERN_RUN_2P: opencl_kernel = device_param->opencl_kernel2p; break;
5498 case KERN_RUN_2: opencl_kernel = device_param->opencl_kernel2; break;
5499 case KERN_RUN_2E: opencl_kernel = device_param->opencl_kernel2e; break;
5500 case KERN_RUN_23: opencl_kernel = device_param->opencl_kernel23; break;
5501 case KERN_RUN_3: opencl_kernel = device_param->opencl_kernel3; break;
5502 case KERN_RUN_4: opencl_kernel = device_param->opencl_kernel4; break;
5503 case KERN_RUN_INIT2: opencl_kernel = device_param->opencl_kernel_init2; break;
5504 case KERN_RUN_LOOP2P: opencl_kernel = device_param->opencl_kernel_loop2p; break;
5505 case KERN_RUN_LOOP2: opencl_kernel = device_param->opencl_kernel_loop2; break;
5506 case KERN_RUN_AUX1: opencl_kernel = device_param->opencl_kernel_aux1; break;
5507 case KERN_RUN_AUX2: opencl_kernel = device_param->opencl_kernel_aux2; break;
5508 case KERN_RUN_AUX3: opencl_kernel = device_param->opencl_kernel_aux3; break;
5509 case KERN_RUN_AUX4: opencl_kernel = device_param->opencl_kernel_aux4; break;
5510 }
5511
5512 for (u32 i = 0; i <= 23; i++)
5513 {
5514 if (hc_clSetKernelArg (hashcat_ctx, opencl_kernel, i, sizeof (cl_mem), device_param->kernel_params[i]) == -1) return -1;
5515 }
5516
5517 for (u32 i = 24; i <= 34; i++)
5518 {
5519 if (hc_clSetKernelArg (hashcat_ctx, opencl_kernel, i, sizeof (cl_uint), device_param->kernel_params[i]) == -1) return -1;
5520 }
5521
5522 for (u32 i = 35; i <= 36; i++)
5523 {
5524 if (hc_clSetKernelArg (hashcat_ctx, opencl_kernel, i, sizeof (cl_ulong), device_param->kernel_params[i]) == -1) return -1;
5525 }
5526
5527 num_elements = round_up_multiple_64 (num_elements, kernel_threads);
5528
5529 cl_event opencl_event;
5530
5531 if (kern_run == KERN_RUN_1)
5532 {
5533 if (hashconfig->opti_type & OPTI_TYPE_SLOW_HASH_SIMD_INIT)
5534 {
5535 num_elements = CEILDIV (num_elements, device_param->vector_width);
5536 }
5537 }
5538 else if (kern_run == KERN_RUN_2)
5539 {
5540 if (hashconfig->opti_type & OPTI_TYPE_SLOW_HASH_SIMD_LOOP)
5541 {
5542 num_elements = CEILDIV (num_elements, device_param->vector_width);
5543 }
5544 }
5545 else if (kern_run == KERN_RUN_3)
5546 {
5547 if (hashconfig->opti_type & OPTI_TYPE_SLOW_HASH_SIMD_COMP)
5548 {
5549 num_elements = CEILDIV (num_elements, device_param->vector_width);
5550 }
5551 }
5552
5553 num_elements = round_up_multiple_64 (num_elements, kernel_threads);
5554
5555 const size_t global_work_size[3] = { num_elements, 1, 1 };
5556 const size_t local_work_size[3] = { kernel_threads, 1, 1 };
5557
5558 if (hc_clEnqueueNDRangeKernel (hashcat_ctx, device_param->opencl_command_queue, opencl_kernel, 1, NULL, global_work_size, local_work_size, 0, NULL, &opencl_event) == -1) return -1;
5559
5560 // spin damper section
5561
5562 const u32 iterationm = iteration % EXPECTED_ITERATIONS;
5563
5564 if (device_param->spin_damp > 0)
5565 {
5566 cl_int opencl_event_status;
5567
5568 size_t param_value_size_ret;
5569
5570 if (hc_clFlush (hashcat_ctx, device_param->opencl_command_queue) == -1) return -1;
5571
5572 if (hc_clGetEventInfo (hashcat_ctx, opencl_event, CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof (opencl_event_status), &opencl_event_status, ¶m_value_size_ret) == -1) return -1;
5573
5574 double spin_total = device_param->spin_damp;
5575
5576 while (opencl_event_status != CL_COMPLETE)
5577 {
5578 if (status_ctx->devices_status == STATUS_RUNNING)
5579 {
5580 switch (kern_run)
5581 {
5582 case KERN_RUN_1: if (device_param->exec_us_prev1[iterationm] > 0) usleep ((useconds_t) (device_param->exec_us_prev1[iterationm] * device_param->spin_damp)); break;
5583 case KERN_RUN_2P: if (device_param->exec_us_prev2p[iterationm] > 0) usleep ((useconds_t) (device_param->exec_us_prev2p[iterationm] * device_param->spin_damp)); break;
5584 case KERN_RUN_2: if (device_param->exec_us_prev2[iterationm] > 0) usleep ((useconds_t) (device_param->exec_us_prev2[iterationm] * device_param->spin_damp)); break;
5585 case KERN_RUN_2E: if (device_param->exec_us_prev2e[iterationm] > 0) usleep ((useconds_t) (device_param->exec_us_prev2e[iterationm] * device_param->spin_damp)); break;
5586 case KERN_RUN_3: if (device_param->exec_us_prev3[iterationm] > 0) usleep ((useconds_t) (device_param->exec_us_prev3[iterationm] * device_param->spin_damp)); break;
5587 case KERN_RUN_4: if (device_param->exec_us_prev4[iterationm] > 0) usleep ((useconds_t) (device_param->exec_us_prev4[iterationm] * device_param->spin_damp)); break;
5588 case KERN_RUN_INIT2: if (device_param->exec_us_prev_init2[iterationm] > 0) usleep ((useconds_t) (device_param->exec_us_prev_init2[iterationm] * device_param->spin_damp)); break;
5589 case KERN_RUN_LOOP2P: if (device_param->exec_us_prev_loop2p[iterationm] > 0) usleep ((useconds_t) (device_param->exec_us_prev_loop2p[iterationm] * device_param->spin_damp)); break;
5590 case KERN_RUN_LOOP2: if (device_param->exec_us_prev_loop2[iterationm] > 0) usleep ((useconds_t) (device_param->exec_us_prev_loop2[iterationm] * device_param->spin_damp)); break;
5591 case KERN_RUN_AUX1: if (device_param->exec_us_prev_aux1[iterationm] > 0) usleep ((useconds_t) (device_param->exec_us_prev_aux1[iterationm] * device_param->spin_damp)); break;
5592 case KERN_RUN_AUX2: if (device_param->exec_us_prev_aux2[iterationm] > 0) usleep ((useconds_t) (device_param->exec_us_prev_aux2[iterationm] * device_param->spin_damp)); break;
5593 case KERN_RUN_AUX3: if (device_param->exec_us_prev_aux3[iterationm] > 0) usleep ((useconds_t) (device_param->exec_us_prev_aux3[iterationm] * device_param->spin_damp)); break;
5594 case KERN_RUN_AUX4: if (device_param->exec_us_prev_aux4[iterationm] > 0) usleep ((useconds_t) (device_param->exec_us_prev_aux4[iterationm] * device_param->spin_damp)); break;
5595 }
5596 }
5597 else
5598 {
5599 // we were told to be nice
5600
5601 sleep (0);
5602 }
5603
5604 if (hc_clGetEventInfo (hashcat_ctx, opencl_event, CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof (opencl_event_status), &opencl_event_status, ¶m_value_size_ret) == -1) return -1;
5605
5606 spin_total += device_param->spin_damp;
5607
5608 if (spin_total > 1)
5609 {
5610 if (hc_clWaitForEvents (hashcat_ctx, 1, &opencl_event) == -1) return -1;
5611
5612 break;
5613 }
5614 }
5615 }
5616 else
5617 {
5618 if (hc_clWaitForEvents (hashcat_ctx, 1, &opencl_event) == -1) return -1;
5619 }
5620
5621 cl_ulong time_start;
5622 cl_ulong time_end;
5623
5624 if (hc_clGetEventProfilingInfo (hashcat_ctx, opencl_event, CL_PROFILING_COMMAND_START, sizeof (time_start), &time_start, NULL) == -1) return -1;
5625 if (hc_clGetEventProfilingInfo (hashcat_ctx, opencl_event, CL_PROFILING_COMMAND_END, sizeof (time_end), &time_end, NULL) == -1) return -1;
5626
5627 const double exec_us = (double) (time_end - time_start) / 1000;
5628
5629 if (device_param->spin_damp > 0)
5630 {
5631 if (status_ctx->devices_status == STATUS_RUNNING)
5632 {
5633 switch (kern_run)
5634 {
5635 case KERN_RUN_1: device_param->exec_us_prev1[iterationm] = exec_us; break;
5636 case KERN_RUN_2P: device_param->exec_us_prev2p[iterationm] = exec_us; break;
5637 case KERN_RUN_2: device_param->exec_us_prev2[iterationm] = exec_us; break;
5638 case KERN_RUN_2E: device_param->exec_us_prev2e[iterationm] = exec_us; break;
5639 case KERN_RUN_3: device_param->exec_us_prev3[iterationm] = exec_us; break;
5640 case KERN_RUN_4: device_param->exec_us_prev4[iterationm] = exec_us; break;
5641 case KERN_RUN_INIT2: device_param->exec_us_prev_init2[iterationm] = exec_us; break;
5642 case KERN_RUN_LOOP2P: device_param->exec_us_prev_loop2p[iterationm] = exec_us; break;
5643 case KERN_RUN_LOOP2: device_param->exec_us_prev_loop2[iterationm] = exec_us; break;
5644 case KERN_RUN_AUX1: device_param->exec_us_prev_aux1[iterationm] = exec_us; break;
5645 case KERN_RUN_AUX2: device_param->exec_us_prev_aux2[iterationm] = exec_us; break;
5646 case KERN_RUN_AUX3: device_param->exec_us_prev_aux3[iterationm] = exec_us; break;
5647 case KERN_RUN_AUX4: device_param->exec_us_prev_aux4[iterationm] = exec_us; break;
5648 }
5649 }
5650 }
5651
5652 if (event_update)
5653 {
5654 u32 exec_pos = device_param->exec_pos;
5655
5656 device_param->exec_msec[exec_pos] = exec_us / 1000;
5657
5658 exec_pos++;
5659
5660 if (exec_pos == EXEC_CACHE)
5661 {
5662 exec_pos = 0;
5663 }
5664
5665 device_param->exec_pos = exec_pos;
5666 }
5667
5668 if (hc_clReleaseEvent (hashcat_ctx, opencl_event) == -1) return -1;
5669 }
5670
5671 return 0;
5672 }
5673
run_kernel_mp(hashcat_ctx_t * hashcat_ctx,hc_device_param_t * device_param,const u32 kern_run,const u64 num)5674 int run_kernel_mp (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u32 kern_run, const u64 num)
5675 {
5676 u64 kernel_threads = 0;
5677
5678 switch (kern_run)
5679 {
5680 case KERN_RUN_MP: kernel_threads = device_param->kernel_wgs_mp; break;
5681 case KERN_RUN_MP_R: kernel_threads = device_param->kernel_wgs_mp_r; break;
5682 case KERN_RUN_MP_L: kernel_threads = device_param->kernel_wgs_mp_l; break;
5683 }
5684
5685 u64 num_elements = num;
5686
5687 switch (kern_run)
5688 {
5689 case KERN_RUN_MP: device_param->kernel_params_mp_buf64[8] = num; break;
5690 case KERN_RUN_MP_R: device_param->kernel_params_mp_r_buf64[8] = num; break;
5691 case KERN_RUN_MP_L: device_param->kernel_params_mp_l_buf64[9] = num; break;
5692 }
5693
5694 if (device_param->is_cuda == true)
5695 {
5696 CUfunction cuda_function = NULL;
5697
5698 void **cuda_args = NULL;
5699
5700 switch (kern_run)
5701 {
5702 case KERN_RUN_MP: cuda_function = device_param->cuda_function_mp;
5703 cuda_args = device_param->kernel_params_mp;
5704 break;
5705 case KERN_RUN_MP_R: cuda_function = device_param->cuda_function_mp_r;
5706 cuda_args = device_param->kernel_params_mp_r;
5707 break;
5708 case KERN_RUN_MP_L: cuda_function = device_param->cuda_function_mp_l;
5709 cuda_args = device_param->kernel_params_mp_l;
5710 break;
5711 }
5712
5713 num_elements = CEILDIV (num_elements, kernel_threads);
5714
5715 if (hc_cuLaunchKernel (hashcat_ctx, cuda_function, num_elements, 1, 1, kernel_threads, 1, 1, 0, device_param->cuda_stream, cuda_args, NULL) == -1) return -1;
5716 }
5717
5718 if (device_param->is_hip == true)
5719 {
5720 hipFunction_t hip_function = NULL;
5721
5722 void **hip_args = NULL;
5723
5724 switch (kern_run)
5725 {
5726 case KERN_RUN_MP: hip_function = device_param->hip_function_mp;
5727 hip_args = device_param->kernel_params_mp;
5728 break;
5729 case KERN_RUN_MP_R: hip_function = device_param->hip_function_mp_r;
5730 hip_args = device_param->kernel_params_mp_r;
5731 break;
5732 case KERN_RUN_MP_L: hip_function = device_param->hip_function_mp_l;
5733 hip_args = device_param->kernel_params_mp_l;
5734 break;
5735 }
5736
5737 num_elements = CEILDIV (num_elements, kernel_threads);
5738
5739 if (hc_hipLaunchKernel (hashcat_ctx, hip_function, num_elements, 1, 1, kernel_threads, 1, 1, 0, device_param->hip_stream, hip_args, NULL) == -1) return -1;
5740 }
5741
5742 if (device_param->is_opencl == true)
5743 {
5744 cl_kernel opencl_kernel = NULL;
5745
5746 switch (kern_run)
5747 {
5748 case KERN_RUN_MP: opencl_kernel = device_param->opencl_kernel_mp; break;
5749 case KERN_RUN_MP_R: opencl_kernel = device_param->opencl_kernel_mp_r; break;
5750 case KERN_RUN_MP_L: opencl_kernel = device_param->opencl_kernel_mp_l; break;
5751 }
5752
5753 switch (kern_run)
5754 {
5755 case KERN_RUN_MP: if (hc_clSetKernelArg (hashcat_ctx, opencl_kernel, 3, sizeof (cl_ulong), device_param->kernel_params_mp[3]) == -1) return -1;
5756 if (hc_clSetKernelArg (hashcat_ctx, opencl_kernel, 4, sizeof (cl_uint), device_param->kernel_params_mp[4]) == -1) return -1;
5757 if (hc_clSetKernelArg (hashcat_ctx, opencl_kernel, 5, sizeof (cl_uint), device_param->kernel_params_mp[5]) == -1) return -1;
5758 if (hc_clSetKernelArg (hashcat_ctx, opencl_kernel, 6, sizeof (cl_uint), device_param->kernel_params_mp[6]) == -1) return -1;
5759 if (hc_clSetKernelArg (hashcat_ctx, opencl_kernel, 7, sizeof (cl_uint), device_param->kernel_params_mp[7]) == -1) return -1;
5760 if (hc_clSetKernelArg (hashcat_ctx, opencl_kernel, 8, sizeof (cl_ulong), device_param->kernel_params_mp[8]) == -1) return -1;
5761 break;
5762 case KERN_RUN_MP_R: if (hc_clSetKernelArg (hashcat_ctx, opencl_kernel, 3, sizeof (cl_ulong), device_param->kernel_params_mp_r[3]) == -1) return -1;
5763 if (hc_clSetKernelArg (hashcat_ctx, opencl_kernel, 4, sizeof (cl_uint), device_param->kernel_params_mp_r[4]) == -1) return -1;
5764 if (hc_clSetKernelArg (hashcat_ctx, opencl_kernel, 5, sizeof (cl_uint), device_param->kernel_params_mp_r[5]) == -1) return -1;
5765 if (hc_clSetKernelArg (hashcat_ctx, opencl_kernel, 6, sizeof (cl_uint), device_param->kernel_params_mp_r[6]) == -1) return -1;
5766 if (hc_clSetKernelArg (hashcat_ctx, opencl_kernel, 7, sizeof (cl_uint), device_param->kernel_params_mp_r[7]) == -1) return -1;
5767 if (hc_clSetKernelArg (hashcat_ctx, opencl_kernel, 8, sizeof (cl_ulong), device_param->kernel_params_mp_r[8]) == -1) return -1;
5768 break;
5769 case KERN_RUN_MP_L: if (hc_clSetKernelArg (hashcat_ctx, opencl_kernel, 3, sizeof (cl_ulong), device_param->kernel_params_mp_l[3]) == -1) return -1;
5770 if (hc_clSetKernelArg (hashcat_ctx, opencl_kernel, 4, sizeof (cl_uint), device_param->kernel_params_mp_l[4]) == -1) return -1;
5771 if (hc_clSetKernelArg (hashcat_ctx, opencl_kernel, 5, sizeof (cl_uint), device_param->kernel_params_mp_l[5]) == -1) return -1;
5772 if (hc_clSetKernelArg (hashcat_ctx, opencl_kernel, 6, sizeof (cl_uint), device_param->kernel_params_mp_l[6]) == -1) return -1;
5773 if (hc_clSetKernelArg (hashcat_ctx, opencl_kernel, 7, sizeof (cl_uint), device_param->kernel_params_mp_l[7]) == -1) return -1;
5774 if (hc_clSetKernelArg (hashcat_ctx, opencl_kernel, 8, sizeof (cl_uint), device_param->kernel_params_mp_l[8]) == -1) return -1;
5775 if (hc_clSetKernelArg (hashcat_ctx, opencl_kernel, 9, sizeof (cl_ulong), device_param->kernel_params_mp_l[9]) == -1) return -1;
5776 break;
5777 }
5778
5779 num_elements = round_up_multiple_64 (num_elements, kernel_threads);
5780
5781 const size_t global_work_size[3] = { num_elements, 1, 1 };
5782 const size_t local_work_size[3] = { kernel_threads, 1, 1 };
5783
5784 if (hc_clEnqueueNDRangeKernel (hashcat_ctx, device_param->opencl_command_queue, opencl_kernel, 1, NULL, global_work_size, local_work_size, 0, NULL, NULL) == -1) return -1;
5785 }
5786
5787 return 0;
5788 }
5789
run_kernel_tm(hashcat_ctx_t * hashcat_ctx,hc_device_param_t * device_param)5790 int run_kernel_tm (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param)
5791 {
5792 const u64 num_elements = 1024; // fixed
5793
5794 const u64 kernel_threads = MIN (num_elements, device_param->kernel_wgs_tm);
5795
5796 if (device_param->is_cuda == true)
5797 {
5798 CUfunction cuda_function = device_param->cuda_function_tm;
5799
5800 if (hc_cuLaunchKernel (hashcat_ctx, cuda_function, num_elements / kernel_threads, 1, 1, kernel_threads, 1, 1, 0, device_param->cuda_stream, device_param->kernel_params_tm, NULL) == -1) return -1;
5801 }
5802
5803 if (device_param->is_hip == true)
5804 {
5805 hipFunction_t hip_function = device_param->hip_function_tm;
5806
5807 if (hc_hipLaunchKernel (hashcat_ctx, hip_function, num_elements / kernel_threads, 1, 1, kernel_threads, 1, 1, 0, device_param->hip_stream, device_param->kernel_params_tm, NULL) == -1) return -1;
5808 }
5809
5810 if (device_param->is_opencl == true)
5811 {
5812 cl_kernel cuda_kernel = device_param->opencl_kernel_tm;
5813
5814 const size_t global_work_size[3] = { num_elements, 1, 1 };
5815 const size_t local_work_size[3] = { kernel_threads, 1, 1 };
5816
5817 if (hc_clEnqueueNDRangeKernel (hashcat_ctx, device_param->opencl_command_queue, cuda_kernel, 1, NULL, global_work_size, local_work_size, 0, NULL, NULL) == -1) return -1;
5818 }
5819
5820 return 0;
5821 }
5822
run_kernel_amp(hashcat_ctx_t * hashcat_ctx,hc_device_param_t * device_param,const u64 num)5823 int run_kernel_amp (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u64 num)
5824 {
5825 device_param->kernel_params_amp_buf64[6] = num;
5826
5827 u64 num_elements = num;
5828
5829 const u64 kernel_threads = device_param->kernel_wgs_amp;
5830
5831 if (device_param->is_cuda == true)
5832 {
5833 num_elements = CEILDIV (num_elements, kernel_threads);
5834
5835 CUfunction cuda_function = device_param->cuda_function_amp;
5836
5837 if (hc_cuLaunchKernel (hashcat_ctx, cuda_function, num_elements, 1, 1, kernel_threads, 1, 1, 0, device_param->cuda_stream, device_param->kernel_params_amp, NULL) == -1) return -1;
5838 }
5839
5840 if (device_param->is_hip == true)
5841 {
5842 num_elements = CEILDIV (num_elements, kernel_threads);
5843
5844 hipFunction_t hip_function = device_param->hip_function_amp;
5845
5846 if (hc_hipLaunchKernel (hashcat_ctx, hip_function, num_elements, 1, 1, kernel_threads, 1, 1, 0, device_param->hip_stream, device_param->kernel_params_amp, NULL) == -1) return -1;
5847 }
5848
5849 if (device_param->is_opencl == true)
5850 {
5851 num_elements = round_up_multiple_64 (num_elements, kernel_threads);
5852
5853 cl_kernel opencl_kernel = device_param->opencl_kernel_amp;
5854
5855 if (hc_clSetKernelArg (hashcat_ctx, opencl_kernel, 6, sizeof (cl_ulong), device_param->kernel_params_amp[6]) == -1) return -1;
5856
5857 const size_t global_work_size[3] = { num_elements, 1, 1 };
5858 const size_t local_work_size[3] = { kernel_threads, 1, 1 };
5859
5860 if (hc_clEnqueueNDRangeKernel (hashcat_ctx, device_param->opencl_command_queue, opencl_kernel, 1, NULL, global_work_size, local_work_size, 0, NULL, NULL) == -1) return -1;
5861 }
5862
5863 return 0;
5864 }
5865
run_kernel_decompress(hashcat_ctx_t * hashcat_ctx,hc_device_param_t * device_param,const u64 num)5866 int run_kernel_decompress (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u64 num)
5867 {
5868 device_param->kernel_params_decompress_buf64[3] = num;
5869
5870 u64 num_elements = num;
5871
5872 const u64 kernel_threads = device_param->kernel_wgs_decompress;
5873
5874 if (device_param->is_cuda == true)
5875 {
5876 num_elements = CEILDIV (num_elements, kernel_threads);
5877
5878 CUfunction cuda_function = device_param->cuda_function_decompress;
5879
5880 if (hc_cuLaunchKernel (hashcat_ctx, cuda_function, num_elements, 1, 1, kernel_threads, 1, 1, 0, device_param->cuda_stream, device_param->kernel_params_decompress, NULL) == -1) return -1;
5881 }
5882
5883 if (device_param->is_hip == true)
5884 {
5885 num_elements = CEILDIV (num_elements, kernel_threads);
5886
5887 hipFunction_t hip_function = device_param->hip_function_decompress;
5888
5889 if (hc_hipLaunchKernel (hashcat_ctx, hip_function, num_elements, 1, 1, kernel_threads, 1, 1, 0, device_param->hip_stream, device_param->kernel_params_decompress, NULL) == -1) return -1;
5890 }
5891
5892 if (device_param->is_opencl == true)
5893 {
5894 num_elements = round_up_multiple_64 (num_elements, kernel_threads);
5895
5896 cl_kernel opencl_kernel = device_param->opencl_kernel_decompress;
5897
5898 const size_t global_work_size[3] = { num_elements, 1, 1 };
5899 const size_t local_work_size[3] = { kernel_threads, 1, 1 };
5900
5901 if (hc_clSetKernelArg (hashcat_ctx, opencl_kernel, 3, sizeof (cl_ulong), device_param->kernel_params_decompress[3]) == -1) return -1;
5902
5903 if (hc_clEnqueueNDRangeKernel (hashcat_ctx, device_param->opencl_command_queue, opencl_kernel, 1, NULL, global_work_size, local_work_size, 0, NULL, NULL) == -1) return -1;
5904 }
5905
5906 return 0;
5907 }
5908
run_copy(hashcat_ctx_t * hashcat_ctx,hc_device_param_t * device_param,const u64 pws_cnt)5909 int run_copy (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u64 pws_cnt)
5910 {
5911 combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx;
5912 hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
5913 user_options_t *user_options = hashcat_ctx->user_options;
5914 user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra;
5915
5916 // init speed timer
5917
5918 #if defined (_WIN)
5919 if (device_param->timer_speed.QuadPart == 0)
5920 {
5921 hc_timer_set (&device_param->timer_speed);
5922 }
5923 #else
5924 if (device_param->timer_speed.tv_sec == 0)
5925 {
5926 hc_timer_set (&device_param->timer_speed);
5927 }
5928 #endif
5929
5930 if (user_options->slow_candidates == true)
5931 {
5932 if (device_param->is_cuda == true)
5933 {
5934 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_pws_idx, device_param->pws_idx, pws_cnt * sizeof (pw_idx_t), device_param->cuda_stream) == -1) return -1;
5935
5936 const pw_idx_t *pw_idx = device_param->pws_idx + pws_cnt;
5937
5938 const u32 off = pw_idx->off;
5939
5940 if (off)
5941 {
5942 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_pws_comp_buf, device_param->pws_comp, off * sizeof (u32), device_param->cuda_stream) == -1) return -1;
5943 }
5944 }
5945
5946 if (device_param->is_hip == true)
5947 {
5948 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_pws_idx, device_param->pws_idx, pws_cnt * sizeof (pw_idx_t), device_param->hip_stream) == -1) return -1;
5949
5950 const pw_idx_t *pw_idx = device_param->pws_idx + pws_cnt;
5951
5952 const u32 off = pw_idx->off;
5953
5954 if (off)
5955 {
5956 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_pws_comp_buf, device_param->pws_comp, off * sizeof (u32), device_param->hip_stream) == -1) return -1;
5957 }
5958 }
5959
5960 if (device_param->is_opencl == true)
5961 {
5962 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_pws_idx, CL_FALSE, 0, pws_cnt * sizeof (pw_idx_t), device_param->pws_idx, 0, NULL, NULL) == -1) return -1;
5963
5964 const pw_idx_t *pw_idx = device_param->pws_idx + pws_cnt;
5965
5966 const u32 off = pw_idx->off;
5967
5968 if (off)
5969 {
5970 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_pws_comp_buf, CL_FALSE, 0, off * sizeof (u32), device_param->pws_comp, 0, NULL, NULL) == -1) return -1;
5971 }
5972 }
5973
5974 if (run_kernel_decompress (hashcat_ctx, device_param, pws_cnt) == -1) return -1;
5975 }
5976 else
5977 {
5978 if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT)
5979 {
5980 if (device_param->is_cuda == true)
5981 {
5982 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_pws_idx, device_param->pws_idx, pws_cnt * sizeof (pw_idx_t), device_param->cuda_stream) == -1) return -1;
5983
5984 const pw_idx_t *pw_idx = device_param->pws_idx + pws_cnt;
5985
5986 const u32 off = pw_idx->off;
5987
5988 if (off)
5989 {
5990 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_pws_comp_buf, device_param->pws_comp, off * sizeof (u32), device_param->cuda_stream) == -1) return -1;
5991 }
5992 }
5993
5994 if (device_param->is_hip == true)
5995 {
5996 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_pws_idx, device_param->pws_idx, pws_cnt * sizeof (pw_idx_t), device_param->hip_stream) == -1) return -1;
5997
5998 const pw_idx_t *pw_idx = device_param->pws_idx + pws_cnt;
5999
6000 const u32 off = pw_idx->off;
6001
6002 if (off)
6003 {
6004 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_pws_comp_buf, device_param->pws_comp, off * sizeof (u32), device_param->hip_stream) == -1) return -1;
6005 }
6006 }
6007
6008 if (device_param->is_opencl == true)
6009 {
6010 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_pws_idx, CL_FALSE, 0, pws_cnt * sizeof (pw_idx_t), device_param->pws_idx, 0, NULL, NULL) == -1) return -1;
6011
6012 const pw_idx_t *pw_idx = device_param->pws_idx + pws_cnt;
6013
6014 const u32 off = pw_idx->off;
6015
6016 if (off)
6017 {
6018 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_pws_comp_buf, CL_FALSE, 0, off * sizeof (u32), device_param->pws_comp, 0, NULL, NULL) == -1) return -1;
6019 }
6020 }
6021
6022 if (run_kernel_decompress (hashcat_ctx, device_param, pws_cnt) == -1) return -1;
6023 }
6024 else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI)
6025 {
6026 if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
6027 {
6028 if (user_options->attack_mode == ATTACK_MODE_COMBI)
6029 {
6030 if (combinator_ctx->combs_mode == COMBINATOR_MODE_BASE_RIGHT)
6031 {
6032 if (hashconfig->opts_type & OPTS_TYPE_PT_ADD01)
6033 {
6034 rebuild_pws_compressed_append (device_param, pws_cnt, 0x01);
6035 }
6036 else if (hashconfig->opts_type & OPTS_TYPE_PT_ADD06)
6037 {
6038 rebuild_pws_compressed_append (device_param, pws_cnt, 0x06);
6039 }
6040 else if (hashconfig->opts_type & OPTS_TYPE_PT_ADD80)
6041 {
6042 rebuild_pws_compressed_append (device_param, pws_cnt, 0x80);
6043 }
6044 }
6045 }
6046 else if (user_options->attack_mode == ATTACK_MODE_HYBRID2)
6047 {
6048 if (hashconfig->opts_type & OPTS_TYPE_PT_ADD01)
6049 {
6050 rebuild_pws_compressed_append (device_param, pws_cnt, 0x01);
6051 }
6052 else if (hashconfig->opts_type & OPTS_TYPE_PT_ADD06)
6053 {
6054 rebuild_pws_compressed_append (device_param, pws_cnt, 0x06);
6055 }
6056 else if (hashconfig->opts_type & OPTS_TYPE_PT_ADD80)
6057 {
6058 rebuild_pws_compressed_append (device_param, pws_cnt, 0x80);
6059 }
6060 }
6061
6062 if (device_param->is_cuda == true)
6063 {
6064 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_pws_idx, device_param->pws_idx, pws_cnt * sizeof (pw_idx_t), device_param->cuda_stream) == -1) return -1;
6065
6066 const pw_idx_t *pw_idx = device_param->pws_idx + pws_cnt;
6067
6068 const u32 off = pw_idx->off;
6069
6070 if (off)
6071 {
6072 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_pws_comp_buf, device_param->pws_comp, off * sizeof (u32), device_param->cuda_stream) == -1) return -1;
6073 }
6074 }
6075
6076 if (device_param->is_hip == true)
6077 {
6078 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_pws_idx, device_param->pws_idx, pws_cnt * sizeof (pw_idx_t), device_param->hip_stream) == -1) return -1;
6079
6080 const pw_idx_t *pw_idx = device_param->pws_idx + pws_cnt;
6081
6082 const u32 off = pw_idx->off;
6083
6084 if (off)
6085 {
6086 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_pws_comp_buf, device_param->pws_comp, off * sizeof (u32), device_param->hip_stream) == -1) return -1;
6087 }
6088 }
6089
6090 if (device_param->is_opencl == true)
6091 {
6092 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_pws_idx, CL_FALSE, 0, pws_cnt * sizeof (pw_idx_t), device_param->pws_idx, 0, NULL, NULL) == -1) return -1;
6093
6094 const pw_idx_t *pw_idx = device_param->pws_idx + pws_cnt;
6095
6096 const u32 off = pw_idx->off;
6097
6098 if (off)
6099 {
6100 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_pws_comp_buf, CL_FALSE, 0, off * sizeof (u32), device_param->pws_comp, 0, NULL, NULL) == -1) return -1;
6101 }
6102 }
6103
6104 if (run_kernel_decompress (hashcat_ctx, device_param, pws_cnt) == -1) return -1;
6105 }
6106 else
6107 {
6108 if (user_options->attack_mode == ATTACK_MODE_COMBI)
6109 {
6110 if (device_param->is_cuda == true)
6111 {
6112 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_pws_idx, device_param->pws_idx, pws_cnt * sizeof (pw_idx_t), device_param->cuda_stream) == -1) return -1;
6113
6114 const pw_idx_t *pw_idx = device_param->pws_idx + pws_cnt;
6115
6116 const u32 off = pw_idx->off;
6117
6118 if (off)
6119 {
6120 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_pws_comp_buf, device_param->pws_comp, off * sizeof (u32), device_param->cuda_stream) == -1) return -1;
6121 }
6122 }
6123
6124 if (device_param->is_hip == true)
6125 {
6126 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_pws_idx, device_param->pws_idx, pws_cnt * sizeof (pw_idx_t), device_param->hip_stream) == -1) return -1;
6127
6128 const pw_idx_t *pw_idx = device_param->pws_idx + pws_cnt;
6129
6130 const u32 off = pw_idx->off;
6131
6132 if (off)
6133 {
6134 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_pws_comp_buf, device_param->pws_comp, off * sizeof (u32), device_param->hip_stream) == -1) return -1;
6135 }
6136 }
6137
6138 if (device_param->is_opencl == true)
6139 {
6140 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_pws_idx, CL_FALSE, 0, pws_cnt * sizeof (pw_idx_t), device_param->pws_idx, 0, NULL, NULL) == -1) return -1;
6141
6142 const pw_idx_t *pw_idx = device_param->pws_idx + pws_cnt;
6143
6144 const u32 off = pw_idx->off;
6145
6146 if (off)
6147 {
6148 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_pws_comp_buf, CL_FALSE, 0, off * sizeof (u32), device_param->pws_comp, 0, NULL, NULL) == -1) return -1;
6149 }
6150 }
6151
6152 if (run_kernel_decompress (hashcat_ctx, device_param, pws_cnt) == -1) return -1;
6153 }
6154 else if (user_options->attack_mode == ATTACK_MODE_HYBRID1)
6155 {
6156 if (device_param->is_cuda == true)
6157 {
6158 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_pws_idx, device_param->pws_idx, pws_cnt * sizeof (pw_idx_t), device_param->cuda_stream) == -1) return -1;
6159
6160 const pw_idx_t *pw_idx = device_param->pws_idx + pws_cnt;
6161
6162 const u32 off = pw_idx->off;
6163
6164 if (off)
6165 {
6166 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_pws_comp_buf, device_param->pws_comp, off * sizeof (u32), device_param->cuda_stream) == -1) return -1;
6167 }
6168 }
6169
6170 if (device_param->is_hip == true)
6171 {
6172 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_pws_idx, device_param->pws_idx, pws_cnt * sizeof (pw_idx_t), device_param->hip_stream) == -1) return -1;
6173
6174 const pw_idx_t *pw_idx = device_param->pws_idx + pws_cnt;
6175
6176 const u32 off = pw_idx->off;
6177
6178 if (off)
6179 {
6180 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_pws_comp_buf, device_param->pws_comp, off * sizeof (u32), device_param->hip_stream) == -1) return -1;
6181 }
6182 }
6183
6184 if (device_param->is_opencl == true)
6185 {
6186 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_pws_idx, CL_FALSE, 0, pws_cnt * sizeof (pw_idx_t), device_param->pws_idx, 0, NULL, NULL) == -1) return -1;
6187
6188 const pw_idx_t *pw_idx = device_param->pws_idx + pws_cnt;
6189
6190 const u32 off = pw_idx->off;
6191
6192 if (off)
6193 {
6194 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_pws_comp_buf, CL_FALSE, 0, off * sizeof (u32), device_param->pws_comp, 0, NULL, NULL) == -1) return -1;
6195 }
6196 }
6197
6198 if (run_kernel_decompress (hashcat_ctx, device_param, pws_cnt) == -1) return -1;
6199 }
6200 else if (user_options->attack_mode == ATTACK_MODE_HYBRID2)
6201 {
6202 const u64 off = device_param->words_off;
6203
6204 device_param->kernel_params_mp_buf64[3] = off;
6205
6206 if (run_kernel_mp (hashcat_ctx, device_param, KERN_RUN_MP, pws_cnt) == -1) return -1;
6207 }
6208 }
6209 }
6210 else if (user_options_extra->attack_kern == ATTACK_KERN_BF)
6211 {
6212 const u64 off = device_param->words_off;
6213
6214 device_param->kernel_params_mp_l_buf64[3] = off;
6215
6216 if (run_kernel_mp (hashcat_ctx, device_param, KERN_RUN_MP_L, pws_cnt) == -1) return -1;
6217 }
6218 }
6219
6220 if (device_param->is_opencl == true)
6221 {
6222 if (hc_clFlush (hashcat_ctx, device_param->opencl_command_queue) == -1) return -1;
6223 }
6224
6225 return 0;
6226 }
6227
run_cracker(hashcat_ctx_t * hashcat_ctx,hc_device_param_t * device_param,const u64 pws_pos,const u64 pws_cnt)6228 int run_cracker (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u64 pws_pos, const u64 pws_cnt)
6229 {
6230 combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx;
6231 hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
6232 hashes_t *hashes = hashcat_ctx->hashes;
6233 mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx;
6234 status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
6235 straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx;
6236 user_options_t *user_options = hashcat_ctx->user_options;
6237 user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra;
6238
6239 // do the on-the-fly combinator mode encoding
6240
6241 bool iconv_enabled = false;
6242
6243 iconv_t iconv_ctx = NULL;
6244
6245 char iconv_tmp[HCBUFSIZ_TINY] = { 0 };
6246
6247 if (strcmp (user_options->encoding_from, user_options->encoding_to) != 0)
6248 {
6249 iconv_enabled = true;
6250
6251 iconv_ctx = iconv_open (user_options->encoding_to, user_options->encoding_from);
6252
6253 if (iconv_ctx == (iconv_t) -1) return -1;
6254 }
6255
6256 // find higest password length, this is for optimization stuff
6257
6258 u32 highest_pw_len = 0;
6259
6260 if (user_options->slow_candidates == true)
6261 {
6262 /*
6263 for (u64 pws_idx = 0; pws_idx < pws_cnt; pws_idx++)
6264 {
6265 pw_idx_t *pw_idx = device_param->pws_idx + pws_idx;
6266
6267 highest_pw_len = MAX (highest_pw_len, pw_idx->len);
6268 }
6269 */
6270 }
6271 else
6272 {
6273 if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT)
6274 {
6275 }
6276 else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI)
6277 {
6278 }
6279 else if (user_options_extra->attack_kern == ATTACK_KERN_BF)
6280 {
6281 highest_pw_len = device_param->kernel_params_mp_l_buf32[4]
6282 + device_param->kernel_params_mp_l_buf32[5];
6283 }
6284 }
6285
6286 // we make use of this in status view
6287
6288 device_param->outerloop_multi = 1;
6289 device_param->outerloop_msec = 0;
6290 device_param->outerloop_pos = 0;
6291 device_param->outerloop_left = pws_cnt;
6292
6293 // we ignore the time to copy data over pci bus in this case
6294
6295 if (user_options->speed_only == true)
6296 {
6297 hc_timer_set (&device_param->timer_speed);
6298 }
6299
6300 // loop start: most outer loop = salt iteration, then innerloops (if multi)
6301
6302 u32 salts_cnt = hashes->salts_cnt;
6303
6304 if (user_options->attack_mode == ATTACK_MODE_ASSOCIATION)
6305 {
6306 // We will replace in-kernel salt_pos with GID via macro
6307
6308 salts_cnt = 1;
6309 }
6310
6311 for (u32 salt_pos = 0; salt_pos < salts_cnt; salt_pos++)
6312 {
6313 while (status_ctx->devices_status == STATUS_PAUSED) sleep (1);
6314
6315 salt_t *salt_buf = &hashes->salts_buf[salt_pos];
6316
6317 device_param->kernel_params_buf32[27] = salt_pos;
6318 device_param->kernel_params_buf32[31] = salt_buf->digests_cnt;
6319 device_param->kernel_params_buf32[32] = salt_buf->digests_offset;
6320
6321 HCFILE *combs_fp = &device_param->combs_fp;
6322
6323 if (user_options->slow_candidates == true)
6324 {
6325 }
6326 else
6327 {
6328 if ((user_options->attack_mode == ATTACK_MODE_COMBI) || (((hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL) == 0) && (user_options->attack_mode == ATTACK_MODE_HYBRID2)))
6329 {
6330 hc_rewind (combs_fp);
6331 }
6332 }
6333
6334 // iteration type
6335
6336 u32 innerloop_step = 0;
6337 u32 innerloop_cnt = 0;
6338
6339 if (user_options->slow_candidates == true)
6340 {
6341 innerloop_step = 1;
6342 innerloop_cnt = 1;
6343 }
6344 else
6345 {
6346 if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL) innerloop_step = device_param->kernel_loops;
6347 else innerloop_step = 1;
6348
6349 if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) innerloop_cnt = straight_ctx->kernel_rules_cnt;
6350 else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) innerloop_cnt = (u32) combinator_ctx->combs_cnt;
6351 else if (user_options_extra->attack_kern == ATTACK_KERN_BF) innerloop_cnt = (u32) mask_ctx->bfs_cnt;
6352 }
6353
6354 // innerloops
6355
6356 for (u32 innerloop_pos = 0; innerloop_pos < innerloop_cnt; innerloop_pos += innerloop_step)
6357 {
6358 while (status_ctx->devices_status == STATUS_PAUSED) sleep (1);
6359
6360 u32 fast_iteration = 0;
6361
6362 u32 innerloop_left = innerloop_cnt - innerloop_pos;
6363
6364 if (innerloop_left > innerloop_step)
6365 {
6366 innerloop_left = innerloop_step;
6367
6368 fast_iteration = 1;
6369 }
6370
6371 hc_thread_mutex_lock (status_ctx->mux_display);
6372
6373 device_param->innerloop_pos = innerloop_pos;
6374 device_param->innerloop_left = innerloop_left;
6375
6376 device_param->kernel_params_buf32[30] = innerloop_left;
6377
6378 device_param->outerloop_multi = (double) innerloop_cnt / (double) (innerloop_pos + innerloop_left);
6379
6380 hc_thread_mutex_unlock (status_ctx->mux_display);
6381
6382 if (user_options->attack_mode == ATTACK_MODE_ASSOCIATION)
6383 {
6384 // does not exist here
6385 }
6386 else
6387 {
6388 if (hashes->salts_shown[salt_pos] == 1)
6389 {
6390 status_ctx->words_progress_done[salt_pos] += pws_cnt * innerloop_left;
6391
6392 continue;
6393 }
6394 }
6395
6396 // initialize and copy amplifiers
6397
6398 if (user_options->slow_candidates == true)
6399 {
6400 }
6401 else
6402 {
6403 if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT)
6404 {
6405 if (device_param->is_cuda == true)
6406 {
6407 if (hc_cuMemcpyDtoDAsync (hashcat_ctx, device_param->cuda_d_rules_c, device_param->cuda_d_rules + (innerloop_pos * sizeof (kernel_rule_t)), innerloop_left * sizeof (kernel_rule_t), device_param->cuda_stream) == -1) return -1;
6408 }
6409
6410 if (device_param->is_hip == true)
6411 {
6412 if (hc_hipMemcpyDtoDAsync (hashcat_ctx, device_param->hip_d_rules_c, device_param->hip_d_rules + (innerloop_pos * sizeof (kernel_rule_t)), innerloop_left * sizeof (kernel_rule_t), device_param->hip_stream) == -1) return -1;
6413 }
6414
6415 if (device_param->is_opencl == true)
6416 {
6417 if (hc_clEnqueueCopyBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_rules, device_param->opencl_d_rules_c, innerloop_pos * sizeof (kernel_rule_t), 0, innerloop_left * sizeof (kernel_rule_t), 0, NULL, NULL) == -1) return -1;
6418 }
6419 }
6420 else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI)
6421 {
6422 if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
6423 {
6424 if (user_options->attack_mode == ATTACK_MODE_COMBI)
6425 {
6426 char *line_buf = device_param->scratch_buf;
6427
6428 u32 i = 0;
6429
6430 while (i < innerloop_left)
6431 {
6432 if (hc_feof (combs_fp)) break;
6433
6434 size_t line_len = fgetl (combs_fp, line_buf, HCBUFSIZ_LARGE);
6435
6436 line_len = convert_from_hex (hashcat_ctx, line_buf, line_len);
6437
6438 if (line_len > PW_MAX) continue;
6439
6440 char *line_buf_new = line_buf;
6441
6442 char rule_buf_out[RP_PASSWORD_SIZE];
6443
6444 if (run_rule_engine (user_options_extra->rule_len_r, user_options->rule_buf_r))
6445 {
6446 if (line_len >= RP_PASSWORD_SIZE) continue;
6447
6448 memset (rule_buf_out, 0, sizeof (rule_buf_out));
6449
6450 const int rule_len_out = _old_apply_rule (user_options->rule_buf_r, user_options_extra->rule_len_r, line_buf, (u32) line_len, rule_buf_out);
6451
6452 if (rule_len_out < 0)
6453 {
6454 if (user_options->attack_mode == ATTACK_MODE_ASSOCIATION)
6455 {
6456 for (u32 association_salt_pos = 0; association_salt_pos < pws_cnt; association_salt_pos++)
6457 {
6458 status_ctx->words_progress_rejected[association_salt_pos] += 1;
6459 }
6460 }
6461 else
6462 {
6463 status_ctx->words_progress_rejected[salt_pos] += pws_cnt;
6464 }
6465
6466 continue;
6467 }
6468
6469 line_len = rule_len_out;
6470
6471 line_buf_new = rule_buf_out;
6472 }
6473
6474 // do the on-the-fly encoding
6475
6476 if (iconv_enabled == true)
6477 {
6478 char *iconv_ptr = iconv_tmp;
6479 size_t iconv_sz = HCBUFSIZ_TINY;
6480
6481 if (iconv (iconv_ctx, &line_buf_new, &line_len, &iconv_ptr, &iconv_sz) == (size_t) -1) continue;
6482
6483 line_buf_new = iconv_tmp;
6484 line_len = HCBUFSIZ_TINY - iconv_sz;
6485 }
6486
6487 line_len = MIN (line_len, PW_MAX);
6488
6489 u8 *ptr = (u8 *) device_param->combs_buf[i].i;
6490
6491 memcpy (ptr, line_buf_new, line_len);
6492
6493 memset (ptr + line_len, 0, PW_MAX - line_len);
6494
6495 if (hashconfig->opts_type & OPTS_TYPE_PT_UPPER)
6496 {
6497 uppercase (ptr, line_len);
6498 }
6499
6500 if (combinator_ctx->combs_mode == COMBINATOR_MODE_BASE_LEFT)
6501 {
6502 if (hashconfig->opts_type & OPTS_TYPE_PT_ADD80)
6503 {
6504 ptr[line_len] = 0x80;
6505 }
6506
6507 if (hashconfig->opts_type & OPTS_TYPE_PT_ADD06)
6508 {
6509 ptr[line_len] = 0x06;
6510 }
6511
6512 if (hashconfig->opts_type & OPTS_TYPE_PT_ADD01)
6513 {
6514 ptr[line_len] = 0x01;
6515 }
6516 }
6517
6518 device_param->combs_buf[i].pw_len = (u32) line_len;
6519
6520 i++;
6521 }
6522
6523 for (u32 j = i; j < innerloop_left; j++)
6524 {
6525 memset (&device_param->combs_buf[j], 0, sizeof (pw_t));
6526 }
6527
6528 innerloop_left = i;
6529
6530 if (device_param->is_cuda == true)
6531 {
6532 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_combs_c, device_param->combs_buf, innerloop_left * sizeof (pw_t), device_param->cuda_stream) == -1) return -1;
6533 }
6534
6535 if (device_param->is_hip == true)
6536 {
6537 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_combs_c, device_param->combs_buf, innerloop_left * sizeof (pw_t), device_param->hip_stream) == -1) return -1;
6538 }
6539
6540 if (device_param->is_opencl == true)
6541 {
6542 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_combs_c, CL_FALSE, 0, innerloop_left * sizeof (pw_t), device_param->combs_buf, 0, NULL, NULL) == -1) return -1;
6543 }
6544 }
6545 else if (user_options->attack_mode == ATTACK_MODE_HYBRID1)
6546 {
6547 u64 off = innerloop_pos;
6548
6549 device_param->kernel_params_mp_buf64[3] = off;
6550
6551 if (run_kernel_mp (hashcat_ctx, device_param, KERN_RUN_MP, innerloop_left) == -1) return -1;
6552
6553 if (device_param->is_cuda == true)
6554 {
6555 if (hc_cuMemcpyDtoDAsync (hashcat_ctx, device_param->cuda_d_combs_c, device_param->cuda_d_combs, innerloop_left * sizeof (pw_t), device_param->cuda_stream) == -1) return -1;
6556 }
6557
6558 if (device_param->is_hip == true)
6559 {
6560 if (hc_hipMemcpyDtoDAsync (hashcat_ctx, device_param->hip_d_combs_c, device_param->hip_d_combs, innerloop_left * sizeof (pw_t), device_param->hip_stream) == -1) return -1;
6561 }
6562
6563 if (device_param->is_opencl == true)
6564 {
6565 if (hc_clEnqueueCopyBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_combs, device_param->opencl_d_combs_c, 0, 0, innerloop_left * sizeof (pw_t), 0, NULL, NULL) == -1) return -1;
6566 }
6567 }
6568 else if (user_options->attack_mode == ATTACK_MODE_HYBRID2)
6569 {
6570 u64 off = innerloop_pos;
6571
6572 device_param->kernel_params_mp_buf64[3] = off;
6573
6574 if (run_kernel_mp (hashcat_ctx, device_param, KERN_RUN_MP, innerloop_left) == -1) return -1;
6575
6576 if (device_param->is_cuda == true)
6577 {
6578 if (hc_cuMemcpyDtoDAsync (hashcat_ctx, device_param->cuda_d_combs_c, device_param->cuda_d_combs, innerloop_left * sizeof (pw_t), device_param->cuda_stream) == -1) return -1;
6579 }
6580
6581 if (device_param->is_hip == true)
6582 {
6583 if (hc_hipMemcpyDtoDAsync (hashcat_ctx, device_param->hip_d_combs_c, device_param->hip_d_combs, innerloop_left * sizeof (pw_t), device_param->hip_stream) == -1) return -1;
6584 }
6585
6586 if (device_param->is_opencl == true)
6587 {
6588 if (hc_clEnqueueCopyBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_combs, device_param->opencl_d_combs_c, 0, 0, innerloop_left * sizeof (pw_t), 0, NULL, NULL) == -1) return -1;
6589 }
6590 }
6591 }
6592 else
6593 {
6594 if ((user_options->attack_mode == ATTACK_MODE_COMBI) || (user_options->attack_mode == ATTACK_MODE_HYBRID2))
6595 {
6596 char *line_buf = device_param->scratch_buf;
6597
6598 u32 i = 0;
6599
6600 while (i < innerloop_left)
6601 {
6602 if (hc_feof (combs_fp)) break;
6603
6604 size_t line_len = fgetl (combs_fp, line_buf, HCBUFSIZ_LARGE);
6605
6606 line_len = convert_from_hex (hashcat_ctx, line_buf, line_len);
6607
6608 if (line_len > PW_MAX) continue;
6609
6610 char *line_buf_new = line_buf;
6611
6612 char rule_buf_out[RP_PASSWORD_SIZE];
6613
6614 if (run_rule_engine (user_options_extra->rule_len_r, user_options->rule_buf_r))
6615 {
6616 if (line_len >= RP_PASSWORD_SIZE) continue;
6617
6618 memset (rule_buf_out, 0, sizeof (rule_buf_out));
6619
6620 const int rule_len_out = _old_apply_rule (user_options->rule_buf_r, user_options_extra->rule_len_r, line_buf, (u32) line_len, rule_buf_out);
6621
6622 if (rule_len_out < 0)
6623 {
6624 if (user_options->attack_mode == ATTACK_MODE_ASSOCIATION)
6625 {
6626 for (u32 association_salt_pos = 0; association_salt_pos < pws_cnt; association_salt_pos++)
6627 {
6628 status_ctx->words_progress_rejected[association_salt_pos] += 1;
6629 }
6630 }
6631 else
6632 {
6633 status_ctx->words_progress_rejected[salt_pos] += pws_cnt;
6634 }
6635
6636 continue;
6637 }
6638
6639 line_len = rule_len_out;
6640
6641 line_buf_new = rule_buf_out;
6642 }
6643
6644 // do the on-the-fly encoding
6645
6646 if (iconv_enabled == true)
6647 {
6648 char *iconv_ptr = iconv_tmp;
6649 size_t iconv_sz = HCBUFSIZ_TINY;
6650
6651 if (iconv (iconv_ctx, &line_buf_new, &line_len, &iconv_ptr, &iconv_sz) == (size_t) -1) continue;
6652
6653 line_buf_new = iconv_tmp;
6654 line_len = HCBUFSIZ_TINY - iconv_sz;
6655 }
6656
6657 line_len = MIN (line_len, PW_MAX);
6658
6659 u8 *ptr = (u8 *) device_param->combs_buf[i].i;
6660
6661 memcpy (ptr, line_buf_new, line_len);
6662
6663 memset (ptr + line_len, 0, PW_MAX - line_len);
6664
6665 if (hashconfig->opts_type & OPTS_TYPE_PT_UPPER)
6666 {
6667 uppercase (ptr, line_len);
6668 }
6669
6670 /*
6671 if (combinator_ctx->combs_mode == COMBINATOR_MODE_BASE_LEFT)
6672 {
6673 if (hashconfig->opts_type & OPTS_TYPE_PT_ADD80)
6674 {
6675 ptr[line_len] = 0x80;
6676 }
6677
6678 if (hashconfig->opts_type & OPTS_TYPE_PT_ADD06)
6679 {
6680 ptr[line_len] = 0x06;
6681 }
6682
6683 if (hashconfig->opts_type & OPTS_TYPE_PT_ADD01)
6684 {
6685 ptr[line_len] = 0x01;
6686 }
6687 }
6688 */
6689
6690 device_param->combs_buf[i].pw_len = (u32) line_len;
6691
6692 i++;
6693 }
6694
6695 for (u32 j = i; j < innerloop_left; j++)
6696 {
6697 memset (&device_param->combs_buf[j], 0, sizeof (pw_t));
6698 }
6699
6700 innerloop_left = i;
6701
6702 if (device_param->is_cuda == true)
6703 {
6704 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_combs_c, device_param->combs_buf, innerloop_left * sizeof (pw_t), device_param->cuda_stream) == -1) return -1;
6705 }
6706
6707 if (device_param->is_hip == true)
6708 {
6709 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_combs_c, device_param->combs_buf, innerloop_left * sizeof (pw_t), device_param->hip_stream) == -1) return -1;
6710 }
6711
6712 if (device_param->is_opencl == true)
6713 {
6714 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_combs_c, CL_FALSE, 0, innerloop_left * sizeof (pw_t), device_param->combs_buf, 0, NULL, NULL) == -1) return -1;
6715 }
6716 }
6717 else if (user_options->attack_mode == ATTACK_MODE_HYBRID1)
6718 {
6719 u64 off = innerloop_pos;
6720
6721 device_param->kernel_params_mp_buf64[3] = off;
6722
6723 if (run_kernel_mp (hashcat_ctx, device_param, KERN_RUN_MP, innerloop_left) == -1) return -1;
6724
6725 if (device_param->is_cuda == true)
6726 {
6727 if (hc_cuMemcpyDtoDAsync (hashcat_ctx, device_param->cuda_d_combs_c, device_param->cuda_d_combs, innerloop_left * sizeof (pw_t), device_param->cuda_stream) == -1) return -1;
6728 }
6729
6730 if (device_param->is_hip == true)
6731 {
6732 if (hc_hipMemcpyDtoDAsync (hashcat_ctx, device_param->hip_d_combs_c, device_param->hip_d_combs, innerloop_left * sizeof (pw_t), device_param->hip_stream) == -1) return -1;
6733 }
6734
6735 if (device_param->is_opencl == true)
6736 {
6737 if (hc_clEnqueueCopyBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_combs, device_param->opencl_d_combs_c, 0, 0, innerloop_left * sizeof (pw_t), 0, NULL, NULL) == -1) return -1;
6738 }
6739 }
6740 }
6741 }
6742 else if (user_options_extra->attack_kern == ATTACK_KERN_BF)
6743 {
6744 u64 off = innerloop_pos;
6745
6746 device_param->kernel_params_mp_r_buf64[3] = off;
6747
6748 if (run_kernel_mp (hashcat_ctx, device_param, KERN_RUN_MP_R, innerloop_left) == -1) return -1;
6749
6750 if (device_param->is_cuda == true)
6751 {
6752 if (hc_cuMemcpyDtoDAsync (hashcat_ctx, device_param->cuda_d_bfs_c, device_param->cuda_d_bfs, innerloop_left * sizeof (bf_t), device_param->cuda_stream) == -1) return -1;
6753 }
6754
6755 if (device_param->is_hip == true)
6756 {
6757 if (hc_hipMemcpyDtoDAsync (hashcat_ctx, device_param->hip_d_bfs_c, device_param->hip_d_bfs, innerloop_left * sizeof (bf_t), device_param->hip_stream) == -1) return -1;
6758 }
6759
6760 if (device_param->is_opencl == true)
6761 {
6762 if (hc_clEnqueueCopyBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_bfs, device_param->opencl_d_bfs_c, 0, 0, innerloop_left * sizeof (bf_t), 0, NULL, NULL) == -1) return -1;
6763 }
6764 }
6765 }
6766
6767 if (choose_kernel (hashcat_ctx, device_param, highest_pw_len, pws_pos, pws_cnt, fast_iteration, salt_pos) == -1) return -1;
6768
6769 /**
6770 * benchmark was aborted because too long kernel runtime (slow hashes only)
6771 */
6772
6773 if ((user_options->speed_only == true) && (device_param->speed_only_finish == true))
6774 {
6775 // nothing to do in that case
6776 }
6777 else
6778 {
6779 /**
6780 * speed
6781 */
6782
6783 if (status_ctx->run_thread_level2 == true)
6784 {
6785 const u64 perf_sum_all = pws_cnt * innerloop_left;
6786
6787 const double speed_msec = hc_timer_get (device_param->timer_speed);
6788
6789 hc_timer_set (&device_param->timer_speed);
6790
6791 u32 speed_pos = device_param->speed_pos;
6792
6793 device_param->speed_cnt[speed_pos] = perf_sum_all;
6794
6795 device_param->speed_msec[speed_pos] = speed_msec;
6796
6797 speed_pos++;
6798
6799 if (speed_pos == SPEED_CACHE)
6800 {
6801 speed_pos = 0;
6802 }
6803
6804 device_param->speed_pos = speed_pos;
6805
6806 /**
6807 * progress
6808 */
6809
6810 hc_thread_mutex_lock (status_ctx->mux_counter);
6811
6812 if (user_options->attack_mode == ATTACK_MODE_ASSOCIATION)
6813 {
6814 for (u32 association_salt_pos = 0; association_salt_pos < pws_cnt; association_salt_pos++)
6815 {
6816 status_ctx->words_progress_done[pws_pos + association_salt_pos] += innerloop_left;
6817 }
6818 }
6819 else
6820 {
6821 status_ctx->words_progress_done[salt_pos] += perf_sum_all;
6822 }
6823
6824 hc_thread_mutex_unlock (status_ctx->mux_counter);
6825 }
6826 }
6827
6828 /**
6829 * benchmark, part2
6830 */
6831
6832 if (user_options->speed_only == true)
6833 {
6834 // let's abort this so that the user doesn't have to wait too long on the result
6835 // for slow hashes it's fine anyway as boost mode should be turned on
6836
6837 if (hashconfig->attack_exec == ATTACK_EXEC_OUTSIDE_KERNEL)
6838 {
6839 device_param->speed_only_finish = true;
6840
6841 break;
6842 }
6843
6844 double total_msec = device_param->speed_msec[0];
6845
6846 for (u32 speed_pos = 1; speed_pos < device_param->speed_pos; speed_pos++)
6847 {
6848 total_msec += device_param->speed_msec[speed_pos];
6849 }
6850
6851 if (user_options->slow_candidates == true)
6852 {
6853 if ((total_msec > 4000) || (device_param->speed_pos == SPEED_CACHE - 1))
6854 {
6855 const u32 speed_pos = device_param->speed_pos;
6856
6857 if (speed_pos)
6858 {
6859 device_param->speed_cnt[0] = device_param->speed_cnt[speed_pos - 1];
6860 device_param->speed_msec[0] = device_param->speed_msec[speed_pos - 1];
6861 }
6862
6863 device_param->speed_pos = 0;
6864
6865 device_param->speed_only_finish = true;
6866
6867 break;
6868 }
6869 }
6870 else
6871 {
6872 // it's unclear if 4s is enough to turn on boost mode for all backend device
6873
6874 if ((total_msec > 4000) || (device_param->speed_pos == SPEED_CACHE - 1))
6875 {
6876 device_param->speed_only_finish = true;
6877
6878 break;
6879 }
6880 }
6881 }
6882
6883 if (device_param->speed_only_finish == true) break;
6884
6885 /**
6886 * result
6887 */
6888
6889 check_cracked (hashcat_ctx, device_param);
6890
6891 if (status_ctx->run_thread_level2 == false) break;
6892 }
6893
6894 if (user_options->speed_only == true) break;
6895
6896 //status screen makes use of this, can't reset here
6897 //device_param->innerloop_msec = 0;
6898 //device_param->innerloop_pos = 0;
6899 //device_param->innerloop_left = 0;
6900
6901 if (status_ctx->run_thread_level2 == false) break;
6902 }
6903
6904 //status screen makes use of this, can't reset here
6905 //device_param->outerloop_msec = 0;
6906 //device_param->outerloop_pos = 0;
6907 //device_param->outerloop_left = 0;
6908
6909 if (user_options->speed_only == true)
6910 {
6911 double total_msec = device_param->speed_msec[0];
6912
6913 for (u32 speed_pos = 1; speed_pos < device_param->speed_pos; speed_pos++)
6914 {
6915 total_msec += device_param->speed_msec[speed_pos];
6916 }
6917
6918 device_param->outerloop_msec = total_msec * hashes->salts_cnt * device_param->outerloop_multi;
6919
6920 device_param->speed_only_finish = true;
6921 }
6922
6923 if (iconv_enabled == true)
6924 {
6925 iconv_close (iconv_ctx);
6926 }
6927
6928 return 0;
6929 }
6930
backend_ctx_init(hashcat_ctx_t * hashcat_ctx)6931 int backend_ctx_init (hashcat_ctx_t *hashcat_ctx)
6932 {
6933 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
6934 user_options_t *user_options = hashcat_ctx->user_options;
6935
6936 backend_ctx->enabled = false;
6937
6938 if (user_options->hash_info == true) return 0;
6939 if (user_options->keyspace == true) return 0;
6940 if (user_options->left == true) return 0;
6941 if (user_options->show == true) return 0;
6942 if (user_options->usage == true) return 0;
6943 if (user_options->version == true) return 0;
6944 if (user_options->identify == true) return 0;
6945
6946 hc_device_param_t *devices_param = (hc_device_param_t *) hccalloc (DEVICES_MAX, sizeof (hc_device_param_t));
6947
6948 backend_ctx->devices_param = devices_param;
6949
6950 /**
6951 * Load and map CUDA library calls, then init CUDA
6952 */
6953
6954 int rc_cuda_init = -1;
6955
6956 if (user_options->backend_ignore_cuda == false)
6957 {
6958 CUDA_PTR *cuda = (CUDA_PTR *) hcmalloc (sizeof (CUDA_PTR));
6959
6960 backend_ctx->cuda = cuda;
6961
6962 rc_cuda_init = cuda_init (hashcat_ctx);
6963
6964 if (rc_cuda_init == -1)
6965 {
6966 backend_ctx->rc_cuda_init = rc_cuda_init;
6967
6968 cuda_close (hashcat_ctx);
6969 }
6970
6971 /**
6972 * Load and map NVRTC library calls
6973 */
6974
6975 NVRTC_PTR *nvrtc = (NVRTC_PTR *) hcmalloc (sizeof (NVRTC_PTR));
6976
6977 backend_ctx->nvrtc = nvrtc;
6978
6979 int rc_nvrtc_init = nvrtc_init (hashcat_ctx);
6980
6981 if (rc_nvrtc_init == -1)
6982 {
6983 backend_ctx->rc_nvrtc_init = rc_nvrtc_init;
6984
6985 nvrtc_close (hashcat_ctx);
6986 }
6987
6988 /**
6989 * Check if both CUDA and NVRTC were load successful
6990 */
6991
6992 if ((rc_cuda_init == 0) && (rc_nvrtc_init == 0))
6993 {
6994 // nvrtc version
6995
6996 int nvrtc_major = 0;
6997 int nvrtc_minor = 0;
6998
6999 if (hc_nvrtcVersion (hashcat_ctx, &nvrtc_major, &nvrtc_minor) == -1) return -1;
7000
7001 int nvrtc_driver_version = (nvrtc_major * 1000) + (nvrtc_minor * 10);
7002
7003 backend_ctx->nvrtc_driver_version = nvrtc_driver_version;
7004
7005 if (nvrtc_driver_version < 9000)
7006 {
7007 event_log_error (hashcat_ctx, "Outdated NVIDIA NVRTC driver version '%d' detected!", nvrtc_driver_version);
7008
7009 event_log_warning (hashcat_ctx, "See hashcat.net for officially supported NVIDIA CUDA Toolkit versions.");
7010 event_log_warning (hashcat_ctx, NULL);
7011
7012 return -1;
7013 }
7014
7015 // cuda version
7016
7017 int cuda_driver_version = 0;
7018
7019 if (hc_cuDriverGetVersion (hashcat_ctx, &cuda_driver_version) == -1) return -1;
7020
7021 backend_ctx->cuda_driver_version = cuda_driver_version;
7022
7023 if (cuda_driver_version < 9000)
7024 {
7025 event_log_error (hashcat_ctx, "Outdated NVIDIA CUDA driver version '%d' detected!", cuda_driver_version);
7026
7027 event_log_warning (hashcat_ctx, "See hashcat.net for officially supported NVIDIA CUDA Toolkit versions.");
7028 event_log_warning (hashcat_ctx, NULL);
7029
7030 return -1;
7031 }
7032 }
7033 else
7034 {
7035 rc_cuda_init = -1;
7036 rc_nvrtc_init = -1;
7037
7038 cuda_close (hashcat_ctx);
7039 nvrtc_close (hashcat_ctx);
7040 }
7041 }
7042
7043 /**
7044 * Load and map HIP library calls, then init HIP
7045 */
7046
7047 int rc_hip_init = -1;
7048
7049 if (user_options->backend_ignore_hip == false)
7050 {
7051 HIP_PTR *hip = (HIP_PTR *) hcmalloc (sizeof (HIP_PTR));
7052
7053 backend_ctx->hip = hip;
7054
7055 rc_hip_init = hip_init (hashcat_ctx);
7056
7057 if (rc_hip_init == -1)
7058 {
7059 backend_ctx->rc_hip_init = rc_hip_init;
7060
7061 hip_close (hashcat_ctx);
7062 }
7063
7064 /**
7065 * Load and map HIPRTC library calls
7066 */
7067
7068 HIPRTC_PTR *hiprtc = (HIPRTC_PTR *) hcmalloc (sizeof (HIPRTC_PTR));
7069
7070 backend_ctx->hiprtc = hiprtc;
7071
7072 int rc_hiprtc_init = hiprtc_init (hashcat_ctx);
7073
7074 if (rc_hiprtc_init == -1)
7075 {
7076 backend_ctx->rc_hiprtc_init = rc_hiprtc_init;
7077
7078 hiprtc_close (hashcat_ctx);
7079 }
7080
7081 /**
7082 * Check if both HIP and HIPRTC were load successful
7083 */
7084
7085 if ((rc_hip_init == 0) && (rc_hiprtc_init == 0))
7086 {
7087 // hip version
7088
7089 int hip_driverVersion;
7090
7091 if (hc_hipDriverGetVersion (hashcat_ctx, &hip_driverVersion) == -1) return -1;
7092
7093 backend_ctx->hip_driverVersion = hip_driverVersion;
7094
7095 int hip_runtimeVersion;
7096
7097 if (hc_hipRuntimeGetVersion (hashcat_ctx, &hip_runtimeVersion) == -1) return -1;
7098
7099 backend_ctx->hip_runtimeVersion = hip_runtimeVersion;
7100
7101 if (hip_runtimeVersion < 1000)
7102 {
7103 if (hip_runtimeVersion < 404)
7104 {
7105 event_log_warning (hashcat_ctx, "Unsupported AMD HIP runtime version '%d.%d' detected! Falling back to OpenCL...", hip_runtimeVersion / 100, hip_runtimeVersion % 10);
7106 event_log_warning (hashcat_ctx, NULL);
7107
7108 rc_hip_init = -1;
7109 rc_hiprtc_init = -1;
7110
7111 backend_ctx->rc_hip_init = rc_hip_init;
7112 backend_ctx->rc_hiprtc_init = rc_hiprtc_init;
7113
7114 backend_ctx->hip = NULL;
7115 backend_ctx->hiprtc = NULL;
7116
7117 backend_ctx->hip = NULL;
7118
7119 // if we call this, opencl stops working?! so we just zero the pointer
7120 // this causes a memleak and an open filehandle but what can we do?
7121 // hip_close (hashcat_ctx);
7122 // hiprtc_close (hashcat_ctx);
7123 }
7124 }
7125 else
7126 {
7127 if (hip_runtimeVersion < 40421401)
7128 {
7129 int hip_version_major = (hip_runtimeVersion - 0) / 10000000;
7130 int hip_version_minor = (hip_runtimeVersion - (hip_version_major * 10000000)) / 100000;
7131 int hip_version_patch = (hip_runtimeVersion - (hip_version_major * 10000000) - (hip_version_minor * 100000));
7132
7133 event_log_warning (hashcat_ctx, "Unsupported AMD HIP runtime version '%d.%d.%d' detected! Falling back to OpenCL...", hip_version_major, hip_version_minor, hip_version_patch);
7134 event_log_warning (hashcat_ctx, NULL);
7135
7136 rc_hip_init = -1;
7137 rc_hiprtc_init = -1;
7138
7139 backend_ctx->rc_hip_init = rc_hip_init;
7140 backend_ctx->rc_hiprtc_init = rc_hiprtc_init;
7141
7142 backend_ctx->hip = NULL;
7143
7144 // if we call this, opencl stops working?! so we just zero the pointer
7145 // this causes a memleak and an open filehandle but what can we do?
7146 // hip_close (hashcat_ctx);
7147 // hiprtc_close (hashcat_ctx);
7148 }
7149 }
7150 }
7151 else
7152 {
7153 rc_hip_init = -1;
7154 rc_hiprtc_init = -1;
7155
7156 backend_ctx->rc_hip_init = rc_hip_init;
7157 backend_ctx->rc_hiprtc_init = rc_hiprtc_init;
7158
7159 backend_ctx->hip = NULL;
7160
7161 // if we call this, opencl stops working?! so we just zero the pointer
7162 // this causes a memleak and an open filehandle but what can we do?
7163 // hip_close (hashcat_ctx);
7164 // hiprtc_close (hashcat_ctx);
7165 }
7166 }
7167
7168 /**
7169 * Load and map OpenCL library calls
7170 */
7171
7172 int rc_ocl_init = -1;
7173
7174 if (user_options->backend_ignore_opencl == false)
7175 {
7176 OCL_PTR *ocl = (OCL_PTR *) hcmalloc (sizeof (OCL_PTR));
7177
7178 backend_ctx->ocl = ocl;
7179
7180 rc_ocl_init = ocl_init (hashcat_ctx);
7181
7182 if (rc_ocl_init == -1)
7183 {
7184 ocl_close (hashcat_ctx);
7185 }
7186
7187 /**
7188 * return if both CUDA and OpenCL initialization failed
7189 */
7190
7191 if ((rc_cuda_init == -1) && (rc_hip_init == -1) && (rc_ocl_init == -1))
7192 {
7193 event_log_error (hashcat_ctx, "ATTENTION! No OpenCL, HIP or CUDA installation found.");
7194
7195 event_log_warning (hashcat_ctx, "You are probably missing the CUDA, HIP or OpenCL runtime installation.");
7196 event_log_warning (hashcat_ctx, NULL);
7197
7198 #if defined (__linux__)
7199 event_log_warning (hashcat_ctx, "* AMD GPUs on Linux require this driver:");
7200 event_log_warning (hashcat_ctx, " \"AMD ROCm\" (4.5 or later)");
7201 #elif defined (_WIN)
7202 event_log_warning (hashcat_ctx, "* AMD GPUs on Windows require this driver:");
7203 event_log_warning (hashcat_ctx, " \"AMD Radeon Adrenalin 2020 Edition\" (21.2.1 or later)");
7204 #endif
7205
7206 event_log_warning (hashcat_ctx, "* Intel CPUs require this runtime:");
7207 event_log_warning (hashcat_ctx, " \"OpenCL Runtime for Intel Core and Intel Xeon Processors\" (16.1.1 or later)");
7208
7209 event_log_warning (hashcat_ctx, "* NVIDIA GPUs require this runtime and/or driver (both):");
7210 event_log_warning (hashcat_ctx, " \"NVIDIA Driver\" (440.64 or later)");
7211 event_log_warning (hashcat_ctx, " \"CUDA Toolkit\" (9.0 or later)");
7212 event_log_warning (hashcat_ctx, NULL);
7213
7214 return -1;
7215 }
7216
7217 /**
7218 * Some permission pre-check, because AMDGPU-PRO Driver crashes if the user has no permission to do this
7219 */
7220
7221 if (ocl_check_dri (hashcat_ctx) == -1) return -1;
7222 }
7223
7224 /**
7225 * Backend device selection
7226 */
7227
7228 u64 backend_devices_filter;
7229
7230 if (setup_backend_devices_filter (hashcat_ctx, user_options->backend_devices, &backend_devices_filter) == false) return -1;
7231
7232 backend_ctx->backend_devices_filter = backend_devices_filter;
7233
7234 /**
7235 * OpenCL device type selection
7236 */
7237
7238 cl_device_type opencl_device_types_filter;
7239
7240 if (setup_opencl_device_types_filter (hashcat_ctx, user_options->opencl_device_types, &opencl_device_types_filter) == false) return -1;
7241
7242 backend_ctx->opencl_device_types_filter = opencl_device_types_filter;
7243
7244 /**
7245 * CUDA API: init
7246 */
7247
7248 if (backend_ctx->cuda)
7249 {
7250 if (hc_cuInit (hashcat_ctx, 0) == -1)
7251 {
7252 cuda_close (hashcat_ctx);
7253 }
7254 }
7255
7256 /**
7257 * HIP API: init
7258 */
7259
7260 if (backend_ctx->hip)
7261 {
7262 if (hc_hipInit (hashcat_ctx, 0) == -1)
7263 {
7264 hip_close (hashcat_ctx);
7265 }
7266 }
7267
7268 /**
7269 * OpenCL API: init
7270 */
7271
7272 if (backend_ctx->ocl)
7273 {
7274 #define FREE_OPENCL_CTX_ON_ERROR \
7275 do { \
7276 hcfree (opencl_platforms); \
7277 hcfree (opencl_platforms_devices); \
7278 hcfree (opencl_platforms_devices_cnt); \
7279 hcfree (opencl_platforms_name); \
7280 hcfree (opencl_platforms_vendor); \
7281 hcfree (opencl_platforms_vendor_id); \
7282 hcfree (opencl_platforms_version); \
7283 } while (0)
7284
7285 cl_platform_id *opencl_platforms = (cl_platform_id *) hccalloc (CL_PLATFORMS_MAX, sizeof (cl_platform_id));
7286 cl_uint opencl_platforms_cnt = 0;
7287 cl_device_id **opencl_platforms_devices = (cl_device_id **) hccalloc (CL_PLATFORMS_MAX, sizeof (cl_device_id *));
7288 cl_uint *opencl_platforms_devices_cnt = (cl_uint *) hccalloc (CL_PLATFORMS_MAX, sizeof (cl_uint));
7289 char **opencl_platforms_name = (char **) hccalloc (CL_PLATFORMS_MAX, sizeof (char *));
7290 char **opencl_platforms_vendor = (char **) hccalloc (CL_PLATFORMS_MAX, sizeof (char *));
7291 cl_uint *opencl_platforms_vendor_id = (cl_uint *) hccalloc (CL_PLATFORMS_MAX, sizeof (cl_uint));
7292 char **opencl_platforms_version = (char **) hccalloc (CL_PLATFORMS_MAX, sizeof (char *));
7293
7294 if (hc_clGetPlatformIDs (hashcat_ctx, CL_PLATFORMS_MAX, opencl_platforms, &opencl_platforms_cnt) == -1)
7295 {
7296 opencl_platforms_cnt = 0;
7297
7298 FREE_OPENCL_CTX_ON_ERROR;
7299
7300 ocl_close (hashcat_ctx);
7301 }
7302
7303 if (opencl_platforms_cnt)
7304 {
7305 for (u32 opencl_platforms_idx = 0; opencl_platforms_idx < opencl_platforms_cnt; opencl_platforms_idx++)
7306 {
7307 cl_platform_id opencl_platform = opencl_platforms[opencl_platforms_idx];
7308
7309 size_t param_value_size = 0;
7310
7311 // platform vendor
7312
7313 if (hc_clGetPlatformInfo (hashcat_ctx, opencl_platform, CL_PLATFORM_VENDOR, 0, NULL, ¶m_value_size) == -1) return -1;
7314
7315 char *opencl_platform_vendor = (char *) hcmalloc (param_value_size);
7316
7317 if (hc_clGetPlatformInfo (hashcat_ctx, opencl_platform, CL_PLATFORM_VENDOR, param_value_size, opencl_platform_vendor, NULL) == -1)
7318 {
7319 hcfree (opencl_platform_vendor);
7320
7321 return -1;
7322 }
7323
7324 opencl_platforms_vendor[opencl_platforms_idx] = opencl_platform_vendor;
7325
7326 // platform name
7327
7328 if (hc_clGetPlatformInfo (hashcat_ctx, opencl_platform, CL_PLATFORM_NAME, 0, NULL, ¶m_value_size) == -1) return -1;
7329
7330 char *opencl_platform_name = (char *) hcmalloc (param_value_size);
7331
7332 if (hc_clGetPlatformInfo (hashcat_ctx, opencl_platform, CL_PLATFORM_NAME, param_value_size, opencl_platform_name, NULL) == -1)
7333 {
7334 hcfree (opencl_platform_name);
7335
7336 return -1;
7337 }
7338
7339 opencl_platforms_name[opencl_platforms_idx] = opencl_platform_name;
7340
7341 // platform version
7342
7343 if (hc_clGetPlatformInfo (hashcat_ctx, opencl_platform, CL_PLATFORM_VERSION, 0, NULL, ¶m_value_size) == -1) return -1;
7344
7345 char *opencl_platform_version = (char *) hcmalloc (param_value_size);
7346
7347 if (hc_clGetPlatformInfo (hashcat_ctx, opencl_platform, CL_PLATFORM_VERSION, param_value_size, opencl_platform_version, NULL) == -1)
7348 {
7349 hcfree (opencl_platform_version);
7350
7351 return -1;
7352 }
7353
7354 opencl_platforms_version[opencl_platforms_idx] = opencl_platform_version;
7355
7356 // find our own platform vendor because pocl and mesa are pushing original vendor_id through opencl
7357 // this causes trouble with vendor id based macros
7358 // we'll assign generic to those without special optimization available
7359
7360 cl_uint opencl_platform_vendor_id = 0;
7361
7362 if (strcmp (opencl_platform_vendor, CL_VENDOR_AMD1) == 0)
7363 {
7364 opencl_platform_vendor_id = VENDOR_ID_AMD;
7365 }
7366 else if (strcmp (opencl_platform_vendor, CL_VENDOR_AMD2) == 0)
7367 {
7368 opencl_platform_vendor_id = VENDOR_ID_AMD;
7369 }
7370 else if (strcmp (opencl_platform_vendor, CL_VENDOR_AMD_USE_INTEL) == 0)
7371 {
7372 opencl_platform_vendor_id = VENDOR_ID_AMD_USE_INTEL;
7373 }
7374 else if (strcmp (opencl_platform_vendor, CL_VENDOR_APPLE) == 0)
7375 {
7376 opencl_platform_vendor_id = VENDOR_ID_APPLE;
7377 }
7378 else if (strcmp (opencl_platform_vendor, CL_VENDOR_INTEL_BEIGNET) == 0)
7379 {
7380 opencl_platform_vendor_id = VENDOR_ID_INTEL_BEIGNET;
7381 }
7382 else if (strcmp (opencl_platform_vendor, CL_VENDOR_INTEL_SDK) == 0)
7383 {
7384 opencl_platform_vendor_id = VENDOR_ID_INTEL_SDK;
7385 }
7386 else if (strcmp (opencl_platform_vendor, CL_VENDOR_MESA) == 0)
7387 {
7388 opencl_platform_vendor_id = VENDOR_ID_MESA;
7389 }
7390 else if (strcmp (opencl_platform_vendor, CL_VENDOR_NV) == 0)
7391 {
7392 opencl_platform_vendor_id = VENDOR_ID_NV;
7393 }
7394 else if (strcmp (opencl_platform_vendor, CL_VENDOR_POCL) == 0)
7395 {
7396 opencl_platform_vendor_id = VENDOR_ID_POCL;
7397 }
7398 else
7399 {
7400 opencl_platform_vendor_id = VENDOR_ID_GENERIC;
7401 }
7402
7403 opencl_platforms_vendor_id[opencl_platforms_idx] = opencl_platform_vendor_id;
7404
7405 cl_device_id *opencl_platform_devices = (cl_device_id *) hccalloc (DEVICES_MAX, sizeof (cl_device_id));
7406
7407 cl_uint opencl_platform_devices_cnt = 0;
7408
7409 const int CL_rc = hc_clGetDeviceIDs (hashcat_ctx, opencl_platform, CL_DEVICE_TYPE_ALL, DEVICES_MAX, opencl_platform_devices, &opencl_platform_devices_cnt);
7410
7411 if (CL_rc == -1)
7412 {
7413 event_log_error (hashcat_ctx, "clGetDeviceIDs(): %s", val2cstr_cl (CL_rc));
7414
7415 // Special handling for CL_DEVICE_NOT_FOUND, see: https://github.com/hashcat/hashcat/issues/2455
7416
7417 #define IGNORE_DEVICE_NOT_FOUND 1
7418
7419 if (IGNORE_DEVICE_NOT_FOUND)
7420 {
7421 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
7422
7423 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
7424
7425 const cl_int CL_err = ocl->clGetDeviceIDs (opencl_platform, CL_DEVICE_TYPE_ALL, DEVICES_MAX, opencl_platform_devices, &opencl_platform_devices_cnt);
7426
7427 if (CL_err == CL_DEVICE_NOT_FOUND)
7428 {
7429 // we ignore this error
7430 }
7431 else
7432 {
7433 return -1;
7434 }
7435 }
7436 else
7437 {
7438 return -1;
7439 }
7440 }
7441
7442 opencl_platforms_devices[opencl_platforms_idx] = opencl_platform_devices;
7443
7444 opencl_platforms_devices_cnt[opencl_platforms_idx] = opencl_platform_devices_cnt;
7445 }
7446
7447 if (user_options->opencl_device_types == NULL)
7448 {
7449 /**
7450 * OpenCL device types:
7451 * In case the user did not specify --opencl-device-types and the user runs hashcat in a system with only a CPU only he probably want to use that CPU.
7452 */
7453
7454 cl_device_type opencl_device_types_all = 0;
7455
7456 for (u32 opencl_platforms_idx = 0; opencl_platforms_idx < opencl_platforms_cnt; opencl_platforms_idx++)
7457 {
7458 cl_device_id *opencl_platform_devices = opencl_platforms_devices[opencl_platforms_idx];
7459 cl_uint opencl_platform_devices_cnt = opencl_platforms_devices_cnt[opencl_platforms_idx];
7460
7461 for (u32 opencl_platform_devices_idx = 0; opencl_platform_devices_idx < opencl_platform_devices_cnt; opencl_platform_devices_idx++)
7462 {
7463 cl_device_id opencl_device = opencl_platform_devices[opencl_platform_devices_idx];
7464
7465 cl_device_type opencl_device_type;
7466
7467 if (hc_clGetDeviceInfo (hashcat_ctx, opencl_device, CL_DEVICE_TYPE, sizeof (opencl_device_type), &opencl_device_type, NULL) == -1)
7468 {
7469 FREE_OPENCL_CTX_ON_ERROR;
7470
7471 return -1;
7472 }
7473
7474 opencl_device_types_all |= opencl_device_type;
7475 }
7476 }
7477
7478 // In such a case, automatically enable CPU device type support, since it's disabled by default.
7479
7480 if ((opencl_device_types_all & (CL_DEVICE_TYPE_GPU | CL_DEVICE_TYPE_ACCELERATOR)) == 0)
7481 {
7482 opencl_device_types_filter |= CL_DEVICE_TYPE_CPU;
7483 }
7484
7485 // In another case, when the user uses --stdout, using CPU devices is much faster to setup
7486 // If we have a CPU device, force it to be used
7487
7488 if (user_options->stdout_flag == true)
7489 {
7490 if (opencl_device_types_all & CL_DEVICE_TYPE_CPU)
7491 {
7492 opencl_device_types_filter = CL_DEVICE_TYPE_CPU;
7493 }
7494 }
7495
7496 backend_ctx->opencl_device_types_filter = opencl_device_types_filter;
7497 }
7498 }
7499
7500 backend_ctx->opencl_platforms = opencl_platforms;
7501 backend_ctx->opencl_platforms_cnt = opencl_platforms_cnt;
7502 backend_ctx->opencl_platforms_devices = opencl_platforms_devices;
7503 backend_ctx->opencl_platforms_devices_cnt = opencl_platforms_devices_cnt;
7504 backend_ctx->opencl_platforms_name = opencl_platforms_name;
7505 backend_ctx->opencl_platforms_vendor = opencl_platforms_vendor;
7506 backend_ctx->opencl_platforms_vendor_id = opencl_platforms_vendor_id;
7507 backend_ctx->opencl_platforms_version = opencl_platforms_version;
7508
7509 #undef FREE_OPENCL_CTX_ON_ERROR
7510 }
7511
7512 /**
7513 * Final checks
7514 */
7515
7516 if ((backend_ctx->cuda == NULL) && (backend_ctx->hip == NULL) && (backend_ctx->ocl == NULL))
7517 {
7518 event_log_error (hashcat_ctx, "ATTENTION! No OpenCL-compatible, HIP-compatible or CUDA-compatible platform found.");
7519
7520 event_log_warning (hashcat_ctx, "You are probably missing the OpenCL, CUDA or HIP runtime installation.");
7521 event_log_warning (hashcat_ctx, NULL);
7522
7523 #if defined (__linux__)
7524 event_log_warning (hashcat_ctx, "* AMD GPUs on Linux require this driver:");
7525 event_log_warning (hashcat_ctx, " \"AMD ROCm\" (4.5 or later)");
7526 #elif defined (_WIN)
7527 event_log_warning (hashcat_ctx, "* AMD GPUs on Windows require this driver:");
7528 event_log_warning (hashcat_ctx, " \"AMD Radeon Adrenalin 2020 Edition\" (21.2.1 or later)");
7529 #endif
7530
7531 event_log_warning (hashcat_ctx, "* Intel CPUs require this runtime:");
7532 event_log_warning (hashcat_ctx, " \"OpenCL Runtime for Intel Core and Intel Xeon Processors\" (16.1.1 or later)");
7533
7534 event_log_warning (hashcat_ctx, "* NVIDIA GPUs require this runtime and/or driver (both):");
7535 event_log_warning (hashcat_ctx, " \"NVIDIA Driver\" (440.64 or later)");
7536 event_log_warning (hashcat_ctx, " \"CUDA Toolkit\" (9.0 or later)");
7537 event_log_warning (hashcat_ctx, NULL);
7538
7539 return -1;
7540 }
7541
7542 backend_ctx->enabled = true;
7543
7544 return 0;
7545 }
7546
backend_ctx_destroy(hashcat_ctx_t * hashcat_ctx)7547 void backend_ctx_destroy (hashcat_ctx_t *hashcat_ctx)
7548 {
7549 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
7550
7551 if (backend_ctx->enabled == false) return;
7552
7553 hcfree (backend_ctx->devices_param);
7554
7555 if (backend_ctx->ocl)
7556 {
7557 hcfree (backend_ctx->opencl_platforms);
7558 hcfree (backend_ctx->opencl_platforms_devices);
7559 hcfree (backend_ctx->opencl_platforms_devices_cnt);
7560 hcfree (backend_ctx->opencl_platforms_name);
7561 hcfree (backend_ctx->opencl_platforms_vendor);
7562 hcfree (backend_ctx->opencl_platforms_vendor_id);
7563 hcfree (backend_ctx->opencl_platforms_version);
7564 }
7565
7566 nvrtc_close (hashcat_ctx);
7567 hiprtc_close (hashcat_ctx);
7568
7569 cuda_close (hashcat_ctx);
7570 hip_close (hashcat_ctx);
7571 ocl_close (hashcat_ctx);
7572
7573 memset (backend_ctx, 0, sizeof (backend_ctx_t));
7574 }
7575
backend_ctx_devices_init(hashcat_ctx_t * hashcat_ctx,const int comptime)7576 int backend_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime)
7577 {
7578 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
7579 user_options_t *user_options = hashcat_ctx->user_options;
7580
7581 if (backend_ctx->enabled == false) return 0;
7582
7583 hc_device_param_t *devices_param = backend_ctx->devices_param;
7584
7585 bool need_adl = false;
7586 bool need_nvml = false;
7587 bool need_nvapi = false;
7588 bool need_sysfs_amdgpu = false;
7589 bool need_sysfs_cpu = false;
7590 bool need_iokit = false;
7591
7592 int backend_devices_idx = 0;
7593
7594 // CUDA
7595
7596 int cuda_devices_cnt = 0;
7597 int cuda_devices_active = 0;
7598
7599 if (backend_ctx->cuda)
7600 {
7601 // device count
7602
7603 if (hc_cuDeviceGetCount (hashcat_ctx, &cuda_devices_cnt) == -1)
7604 {
7605 cuda_close (hashcat_ctx);
7606 }
7607
7608 backend_ctx->cuda_devices_cnt = cuda_devices_cnt;
7609
7610 // device specific
7611
7612 for (int cuda_devices_idx = 0; cuda_devices_idx < cuda_devices_cnt; cuda_devices_idx++, backend_devices_idx++)
7613 {
7614 const u32 device_id = backend_devices_idx;
7615
7616 hc_device_param_t *device_param = &devices_param[backend_devices_idx];
7617
7618 device_param->device_id = device_id;
7619
7620 backend_ctx->backend_device_from_cuda[cuda_devices_idx] = backend_devices_idx;
7621
7622 CUdevice cuda_device;
7623
7624 if (hc_cuDeviceGet (hashcat_ctx, &cuda_device, cuda_devices_idx) == -1)
7625 {
7626 device_param->skipped = true;
7627 continue;
7628 }
7629
7630 device_param->cuda_device = cuda_device;
7631
7632 device_param->is_cuda = true;
7633 device_param->is_hip = false;
7634 device_param->is_opencl = false;
7635
7636
7637 device_param->use_opencl12 = false;
7638 device_param->use_opencl20 = false;
7639 device_param->use_opencl21 = false;
7640
7641 // device_name
7642
7643 char *device_name = (char *) hcmalloc (HCBUFSIZ_TINY);
7644
7645 if (hc_cuDeviceGetName (hashcat_ctx, device_name, HCBUFSIZ_TINY, cuda_device) == -1)
7646 {
7647 device_param->skipped = true;
7648 hcfree (device_name);
7649 continue;
7650 }
7651
7652 device_param->device_name = device_name;
7653
7654 hc_string_trim_leading (device_name);
7655
7656 hc_string_trim_trailing (device_name);
7657
7658 // device_processors
7659
7660 int device_processors = 0;
7661
7662 if (hc_cuDeviceGetAttribute (hashcat_ctx, &device_processors, CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT, cuda_device) == -1)
7663 {
7664 device_param->skipped = true;
7665 continue;
7666 }
7667
7668 device_param->device_processors = device_processors;
7669
7670 // device_global_mem, device_maxmem_alloc, device_available_mem
7671
7672 size_t bytes = 0;
7673
7674 if (hc_cuDeviceTotalMem (hashcat_ctx, &bytes, cuda_device) == -1)
7675 {
7676 device_param->skipped = true;
7677 continue;
7678 }
7679
7680 device_param->device_global_mem = (u64) bytes;
7681
7682 device_param->device_maxmem_alloc = (u64) bytes;
7683
7684 device_param->device_available_mem = 0;
7685
7686 // warp size
7687
7688 int cuda_warp_size = 0;
7689
7690 if (hc_cuDeviceGetAttribute (hashcat_ctx, &cuda_warp_size, CU_DEVICE_ATTRIBUTE_WARP_SIZE, cuda_device) == -1)
7691 {
7692 device_param->skipped = true;
7693 continue;
7694 }
7695
7696 device_param->cuda_warp_size = cuda_warp_size;
7697
7698 // sm_minor, sm_major
7699
7700 int sm_major = 0;
7701 int sm_minor = 0;
7702
7703 if (hc_cuDeviceGetAttribute (hashcat_ctx, &sm_major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, cuda_device) == -1)
7704 {
7705 device_param->skipped = true;
7706 continue;
7707 }
7708
7709 if (hc_cuDeviceGetAttribute (hashcat_ctx, &sm_minor, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, cuda_device) == -1)
7710 {
7711 device_param->skipped = true;
7712 continue;
7713 }
7714
7715 device_param->sm_major = sm_major;
7716 device_param->sm_minor = sm_minor;
7717
7718 // device_maxworkgroup_size
7719
7720 int device_maxworkgroup_size = 0;
7721
7722 if (hc_cuDeviceGetAttribute (hashcat_ctx, &device_maxworkgroup_size, CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_BLOCK, cuda_device) == -1)
7723 {
7724 device_param->skipped = true;
7725 continue;
7726 }
7727
7728 device_param->device_maxworkgroup_size = device_maxworkgroup_size;
7729
7730 // max_clock_frequency
7731
7732 int device_maxclock_frequency = 0;
7733
7734 if (hc_cuDeviceGetAttribute (hashcat_ctx, &device_maxclock_frequency, CU_DEVICE_ATTRIBUTE_CLOCK_RATE, cuda_device) == -1)
7735 {
7736 device_param->skipped = true;
7737 continue;
7738 }
7739
7740 device_param->device_maxclock_frequency = device_maxclock_frequency / 1000;
7741
7742 // pcie_bus, pcie_device, pcie_function
7743
7744 int pci_domain_id_nv = 0;
7745 int pci_bus_id_nv = 0;
7746 int pci_slot_id_nv = 0;
7747
7748 if (hc_cuDeviceGetAttribute (hashcat_ctx, &pci_domain_id_nv, CU_DEVICE_ATTRIBUTE_PCI_DOMAIN_ID, cuda_device) == -1)
7749 {
7750 device_param->skipped = true;
7751 continue;
7752 }
7753
7754 if (hc_cuDeviceGetAttribute (hashcat_ctx, &pci_bus_id_nv, CU_DEVICE_ATTRIBUTE_PCI_BUS_ID, cuda_device) == -1)
7755 {
7756 device_param->skipped = true;
7757 continue;
7758 }
7759
7760 if (hc_cuDeviceGetAttribute (hashcat_ctx, &pci_slot_id_nv, CU_DEVICE_ATTRIBUTE_PCI_DEVICE_ID, cuda_device) == -1)
7761 {
7762 device_param->skipped = true;
7763 continue;
7764 }
7765
7766 device_param->pcie_domain = (u8) (pci_domain_id_nv);
7767 device_param->pcie_bus = (u8) (pci_bus_id_nv);
7768 device_param->pcie_device = (u8) (pci_slot_id_nv >> 3);
7769 device_param->pcie_function = (u8) (pci_slot_id_nv & 7);
7770
7771 // kernel_exec_timeout
7772
7773 int kernel_exec_timeout = 0;
7774
7775 if (hc_cuDeviceGetAttribute (hashcat_ctx, &kernel_exec_timeout, CU_DEVICE_ATTRIBUTE_KERNEL_EXEC_TIMEOUT, cuda_device) == -1)
7776 {
7777 device_param->skipped = true;
7778 continue;
7779 }
7780
7781 device_param->kernel_exec_timeout = kernel_exec_timeout;
7782
7783 // warp size
7784
7785 int warp_size = 0;
7786
7787 if (hc_cuDeviceGetAttribute (hashcat_ctx, &warp_size, CU_DEVICE_ATTRIBUTE_WARP_SIZE, cuda_device) == -1)
7788 {
7789 device_param->skipped = true;
7790 continue;
7791 }
7792
7793 device_param->kernel_preferred_wgs_multiple = warp_size;
7794
7795 // max_shared_memory_per_block
7796
7797 int max_shared_memory_per_block = 0;
7798
7799 if (hc_cuDeviceGetAttribute (hashcat_ctx, &max_shared_memory_per_block, CU_DEVICE_ATTRIBUTE_MAX_SHARED_MEMORY_PER_BLOCK_OPTIN, cuda_device) == -1)
7800 {
7801 device_param->skipped = true;
7802 continue;
7803 }
7804
7805 if (max_shared_memory_per_block < 32768)
7806 {
7807 event_log_error (hashcat_ctx, "* Device #%u: This device's shared buffer size is too small.", device_id + 1);
7808
7809 device_param->skipped = true;
7810 }
7811
7812 device_param->device_local_mem_size = max_shared_memory_per_block;
7813
7814 // device_max_constant_buffer_size
7815
7816 int device_max_constant_buffer_size = 0;
7817
7818 if (hc_cuDeviceGetAttribute (hashcat_ctx, &device_max_constant_buffer_size, CU_DEVICE_ATTRIBUTE_TOTAL_CONSTANT_MEMORY, cuda_device) == -1)
7819 {
7820 device_param->skipped = true;
7821 continue;
7822 }
7823
7824 if (device_max_constant_buffer_size < 65536)
7825 {
7826 event_log_error (hashcat_ctx, "* Device #%u: This device's local mem size is too small.", device_id + 1);
7827
7828 device_param->skipped = true;
7829 }
7830
7831 // some attributes have to be hardcoded values because they are used for instance in the build options
7832
7833 device_param->device_local_mem_type = CL_LOCAL;
7834 device_param->opencl_device_type = CL_DEVICE_TYPE_GPU;
7835 device_param->opencl_device_vendor_id = VENDOR_ID_NV;
7836 device_param->opencl_platform_vendor_id = VENDOR_ID_NV;
7837
7838 // or in the cached kernel checksum
7839
7840 device_param->opencl_device_version = "";
7841 device_param->opencl_driver_version = "";
7842
7843 // or just to make sure they are not NULL
7844
7845 device_param->opencl_device_vendor = "";
7846 device_param->opencl_device_c_version = "";
7847
7848 // skipped
7849
7850 if ((backend_ctx->backend_devices_filter & (1ULL << device_id)) == 0)
7851 {
7852 device_param->skipped = true;
7853 }
7854
7855 #if !defined (__APPLE__)
7856 if ((backend_ctx->opencl_device_types_filter & CL_DEVICE_TYPE_GPU) == 0)
7857 {
7858 device_param->skipped = true;
7859 }
7860 #endif
7861
7862 if ((device_param->opencl_platform_vendor_id == VENDOR_ID_NV) && (device_param->opencl_device_vendor_id == VENDOR_ID_NV))
7863 {
7864 need_nvml = true;
7865
7866 #if defined (_WIN) || defined (__CYGWIN__)
7867 need_nvapi = true;
7868 #endif
7869 }
7870
7871 // CPU burning loop damper
7872 // Value is given as number between 0-100
7873 // By default 8%
7874 // in theory not needed with CUDA
7875
7876 device_param->spin_damp = (double) user_options->spin_damp / 100;
7877
7878 // common driver check
7879
7880 if (device_param->skipped == false)
7881 {
7882 if ((user_options->force == false) && (user_options->backend_info == false))
7883 {
7884 // CUDA does not support query nvidia driver version, therefore no driver checks here
7885 // IF needed, could be retrieved using nvmlSystemGetDriverVersion()
7886
7887 if (device_param->sm_major < 5)
7888 {
7889 if (user_options->quiet == false) event_log_warning (hashcat_ctx, "* Device #%u: This hardware has outdated CUDA compute capability (%u.%u).", device_id + 1, device_param->sm_major, device_param->sm_minor);
7890 if (user_options->quiet == false) event_log_warning (hashcat_ctx, " For modern OpenCL performance, upgrade to hardware that supports");
7891 if (user_options->quiet == false) event_log_warning (hashcat_ctx, " CUDA compute capability version 5.0 (Maxwell) or higher.");
7892 }
7893
7894 if (device_param->kernel_exec_timeout != 0)
7895 {
7896 if (user_options->quiet == false) event_log_advice (hashcat_ctx, "* Device #%u: WARNING! Kernel exec timeout is not disabled.", device_id + 1);
7897 if (user_options->quiet == false) event_log_advice (hashcat_ctx, " This may cause \"CL_OUT_OF_RESOURCES\" or related errors.");
7898 if (user_options->quiet == false) event_log_advice (hashcat_ctx, " To disable the timeout, see: https://hashcat.net/q/timeoutpatch");
7899 }
7900 }
7901
7902 // activate device moved below, at end
7903 }
7904
7905 // instruction set
7906
7907 // bcrypt optimization?
7908 //const int rc_cuCtxSetCacheConfig = hc_cuCtxSetCacheConfig (hashcat_ctx, CU_FUNC_CACHE_PREFER_SHARED);
7909 //
7910 //if (rc_cuCtxSetCacheConfig == -1) return -1;
7911
7912 const int sm = (device_param->sm_major * 10) + device_param->sm_minor;
7913
7914 device_param->has_add = (sm >= 12) ? true : false;
7915 device_param->has_addc = (sm >= 12) ? true : false;
7916 device_param->has_sub = (sm >= 12) ? true : false;
7917 device_param->has_subc = (sm >= 12) ? true : false;
7918 device_param->has_bfe = (sm >= 20) ? true : false;
7919 device_param->has_lop3 = (sm >= 50) ? true : false;
7920 device_param->has_mov64 = (sm >= 10) ? true : false;
7921 device_param->has_prmt = (sm >= 20) ? true : false;
7922
7923 // device_available_mem
7924
7925 CUcontext cuda_context;
7926
7927 if (hc_cuCtxCreate (hashcat_ctx, &cuda_context, CU_CTX_SCHED_BLOCKING_SYNC, device_param->cuda_device) == -1)
7928 {
7929 device_param->skipped = true;
7930 continue;
7931 }
7932
7933 if (hc_cuCtxPushCurrent (hashcat_ctx, cuda_context) == -1)
7934 {
7935 device_param->skipped = true;
7936 continue;
7937 }
7938
7939 size_t free = 0;
7940 size_t total = 0;
7941
7942 if (hc_cuMemGetInfo (hashcat_ctx, &free, &total) == -1)
7943 {
7944 device_param->skipped = true;
7945 continue;
7946 }
7947
7948 device_param->device_available_mem = (u64) free;
7949
7950 if (hc_cuCtxPopCurrent (hashcat_ctx, &cuda_context) == -1)
7951 {
7952 device_param->skipped = true;
7953 continue;
7954 }
7955
7956 if (hc_cuCtxDestroy (hashcat_ctx, cuda_context) == -1)
7957 {
7958 device_param->skipped = true;
7959 continue;
7960 }
7961
7962 /**
7963 * activate device
7964 */
7965
7966 if (device_param->skipped == false) cuda_devices_active++;
7967 }
7968 }
7969
7970 backend_ctx->cuda_devices_cnt = cuda_devices_cnt;
7971 backend_ctx->cuda_devices_active = cuda_devices_active;
7972
7973 // HIP
7974
7975 int hip_devices_cnt = 0;
7976 int hip_devices_active = 0;
7977
7978 if (backend_ctx->hip)
7979 {
7980 // device count
7981
7982 if (hc_hipDeviceGetCount (hashcat_ctx, &hip_devices_cnt) == -1)
7983 {
7984 hip_close (hashcat_ctx);
7985 }
7986
7987 backend_ctx->hip_devices_cnt = hip_devices_cnt;
7988
7989 // device specific
7990
7991 for (int hip_devices_idx = 0; hip_devices_idx < hip_devices_cnt; hip_devices_idx++, backend_devices_idx++)
7992 {
7993 const u32 device_id = backend_devices_idx;
7994
7995 hc_device_param_t *device_param = &devices_param[backend_devices_idx];
7996
7997 device_param->device_id = device_id;
7998
7999 backend_ctx->backend_device_from_hip[hip_devices_idx] = backend_devices_idx;
8000
8001 hipDevice_t hip_device;
8002
8003 if (hc_hipDeviceGet (hashcat_ctx, &hip_device, hip_devices_idx) == -1)
8004 {
8005 device_param->skipped = true;
8006 continue;
8007 }
8008
8009 device_param->hip_device = hip_device;
8010
8011 device_param->is_cuda = false;
8012 device_param->is_hip = true;
8013 device_param->is_opencl = false;
8014
8015 device_param->use_opencl12 = false;
8016 device_param->use_opencl20 = false;
8017 device_param->use_opencl21 = false;
8018
8019 // device_name
8020
8021 char *device_name = (char *) hcmalloc (HCBUFSIZ_TINY);
8022
8023 if (hc_hipDeviceGetName (hashcat_ctx, device_name, HCBUFSIZ_TINY, hip_device) == -1)
8024 {
8025 device_param->skipped = true;
8026 hcfree (device_name);
8027 continue;
8028 }
8029
8030 device_param->device_name = device_name;
8031
8032 hc_string_trim_leading (device_name);
8033
8034 hc_string_trim_trailing (device_name);
8035
8036 // device_processors
8037
8038 int device_processors = 0;
8039
8040 if (hc_hipDeviceGetAttribute (hashcat_ctx, &device_processors, hipDeviceAttributeMultiprocessorCount, hip_device) == -1)
8041 {
8042 device_param->skipped = true;
8043 continue;
8044 }
8045
8046 device_param->device_processors = device_processors;
8047
8048 // device_global_mem, device_maxmem_alloc, device_available_mem
8049
8050 size_t bytes = 0;
8051
8052 if (hc_hipDeviceTotalMem (hashcat_ctx, &bytes, hip_device) == -1)
8053 {
8054 device_param->skipped = true;
8055 continue;
8056 }
8057
8058 device_param->device_global_mem = (u64) bytes;
8059
8060 device_param->device_maxmem_alloc = (u64) bytes;
8061
8062 device_param->device_available_mem = 0;
8063
8064 // warp size
8065
8066 int hip_warp_size = 0;
8067
8068 if (hc_hipDeviceGetAttribute (hashcat_ctx, &hip_warp_size, hipDeviceAttributeWarpSize, hip_device) == -1)
8069 {
8070 device_param->skipped = true;
8071 continue;
8072 }
8073
8074 device_param->hip_warp_size = hip_warp_size;
8075
8076 // sm_minor, sm_major
8077
8078 int sm_major = 0;
8079 int sm_minor = 0;
8080
8081 if (hc_hipDeviceGetAttribute (hashcat_ctx, &sm_major, hipDeviceAttributeComputeCapabilityMajor, hip_device) == -1)
8082 {
8083 device_param->skipped = true;
8084 continue;
8085 }
8086
8087 if (hc_hipDeviceGetAttribute (hashcat_ctx, &sm_minor, hipDeviceAttributeComputeCapabilityMinor, hip_device) == -1)
8088 {
8089 device_param->skipped = true;
8090 continue;
8091 }
8092
8093 device_param->sm_major = sm_major;
8094 device_param->sm_minor = sm_minor;
8095
8096 // device_maxworkgroup_size
8097
8098 int device_maxworkgroup_size = 0;
8099
8100 if (hc_hipDeviceGetAttribute (hashcat_ctx, &device_maxworkgroup_size, hipDeviceAttributeMaxThreadsPerBlock, hip_device) == -1)
8101 {
8102 device_param->skipped = true;
8103 continue;
8104 }
8105
8106 device_param->device_maxworkgroup_size = device_maxworkgroup_size;
8107
8108 // max_clock_frequency
8109
8110 int device_maxclock_frequency = 0;
8111
8112 if (hc_hipDeviceGetAttribute (hashcat_ctx, &device_maxclock_frequency, hipDeviceAttributeClockRate, hip_device) == -1)
8113 {
8114 device_param->skipped = true;
8115 continue;
8116 }
8117
8118 device_param->device_maxclock_frequency = device_maxclock_frequency / 1000;
8119
8120 // pcie_bus, pcie_device, pcie_function
8121
8122 int pci_domain_id_nv = 0;
8123 int pci_bus_id_nv = 0;
8124 int pci_slot_id_nv = 0;
8125
8126 // Not supported by HIP
8127 //if (hc_hipDeviceGetAttribute (hashcat_ctx, &pci_domain_id_nv, hipDeviceAttributePciDomainID, hip_device) == -1)
8128 //{
8129 // device_param->skipped = true;
8130 // continue;
8131 //}
8132
8133 if (hc_hipDeviceGetAttribute (hashcat_ctx, &pci_bus_id_nv, hipDeviceAttributePciBusId, hip_device) == -1)
8134 {
8135 device_param->skipped = true;
8136 continue;
8137 }
8138
8139 if (hc_hipDeviceGetAttribute (hashcat_ctx, &pci_slot_id_nv, hipDeviceAttributePciDeviceId, hip_device) == -1)
8140 {
8141 device_param->skipped = true;
8142 continue;
8143 }
8144
8145 device_param->pcie_domain = (u8) (pci_domain_id_nv);
8146 device_param->pcie_bus = (u8) (pci_bus_id_nv);
8147
8148 device_param->pcie_device = (u8) (pci_slot_id_nv >> 3);
8149 device_param->pcie_function = (u8) (pci_slot_id_nv & 7);
8150
8151 // kernel_exec_timeout
8152
8153 int kernel_exec_timeout = 0;
8154
8155 if (hc_hipDeviceGetAttribute (hashcat_ctx, &kernel_exec_timeout, hipDeviceAttributeKernelExecTimeout, hip_device) == -1)
8156 {
8157 device_param->skipped = true;
8158 continue;
8159 }
8160
8161 device_param->kernel_exec_timeout = kernel_exec_timeout;
8162
8163 // warp size
8164
8165 int warp_size = 0;
8166
8167 if (hc_hipDeviceGetAttribute (hashcat_ctx, &warp_size, hipDeviceAttributeWarpSize, hip_device) == -1)
8168 {
8169 device_param->skipped = true;
8170 continue;
8171 }
8172
8173 device_param->kernel_preferred_wgs_multiple = warp_size;
8174
8175 // max_shared_memory_per_block
8176
8177 int max_shared_memory_per_block = 0;
8178
8179 if (hc_hipDeviceGetAttribute (hashcat_ctx, &max_shared_memory_per_block, hipDeviceAttributeMaxSharedMemoryPerBlock, hip_device) == -1)
8180 {
8181 device_param->skipped = true;
8182 continue;
8183 }
8184
8185 if (max_shared_memory_per_block < 32768)
8186 {
8187 event_log_error (hashcat_ctx, "* Device #%u: This device's shared buffer size is too small.", device_id + 1);
8188
8189 device_param->skipped = true;
8190 }
8191
8192 device_param->device_local_mem_size = max_shared_memory_per_block;
8193
8194 // device_max_constant_buffer_size
8195
8196 int device_max_constant_buffer_size = 0;
8197
8198 if (hc_hipDeviceGetAttribute (hashcat_ctx, &device_max_constant_buffer_size, hipDeviceAttributeTotalConstantMemory, hip_device) == -1)
8199 {
8200 device_param->skipped = true;
8201 continue;
8202 }
8203
8204 // TODO: broken on HIP?
8205
8206 device_max_constant_buffer_size = 65536;
8207
8208 if (device_max_constant_buffer_size < 65536)
8209 {
8210 event_log_error (hashcat_ctx, "* Device #%u: This device's local mem size is too small.", device_id + 1);
8211
8212 device_param->skipped = true;
8213 }
8214
8215 // some attributes have to be hardcoded values because they are used for instance in the build options
8216
8217 device_param->device_local_mem_type = CL_LOCAL;
8218 device_param->opencl_device_type = CL_DEVICE_TYPE_GPU;
8219 device_param->opencl_device_vendor_id = VENDOR_ID_AMD_USE_HIP;
8220 device_param->opencl_platform_vendor_id = VENDOR_ID_AMD_USE_HIP;
8221
8222 // or in the cached kernel checksum
8223
8224 device_param->opencl_device_version = "";
8225 device_param->opencl_driver_version = "";
8226
8227 // or just to make sure they are not NULL
8228
8229 device_param->opencl_device_vendor = "";
8230 device_param->opencl_device_c_version = "";
8231
8232 // skipped
8233
8234 if ((backend_ctx->backend_devices_filter & (1ULL << device_id)) == 0)
8235 {
8236 device_param->skipped = true;
8237 }
8238
8239 #if !defined (__APPLE__)
8240 if ((backend_ctx->opencl_device_types_filter & CL_DEVICE_TYPE_GPU) == 0)
8241 {
8242 device_param->skipped = true;
8243 }
8244 #endif
8245
8246 if ((device_param->opencl_platform_vendor_id == VENDOR_ID_AMD_USE_HIP) && (device_param->opencl_device_vendor_id == VENDOR_ID_AMD_USE_HIP))
8247 {
8248 need_adl = true;
8249
8250 #if defined (__linux__)
8251 need_sysfs_amdgpu = true;
8252 #endif
8253 }
8254
8255 // CPU burning loop damper
8256 // Value is given as number between 0-100
8257 // By default 8%
8258 // in theory not needed with HIP
8259
8260 device_param->spin_damp = (double) user_options->spin_damp / 100;
8261
8262 // common driver check
8263
8264 if (device_param->skipped == false)
8265 {
8266 if ((user_options->force == false) && (user_options->backend_info == false))
8267 {
8268 // CUDA does not support query nvidia driver version, therefore no driver checks here
8269 // IF needed, could be retrieved using nvmlSystemGetDriverVersion()
8270
8271 if (device_param->sm_major < 5)
8272 {
8273 if (user_options->quiet == false) event_log_warning (hashcat_ctx, "* Device #%u: This hardware has outdated CUDA compute capability (%u.%u).", device_id + 1, device_param->sm_major, device_param->sm_minor);
8274 if (user_options->quiet == false) event_log_warning (hashcat_ctx, " For modern OpenCL performance, upgrade to hardware that supports");
8275 if (user_options->quiet == false) event_log_warning (hashcat_ctx, " CUDA compute capability version 5.0 (Maxwell) or higher.");
8276 }
8277
8278 if (device_param->kernel_exec_timeout != 0)
8279 {
8280 if (user_options->quiet == false) event_log_advice (hashcat_ctx, "* Device #%u: WARNING! Kernel exec timeout is not disabled.", device_id + 1);
8281 if (user_options->quiet == false) event_log_advice (hashcat_ctx, " This may cause \"CL_OUT_OF_RESOURCES\" or related errors.");
8282 if (user_options->quiet == false) event_log_advice (hashcat_ctx, " To disable the timeout, see: https://hashcat.net/q/timeoutpatch");
8283 }
8284 }
8285
8286 // activate device moved below, at end
8287 }
8288
8289 // instruction set
8290
8291 device_param->has_add = false;
8292 device_param->has_addc = false;
8293 device_param->has_sub = false;
8294 device_param->has_subc = false;
8295 device_param->has_bfe = false;
8296 device_param->has_lop3 = false;
8297 device_param->has_mov64 = false;
8298 device_param->has_prmt = false;
8299
8300 // device_available_mem
8301
8302 hipCtx_t hip_context;
8303
8304 if (hc_hipCtxCreate (hashcat_ctx, &hip_context, hipDeviceScheduleBlockingSync, device_param->hip_device) == -1)
8305 {
8306 device_param->skipped = true;
8307 continue;
8308 }
8309
8310 if (hc_hipCtxPushCurrent (hashcat_ctx, hip_context) == -1)
8311 {
8312 device_param->skipped = true;
8313 continue;
8314 }
8315
8316 size_t free = 0;
8317 size_t total = 0;
8318
8319 if (hc_hipMemGetInfo (hashcat_ctx, &free, &total) == -1)
8320 {
8321 device_param->skipped = true;
8322 continue;
8323 }
8324
8325 device_param->device_available_mem = (u64) free;
8326
8327 if (hc_hipCtxPopCurrent (hashcat_ctx, &hip_context) == -1)
8328 {
8329 device_param->skipped = true;
8330 continue;
8331 }
8332
8333 if (hc_hipCtxDestroy (hashcat_ctx, hip_context) == -1)
8334 {
8335 device_param->skipped = true;
8336 continue;
8337 }
8338
8339 /**
8340 * activate device
8341 */
8342
8343 if (device_param->skipped == false) hip_devices_active++;
8344 }
8345 }
8346
8347 backend_ctx->hip_devices_cnt = hip_devices_cnt;
8348 backend_ctx->hip_devices_active = hip_devices_active;
8349
8350 // OCL
8351
8352 int opencl_devices_cnt = 0;
8353 int opencl_devices_active = 0;
8354
8355 if (backend_ctx->ocl)
8356 {
8357 /**
8358 * OpenCL devices: simply push all devices from all platforms into the same device array
8359 */
8360
8361 cl_uint opencl_platforms_cnt = backend_ctx->opencl_platforms_cnt;
8362 cl_device_id **opencl_platforms_devices = backend_ctx->opencl_platforms_devices;
8363 cl_uint *opencl_platforms_devices_cnt = backend_ctx->opencl_platforms_devices_cnt;
8364 cl_uint *opencl_platforms_vendor_id = backend_ctx->opencl_platforms_vendor_id;
8365 char **opencl_platforms_version = backend_ctx->opencl_platforms_version;
8366
8367 for (u32 opencl_platforms_idx = 0; opencl_platforms_idx < opencl_platforms_cnt; opencl_platforms_idx++)
8368 {
8369 cl_device_id *opencl_platform_devices = opencl_platforms_devices[opencl_platforms_idx];
8370 cl_uint opencl_platform_devices_cnt = opencl_platforms_devices_cnt[opencl_platforms_idx];
8371 cl_uint opencl_platform_vendor_id = opencl_platforms_vendor_id[opencl_platforms_idx];
8372 char *opencl_platform_version = opencl_platforms_version[opencl_platforms_idx];
8373
8374 for (u32 opencl_platform_devices_idx = 0; opencl_platform_devices_idx < opencl_platform_devices_cnt; opencl_platform_devices_idx++, backend_devices_idx++, opencl_devices_cnt++)
8375 {
8376 const u32 device_id = backend_devices_idx;
8377
8378 hc_device_param_t *device_param = &devices_param[device_id];
8379
8380 device_param->device_id = device_id;
8381
8382 backend_ctx->backend_device_from_opencl[opencl_devices_cnt] = backend_devices_idx;
8383
8384 backend_ctx->backend_device_from_opencl_platform[opencl_platforms_idx][opencl_platform_devices_idx] = backend_devices_idx;
8385
8386 device_param->opencl_platform_vendor_id = opencl_platform_vendor_id;
8387
8388 device_param->opencl_device = opencl_platform_devices[opencl_platform_devices_idx];
8389
8390 //device_param->opencl_platform = opencl_platform;
8391
8392 device_param->is_cuda = false;
8393 device_param->is_hip = false;
8394 device_param->is_opencl = true;
8395
8396 // store opencl platform i
8397
8398 device_param->opencl_platform_id = opencl_platforms_idx;
8399
8400 // check OpenCL version
8401
8402 device_param->use_opencl12 = false;
8403 device_param->use_opencl20 = false;
8404 device_param->use_opencl21 = false;
8405
8406 int opencl_version_min = 0;
8407 int opencl_version_maj = 0;
8408
8409 if (sscanf (opencl_platform_version, "OpenCL %d.%d", &opencl_version_min, &opencl_version_maj) == 2)
8410 {
8411 if ((opencl_version_min == 1) && (opencl_version_maj == 2))
8412 {
8413 device_param->use_opencl12 = true;
8414 }
8415 else if ((opencl_version_min == 2) && (opencl_version_maj == 0))
8416 {
8417 device_param->use_opencl20 = true;
8418 }
8419 else if ((opencl_version_min == 2) && (opencl_version_maj == 1))
8420 {
8421 device_param->use_opencl21 = true;
8422 }
8423 }
8424
8425 size_t param_value_size = 0;
8426
8427 // opencl_device_type
8428
8429 cl_device_type opencl_device_type;
8430
8431 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_TYPE, sizeof (opencl_device_type), &opencl_device_type, NULL) == -1)
8432 {
8433 device_param->skipped = true;
8434 continue;
8435 }
8436
8437 opencl_device_type &= ~CL_DEVICE_TYPE_DEFAULT;
8438
8439 device_param->opencl_device_type = opencl_device_type;
8440
8441 // device_name
8442
8443 // try CL_DEVICE_BOARD_NAME_AMD first, if it fails fall back to CL_DEVICE_NAME
8444 // since AMD ROCm does not identify itself at this stage we simply check for return code from clGetDeviceInfo()
8445
8446 #define CHECK_BOARD_NAME_AMD 1
8447
8448 cl_int rc_board_name_amd = CL_INVALID_VALUE;
8449
8450 if (CHECK_BOARD_NAME_AMD)
8451 {
8452 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
8453
8454 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
8455
8456 rc_board_name_amd = ocl->clGetDeviceInfo (device_param->opencl_device, CL_DEVICE_BOARD_NAME_AMD, 0, NULL, NULL);
8457 }
8458
8459 if (rc_board_name_amd == CL_SUCCESS)
8460 {
8461 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_BOARD_NAME_AMD, 0, NULL, ¶m_value_size) == -1)
8462 {
8463 device_param->skipped = true;
8464 continue;
8465 }
8466
8467 char *device_name = (char *) hcmalloc (param_value_size);
8468
8469 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_BOARD_NAME_AMD, param_value_size, device_name, NULL) == -1)
8470 {
8471 device_param->skipped = true;
8472 hcfree (device_name);
8473 continue;
8474 }
8475
8476 device_param->device_name = device_name;
8477 }
8478 else
8479 {
8480 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_NAME, 0, NULL, ¶m_value_size) == -1)
8481 {
8482 device_param->skipped = true;
8483 continue;
8484 }
8485
8486 char *device_name = (char *) hcmalloc (param_value_size);
8487
8488 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_NAME, param_value_size, device_name, NULL) == -1)
8489 {
8490 device_param->skipped = true;
8491 hcfree (device_name);
8492 continue;
8493 }
8494
8495 device_param->device_name = device_name;
8496 }
8497
8498 hc_string_trim_leading (device_param->device_name);
8499
8500 hc_string_trim_trailing (device_param->device_name);
8501
8502 // device_vendor
8503
8504 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_VENDOR, 0, NULL, ¶m_value_size) == -1)
8505 {
8506 device_param->skipped = true;
8507 continue;
8508 }
8509
8510 char *opencl_device_vendor = (char *) hcmalloc (param_value_size);
8511
8512 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_VENDOR, param_value_size, opencl_device_vendor, NULL) == -1)
8513 {
8514 device_param->skipped = true;
8515 hcfree (opencl_device_vendor);
8516 continue;
8517 }
8518
8519 device_param->opencl_device_vendor = opencl_device_vendor;
8520
8521 cl_uint opencl_device_vendor_id = 0;
8522
8523 if (strcmp (opencl_device_vendor, CL_VENDOR_AMD1) == 0)
8524 {
8525 opencl_device_vendor_id = VENDOR_ID_AMD;
8526 }
8527 else if (strcmp (opencl_device_vendor, CL_VENDOR_AMD2) == 0)
8528 {
8529 opencl_device_vendor_id = VENDOR_ID_AMD;
8530 }
8531 else if (strcmp (opencl_device_vendor, CL_VENDOR_AMD_USE_INTEL) == 0)
8532 {
8533 opencl_device_vendor_id = VENDOR_ID_AMD_USE_INTEL;
8534 }
8535 else if (strcmp (opencl_device_vendor, CL_VENDOR_APPLE) == 0)
8536 {
8537 opencl_device_vendor_id = VENDOR_ID_APPLE;
8538 }
8539 else if (strcmp (opencl_device_vendor, CL_VENDOR_APPLE_USE_AMD) == 0)
8540 {
8541 opencl_device_vendor_id = VENDOR_ID_AMD;
8542 }
8543 else if (strcmp (opencl_device_vendor, CL_VENDOR_APPLE_USE_NV) == 0)
8544 {
8545 opencl_device_vendor_id = VENDOR_ID_NV;
8546 }
8547 else if (strcmp (opencl_device_vendor, CL_VENDOR_APPLE_USE_INTEL) == 0)
8548 {
8549 opencl_device_vendor_id = VENDOR_ID_INTEL_SDK;
8550 }
8551 else if (strcmp (opencl_device_vendor, CL_VENDOR_APPLE_USE_INTEL2) == 0)
8552 {
8553 opencl_device_vendor_id = VENDOR_ID_INTEL_SDK;
8554 }
8555 else if (strcmp (opencl_device_vendor, CL_VENDOR_INTEL_BEIGNET) == 0)
8556 {
8557 opencl_device_vendor_id = VENDOR_ID_INTEL_BEIGNET;
8558 }
8559 else if (strcmp (opencl_device_vendor, CL_VENDOR_INTEL_SDK) == 0)
8560 {
8561 opencl_device_vendor_id = VENDOR_ID_INTEL_SDK;
8562 }
8563 else if (strcmp (opencl_device_vendor, CL_VENDOR_MESA) == 0)
8564 {
8565 opencl_device_vendor_id = VENDOR_ID_MESA;
8566 }
8567 else if (strcmp (opencl_device_vendor, CL_VENDOR_NV) == 0)
8568 {
8569 opencl_device_vendor_id = VENDOR_ID_NV;
8570 }
8571 else if (strcmp (opencl_device_vendor, CL_VENDOR_POCL) == 0)
8572 {
8573 opencl_device_vendor_id = VENDOR_ID_POCL;
8574 }
8575 else
8576 {
8577 opencl_device_vendor_id = VENDOR_ID_GENERIC;
8578 }
8579
8580 device_param->opencl_device_vendor_id = opencl_device_vendor_id;
8581
8582 // device_version
8583
8584 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_VERSION, 0, NULL, ¶m_value_size) == -1)
8585 {
8586 device_param->skipped = true;
8587 continue;
8588 }
8589
8590 char *opencl_device_version = (char *) hcmalloc (param_value_size);
8591
8592 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_VERSION, param_value_size, opencl_device_version, NULL) == -1)
8593 {
8594 device_param->skipped = true;
8595 hcfree (opencl_device_version);
8596 continue;
8597 }
8598
8599 device_param->opencl_device_version = opencl_device_version;
8600
8601 // opencl_device_c_version
8602
8603 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_OPENCL_C_VERSION, 0, NULL, ¶m_value_size) == -1)
8604 {
8605 device_param->skipped = true;
8606 continue;
8607 }
8608
8609 char *opencl_device_c_version = (char *) hcmalloc (param_value_size);
8610
8611 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_OPENCL_C_VERSION, param_value_size, opencl_device_c_version, NULL) == -1)
8612 {
8613 device_param->skipped = true;
8614 hcfree (opencl_device_c_version);
8615 continue;
8616 }
8617
8618 device_param->opencl_device_c_version = opencl_device_c_version;
8619
8620 // max_compute_units
8621
8622 cl_uint device_processors = 0;
8623
8624 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_MAX_COMPUTE_UNITS, sizeof (device_processors), &device_processors, NULL) == -1)
8625 {
8626 device_param->skipped = true;
8627 continue;
8628 }
8629
8630 device_param->device_processors = device_processors;
8631
8632 // device_host_unified_memory
8633
8634 cl_bool device_host_unified_memory = false;
8635
8636 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_HOST_UNIFIED_MEMORY, sizeof (device_host_unified_memory), &device_host_unified_memory, NULL) == -1)
8637 {
8638 device_param->skipped = true;
8639 continue;
8640 }
8641
8642 device_param->device_host_unified_memory = (device_host_unified_memory == CL_TRUE) ? 1 : 0;
8643
8644 // device_global_mem
8645
8646 cl_ulong device_global_mem = 0;
8647
8648 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof (device_global_mem), &device_global_mem, NULL) == -1)
8649 {
8650 device_param->skipped = true;
8651 continue;
8652 }
8653
8654 device_param->device_global_mem = device_global_mem;
8655
8656 device_param->device_available_mem = 0;
8657
8658 // device_maxmem_alloc
8659
8660 cl_ulong device_maxmem_alloc = 0;
8661
8662 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof (device_maxmem_alloc), &device_maxmem_alloc, NULL) == -1)
8663 {
8664 device_param->skipped = true;
8665 continue;
8666 }
8667
8668 device_param->device_maxmem_alloc = device_maxmem_alloc;
8669
8670 if (device_param->device_host_unified_memory == 1)
8671 {
8672 // so, we actually have only half the memory because we need the same buffers on host side
8673
8674 device_param->device_maxmem_alloc /= 2;
8675 }
8676
8677 // note we'll limit to 2gb, otherwise this causes all kinds of weird errors because of possible integer overflows in opencl runtimes
8678 // testwise disabling that
8679 //device_param->device_maxmem_alloc = MIN (device_maxmem_alloc, 0x7fffffff);
8680
8681 // max_work_group_size
8682
8683 size_t device_maxworkgroup_size = 0;
8684
8685 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof (device_maxworkgroup_size), &device_maxworkgroup_size, NULL) == -1)
8686 {
8687 device_param->skipped = true;
8688 continue;
8689 }
8690
8691 device_param->device_maxworkgroup_size = device_maxworkgroup_size;
8692
8693 // max_clock_frequency
8694
8695 cl_uint device_maxclock_frequency = 0;
8696
8697 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_MAX_CLOCK_FREQUENCY, sizeof (device_maxclock_frequency), &device_maxclock_frequency, NULL) == -1)
8698 {
8699 device_param->skipped = true;
8700 continue;
8701 }
8702
8703 device_param->device_maxclock_frequency = device_maxclock_frequency;
8704
8705 // device_endian_little
8706
8707 cl_bool device_endian_little = CL_FALSE;
8708
8709 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_ENDIAN_LITTLE, sizeof (device_endian_little), &device_endian_little, NULL) == -1)
8710 {
8711 device_param->skipped = true;
8712 continue;
8713 }
8714
8715 if (device_endian_little == CL_FALSE)
8716 {
8717 event_log_error (hashcat_ctx, "* Device #%u: This device is not little-endian.", device_id + 1);
8718
8719 device_param->skipped = true;
8720 }
8721
8722 // device_available
8723
8724 cl_bool device_available = CL_FALSE;
8725
8726 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_AVAILABLE, sizeof (device_available), &device_available, NULL) == -1)
8727 {
8728 device_param->skipped = true;
8729 continue;
8730 }
8731
8732 if (device_available == CL_FALSE)
8733 {
8734 event_log_error (hashcat_ctx, "* Device #%u: This device is not available.", device_id + 1);
8735
8736 device_param->skipped = true;
8737 }
8738
8739 // device_compiler_available
8740
8741 cl_bool device_compiler_available = CL_FALSE;
8742
8743 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_COMPILER_AVAILABLE, sizeof (device_compiler_available), &device_compiler_available, NULL) == -1)
8744 {
8745 device_param->skipped = true;
8746 continue;
8747 }
8748
8749 if (device_compiler_available == CL_FALSE)
8750 {
8751 event_log_error (hashcat_ctx, "* Device #%u: No compiler is available for this device.", device_id + 1);
8752
8753 device_param->skipped = true;
8754 }
8755
8756 // device_execution_capabilities
8757
8758 cl_device_exec_capabilities device_execution_capabilities;
8759
8760 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_EXECUTION_CAPABILITIES, sizeof (device_execution_capabilities), &device_execution_capabilities, NULL) == -1)
8761 {
8762 device_param->skipped = true;
8763 continue;
8764 }
8765
8766 if ((device_execution_capabilities & CL_EXEC_KERNEL) == 0)
8767 {
8768 event_log_error (hashcat_ctx, "* Device #%u: This device does not support executing kernels.", device_id + 1);
8769
8770 device_param->skipped = true;
8771 }
8772
8773 // device_extensions
8774
8775 size_t device_extensions_size;
8776
8777 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_EXTENSIONS, 0, NULL, &device_extensions_size) == -1)
8778 {
8779 device_param->skipped = true;
8780 continue;
8781 }
8782
8783 char *device_extensions = (char *) hcmalloc (device_extensions_size + 1);
8784
8785 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_EXTENSIONS, device_extensions_size, device_extensions, NULL) == -1)
8786 {
8787 device_param->skipped = true;
8788 hcfree (device_extensions);
8789 continue;
8790 }
8791
8792 if (strstr (device_extensions, "base_atomics") == 0)
8793 {
8794 event_log_error (hashcat_ctx, "* Device #%u: This device does not support base atomics.", device_id + 1);
8795
8796 device_param->skipped = true;
8797 }
8798
8799 if (strstr (device_extensions, "byte_addressable_store") == 0)
8800 {
8801 event_log_error (hashcat_ctx, "* Device #%u: This device does not support byte-addressable store.", device_id + 1);
8802
8803 device_param->skipped = true;
8804 }
8805
8806 hcfree (device_extensions);
8807
8808 // kernel_preferred_wgs_multiple
8809
8810 // There is global query for this attribute on OpenCL that is not linked to a specific kernel, so we set it to a fixed value
8811 // Later in the code, we add vendor specific extensions to query it
8812
8813 device_param->kernel_preferred_wgs_multiple = 8;
8814
8815 // device_local_mem_type
8816
8817 cl_device_local_mem_type device_local_mem_type;
8818
8819 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_LOCAL_MEM_TYPE, sizeof (device_local_mem_type), &device_local_mem_type, NULL) == -1)
8820 {
8821 device_param->skipped = true;
8822 continue;
8823 }
8824
8825 device_param->device_local_mem_type = device_local_mem_type;
8826
8827 // device_max_constant_buffer_size
8828
8829 cl_ulong device_max_constant_buffer_size;
8830
8831 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, sizeof (device_max_constant_buffer_size), &device_max_constant_buffer_size, NULL) == -1)
8832 {
8833 device_param->skipped = true;
8834 continue;
8835 }
8836
8837 if (device_local_mem_type == CL_LOCAL)
8838 {
8839 if (device_max_constant_buffer_size < 65536)
8840 {
8841 event_log_error (hashcat_ctx, "* Device #%u: This device's constant buffer size is too small.", device_id + 1);
8842
8843 device_param->skipped = true;
8844 }
8845 }
8846
8847 // device_local_mem_size
8848
8849 cl_ulong device_local_mem_size = 0;
8850
8851 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_LOCAL_MEM_SIZE, sizeof (device_local_mem_size), &device_local_mem_size, NULL) == -1)
8852 {
8853 device_param->skipped = true;
8854 continue;
8855 }
8856
8857 if (device_local_mem_type == CL_LOCAL)
8858 {
8859 if (device_local_mem_size < 32768)
8860 {
8861 event_log_error (hashcat_ctx, "* Device #%u: This device's local mem size is too small.", device_id + 1);
8862
8863 device_param->skipped = true;
8864 }
8865 }
8866
8867 // workaround inc!
8868 // allocating all reported local memory causes jit to fail with: SC failed. No reason given.
8869 // if we limit ourself to 32k it seems to work
8870
8871 if (device_param->opencl_device_type & CL_DEVICE_TYPE_GPU)
8872 {
8873 if (device_param->opencl_platform_vendor_id == VENDOR_ID_APPLE)
8874 {
8875 if (device_param->opencl_device_vendor_id == VENDOR_ID_AMD)
8876 {
8877 device_local_mem_size = MIN (device_local_mem_size, 32768);
8878 }
8879 }
8880 }
8881
8882 device_param->device_local_mem_size = device_local_mem_size;
8883
8884 // older POCL version and older LLVM versions are known to fail compiling kernels
8885 // we need to inform the user to update
8886 // https://github.com/hashcat/hashcat/issues/2344
8887
8888 if (opencl_platform_vendor_id == VENDOR_ID_POCL)
8889 {
8890 char *pocl_version_ptr = strstr (opencl_platform_version, "pocl ");
8891 char *llvm_version_ptr = strstr (opencl_platform_version, "LLVM ");
8892
8893 if ((pocl_version_ptr != NULL) && (llvm_version_ptr != NULL))
8894 {
8895 bool pocl_skip = false;
8896
8897 int pocl_maj = 0;
8898 int pocl_min = 0;
8899
8900 const int res1 = sscanf (pocl_version_ptr, "pocl %d.%d", &pocl_maj, &pocl_min);
8901
8902 if (res1 == 2)
8903 {
8904 const int pocl_version = (pocl_maj * 100) + pocl_min;
8905
8906 if (pocl_version < 105)
8907 {
8908 pocl_skip = true;
8909 }
8910 }
8911
8912 int llvm_maj = 0;
8913 int llvm_min = 0;
8914
8915 const int res2 = sscanf (llvm_version_ptr, "LLVM %d.%d", &llvm_maj, &llvm_min);
8916
8917 if (res2 == 2)
8918 {
8919 const int llvm_version = (llvm_maj * 100) + llvm_min;
8920
8921 if (llvm_version < 900)
8922 {
8923 pocl_skip = true;
8924 }
8925 }
8926
8927 if (pocl_skip == true)
8928 {
8929 if (user_options->force == false)
8930 {
8931 event_log_error (hashcat_ctx, "* Device #%u: Outdated POCL OpenCL driver detected!", device_id + 1);
8932
8933 if (user_options->quiet == false) event_log_warning (hashcat_ctx, "This OpenCL driver may fail kernel compilation or produce false negatives.");
8934 if (user_options->quiet == false) event_log_warning (hashcat_ctx, "You can use --force to override, but do not report related errors.");
8935 if (user_options->quiet == false) event_log_warning (hashcat_ctx, NULL);
8936
8937 device_param->skipped = true;
8938 }
8939 }
8940 }
8941 }
8942
8943 char *opencl_device_version_lower = hcstrdup (opencl_device_version);
8944
8945 lowercase ((u8 *) opencl_device_version_lower, strlen (opencl_device_version_lower));
8946
8947 if ((strstr (opencl_device_version_lower, "beignet "))
8948 || (strstr (opencl_device_version_lower, " beignet"))
8949 || (strstr (opencl_device_version_lower, "mesa "))
8950 || (strstr (opencl_device_version_lower, " mesa")))
8951 {
8952 // BEIGNET: https://github.com/hashcat/hashcat/issues/2243
8953 // MESA: https://github.com/hashcat/hashcat/issues/2269
8954
8955 if (user_options->force == false)
8956 {
8957 event_log_error (hashcat_ctx, "* Device #%u: Unstable OpenCL driver detected!", device_id + 1);
8958
8959 if (user_options->quiet == false) event_log_warning (hashcat_ctx, "This OpenCL driver may fail kernel compilation or produce false negatives.");
8960 if (user_options->quiet == false) event_log_warning (hashcat_ctx, "You can use --force to override, but do not report related errors.");
8961 if (user_options->quiet == false) event_log_warning (hashcat_ctx, NULL);
8962
8963 device_param->skipped = true;
8964 }
8965 }
8966
8967 hcfree (opencl_device_version_lower);
8968
8969 // Since some times we get reports from users about not working hashcat, dropping error messages like:
8970 // CL_INVALID_COMMAND_QUEUE and CL_OUT_OF_RESOURCES
8971 // Turns out that this is caused by Intel OpenCL runtime handling their GPU devices
8972 // Disable such devices unless the user forces to use it
8973 // This is successfully workaround with new threading model and new memory management
8974 // Tested on Windows 10
8975 // OpenCL.Version.: OpenCL C 2.1
8976 // Driver.Version.: 23.20.16.4973
8977
8978 /*
8979 #if !defined (__APPLE__)
8980 if (opencl_device_type & CL_DEVICE_TYPE_GPU)
8981 {
8982 if ((device_param->opencl_device_vendor_id == VENDOR_ID_INTEL_SDK) || (device_param->opencl_device_vendor_id == VENDOR_ID_INTEL_BEIGNET))
8983 {
8984 if (user_options->force == false)
8985 {
8986 if (user_options->quiet == false) event_log_warning (hashcat_ctx, "* Device #%u: Intel's OpenCL runtime (GPU only) is currently broken.", device_id + 1);
8987 if (user_options->quiet == false) event_log_warning (hashcat_ctx, " We are waiting for updated OpenCL drivers from Intel.");
8988 if (user_options->quiet == false) event_log_warning (hashcat_ctx, " You can use --force to override, but do not report related errors.");
8989 if (user_options->quiet == false) event_log_warning (hashcat_ctx, NULL);
8990
8991 device_param->skipped = true;
8992 }
8993 }
8994 }
8995 #endif // __APPLE__
8996 */
8997
8998 // skipped
8999
9000 if ((backend_ctx->backend_devices_filter & (1ULL << device_id)) == 0)
9001 {
9002 device_param->skipped = true;
9003 }
9004
9005 if ((backend_ctx->opencl_device_types_filter & (opencl_device_type)) == 0)
9006 {
9007 device_param->skipped = true;
9008 }
9009
9010 #if defined (__APPLE__)
9011 if (opencl_device_type & CL_DEVICE_TYPE_GPU)
9012 {
9013 //if (user_options->force == false)
9014 if (device_param->skipped == false)
9015 {
9016 if (user_options->quiet == false) event_log_warning (hashcat_ctx, "* Device #%u: Apple's OpenCL drivers (GPU) are known to be unreliable.", device_id + 1);
9017 if (user_options->quiet == false) event_log_warning (hashcat_ctx, " You have been warned.");
9018 //if (user_options->quiet == false) event_log_warning (hashcat_ctx, " There are many reports of false negatives and other issues.");
9019 //if (user_options->quiet == false) event_log_warning (hashcat_ctx, " This is not a hashcat issue. Other projects report issues with these drivers.");
9020 //if (user_options->quiet == false) event_log_warning (hashcat_ctx, " You can use --force to override, but do not report related errors. You have been warned.");
9021 if (user_options->quiet == false) event_log_warning (hashcat_ctx, NULL);
9022
9023 //device_param->skipped = true;
9024 }
9025 }
9026 #endif // __APPLE__
9027
9028 // driver_version
9029
9030 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DRIVER_VERSION, 0, NULL, ¶m_value_size) == -1)
9031 {
9032 device_param->skipped = true;
9033 continue;
9034 }
9035
9036 char *opencl_driver_version = (char *) hcmalloc (param_value_size);
9037
9038 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DRIVER_VERSION, param_value_size, opencl_driver_version, NULL) == -1)
9039 {
9040 device_param->skipped = true;
9041 hcfree (opencl_driver_version);
9042 continue;
9043 }
9044
9045 device_param->opencl_driver_version = opencl_driver_version;
9046
9047 // vendor specific
9048
9049 if (device_param->opencl_device_type & CL_DEVICE_TYPE_CPU)
9050 {
9051 #if defined (__APPLE__)
9052 if (device_param->opencl_platform_vendor_id == VENDOR_ID_APPLE)
9053 {
9054 if (device_param->skipped == false)
9055 {
9056 need_iokit = true;
9057 }
9058 }
9059 #endif
9060
9061 #if defined (__linux__)
9062 need_sysfs_cpu = true;
9063 #endif
9064 }
9065
9066 if (device_param->opencl_device_type & CL_DEVICE_TYPE_GPU)
9067 {
9068 if ((device_param->opencl_platform_vendor_id == VENDOR_ID_AMD) && (device_param->opencl_device_vendor_id == VENDOR_ID_AMD))
9069 {
9070 need_adl = true;
9071
9072 #if defined (__linux__)
9073 need_sysfs_amdgpu = true;
9074 #endif
9075 }
9076
9077 if ((device_param->opencl_platform_vendor_id == VENDOR_ID_NV) && (device_param->opencl_device_vendor_id == VENDOR_ID_NV))
9078 {
9079 need_nvml = true;
9080
9081 #if defined (_WIN) || defined (__CYGWIN__)
9082 need_nvapi = true;
9083 #endif
9084 }
9085 }
9086
9087 if (device_param->opencl_device_type & CL_DEVICE_TYPE_CPU)
9088 {
9089 // they like this
9090
9091 device_param->kernel_preferred_wgs_multiple = 1;
9092 }
9093
9094 if (device_param->opencl_device_type & CL_DEVICE_TYPE_GPU)
9095 {
9096 if ((device_param->opencl_platform_vendor_id == VENDOR_ID_APPLE) && (device_param->opencl_device_vendor_id == VENDOR_ID_AMD))
9097 {
9098 // from https://www.khronos.org/registry/OpenCL/extensions/amd/cl_amd_device_attribute_query.txt
9099 #define CL_DEVICE_WAVEFRONT_WIDTH_AMD 0x4043
9100
9101 // crazy, but apple does not support this query!
9102 // the best alternative is "Preferred work group size multiple (kernel)", but requires to specify a kernel.
9103 // so we will set kernel_preferred_wgs_multiple intentionally to 0 because otherwise it it set to 8 by default.
9104 // we then assign the value kernel_preferred_wgs_multiple a small kernel like bzero after test if this was set to 0.
9105
9106 device_param->kernel_preferred_wgs_multiple = 0;
9107 }
9108
9109 if ((device_param->opencl_platform_vendor_id == VENDOR_ID_AMD) && (device_param->opencl_device_vendor_id == VENDOR_ID_AMD))
9110 {
9111 cl_uint device_wavefront_width_amd;
9112
9113 // from https://www.khronos.org/registry/OpenCL/extensions/amd/cl_amd_device_attribute_query.txt
9114 #define CL_DEVICE_WAVEFRONT_WIDTH_AMD 0x4043
9115
9116 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_WAVEFRONT_WIDTH_AMD, sizeof (device_wavefront_width_amd), &device_wavefront_width_amd, NULL) == -1)
9117 {
9118 device_param->skipped = true;
9119 continue;
9120 }
9121
9122 device_param->kernel_preferred_wgs_multiple = device_wavefront_width_amd;
9123
9124 cl_device_topology_amd amdtopo;
9125
9126 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_TOPOLOGY_AMD, sizeof (amdtopo), &amdtopo, NULL) == -1)
9127 {
9128 device_param->skipped = true;
9129 continue;
9130 }
9131
9132 device_param->pcie_domain = 0; // no attribute to query
9133 device_param->pcie_bus = amdtopo.pcie.bus;
9134 device_param->pcie_device = amdtopo.pcie.device;
9135 device_param->pcie_function = amdtopo.pcie.function;
9136 }
9137
9138 if ((device_param->opencl_platform_vendor_id == VENDOR_ID_NV) && (device_param->opencl_device_vendor_id == VENDOR_ID_NV))
9139 {
9140 cl_uint device_warp_size_nv;
9141
9142 // from deps/OpenCL-Headers/CL/cl_ext.h
9143 #define CL_DEVICE_WARP_SIZE_NV 0x4003
9144
9145 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_WARP_SIZE_NV, sizeof (device_warp_size_nv), &device_warp_size_nv, NULL) == -1)
9146 {
9147 device_param->skipped = true;
9148 continue;
9149 }
9150
9151 device_param->kernel_preferred_wgs_multiple = device_warp_size_nv;
9152
9153 cl_uint pci_bus_id_nv; // is cl_uint the right type for them??
9154 cl_uint pci_slot_id_nv;
9155
9156 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_PCI_BUS_ID_NV, sizeof (pci_bus_id_nv), &pci_bus_id_nv, NULL) == -1)
9157 {
9158 device_param->skipped = true;
9159 continue;
9160 }
9161
9162 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_PCI_SLOT_ID_NV, sizeof (pci_slot_id_nv), &pci_slot_id_nv, NULL) == -1)
9163 {
9164 device_param->skipped = true;
9165 continue;
9166 }
9167
9168 device_param->pcie_domain = 0; // no attribute to query
9169 device_param->pcie_bus = (u8) (pci_bus_id_nv);
9170 device_param->pcie_device = (u8) (pci_slot_id_nv >> 3);
9171 device_param->pcie_function = (u8) (pci_slot_id_nv & 7);
9172
9173 int sm_minor = 0;
9174 int sm_major = 0;
9175
9176 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, sizeof (sm_minor), &sm_minor, NULL) == -1)
9177 {
9178 device_param->skipped = true;
9179 continue;
9180 }
9181
9182 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, sizeof (sm_major), &sm_major, NULL) == -1)
9183 {
9184 device_param->skipped = true;
9185 continue;
9186 }
9187
9188 device_param->sm_minor = sm_minor;
9189 device_param->sm_major = sm_major;
9190
9191 cl_uint kernel_exec_timeout = 0;
9192
9193 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, sizeof (kernel_exec_timeout), &kernel_exec_timeout, NULL) == -1)
9194 {
9195 device_param->skipped = true;
9196 continue;
9197 }
9198
9199 device_param->kernel_exec_timeout = kernel_exec_timeout;
9200
9201 // CPU burning loop damper
9202 // Value is given as number between 0-100
9203 // By default 8%
9204
9205 device_param->spin_damp = (double) user_options->spin_damp / 100;
9206
9207 if (user_options->stdout_flag == false)
9208 {
9209 // recommend CUDA
9210
9211 if ((backend_ctx->cuda == NULL) || (backend_ctx->nvrtc == NULL))
9212 {
9213 if (user_options->backend_ignore_cuda == false)
9214 {
9215 if (backend_ctx->rc_cuda_init == -1)
9216 {
9217 event_log_warning (hashcat_ctx, "Failed to initialize NVIDIA CUDA library.");
9218 event_log_warning (hashcat_ctx, NULL);
9219 }
9220 else
9221 {
9222 event_log_warning (hashcat_ctx, "Successfully initialized NVIDIA CUDA library.");
9223 event_log_warning (hashcat_ctx, NULL);
9224 }
9225
9226 if (backend_ctx->rc_nvrtc_init == -1)
9227 {
9228 event_log_warning (hashcat_ctx, "Failed to initialize NVIDIA RTC library.");
9229 event_log_warning (hashcat_ctx, NULL);
9230 }
9231 else
9232 {
9233 event_log_warning (hashcat_ctx, "Successfully initialized NVIDIA RTC library.");
9234 event_log_warning (hashcat_ctx, NULL);
9235 }
9236
9237 event_log_warning (hashcat_ctx, "* Device #%u: CUDA SDK Toolkit not installed or incorrectly installed.", device_id + 1);
9238 event_log_warning (hashcat_ctx, " CUDA SDK Toolkit required for proper device support and utilization.");
9239 event_log_warning (hashcat_ctx, " Falling back to OpenCL runtime.");
9240
9241 event_log_warning (hashcat_ctx, NULL);
9242 }
9243 }
9244 }
9245 }
9246 }
9247
9248 // instruction set
9249
9250 // fixed values works only for nvidia devices
9251 // dynamical values for amd see time intensive section below
9252
9253 if ((device_param->opencl_device_type & CL_DEVICE_TYPE_GPU) && (device_param->opencl_platform_vendor_id == VENDOR_ID_NV))
9254 {
9255 const int sm = (device_param->sm_major * 10) + device_param->sm_minor;
9256
9257 device_param->has_add = (sm >= 12) ? true : false;
9258 device_param->has_addc = (sm >= 12) ? true : false;
9259 device_param->has_sub = (sm >= 12) ? true : false;
9260 device_param->has_subc = (sm >= 12) ? true : false;
9261 device_param->has_bfe = (sm >= 20) ? true : false;
9262 device_param->has_lop3 = (sm >= 50) ? true : false;
9263 device_param->has_mov64 = (sm >= 10) ? true : false;
9264 device_param->has_prmt = (sm >= 20) ? true : false;
9265 }
9266
9267 // common driver check
9268
9269 if (device_param->skipped == false)
9270 {
9271 if ((user_options->force == false) && (user_options->backend_info == false))
9272 {
9273 if (opencl_device_type & CL_DEVICE_TYPE_CPU)
9274 {
9275 if (device_param->opencl_platform_vendor_id == VENDOR_ID_INTEL_SDK)
9276 {
9277 bool intel_warn = false;
9278
9279 // Intel OpenCL runtime 18
9280
9281 int opencl_driver1 = 0;
9282 int opencl_driver2 = 0;
9283 int opencl_driver3 = 0;
9284 int opencl_driver4 = 0;
9285
9286 const int res18 = sscanf (device_param->opencl_driver_version, "%d.%d.%d.%d", &opencl_driver1, &opencl_driver2, &opencl_driver3, &opencl_driver4);
9287
9288 if (res18 == 4)
9289 {
9290 // so far all versions 18 are ok
9291 }
9292 else
9293 {
9294 // Intel OpenCL runtime 16
9295
9296 float opencl_version = 0;
9297 int opencl_build = 0;
9298
9299 const int res16 = sscanf (device_param->opencl_device_version, "OpenCL %f (Build %d)", &opencl_version, &opencl_build);
9300
9301 if (res16 == 2)
9302 {
9303 if (opencl_build < 25) intel_warn = true;
9304 }
9305 }
9306
9307 if (intel_warn == true)
9308 {
9309 event_log_error (hashcat_ctx, "* Device #%u: Outdated or broken Intel OpenCL runtime '%s' detected!", device_id + 1, device_param->opencl_driver_version);
9310
9311 event_log_warning (hashcat_ctx, "You are STRONGLY encouraged to use the officially supported runtime.");
9312 event_log_warning (hashcat_ctx, "See hashcat.net for the officially supported Intel OpenCL runtime.");
9313 event_log_warning (hashcat_ctx, "See also: https://hashcat.net/faq/wrongdriver");
9314 event_log_warning (hashcat_ctx, "You can use --force to override this, but do not report related errors.");
9315 event_log_warning (hashcat_ctx, NULL);
9316
9317 device_param->skipped = true;
9318 continue;
9319 }
9320 }
9321 }
9322 else if (opencl_device_type & CL_DEVICE_TYPE_GPU)
9323 {
9324 if (device_param->opencl_platform_vendor_id == VENDOR_ID_AMD)
9325 {
9326 bool amd_warn = true;
9327
9328 #if defined (__linux__)
9329 // AMDGPU-PRO Driver 16.40 and higher
9330 if (strtoul (device_param->opencl_driver_version, NULL, 10) >= 2117) amd_warn = false;
9331 // AMDGPU-PRO Driver 16.50 is known to be broken
9332 if (strtoul (device_param->opencl_driver_version, NULL, 10) == 2236) amd_warn = true;
9333 // AMDGPU-PRO Driver 16.60 is known to be broken
9334 if (strtoul (device_param->opencl_driver_version, NULL, 10) == 2264) amd_warn = true;
9335 // AMDGPU-PRO Driver 17.10 is known to be broken
9336 if (strtoul (device_param->opencl_driver_version, NULL, 10) == 2348) amd_warn = true;
9337 // AMDGPU-PRO Driver 17.20 (2416) is fine, doesn't need check will match >= 2117
9338 #elif defined (_WIN)
9339 // AMD Radeon Software 14.9 and higher, should be updated to 15.12
9340 if (strtoul (device_param->opencl_driver_version, NULL, 10) >= 1573) amd_warn = false;
9341 #else
9342 // we have no information about other os
9343 if (amd_warn == true) amd_warn = false;
9344 #endif
9345
9346 if (amd_warn == true)
9347 {
9348 event_log_error (hashcat_ctx, "* Device #%u: Outdated or broken AMD driver '%s' detected!", device_id + 1, device_param->opencl_driver_version);
9349
9350 event_log_warning (hashcat_ctx, "You are STRONGLY encouraged to use the officially supported driver.");
9351 event_log_warning (hashcat_ctx, "See hashcat.net for officially supported AMD drivers.");
9352 event_log_warning (hashcat_ctx, "See also: https://hashcat.net/faq/wrongdriver");
9353 event_log_warning (hashcat_ctx, "You can use --force to override this, but do not report related errors.");
9354 event_log_warning (hashcat_ctx, NULL);
9355
9356 device_param->skipped = true;
9357 continue;
9358 }
9359 }
9360
9361 if (device_param->opencl_platform_vendor_id == VENDOR_ID_NV)
9362 {
9363 int nv_warn = true;
9364
9365 int version_maj = 0;
9366 int version_min = 0;
9367
9368 const int r = sscanf (device_param->opencl_driver_version, "%d.%d", &version_maj, &version_min);
9369
9370 if (r == 2)
9371 {
9372 // nvidia 441.x looks ok
9373
9374 if (version_maj == 440)
9375 {
9376 if (version_min >= 64)
9377 {
9378 nv_warn = false;
9379 }
9380 }
9381 else
9382 {
9383 // unknown version scheme, probably new driver version
9384
9385 nv_warn = false;
9386 }
9387 }
9388 else
9389 {
9390 // unknown version scheme, probably new driver version
9391
9392 nv_warn = false;
9393 }
9394
9395 if (nv_warn == true)
9396 {
9397 event_log_warning (hashcat_ctx, "* Device #%u: Outdated or broken NVIDIA driver '%s' detected!", device_id + 1, device_param->opencl_driver_version);
9398 event_log_warning (hashcat_ctx, NULL);
9399
9400 event_log_warning (hashcat_ctx, "You are STRONGLY encouraged to use the officially supported driver.");
9401 event_log_warning (hashcat_ctx, "See hashcat's homepage for officially supported NVIDIA drivers.");
9402 event_log_warning (hashcat_ctx, "See also: https://hashcat.net/faq/wrongdriver");
9403 event_log_warning (hashcat_ctx, "You can use --force to override this, but do not report related errors.");
9404 event_log_warning (hashcat_ctx, NULL);
9405
9406 device_param->skipped = true;
9407 continue;
9408 }
9409
9410 if (device_param->sm_major < 5)
9411 {
9412 if (user_options->quiet == false) event_log_warning (hashcat_ctx, "* Device #%u: This hardware has outdated CUDA compute capability (%u.%u).", device_id + 1, device_param->sm_major, device_param->sm_minor);
9413 if (user_options->quiet == false) event_log_warning (hashcat_ctx, " For modern OpenCL performance, upgrade to hardware that supports");
9414 if (user_options->quiet == false) event_log_warning (hashcat_ctx, " CUDA compute capability version 5.0 (Maxwell) or higher.");
9415 }
9416
9417 if (device_param->kernel_exec_timeout != 0)
9418 {
9419 if (user_options->quiet == false) event_log_warning (hashcat_ctx, "* Device #%u: WARNING! Kernel exec timeout is not disabled.", device_id + 1);
9420 if (user_options->quiet == false) event_log_warning (hashcat_ctx, " This may cause \"CL_OUT_OF_RESOURCES\" or related errors.");
9421 if (user_options->quiet == false) event_log_warning (hashcat_ctx, " To disable the timeout, see: https://hashcat.net/q/timeoutpatch");
9422 }
9423 }
9424 }
9425 }
9426
9427 /**
9428 * activate device
9429 */
9430
9431 opencl_devices_active++;
9432 }
9433 }
9434 }
9435 }
9436
9437 backend_ctx->opencl_devices_cnt = opencl_devices_cnt;
9438 backend_ctx->opencl_devices_active = opencl_devices_active;
9439
9440 // all devices combined go into backend_* variables
9441
9442 backend_ctx->backend_devices_cnt = cuda_devices_cnt + hip_devices_cnt + opencl_devices_cnt;
9443 backend_ctx->backend_devices_active = cuda_devices_active + hip_devices_active + opencl_devices_active;
9444
9445 // find duplicate devices
9446
9447 //if ((cuda_devices_cnt > 0) && (hip_devices_cnt > 0) && (opencl_devices_cnt > 0))
9448 //{
9449 // using force here enables both devices, which is the worst possible outcome
9450 // many users force by default, so this is not a good idea
9451
9452 //if (user_options->force == false)
9453 //{
9454 backend_ctx_find_alias_devices (hashcat_ctx);
9455 //{
9456 //}
9457
9458 if (backend_ctx->backend_devices_active == 0)
9459 {
9460 event_log_error (hashcat_ctx, "No devices found/left.");
9461
9462 return -1;
9463 }
9464
9465 // now we can calculate the number of parallel running hook threads based on
9466 // the number cpu cores and the number of active compute devices
9467 // unless overwritten by the user
9468
9469 if (user_options->hook_threads == HOOK_THREADS)
9470 {
9471 const u32 processor_count = hc_get_processor_count ();
9472
9473 const u32 processor_count_cu = CEILDIV (processor_count, backend_ctx->backend_devices_active); // should never reach 0
9474
9475 user_options->hook_threads = processor_count_cu;
9476 }
9477
9478 // additional check to see if the user has chosen a device that is not within the range of available devices (i.e. larger than devices_cnt)
9479
9480 if (backend_ctx->backend_devices_filter != (u64) -1)
9481 {
9482 const u64 backend_devices_cnt_mask = ~(((u64) -1 >> backend_ctx->backend_devices_cnt) << backend_ctx->backend_devices_cnt);
9483
9484 if (backend_ctx->backend_devices_filter > backend_devices_cnt_mask)
9485 {
9486 event_log_error (hashcat_ctx, "An invalid device was specified using the --backend-devices parameter.");
9487 event_log_error (hashcat_ctx, "The specified device was higher than the number of available devices (%u).", backend_ctx->backend_devices_cnt);
9488
9489 return -1;
9490 }
9491 }
9492
9493 // time or resource intensive operations which we do not run if the corresponding device was skipped by the user
9494
9495 if (backend_ctx->cuda)
9496 {
9497 // instruction test for cuda devices was replaced with fixed values (see above)
9498
9499 /*
9500 CUcontext cuda_context;
9501
9502 if (hc_cuCtxCreate (hashcat_ctx, &cuda_context, CU_CTX_SCHED_BLOCKING_SYNC, device_param->cuda_device) == -1) return -1;
9503
9504 if (hc_cuCtxSetCurrent (hashcat_ctx, cuda_context) == -1) return -1;
9505
9506 #define RUN_INSTRUCTION_CHECKS() \
9507 device_param->has_add = cuda_test_instruction (hashcat_ctx, sm_major, sm_minor, "__global__ void test () { unsigned int r; asm volatile (\"add.cc.u32 %0, 0, 0;\" : \"=r\"(r)); }"); \
9508 device_param->has_addc = cuda_test_instruction (hashcat_ctx, sm_major, sm_minor, "__global__ void test () { unsigned int r; asm volatile (\"addc.cc.u32 %0, 0, 0;\" : \"=r\"(r)); }"); \
9509 device_param->has_sub = cuda_test_instruction (hashcat_ctx, sm_major, sm_minor, "__global__ void test () { unsigned int r; asm volatile (\"sub.cc.u32 %0, 0, 0;\" : \"=r\"(r)); }"); \
9510 device_param->has_subc = cuda_test_instruction (hashcat_ctx, sm_major, sm_minor, "__global__ void test () { unsigned int r; asm volatile (\"subc.cc.u32 %0, 0, 0;\" : \"=r\"(r)); }"); \
9511 device_param->has_bfe = cuda_test_instruction (hashcat_ctx, sm_major, sm_minor, "__global__ void test () { unsigned int r; asm volatile (\"bfe.u32 %0, 0, 0, 0;\" : \"=r\"(r)); }"); \
9512 device_param->has_lop3 = cuda_test_instruction (hashcat_ctx, sm_major, sm_minor, "__global__ void test () { unsigned int r; asm volatile (\"lop3.b32 %0, 0, 0, 0, 0;\" : \"=r\"(r)); }"); \
9513 device_param->has_mov64 = cuda_test_instruction (hashcat_ctx, sm_major, sm_minor, "__global__ void test () { unsigned long long r; unsigned int a; unsigned int b; asm volatile (\"mov.b64 %0, {%1, %2};\" : \"=l\"(r) : \"r\"(a), \"r\"(b)); }"); \
9514 device_param->has_prmt = cuda_test_instruction (hashcat_ctx, sm_major, sm_minor, "__global__ void test () { unsigned int r; asm volatile (\"prmt.b32 %0, 0, 0, 0;\" : \"=r\"(r)); }"); \
9515
9516 if (backend_devices_idx > 0)
9517 {
9518 hc_device_param_t *device_param_prev = &devices_param[backend_devices_idx - 1];
9519
9520 if (is_same_device_type (device_param, device_param_prev) == true)
9521 {
9522 device_param->has_add = device_param_prev->has_add;
9523 device_param->has_addc = device_param_prev->has_addc;
9524 device_param->has_sub = device_param_prev->has_sub;
9525 device_param->has_subc = device_param_prev->has_subc;
9526 device_param->has_bfe = device_param_prev->has_bfe;
9527 device_param->has_lop3 = device_param_prev->has_lop3;
9528 device_param->has_mov64 = device_param_prev->has_mov64;
9529 device_param->has_prmt = device_param_prev->has_prmt;
9530 }
9531 else
9532 {
9533 RUN_INSTRUCTION_CHECKS();
9534 }
9535 }
9536 else
9537 {
9538 RUN_INSTRUCTION_CHECKS();
9539 }
9540
9541 #undef RUN_INSTRUCTION_CHECKS
9542
9543 if (hc_cuCtxDestroy (hashcat_ctx, cuda_context) == -1) return -1;
9544
9545 */
9546 }
9547
9548 if (backend_ctx->hip)
9549 {
9550 // TODO HIP?
9551 // Maybe all devices supported by hip have these instructions guaranteed?
9552
9553 for (int backend_devices_cnt = 0; backend_devices_cnt < backend_ctx->backend_devices_cnt; backend_devices_cnt++)
9554 {
9555 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_cnt];
9556
9557 if (device_param->is_hip == false) continue;
9558
9559 device_param->has_vadd = true;
9560 device_param->has_vaddc = true;
9561 device_param->has_vadd_co = true;
9562 device_param->has_vaddc_co = true;
9563 device_param->has_vsub = true;
9564 device_param->has_vsubb = true;
9565 device_param->has_vsub_co = true;
9566 device_param->has_vsubb_co = true;
9567 device_param->has_vadd3 = true;
9568 device_param->has_vbfe = true;
9569 device_param->has_vperm = true;
9570 }
9571 }
9572
9573 if (backend_ctx->ocl)
9574 {
9575 for (int backend_devices_cnt = 0; backend_devices_cnt < backend_ctx->backend_devices_cnt; backend_devices_cnt++)
9576 {
9577 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_cnt];
9578
9579 if (device_param->is_opencl == false) continue;
9580
9581 if (user_options->backend_info == false)
9582 {
9583 // do not ignore in case -I because user expects a value also for skipped devices
9584
9585 if (device_param->skipped == true) continue;
9586 }
9587
9588 /**
9589 * create context for each device
9590 */
9591
9592 cl_context context;
9593
9594 /*
9595 cl_context_properties properties[3];
9596
9597 properties[0] = CL_CONTEXT_PLATFORM;
9598 properties[1] = (cl_context_properties) device_param->opencl_platform;
9599 properties[2] = 0;
9600
9601 CL_rc = hc_clCreateContext (hashcat_ctx, properties, 1, &device_param->opencl_device, NULL, NULL, &context);
9602 */
9603
9604 if (hc_clCreateContext (hashcat_ctx, NULL, 1, &device_param->opencl_device, NULL, NULL, &context) == -1)
9605 {
9606 device_param->skipped = true;
9607 continue;
9608 }
9609
9610 /**
9611 * create command-queue
9612 */
9613
9614 cl_command_queue command_queue;
9615
9616 if (hc_clCreateCommandQueue (hashcat_ctx, context, device_param->opencl_device, 0, &command_queue) == -1)
9617 {
9618 device_param->skipped = true;
9619 continue;
9620 }
9621
9622 // instruction set
9623
9624 if ((device_param->opencl_device_type & CL_DEVICE_TYPE_GPU) && (device_param->opencl_platform_vendor_id == VENDOR_ID_AMD))
9625 {
9626 #define RUN_INSTRUCTION_CHECKS()
9627 device_param->has_vadd = opencl_test_instruction (hashcat_ctx, context, device_param->opencl_device, "__kernel void test () { uint r1; __asm__ __volatile__ (\"V_ADD_U32 %0, vcc, 0, 0;\" : \"=v\"(r1)); }"); \
9628 device_param->has_vaddc = opencl_test_instruction (hashcat_ctx, context, device_param->opencl_device, "__kernel void test () { uint r1; __asm__ __volatile__ (\"V_ADDC_U32 %0, vcc, 0, 0, vcc;\" : \"=v\"(r1)); }"); \
9629 device_param->has_vadd_co = opencl_test_instruction (hashcat_ctx, context, device_param->opencl_device, "__kernel void test () { uint r1; __asm__ __volatile__ (\"V_ADD_CO_U32 %0, vcc, 0, 0;\" : \"=v\"(r1)); }"); \
9630 device_param->has_vaddc_co = opencl_test_instruction (hashcat_ctx, context, device_param->opencl_device, "__kernel void test () { uint r1; __asm__ __volatile__ (\"V_ADDC_CO_U32 %0, vcc, 0, 0, vcc;\" : \"=v\"(r1)); }"); \
9631 device_param->has_vsub = opencl_test_instruction (hashcat_ctx, context, device_param->opencl_device, "__kernel void test () { uint r1; __asm__ __volatile__ (\"V_SUB_U32 %0, vcc, 0, 0;\" : \"=v\"(r1)); }"); \
9632 device_param->has_vsubb = opencl_test_instruction (hashcat_ctx, context, device_param->opencl_device, "__kernel void test () { uint r1; __asm__ __volatile__ (\"V_SUBB_U32 %0, vcc, 0, 0, vcc;\" : \"=v\"(r1)); }"); \
9633 device_param->has_vsub_co = opencl_test_instruction (hashcat_ctx, context, device_param->opencl_device, "__kernel void test () { uint r1; __asm__ __volatile__ (\"V_SUB_CO_U32 %0, vcc, 0, 0;\" : \"=v\"(r1)); }"); \
9634 device_param->has_vsubb_co = opencl_test_instruction (hashcat_ctx, context, device_param->opencl_device, "__kernel void test () { uint r1; __asm__ __volatile__ (\"V_SUBB_CO_U32 %0, vcc, 0, 0, vcc;\" : \"=v\"(r1)); }"); \
9635 device_param->has_vadd3 = opencl_test_instruction (hashcat_ctx, context, device_param->opencl_device, "__kernel void test () { uint r1; __asm__ __volatile__ (\"V_ADD3_U32 %0, 0, 0, 0;\" : \"=v\"(r1)); }"); \
9636 device_param->has_vbfe = opencl_test_instruction (hashcat_ctx, context, device_param->opencl_device, "__kernel void test () { uint r1; __asm__ __volatile__ (\"V_BFE_U32 %0, 0, 0, 0;\" : \"=v\"(r1)); }"); \
9637 device_param->has_vperm = opencl_test_instruction (hashcat_ctx, context, device_param->opencl_device, "__kernel void test () { uint r1; __asm__ __volatile__ (\"V_PERM_B32 %0, 0, 0, 0;\" : \"=v\"(r1)); }"); \
9638
9639 if (backend_devices_idx > 0)
9640 {
9641 hc_device_param_t *device_param_prev = &devices_param[backend_devices_idx - 1];
9642
9643 if (is_same_device_type (device_param, device_param_prev) == true)
9644 {
9645 device_param->has_vadd = device_param_prev->has_vadd;
9646 device_param->has_vaddc = device_param_prev->has_vaddc;
9647 device_param->has_vadd_co = device_param_prev->has_vadd_co;
9648 device_param->has_vaddc_co = device_param_prev->has_vaddc_co;
9649 device_param->has_vsub = device_param_prev->has_vsub;
9650 device_param->has_vsubb = device_param_prev->has_vsubb;
9651 device_param->has_vsub_co = device_param_prev->has_vsub_co;
9652 device_param->has_vsubb_co = device_param_prev->has_vsubb_co;
9653 device_param->has_vadd3 = device_param_prev->has_vadd3;
9654 device_param->has_vbfe = device_param_prev->has_vbfe;
9655 device_param->has_vperm = device_param_prev->has_vperm;
9656 }
9657 else
9658 {
9659 RUN_INSTRUCTION_CHECKS();
9660 }
9661 }
9662 else
9663 {
9664 RUN_INSTRUCTION_CHECKS();
9665 }
9666
9667 #undef RUN_INSTRUCTION_CHECKS
9668 }
9669
9670 if ((device_param->opencl_device_type & CL_DEVICE_TYPE_GPU) && (device_param->opencl_platform_vendor_id == VENDOR_ID_NV))
9671 {
9672 // replaced with fixed values see non time intensive section above
9673
9674 /*
9675 #define RUN_INSTRUCTION_CHECKS() \
9676 device_param->has_add = opencl_test_instruction (hashcat_ctx, context, device_param->opencl_device, "__kernel void test () { uint r; asm volatile (\"add.cc.u32 %0, 0, 0;\" : \"=r\"(r)); }"); \
9677 device_param->has_addc = opencl_test_instruction (hashcat_ctx, context, device_param->opencl_device, "__kernel void test () { uint r; asm volatile (\"addc.cc.u32 %0, 0, 0;\" : \"=r\"(r)); }"); \
9678 device_param->has_sub = opencl_test_instruction (hashcat_ctx, context, device_param->opencl_device, "__kernel void test () { uint r; asm volatile (\"sub.cc.u32 %0, 0, 0;\" : \"=r\"(r)); }"); \
9679 device_param->has_subc = opencl_test_instruction (hashcat_ctx, context, device_param->opencl_device, "__kernel void test () { uint r; asm volatile (\"subc.cc.u32 %0, 0, 0;\" : \"=r\"(r)); }"); \
9680 device_param->has_bfe = opencl_test_instruction (hashcat_ctx, context, device_param->opencl_device, "__kernel void test () { uint r; asm volatile (\"bfe.u32 %0, 0, 0, 0;\" : \"=r\"(r)); }"); \
9681 device_param->has_lop3 = opencl_test_instruction (hashcat_ctx, context, device_param->opencl_device, "__kernel void test () { uint r; asm volatile (\"lop3.b32 %0, 0, 0, 0, 0;\" : \"=r\"(r)); }"); \
9682 device_param->has_mov64 = opencl_test_instruction (hashcat_ctx, context, device_param->opencl_device, "__kernel void test () { ulong r; uint a; uint b; asm volatile (\"mov.b64 %0, {%1, %2};\" : \"=l\"(r) : \"r\"(a), \"r\"(b)); }"); \
9683 device_param->has_prmt = opencl_test_instruction (hashcat_ctx, context, device_param->opencl_device, "__kernel void test () { uint r; asm volatile (\"prmt.b32 %0, 0, 0, 0;\" : \"=r\"(r)); }"); \
9684
9685 if (backend_devices_idx > 0)
9686 {
9687 hc_device_param_t *device_param_prev = &devices_param[backend_devices_idx - 1];
9688
9689 if (is_same_device_type (device_param, device_param_prev) == true)
9690 {
9691 device_param->has_add = device_param_prev->has_add;
9692 device_param->has_addc = device_param_prev->has_addc;
9693 device_param->has_sub = device_param_prev->has_sub;
9694 device_param->has_subc = device_param_prev->has_subc;
9695 device_param->has_bfe = device_param_prev->has_bfe;
9696 device_param->has_lop3 = device_param_prev->has_lop3;
9697 device_param->has_mov64 = device_param_prev->has_mov64;
9698 device_param->has_prmt = device_param_prev->has_prmt;
9699 }
9700 else
9701 {
9702 RUN_INSTRUCTION_CHECKS();
9703 }
9704 }
9705 else
9706 {
9707 RUN_INSTRUCTION_CHECKS();
9708 }
9709
9710 #undef RUN_INSTRUCTION_CHECKS
9711 */
9712 }
9713
9714 // available device memory
9715 // This test causes an GPU memory usage spike.
9716 // In case there are multiple hashcat instances starting at the same time this will cause GPU out of memory errors which otherwise would not exist.
9717 // We will simply not run it if that device was skipped by the user.
9718
9719 #define MAX_ALLOC_CHECKS_CNT 8192
9720 #define MAX_ALLOC_CHECKS_SIZE (64 * 1024 * 1024)
9721
9722 device_param->device_available_mem = device_param->device_global_mem - MAX_ALLOC_CHECKS_SIZE;
9723
9724 if (device_param->opencl_device_type & CL_DEVICE_TYPE_GPU)
9725 {
9726 // OK, so the problem here is the following:
9727 // There's just CL_DEVICE_GLOBAL_MEM_SIZE to ask OpenCL about the total memory on the device,
9728 // but there's no way to ask for available memory on the device.
9729 // In combination, most OpenCL runtimes implementation of clCreateBuffer()
9730 // are doing so called lazy memory allocation on the device.
9731 // Now, if the user has X11 (or a game or anything that takes a lot of GPU memory)
9732 // running on the host we end up with an error type of this:
9733 // clEnqueueNDRangeKernel(): CL_MEM_OBJECT_ALLOCATION_FAILURE
9734 // The clEnqueueNDRangeKernel() is because of the lazy allocation
9735 // The best way to workaround this problem is if we would be able to ask for available memory,
9736 // The idea here is to try to evaluate available memory by allocating it till it errors
9737
9738 cl_mem *tmp_device = (cl_mem *) hccalloc (MAX_ALLOC_CHECKS_CNT, sizeof (cl_mem));
9739
9740 u64 c;
9741
9742 for (c = 0; c < MAX_ALLOC_CHECKS_CNT; c++)
9743 {
9744 if (((c + 1 + 1) * MAX_ALLOC_CHECKS_SIZE) >= device_param->device_global_mem) break;
9745
9746 cl_int CL_err;
9747
9748 OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl;
9749
9750 tmp_device[c] = ocl->clCreateBuffer (context, CL_MEM_READ_WRITE, MAX_ALLOC_CHECKS_SIZE, NULL, &CL_err);
9751
9752 if (CL_err != CL_SUCCESS)
9753 {
9754 c--;
9755
9756 break;
9757 }
9758
9759 // transfer only a few byte should be enough to force the runtime to actually allocate the memory
9760
9761 u8 tmp_host[8];
9762
9763 if (ocl->clEnqueueReadBuffer (command_queue, tmp_device[c], CL_TRUE, 0, sizeof (tmp_host), tmp_host, 0, NULL, NULL) != CL_SUCCESS) break;
9764
9765 if (ocl->clEnqueueWriteBuffer (command_queue, tmp_device[c], CL_TRUE, 0, sizeof (tmp_host), tmp_host, 0, NULL, NULL) != CL_SUCCESS) break;
9766
9767 if (ocl->clEnqueueReadBuffer (command_queue, tmp_device[c], CL_TRUE, MAX_ALLOC_CHECKS_SIZE - sizeof (tmp_host), sizeof (tmp_host), tmp_host, 0, NULL, NULL) != CL_SUCCESS) break;
9768
9769 if (ocl->clEnqueueWriteBuffer (command_queue, tmp_device[c], CL_TRUE, MAX_ALLOC_CHECKS_SIZE - sizeof (tmp_host), sizeof (tmp_host), tmp_host, 0, NULL, NULL) != CL_SUCCESS) break;
9770 }
9771
9772 device_param->device_available_mem = MAX_ALLOC_CHECKS_SIZE;
9773
9774 if (c > 0)
9775 {
9776 device_param->device_available_mem *= c;
9777 }
9778
9779 // clean up
9780
9781 for (c = 0; c < MAX_ALLOC_CHECKS_CNT; c++)
9782 {
9783 if (((c + 1 + 1) * MAX_ALLOC_CHECKS_SIZE) >= device_param->device_global_mem) break;
9784
9785 if (tmp_device[c] != NULL)
9786 {
9787 if (hc_clReleaseMemObject (hashcat_ctx, tmp_device[c]) == -1) return -1;
9788 }
9789 }
9790
9791 hcfree (tmp_device);
9792 }
9793
9794 hc_clReleaseCommandQueue (hashcat_ctx, command_queue);
9795
9796 hc_clReleaseContext (hashcat_ctx, context);
9797
9798 if (device_param->device_host_unified_memory == 1)
9799 {
9800 // so, we actually have only half the memory because we need the same buffers on host side
9801
9802 device_param->device_available_mem /= 2;
9803 }
9804 }
9805 }
9806
9807 backend_ctx->target_msec = TARGET_MSEC_PROFILE[user_options->workload_profile - 1];
9808
9809 backend_ctx->need_adl = need_adl;
9810 backend_ctx->need_nvml = need_nvml;
9811 backend_ctx->need_nvapi = need_nvapi;
9812 backend_ctx->need_sysfs_amdgpu = need_sysfs_amdgpu;
9813 backend_ctx->need_sysfs_cpu = need_sysfs_cpu;
9814 backend_ctx->need_iokit = need_iokit;
9815
9816 backend_ctx->comptime = comptime;
9817
9818 return 0;
9819 }
9820
backend_ctx_devices_destroy(hashcat_ctx_t * hashcat_ctx)9821 void backend_ctx_devices_destroy (hashcat_ctx_t *hashcat_ctx)
9822 {
9823 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
9824
9825 if (backend_ctx->enabled == false) return;
9826
9827 for (u32 opencl_platforms_idx = 0; opencl_platforms_idx < backend_ctx->opencl_platforms_cnt; opencl_platforms_idx++)
9828 {
9829 hcfree (backend_ctx->opencl_platforms_devices[opencl_platforms_idx]);
9830 hcfree (backend_ctx->opencl_platforms_name[opencl_platforms_idx]);
9831 hcfree (backend_ctx->opencl_platforms_vendor[opencl_platforms_idx]);
9832 hcfree (backend_ctx->opencl_platforms_version[opencl_platforms_idx]);
9833 }
9834
9835 for (int backend_devices_idx = 0; backend_devices_idx < backend_ctx->backend_devices_cnt; backend_devices_idx++)
9836 {
9837 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
9838
9839 hcfree (device_param->device_name);
9840
9841 if (device_param->is_opencl == true)
9842 {
9843 hcfree (device_param->opencl_driver_version);
9844 hcfree (device_param->opencl_device_version);
9845 hcfree (device_param->opencl_device_c_version);
9846 hcfree (device_param->opencl_device_vendor);
9847 }
9848 }
9849
9850 backend_ctx->backend_devices_cnt = 0;
9851 backend_ctx->backend_devices_active = 0;
9852 backend_ctx->cuda_devices_cnt = 0;
9853 backend_ctx->cuda_devices_active = 0;
9854 backend_ctx->hip_devices_cnt = 0;
9855 backend_ctx->hip_devices_active = 0;
9856 backend_ctx->opencl_devices_cnt = 0;
9857 backend_ctx->opencl_devices_active = 0;
9858
9859 backend_ctx->need_adl = false;
9860 backend_ctx->need_nvml = false;
9861 backend_ctx->need_nvapi = false;
9862 backend_ctx->need_sysfs_amdgpu = false;
9863 backend_ctx->need_sysfs_cpu = false;
9864 backend_ctx->need_iokit = false;
9865 }
9866
backend_ctx_devices_sync_tuning(hashcat_ctx_t * hashcat_ctx)9867 void backend_ctx_devices_sync_tuning (hashcat_ctx_t *hashcat_ctx)
9868 {
9869 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
9870 hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
9871
9872 if (backend_ctx->enabled == false) return;
9873
9874 for (int backend_devices_cnt_src = 0; backend_devices_cnt_src < backend_ctx->backend_devices_cnt; backend_devices_cnt_src++)
9875 {
9876 hc_device_param_t *device_param_src = &backend_ctx->devices_param[backend_devices_cnt_src];
9877
9878 if (device_param_src->skipped == true) continue;
9879
9880 if (device_param_src->skipped_warning == true) continue;
9881
9882 for (int backend_devices_cnt_dst = backend_devices_cnt_src + 1; backend_devices_cnt_dst < backend_ctx->backend_devices_cnt; backend_devices_cnt_dst++)
9883 {
9884 hc_device_param_t *device_param_dst = &backend_ctx->devices_param[backend_devices_cnt_dst];
9885
9886 if (device_param_dst->skipped == true) continue;
9887
9888 if (device_param_dst->skipped_warning == true) continue;
9889
9890 if (is_same_device_type (device_param_src, device_param_dst) == false) continue;
9891
9892 device_param_dst->kernel_accel = device_param_src->kernel_accel;
9893 device_param_dst->kernel_loops = device_param_src->kernel_loops;
9894 device_param_dst->kernel_threads = device_param_src->kernel_threads;
9895
9896 const u32 hardware_power = ((hashconfig->opts_type & OPTS_TYPE_MP_MULTI_DISABLE) ? 1 : device_param_dst->device_processors) * device_param_dst->kernel_threads;
9897
9898 device_param_dst->hardware_power = hardware_power;
9899
9900 const u32 kernel_power = device_param_dst->hardware_power * device_param_dst->kernel_accel;
9901
9902 device_param_dst->kernel_power = kernel_power;
9903 }
9904 }
9905 }
9906
backend_ctx_devices_update_power(hashcat_ctx_t * hashcat_ctx)9907 void backend_ctx_devices_update_power (hashcat_ctx_t *hashcat_ctx)
9908 {
9909 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
9910 status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
9911 user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra;
9912 user_options_t *user_options = hashcat_ctx->user_options;
9913
9914 if (backend_ctx->enabled == false) return;
9915
9916 u32 kernel_power_all = 0;
9917
9918 for (int backend_devices_idx = 0; backend_devices_idx < backend_ctx->backend_devices_cnt; backend_devices_idx++)
9919 {
9920 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
9921
9922 if (device_param->skipped == true) continue;
9923
9924 if (device_param->skipped_warning == true) continue;
9925
9926 kernel_power_all += device_param->kernel_power;
9927 }
9928
9929 backend_ctx->kernel_power_all = kernel_power_all;
9930
9931 /*
9932 * Inform user about possible slow speeds
9933 */
9934
9935 if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK))
9936 {
9937 if (status_ctx->words_base < kernel_power_all)
9938 {
9939 if (user_options->quiet == false)
9940 {
9941 clear_prompt (hashcat_ctx);
9942
9943 event_log_advice (hashcat_ctx, "The wordlist or mask that you are using is too small.");
9944 event_log_advice (hashcat_ctx, "This means that hashcat cannot use the full parallel power of your device(s).");
9945 event_log_advice (hashcat_ctx, "Unless you supply more work, your cracking speed will drop.");
9946 event_log_advice (hashcat_ctx, "For tips on supplying more work, see: https://hashcat.net/faq/morework");
9947 event_log_advice (hashcat_ctx, NULL);
9948 }
9949 }
9950 }
9951 }
9952
backend_ctx_devices_kernel_loops(hashcat_ctx_t * hashcat_ctx)9953 void backend_ctx_devices_kernel_loops (hashcat_ctx_t *hashcat_ctx)
9954 {
9955 combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx;
9956 hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
9957 hashes_t *hashes = hashcat_ctx->hashes;
9958 mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx;
9959 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
9960 straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx;
9961 user_options_t *user_options = hashcat_ctx->user_options;
9962 user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra;
9963
9964 if (backend_ctx->enabled == false) return;
9965
9966 for (int backend_devices_idx = 0; backend_devices_idx < backend_ctx->backend_devices_cnt; backend_devices_idx++)
9967 {
9968 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
9969
9970 if (device_param->skipped == true) continue;
9971
9972 if (device_param->skipped_warning == true) continue;
9973
9974 device_param->kernel_loops_min = device_param->kernel_loops_min_sav;
9975 device_param->kernel_loops_max = device_param->kernel_loops_max_sav;
9976
9977 if (device_param->kernel_loops_min < device_param->kernel_loops_max)
9978 {
9979 u32 innerloop_cnt = 0;
9980
9981 if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
9982 {
9983 if (user_options->slow_candidates == true)
9984 {
9985 innerloop_cnt = 1;
9986 }
9987 else
9988 {
9989 if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) innerloop_cnt = MIN (KERNEL_RULES, (u32) straight_ctx->kernel_rules_cnt);
9990 else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) innerloop_cnt = MIN (KERNEL_COMBS, (u32) combinator_ctx->combs_cnt);
9991 else if (user_options_extra->attack_kern == ATTACK_KERN_BF) innerloop_cnt = MIN (KERNEL_BFS, (u32) mask_ctx->bfs_cnt);
9992 }
9993 }
9994 else
9995 {
9996 innerloop_cnt = hashes->salts_buf[0].salt_iter;
9997 }
9998
9999 if ((innerloop_cnt >= device_param->kernel_loops_min) &&
10000 (innerloop_cnt <= device_param->kernel_loops_max))
10001 {
10002 device_param->kernel_loops_max = innerloop_cnt;
10003 }
10004 }
10005 }
10006 }
10007
get_cuda_kernel_wgs(hashcat_ctx_t * hashcat_ctx,CUfunction function,u32 * result)10008 static int get_cuda_kernel_wgs (hashcat_ctx_t *hashcat_ctx, CUfunction function, u32 *result)
10009 {
10010 int max_threads_per_block;
10011
10012 if (hc_cuFuncGetAttribute (hashcat_ctx, &max_threads_per_block, CU_FUNC_ATTRIBUTE_MAX_THREADS_PER_BLOCK, function) == -1) return -1;
10013
10014 *result = (u32) max_threads_per_block;
10015
10016 return 0;
10017 }
10018
get_cuda_kernel_local_mem_size(hashcat_ctx_t * hashcat_ctx,CUfunction function,u64 * result)10019 static int get_cuda_kernel_local_mem_size (hashcat_ctx_t *hashcat_ctx, CUfunction function, u64 *result)
10020 {
10021 int shared_size_bytes;
10022
10023 if (hc_cuFuncGetAttribute (hashcat_ctx, &shared_size_bytes, CU_FUNC_ATTRIBUTE_SHARED_SIZE_BYTES, function) == -1) return -1;
10024
10025 *result = (u64) shared_size_bytes;
10026
10027 return 0;
10028 }
10029
get_hip_kernel_wgs(hashcat_ctx_t * hashcat_ctx,hipFunction_t function,u32 * result)10030 static int get_hip_kernel_wgs (hashcat_ctx_t *hashcat_ctx, hipFunction_t function, u32 *result)
10031 {
10032 int max_threads_per_block;
10033
10034 if (hc_hipFuncGetAttribute (hashcat_ctx, &max_threads_per_block, HIP_FUNC_ATTRIBUTE_MAX_THREADS_PER_BLOCK, function) == -1) return -1;
10035
10036 *result = (u32) max_threads_per_block;
10037
10038 return 0;
10039 }
10040
get_hip_kernel_local_mem_size(hashcat_ctx_t * hashcat_ctx,hipFunction_t function,u64 * result)10041 static int get_hip_kernel_local_mem_size (hashcat_ctx_t *hashcat_ctx, hipFunction_t function, u64 *result)
10042 {
10043 int shared_size_bytes;
10044
10045 if (hc_hipFuncGetAttribute (hashcat_ctx, &shared_size_bytes, HIP_FUNC_ATTRIBUTE_SHARED_SIZE_BYTES, function) == -1) return -1;
10046
10047 *result = (u64) shared_size_bytes;
10048
10049 return 0;
10050 }
10051
get_opencl_kernel_wgs(hashcat_ctx_t * hashcat_ctx,hc_device_param_t * device_param,cl_kernel kernel,u32 * result)10052 static int get_opencl_kernel_wgs (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, cl_kernel kernel, u32 *result)
10053 {
10054 size_t work_group_size = 0;
10055
10056 if (hc_clGetKernelWorkGroupInfo (hashcat_ctx, kernel, device_param->opencl_device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (work_group_size), &work_group_size, NULL) == -1) return -1;
10057
10058 u32 kernel_threads = (u32) work_group_size;
10059
10060 size_t compile_work_group_size[3] = { 0, 0, 0 };
10061
10062 if (hc_clGetKernelWorkGroupInfo (hashcat_ctx, kernel, device_param->opencl_device, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, sizeof (compile_work_group_size), &compile_work_group_size, NULL) == -1) return -1;
10063
10064 const size_t cwgs_total = compile_work_group_size[0] * compile_work_group_size[1] * compile_work_group_size[2];
10065
10066 if (cwgs_total > 0)
10067 {
10068 kernel_threads = MIN (kernel_threads, (u32) cwgs_total);
10069 }
10070
10071 *result = kernel_threads;
10072
10073 return 0;
10074 }
10075
get_opencl_kernel_preferred_wgs_multiple(hashcat_ctx_t * hashcat_ctx,hc_device_param_t * device_param,cl_kernel kernel,u32 * result)10076 static int get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, cl_kernel kernel, u32 *result)
10077 {
10078 size_t preferred_work_group_size_multiple = 0;
10079
10080 if (hc_clGetKernelWorkGroupInfo (hashcat_ctx, kernel, device_param->opencl_device, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, sizeof (preferred_work_group_size_multiple), &preferred_work_group_size_multiple, NULL) == -1) return -1;
10081
10082 *result = (u32) preferred_work_group_size_multiple;
10083
10084 return 0;
10085 }
10086
get_opencl_kernel_local_mem_size(hashcat_ctx_t * hashcat_ctx,hc_device_param_t * device_param,cl_kernel kernel,u64 * result)10087 static int get_opencl_kernel_local_mem_size (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, cl_kernel kernel, u64 *result)
10088 {
10089 cl_ulong local_mem_size = 0;
10090
10091 if (hc_clGetKernelWorkGroupInfo (hashcat_ctx, kernel, device_param->opencl_device, CL_KERNEL_LOCAL_MEM_SIZE, sizeof (local_mem_size), &local_mem_size, NULL) == -1) return -1;
10092
10093 *result = local_mem_size;
10094
10095 return 0;
10096 }
10097
get_opencl_kernel_dynamic_local_mem_size(hashcat_ctx_t * hashcat_ctx,hc_device_param_t * device_param,cl_kernel kernel,u64 * result)10098 static int get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, cl_kernel kernel, u64 *result)
10099 {
10100 cl_ulong dynamic_local_mem_size = 0;
10101
10102 if (hc_clGetKernelWorkGroupInfo (hashcat_ctx, kernel, device_param->opencl_device, CL_KERNEL_LOCAL_MEM_SIZE, sizeof (dynamic_local_mem_size), &dynamic_local_mem_size, NULL) == -1) return -1;
10103
10104 // unknown how to query this information in OpenCL
10105 // we therefore reset to zero
10106 // the above call to hc_clGetKernelWorkGroupInfo() is just to avoid compiler warnings
10107
10108 dynamic_local_mem_size = 0;
10109
10110 *result = dynamic_local_mem_size;
10111
10112 return 0;
10113 }
10114
load_kernel(hashcat_ctx_t * hashcat_ctx,hc_device_param_t * device_param,const char * kernel_name,char * source_file,char * cached_file,const char * build_options_buf,const bool cache_disable,cl_program * opencl_program,CUmodule * cuda_module,hipModule_t * hip_module)10115 static bool load_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const char *kernel_name, char *source_file, char *cached_file, const char *build_options_buf, const bool cache_disable, cl_program *opencl_program, CUmodule *cuda_module, hipModule_t *hip_module)
10116 {
10117 const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
10118 const folder_config_t *folder_config = hashcat_ctx->folder_config;
10119 const user_options_t *user_options = hashcat_ctx->user_options;
10120
10121 bool cached = true;
10122
10123 if (cache_disable == true)
10124 {
10125 cached = false;
10126 }
10127
10128 if (hc_path_read (cached_file) == false)
10129 {
10130 cached = false;
10131 }
10132
10133 if (hc_path_is_empty (cached_file) == true)
10134 {
10135 cached = false;
10136 }
10137
10138 /**
10139 * kernel compile or load
10140 */
10141
10142 size_t kernel_lengths_buf = 0;
10143
10144 size_t *kernel_lengths = &kernel_lengths_buf;
10145
10146 char *kernel_sources_buf = NULL;
10147
10148 char **kernel_sources = &kernel_sources_buf;
10149
10150 if (cached == false)
10151 {
10152 #if defined (DEBUG)
10153 if (user_options->quiet == false) event_log_warning (hashcat_ctx, "* Device #%u: Kernel %s not found in cache. Please be patient...", device_param->device_id + 1, filename_from_filepath (cached_file));
10154 #endif
10155
10156 if (read_kernel_binary (hashcat_ctx, source_file, kernel_lengths, kernel_sources) == false) return false;
10157
10158 if (device_param->is_cuda == true)
10159 {
10160 nvrtcProgram program;
10161
10162 if (hc_nvrtcCreateProgram (hashcat_ctx, &program, kernel_sources[0], kernel_name, 0, NULL, NULL) == -1) return false;
10163
10164 char **nvrtc_options = (char **) hccalloc (6 + strlen (build_options_buf) + 1, sizeof (char *)); // ...
10165
10166 nvrtc_options[0] = "--restrict";
10167 nvrtc_options[1] = "--device-as-default-execution-space";
10168 nvrtc_options[2] = "--gpu-architecture";
10169
10170 hc_asprintf (&nvrtc_options[3], "compute_%d%d", device_param->sm_major, device_param->sm_minor);
10171
10172 nvrtc_options[4] = "-I";
10173 nvrtc_options[5] = folder_config->cpath_real;
10174
10175 char *nvrtc_options_string = hcstrdup (build_options_buf);
10176
10177 const int num_options = 6 + nvrtc_make_options_array_from_string (nvrtc_options_string, nvrtc_options + 6);
10178
10179 const int rc_nvrtcCompileProgram = hc_nvrtcCompileProgram (hashcat_ctx, program, num_options, (const char * const *) nvrtc_options);
10180
10181 hcfree (nvrtc_options_string);
10182 hcfree (nvrtc_options);
10183
10184 size_t build_log_size = 0;
10185
10186 hc_nvrtcGetProgramLogSize (hashcat_ctx, program, &build_log_size);
10187
10188 #if defined (DEBUG)
10189 if ((build_log_size > 1) || (rc_nvrtcCompileProgram == -1))
10190 #else
10191 if (rc_nvrtcCompileProgram == -1)
10192 #endif
10193 {
10194 char *build_log = (char *) hcmalloc (build_log_size + 1);
10195
10196 if (hc_nvrtcGetProgramLog (hashcat_ctx, program, build_log) == -1)
10197 {
10198 hcfree (build_log);
10199
10200 return false;
10201 }
10202
10203 build_log[build_log_size] = 0;
10204
10205 puts (build_log);
10206
10207 hcfree (build_log);
10208 }
10209
10210 if (rc_nvrtcCompileProgram == -1)
10211 {
10212 event_log_error (hashcat_ctx, "* Device #%u: Kernel %s build failed.", device_param->device_id + 1, source_file);
10213
10214 return false;
10215 }
10216
10217 size_t binary_size = 0;
10218
10219 if (hc_nvrtcGetPTXSize (hashcat_ctx, program, &binary_size) == -1) return false;
10220
10221 char *binary = (char *) hcmalloc (binary_size);
10222
10223 if (hc_nvrtcGetPTX (hashcat_ctx, program, binary) == -1) return false;
10224
10225 if (hc_nvrtcDestroyProgram (hashcat_ctx, &program) == -1) return false;
10226
10227 #define LOG_SIZE 8192
10228
10229 char *mod_info_log = (char *) hcmalloc (LOG_SIZE + 1);
10230 char *mod_error_log = (char *) hcmalloc (LOG_SIZE + 1);
10231
10232 int mod_cnt = 6;
10233
10234 CUjit_option mod_opts[7];
10235 void *mod_vals[7];
10236
10237 mod_opts[0] = CU_JIT_TARGET_FROM_CUCONTEXT;
10238 mod_vals[0] = (void *) 0;
10239
10240 mod_opts[1] = CU_JIT_LOG_VERBOSE;
10241 mod_vals[1] = (void *) 1;
10242
10243 mod_opts[2] = CU_JIT_INFO_LOG_BUFFER;
10244 mod_vals[2] = (void *) mod_info_log;
10245
10246 mod_opts[3] = CU_JIT_INFO_LOG_BUFFER_SIZE_BYTES;
10247 mod_vals[3] = (void *) LOG_SIZE;
10248
10249 mod_opts[4] = CU_JIT_ERROR_LOG_BUFFER;
10250 mod_vals[4] = (void *) mod_error_log;
10251
10252 mod_opts[5] = CU_JIT_ERROR_LOG_BUFFER_SIZE_BYTES;
10253 mod_vals[5] = (void *) LOG_SIZE;
10254
10255 if (hashconfig->opti_type & OPTI_TYPE_REGISTER_LIMIT)
10256 {
10257 mod_opts[6] = CU_JIT_MAX_REGISTERS;
10258 mod_vals[6] = (void *) 128;
10259
10260 mod_cnt++;
10261 }
10262
10263 #if defined (WITH_CUBIN)
10264
10265 char *jit_info_log = (char *) hcmalloc (LOG_SIZE + 1);
10266 char *jit_error_log = (char *) hcmalloc (LOG_SIZE + 1);
10267
10268 int jit_cnt = 6;
10269
10270 CUjit_option jit_opts[7];
10271 void *jit_vals[7];
10272
10273 jit_opts[0] = CU_JIT_TARGET_FROM_CUCONTEXT;
10274 jit_vals[0] = (void *) 0;
10275
10276 jit_opts[1] = CU_JIT_LOG_VERBOSE;
10277 jit_vals[1] = (void *) 1;
10278
10279 jit_opts[2] = CU_JIT_INFO_LOG_BUFFER;
10280 jit_vals[2] = (void *) jit_info_log;
10281
10282 jit_opts[3] = CU_JIT_INFO_LOG_BUFFER_SIZE_BYTES;
10283 jit_vals[3] = (void *) LOG_SIZE;
10284
10285 jit_opts[4] = CU_JIT_ERROR_LOG_BUFFER;
10286 jit_vals[4] = (void *) jit_error_log;
10287
10288 jit_opts[5] = CU_JIT_ERROR_LOG_BUFFER_SIZE_BYTES;
10289 jit_vals[5] = (void *) LOG_SIZE;
10290
10291 if (hashconfig->opti_type & OPTI_TYPE_REGISTER_LIMIT)
10292 {
10293 jit_opts[6] = CU_JIT_MAX_REGISTERS;
10294 jit_vals[6] = (void *) 128;
10295
10296 jit_cnt++;
10297 }
10298
10299 CUlinkState state;
10300
10301 if (hc_cuLinkCreate (hashcat_ctx, jit_cnt, jit_opts, jit_vals, &state) == -1)
10302 {
10303 event_log_error (hashcat_ctx, "* Device #%u: Kernel %s link failed. Error Log:", device_param->device_id + 1, source_file);
10304 event_log_error (hashcat_ctx, "%s", jit_error_log);
10305 event_log_error (hashcat_ctx, NULL);
10306
10307 return false;
10308 }
10309
10310 if (hc_cuLinkAddData (hashcat_ctx, state, CU_JIT_INPUT_PTX, binary, binary_size, kernel_name, 0, NULL, NULL) == -1)
10311 {
10312 event_log_error (hashcat_ctx, "* Device #%u: Kernel %s link failed. Error Log:", device_param->device_id + 1, source_file);
10313 event_log_error (hashcat_ctx, "%s", jit_error_log);
10314 event_log_error (hashcat_ctx, NULL);
10315
10316 return false;
10317 }
10318
10319 void *cubin = NULL;
10320
10321 size_t cubin_size = 0;
10322
10323 if (hc_cuLinkComplete (hashcat_ctx, state, &cubin, &cubin_size) == -1)
10324 {
10325 event_log_error (hashcat_ctx, "* Device #%u: Kernel %s link failed. Error Log:", device_param->device_id + 1, source_file);
10326 event_log_error (hashcat_ctx, "%s", jit_error_log);
10327 event_log_error (hashcat_ctx, NULL);
10328
10329 return false;
10330 }
10331
10332 #if defined (DEBUG)
10333 event_log_info (hashcat_ctx, "* Device #%u: Kernel %s link successful. Info Log:", device_param->device_id + 1, source_file);
10334 event_log_info (hashcat_ctx, "%s", jit_info_log);
10335 event_log_info (hashcat_ctx, NULL);
10336 #endif
10337
10338 if (hc_cuModuleLoadDataEx (hashcat_ctx, cuda_module, cubin, mod_cnt, mod_opts, mod_vals) == -1)
10339 {
10340 event_log_error (hashcat_ctx, "* Device #%u: Kernel %s load failed. Error Log:", device_param->device_id + 1, source_file);
10341 event_log_error (hashcat_ctx, "%s", mod_error_log);
10342 event_log_error (hashcat_ctx, NULL);
10343
10344 return false;
10345 }
10346
10347 #if defined (DEBUG)
10348 event_log_info (hashcat_ctx, "* Device #%u: Kernel %s load successful. Info Log:", device_param->device_id + 1, source_file);
10349 event_log_info (hashcat_ctx, "%s", mod_info_log);
10350 event_log_info (hashcat_ctx, NULL);
10351 #endif
10352
10353 if (cache_disable == false)
10354 {
10355 if (write_kernel_binary (hashcat_ctx, cached_file, cubin, cubin_size) == false) return false;
10356 }
10357
10358 if (hc_cuLinkDestroy (hashcat_ctx, state) == -1) return false;
10359
10360 hcfree (jit_info_log);
10361 hcfree (jit_error_log);
10362
10363 #else
10364
10365 if (hc_cuModuleLoadDataEx (hashcat_ctx, cuda_module, binary, mod_cnt, mod_opts, mod_vals) == -1)
10366 {
10367 event_log_error (hashcat_ctx, "* Device #%u: Kernel %s load failed. Error Log:", device_param->device_id + 1, source_file);
10368 event_log_error (hashcat_ctx, "%s", mod_error_log);
10369 event_log_error (hashcat_ctx, NULL);
10370
10371 return false;
10372 }
10373
10374 #if defined (DEBUG)
10375 event_log_info (hashcat_ctx, "* Device #%u: Kernel %s load successful. Info Log:", device_param->device_id + 1, source_file);
10376 event_log_info (hashcat_ctx, "%s", mod_info_log);
10377 event_log_info (hashcat_ctx, NULL);
10378 #endif
10379
10380 if (cache_disable == false)
10381 {
10382 if (write_kernel_binary (hashcat_ctx, cached_file, binary, binary_size) == false) return false;
10383 }
10384
10385 #endif
10386
10387 hcfree (mod_info_log);
10388 hcfree (mod_error_log);
10389
10390 hcfree (binary);
10391 }
10392
10393 if (device_param->is_hip == true)
10394 {
10395 hiprtcProgram program;
10396
10397 if (hc_hiprtcCreateProgram (hashcat_ctx, &program, kernel_sources[0], kernel_name, 0, NULL, NULL) == -1) return false;
10398
10399 char **hiprtc_options = (char **) hccalloc (7 + strlen (build_options_buf) + 1, sizeof (char *)); // ...
10400
10401 //hiprtc_options[0] = "--restrict";
10402 //hiprtc_options[1] = "--device-as-default-execution-space";
10403 //hiprtc_options[2] = "--gpu-architecture";
10404
10405 hc_asprintf (&hiprtc_options[0], "--gpu-max-threads-per-block=%d", (user_options->kernel_threads_chgd == true) ? user_options->kernel_threads : device_param->kernel_threads_max);
10406
10407 /* 4.3 linux
10408 hiprtc_options[1] = "-I";
10409 hiprtc_options[2] = "/opt/rocm/hip/bin/include";
10410 hiprtc_options[3] = "-I";
10411 hiprtc_options[4] = "/opt/rocm/include";
10412 hiprtc_options[5] = "-I";
10413 */
10414
10415 hiprtc_options[1] = "-nocudainc";
10416 hiprtc_options[2] = "-nocudalib";
10417 hiprtc_options[3] = "";
10418 hiprtc_options[4] = "";
10419 hiprtc_options[5] = "-I";
10420 hiprtc_options[6] = folder_config->cpath_real;
10421
10422 char *hiprtc_options_string = hcstrdup (build_options_buf);
10423
10424 const int num_options = 7 + hiprtc_make_options_array_from_string (hiprtc_options_string, hiprtc_options + 7);
10425
10426 const int rc_hiprtcCompileProgram = hc_hiprtcCompileProgram (hashcat_ctx, program, num_options, (const char * const *) hiprtc_options);
10427
10428 hcfree (hiprtc_options_string);
10429 hcfree (hiprtc_options);
10430
10431 size_t build_log_size = 0;
10432
10433 hc_hiprtcGetProgramLogSize (hashcat_ctx, program, &build_log_size);
10434
10435 #if defined (DEBUG)
10436 if ((build_log_size > 1) || (rc_hiprtcCompileProgram == -1))
10437 #else
10438 if (rc_hiprtcCompileProgram == -1)
10439 #endif
10440 {
10441 char *build_log = (char *) hcmalloc (build_log_size + 1);
10442
10443 if (hc_hiprtcGetProgramLog (hashcat_ctx, program, build_log) == -1)
10444 {
10445 hcfree (build_log);
10446
10447 return false;
10448 }
10449
10450 build_log[build_log_size] = 0;
10451
10452 puts (build_log);
10453
10454 hcfree (build_log);
10455 }
10456
10457 if (rc_hiprtcCompileProgram == -1)
10458 {
10459 event_log_error (hashcat_ctx, "* Device #%u: Kernel %s build failed.", device_param->device_id + 1, source_file);
10460
10461 return false;
10462 }
10463
10464 size_t binary_size = 0;
10465
10466 if (hc_hiprtcGetCodeSize (hashcat_ctx, program, &binary_size) == -1) return false;
10467
10468 char *binary = (char *) hcmalloc (binary_size);
10469
10470 if (hc_hiprtcGetCode (hashcat_ctx, program, binary) == -1) return false;
10471
10472 if (hc_hiprtcDestroyProgram (hashcat_ctx, &program) == -1) return false;
10473
10474 #define LOG_SIZE 8192
10475
10476 char *mod_info_log = (char *) hcmalloc (LOG_SIZE + 1);
10477 char *mod_error_log = (char *) hcmalloc (LOG_SIZE + 1);
10478
10479 int mod_cnt = 6;
10480
10481 hipJitOption mod_opts[6];
10482 void *mod_vals[6];
10483
10484 mod_opts[0] = hipJitOptionTargetFromContext;
10485 mod_vals[0] = (void *) 0;
10486
10487 mod_opts[1] = hipJitOptionLogVerbose;
10488 mod_vals[1] = (void *) 1;
10489
10490 mod_opts[2] = hipJitOptionInfoLogBuffer;
10491 mod_vals[2] = (void *) mod_info_log;
10492
10493 mod_opts[3] = hipJitOptionInfoLogBufferSizeBytes;
10494 mod_vals[3] = (void *) LOG_SIZE;
10495
10496 mod_opts[4] = hipJitOptionErrorLogBuffer;
10497 mod_vals[4] = (void *) mod_error_log;
10498
10499 mod_opts[5] = hipJitOptionErrorLogBufferSizeBytes;
10500 mod_vals[5] = (void *) LOG_SIZE;
10501
10502 if (hc_hipModuleLoadDataEx (hashcat_ctx, hip_module, binary, mod_cnt, mod_opts, mod_vals) == -1)
10503 {
10504 event_log_error (hashcat_ctx, "* Device #%u: Kernel %s load failed. Error Log:", device_param->device_id + 1, source_file);
10505 event_log_error (hashcat_ctx, "%s", mod_error_log);
10506 event_log_error (hashcat_ctx, NULL);
10507
10508 return false;
10509 }
10510
10511 #if defined (DEBUG)
10512 event_log_info (hashcat_ctx, "* Device #%u: Kernel %s load successful. Info Log:", device_param->device_id + 1, source_file);
10513 event_log_info (hashcat_ctx, "%s", mod_info_log);
10514 event_log_info (hashcat_ctx, NULL);
10515 #endif
10516
10517 if (cache_disable == false)
10518 {
10519 if (write_kernel_binary (hashcat_ctx, cached_file, binary, binary_size) == false) return false;
10520 }
10521
10522 hcfree (mod_info_log);
10523 hcfree (mod_error_log);
10524
10525 hcfree (binary);
10526 }
10527
10528 if (device_param->is_opencl == true)
10529 {
10530 size_t build_log_size = 0;
10531
10532 int CL_rc;
10533
10534 cl_program p1 = NULL;
10535
10536 // workaround opencl issue with Apple Silicon
10537
10538 if (strcmp (device_param->device_name, "Apple M") != 0)
10539 {
10540 if (hc_clCreateProgramWithSource (hashcat_ctx, device_param->opencl_context, 1, (const char **) kernel_sources, NULL, opencl_program) == -1) return false;
10541
10542 CL_rc = hc_clBuildProgram (hashcat_ctx, *opencl_program, 1, &device_param->opencl_device, build_options_buf, NULL, NULL);
10543
10544 hc_clGetProgramBuildInfo (hashcat_ctx, *opencl_program, device_param->opencl_device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size);
10545 }
10546 else
10547 {
10548 if (hc_clCreateProgramWithSource (hashcat_ctx, device_param->opencl_context, 1, (const char **) kernel_sources, NULL, &p1) == -1) return false;
10549
10550 CL_rc = hc_clCompileProgram (hashcat_ctx, p1, 1, &device_param->opencl_device, build_options_buf, 0, NULL, NULL, NULL, NULL);
10551
10552 hc_clGetProgramBuildInfo (hashcat_ctx, p1, device_param->opencl_device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size);
10553 }
10554
10555 #if defined (DEBUG)
10556 if ((build_log_size > 1) || (CL_rc == -1))
10557 #else
10558 if (CL_rc == -1)
10559 #endif
10560 {
10561 char *build_log = (char *) hcmalloc (build_log_size + 1);
10562
10563 int rc_clGetProgramBuildInfo;
10564
10565 if (strcmp (device_param->device_name, "Apple M") != 0)
10566 {
10567 rc_clGetProgramBuildInfo = hc_clGetProgramBuildInfo (hashcat_ctx, *opencl_program, device_param->opencl_device, CL_PROGRAM_BUILD_LOG, build_log_size, build_log, NULL);
10568 }
10569 else
10570 {
10571 rc_clGetProgramBuildInfo = hc_clGetProgramBuildInfo (hashcat_ctx, p1, device_param->opencl_device, CL_PROGRAM_BUILD_LOG, build_log_size, build_log, NULL);
10572 }
10573
10574 if (rc_clGetProgramBuildInfo == -1)
10575 {
10576 hcfree (build_log);
10577
10578 return false;
10579 }
10580
10581 build_log[build_log_size] = 0;
10582
10583 puts (build_log);
10584
10585 hcfree (build_log);
10586 }
10587
10588 if (CL_rc == -1) return false;
10589
10590 // workaround opencl issue with Apple Silicon
10591
10592 if (strcmp (device_param->device_name, "Apple M") != 0)
10593 {
10594 }
10595 else
10596 {
10597 cl_program t2[1];
10598
10599 t2[0] = p1;
10600
10601 cl_program fin;
10602
10603 if (hc_clLinkProgram (hashcat_ctx, device_param->opencl_context, 1, &device_param->opencl_device, NULL, 1, t2, NULL, NULL, &fin) == -1) return false;
10604
10605 // it seems errors caused by clLinkProgram() do not go into CL_PROGRAM_BUILD
10606 // I couldn't find any information on the web explaining how else to retrieve the error messages from the linker
10607
10608 *opencl_program = fin;
10609
10610 hc_clReleaseProgram (hashcat_ctx, p1);
10611 }
10612
10613 if (cache_disable == false)
10614 {
10615 size_t binary_size;
10616
10617 if (hc_clGetProgramInfo (hashcat_ctx, *opencl_program, CL_PROGRAM_BINARY_SIZES, sizeof (size_t), &binary_size, NULL) == -1) return false;
10618
10619 char *binary = (char *) hcmalloc (binary_size);
10620
10621 if (hc_clGetProgramInfo (hashcat_ctx, *opencl_program, CL_PROGRAM_BINARIES, sizeof (char *), &binary, NULL) == -1) return false;
10622
10623 if (write_kernel_binary (hashcat_ctx, cached_file, binary, binary_size) == false) return false;
10624
10625 hcfree (binary);
10626 }
10627 }
10628 }
10629 else
10630 {
10631 if (read_kernel_binary (hashcat_ctx, cached_file, kernel_lengths, kernel_sources) == false) return false;
10632
10633 if (device_param->is_cuda == true)
10634 {
10635 #define LOG_SIZE 8192
10636
10637 char *mod_info_log = (char *) hcmalloc (LOG_SIZE + 1);
10638 char *mod_error_log = (char *) hcmalloc (LOG_SIZE + 1);
10639
10640 int mod_cnt = 6;
10641
10642 CUjit_option mod_opts[7];
10643 void *mod_vals[7];
10644
10645 mod_opts[0] = CU_JIT_TARGET_FROM_CUCONTEXT;
10646 mod_vals[0] = (void *) 0;
10647
10648 mod_opts[1] = CU_JIT_LOG_VERBOSE;
10649 mod_vals[1] = (void *) 1;
10650
10651 mod_opts[2] = CU_JIT_INFO_LOG_BUFFER;
10652 mod_vals[2] = (void *) mod_info_log;
10653
10654 mod_opts[3] = CU_JIT_INFO_LOG_BUFFER_SIZE_BYTES;
10655 mod_vals[3] = (void *) LOG_SIZE;
10656
10657 mod_opts[4] = CU_JIT_ERROR_LOG_BUFFER;
10658 mod_vals[4] = (void *) mod_error_log;
10659
10660 mod_opts[5] = CU_JIT_ERROR_LOG_BUFFER_SIZE_BYTES;
10661 mod_vals[5] = (void *) LOG_SIZE;
10662
10663 if (hashconfig->opti_type & OPTI_TYPE_REGISTER_LIMIT)
10664 {
10665 mod_opts[6] = CU_JIT_MAX_REGISTERS;
10666 mod_vals[6] = (void *) 128;
10667
10668 mod_cnt++;
10669 }
10670
10671 if (hc_cuModuleLoadDataEx (hashcat_ctx, cuda_module, kernel_sources[0], mod_cnt, mod_opts, mod_vals) == -1)
10672 {
10673 event_log_error (hashcat_ctx, "* Device #%u: Kernel %s load failed. Error Log:", device_param->device_id + 1, source_file);
10674 event_log_error (hashcat_ctx, "%s", mod_error_log);
10675 event_log_error (hashcat_ctx, NULL);
10676
10677 return false;
10678 }
10679
10680 #if defined (DEBUG)
10681 event_log_info (hashcat_ctx, "* Device #%u: Kernel %s load successful. Info Log:", device_param->device_id + 1, source_file);
10682 event_log_info (hashcat_ctx, "%s", mod_info_log);
10683 event_log_info (hashcat_ctx, NULL);
10684 #endif
10685
10686 hcfree (mod_info_log);
10687 hcfree (mod_error_log);
10688 }
10689
10690 if (device_param->is_hip == true)
10691 {
10692 #define LOG_SIZE 8192
10693
10694 char *mod_info_log = (char *) hcmalloc (LOG_SIZE + 1);
10695 char *mod_error_log = (char *) hcmalloc (LOG_SIZE + 1);
10696
10697 int mod_cnt = 6;
10698
10699 hipJitOption mod_opts[6];
10700 void *mod_vals[6];
10701
10702 mod_opts[0] = hipJitOptionTargetFromContext;
10703 mod_vals[0] = (void *) 0;
10704
10705 mod_opts[1] = hipJitOptionLogVerbose;
10706 mod_vals[1] = (void *) 1;
10707
10708 mod_opts[2] = hipJitOptionInfoLogBuffer;
10709 mod_vals[2] = (void *) mod_info_log;
10710
10711 mod_opts[3] = hipJitOptionInfoLogBufferSizeBytes;
10712 mod_vals[3] = (void *) LOG_SIZE;
10713
10714 mod_opts[4] = hipJitOptionErrorLogBuffer;
10715 mod_vals[4] = (void *) mod_error_log;
10716
10717 mod_opts[5] = hipJitOptionErrorLogBufferSizeBytes;
10718 mod_vals[5] = (void *) LOG_SIZE;
10719
10720 if (hc_hipModuleLoadDataEx (hashcat_ctx, hip_module, kernel_sources[0], mod_cnt, mod_opts, mod_vals) == -1)
10721 {
10722 event_log_error (hashcat_ctx, "* Device #%u: Kernel %s load failed. Error Log:", device_param->device_id + 1, source_file);
10723 event_log_error (hashcat_ctx, "%s", mod_error_log);
10724 event_log_error (hashcat_ctx, NULL);
10725
10726 return false;
10727 }
10728
10729 #if defined (DEBUG)
10730 event_log_info (hashcat_ctx, "* Device #%u: Kernel %s load successful. Info Log:", device_param->device_id + 1, source_file);
10731 event_log_info (hashcat_ctx, "%s", mod_info_log);
10732 event_log_info (hashcat_ctx, NULL);
10733 #endif
10734
10735 hcfree (mod_info_log);
10736 hcfree (mod_error_log);
10737 }
10738
10739 if (device_param->is_opencl == true)
10740 {
10741 if (hc_clCreateProgramWithBinary (hashcat_ctx, device_param->opencl_context, 1, &device_param->opencl_device, kernel_lengths, (const unsigned char **) kernel_sources, NULL, opencl_program) == -1) return false;
10742
10743 if (hc_clBuildProgram (hashcat_ctx, *opencl_program, 1, &device_param->opencl_device, build_options_buf, NULL, NULL) == -1) return false;
10744 }
10745 }
10746
10747 hcfree (kernel_sources[0]);
10748
10749 return true;
10750 }
10751
backend_session_begin(hashcat_ctx_t * hashcat_ctx)10752 int backend_session_begin (hashcat_ctx_t *hashcat_ctx)
10753 {
10754 const bitmap_ctx_t *bitmap_ctx = hashcat_ctx->bitmap_ctx;
10755 const folder_config_t *folder_config = hashcat_ctx->folder_config;
10756 const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
10757 const hashes_t *hashes = hashcat_ctx->hashes;
10758 const module_ctx_t *module_ctx = hashcat_ctx->module_ctx;
10759 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
10760 const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx;
10761 const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra;
10762 const user_options_t *user_options = hashcat_ctx->user_options;
10763
10764 if (backend_ctx->enabled == false) return 0;
10765
10766 u64 size_total_host_all = 0;
10767
10768 u32 hardware_power_all = 0;
10769
10770 for (int backend_devices_idx = 0; backend_devices_idx < backend_ctx->backend_devices_cnt; backend_devices_idx++)
10771 {
10772 /**
10773 * host buffer
10774 */
10775
10776 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
10777
10778 if (device_param->skipped == true) continue;
10779
10780 EVENT_DATA (EVENT_BACKEND_DEVICE_INIT_PRE, &backend_devices_idx, sizeof (int));
10781
10782 const int device_id = device_param->device_id;
10783
10784 /**
10785 * module depending checks
10786 */
10787
10788 device_param->skipped_warning = false;
10789
10790 if (module_ctx->module_unstable_warning != MODULE_DEFAULT)
10791 {
10792 const bool unstable_warning = module_ctx->module_unstable_warning (hashconfig, user_options, user_options_extra, device_param);
10793
10794 if ((unstable_warning == true) && (user_options->force == false))
10795 {
10796 event_log_warning (hashcat_ctx, "* Device #%u: Skipping (hash-mode %u)", device_id + 1, hashconfig->hash_mode);
10797 event_log_warning (hashcat_ctx, " This is due to a known CUDA/HIP/OpenCL runtime/driver issue (not a hashcat issue)");
10798 event_log_warning (hashcat_ctx, " You can use --force to override, but do not report related errors.");
10799
10800 device_param->skipped_warning = true;
10801
10802 continue;
10803 }
10804 }
10805
10806 /**
10807 * tuning db
10808 */
10809
10810 if (module_ctx->module_extra_tuningdb_block != MODULE_DEFAULT)
10811 {
10812 const char *extra_tuningdb_block = module_ctx->module_extra_tuningdb_block (hashconfig, user_options, user_options_extra);
10813
10814 char *lines_buf = hcstrdup (extra_tuningdb_block);
10815
10816 char *saveptr = NULL;
10817
10818 char *next = strtok_r (lines_buf, "\n", &saveptr);
10819
10820 int line_num = 0;
10821
10822 do
10823 {
10824 line_num++;
10825
10826 const size_t line_len = strlen (next);
10827
10828 if (line_len == 0) continue;
10829
10830 if (next[0] == '#') continue;
10831
10832 tuning_db_process_line (hashcat_ctx, next, line_num);
10833
10834 } while ((next = strtok_r ((char *) NULL, "\n", &saveptr)) != NULL);
10835
10836 hcfree (lines_buf);
10837
10838 // todo: print loaded 'cnt' message
10839
10840 // sort the database
10841
10842 tuning_db_t *tuning_db = hashcat_ctx->tuning_db;
10843
10844 qsort (tuning_db->alias_buf, tuning_db->alias_cnt, sizeof (tuning_db_alias_t), sort_by_tuning_db_alias);
10845 qsort (tuning_db->entry_buf, tuning_db->entry_cnt, sizeof (tuning_db_entry_t), sort_by_tuning_db_entry);
10846 }
10847
10848 // vector_width
10849
10850 int vector_width = 0;
10851
10852 if (user_options->backend_vector_width_chgd == false)
10853 {
10854 // tuning db
10855
10856 tuning_db_entry_t *tuningdb_entry;
10857
10858 if (user_options->slow_candidates == true)
10859 {
10860 tuningdb_entry = tuning_db_search (hashcat_ctx, device_param->device_name, device_param->opencl_device_type, 0, hashconfig->hash_mode);
10861 }
10862 else
10863 {
10864 tuningdb_entry = tuning_db_search (hashcat_ctx, device_param->device_name, device_param->opencl_device_type, user_options->attack_mode, hashconfig->hash_mode);
10865 }
10866
10867 if (tuningdb_entry == NULL || tuningdb_entry->vector_width == -1)
10868 {
10869 if (hashconfig->opti_type & OPTI_TYPE_USES_BITS_64)
10870 {
10871 if (device_param->is_cuda == true)
10872 {
10873 // cuda does not support this query
10874
10875 vector_width = 1;
10876 }
10877
10878 if (device_param->is_hip == true)
10879 {
10880 // hip does not support this query
10881
10882 vector_width = 1;
10883 }
10884
10885 if (device_param->is_opencl == true)
10886 {
10887 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, sizeof (vector_width), &vector_width, NULL) == -1)
10888 {
10889 device_param->skipped = true;
10890 continue;
10891 }
10892 }
10893 }
10894 else
10895 {
10896 if (device_param->is_cuda == true)
10897 {
10898 // cuda does not support this query
10899
10900 vector_width = 1;
10901 }
10902
10903 if (device_param->is_hip == true)
10904 {
10905 // hip does not support this query
10906
10907 vector_width = 1;
10908 }
10909
10910 if (device_param->is_opencl == true)
10911 {
10912 if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, sizeof (vector_width), &vector_width, NULL) == -1)
10913 {
10914 device_param->skipped = true;
10915 continue;
10916 }
10917 }
10918 }
10919 }
10920 else
10921 {
10922 vector_width = (cl_uint) tuningdb_entry->vector_width;
10923 }
10924 }
10925 else
10926 {
10927 vector_width = user_options->backend_vector_width;
10928 }
10929
10930 // We can't have SIMD in kernels where we have an unknown final password length
10931 // It also turns out that pure kernels (that have a higher register pressure)
10932 // actually run faster on scalar GPU (like 1080) without SIMD
10933
10934 if ((hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL) == 0)
10935 {
10936 if (device_param->opencl_device_type & CL_DEVICE_TYPE_GPU)
10937 {
10938 vector_width = 1;
10939 }
10940 }
10941
10942 if (user_options->attack_mode == ATTACK_MODE_ASSOCIATION)
10943 {
10944 // not working in this mode because the GID does not align with password candidate count
10945 // and if it cracks, it will crack the same hash twice, running into segfaults
10946
10947 vector_width = 1;
10948 }
10949
10950 if (vector_width > 16) vector_width = 16;
10951
10952 device_param->vector_width = vector_width;
10953
10954 /**
10955 * kernel accel and loops tuning db adjustment
10956 */
10957
10958 device_param->kernel_accel_min = hashconfig->kernel_accel_min;
10959 device_param->kernel_accel_max = hashconfig->kernel_accel_max;
10960 device_param->kernel_loops_min = hashconfig->kernel_loops_min;
10961 device_param->kernel_loops_max = hashconfig->kernel_loops_max;
10962 device_param->kernel_threads_min = hashconfig->kernel_threads_min;
10963 device_param->kernel_threads_max = hashconfig->kernel_threads_max;
10964
10965 tuning_db_entry_t *tuningdb_entry = NULL;
10966
10967 if (user_options->slow_candidates == true)
10968 {
10969 tuningdb_entry = tuning_db_search (hashcat_ctx, device_param->device_name, device_param->opencl_device_type, 0, hashconfig->hash_mode);
10970 }
10971 else
10972 {
10973 tuningdb_entry = tuning_db_search (hashcat_ctx, device_param->device_name, device_param->opencl_device_type, user_options->attack_mode, hashconfig->hash_mode);
10974 }
10975
10976 // user commandline option override tuning db
10977 // but both have to stay inside the boundaries of the module
10978
10979 if (user_options->kernel_accel_chgd == true)
10980 {
10981 const u32 _kernel_accel = user_options->kernel_accel;
10982
10983 if ((_kernel_accel >= device_param->kernel_accel_min) && (_kernel_accel <= device_param->kernel_accel_max))
10984 {
10985 device_param->kernel_accel_min = _kernel_accel;
10986 device_param->kernel_accel_max = _kernel_accel;
10987 }
10988 }
10989 else
10990 {
10991 if (tuningdb_entry != NULL)
10992 {
10993 const u32 _kernel_accel = tuningdb_entry->kernel_accel;
10994
10995 if (_kernel_accel == (u32) -1) // native, makes sense if OPTS_TYPE_MP_MULTI_DISABLE is used
10996 {
10997 device_param->kernel_accel_min = device_param->device_processors;
10998 device_param->kernel_accel_max = device_param->device_processors;
10999 }
11000 else
11001 {
11002 if (_kernel_accel)
11003 {
11004 if ((_kernel_accel >= device_param->kernel_accel_min) && (_kernel_accel <= device_param->kernel_accel_max))
11005 {
11006 device_param->kernel_accel_min = _kernel_accel;
11007 device_param->kernel_accel_max = _kernel_accel;
11008 }
11009 }
11010 }
11011 }
11012 }
11013
11014 if (user_options->kernel_loops_chgd == true)
11015 {
11016 const u32 _kernel_loops = user_options->kernel_loops;
11017
11018 if ((_kernel_loops >= device_param->kernel_loops_min) && (_kernel_loops <= device_param->kernel_loops_max))
11019 {
11020 device_param->kernel_loops_min = _kernel_loops;
11021 device_param->kernel_loops_max = _kernel_loops;
11022 }
11023 }
11024 else
11025 {
11026 if (tuningdb_entry != NULL)
11027 {
11028 u32 _kernel_loops = tuningdb_entry->kernel_loops;
11029
11030 if (_kernel_loops)
11031 {
11032 if (user_options->workload_profile == 1)
11033 {
11034 _kernel_loops = (_kernel_loops > 8) ? _kernel_loops / 8 : 1;
11035 }
11036 else if (user_options->workload_profile == 2)
11037 {
11038 _kernel_loops = (_kernel_loops > 4) ? _kernel_loops / 4 : 1;
11039 }
11040
11041 if ((_kernel_loops >= device_param->kernel_loops_min) && (_kernel_loops <= device_param->kernel_loops_max))
11042 {
11043 device_param->kernel_loops_min = _kernel_loops;
11044 device_param->kernel_loops_max = _kernel_loops;
11045 }
11046 }
11047 }
11048 }
11049
11050 // there's no thread column in tuning db, stick to commandline if defined
11051
11052 if (user_options->kernel_threads_chgd == true)
11053 {
11054 const u32 _kernel_threads = user_options->kernel_threads;
11055
11056 if ((_kernel_threads >= device_param->kernel_threads_min) && (_kernel_threads <= device_param->kernel_threads_max))
11057 {
11058 device_param->kernel_threads_min = _kernel_threads;
11059 device_param->kernel_threads_max = _kernel_threads;
11060 }
11061 }
11062
11063 if (user_options->slow_candidates == true)
11064 {
11065 }
11066 else
11067 {
11068 // we have some absolute limits for fast hashes (because of limit constant memory), make sure not to overstep
11069
11070 if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
11071 {
11072 if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT)
11073 {
11074 device_param->kernel_loops_min = MIN (device_param->kernel_loops_min, KERNEL_RULES);
11075 device_param->kernel_loops_max = MIN (device_param->kernel_loops_max, KERNEL_RULES);
11076 }
11077 else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI)
11078 {
11079 device_param->kernel_loops_min = MIN (device_param->kernel_loops_min, KERNEL_COMBS);
11080 device_param->kernel_loops_max = MIN (device_param->kernel_loops_max, KERNEL_COMBS);
11081 }
11082 else if (user_options_extra->attack_kern == ATTACK_KERN_BF)
11083 {
11084 device_param->kernel_loops_min = MIN (device_param->kernel_loops_min, KERNEL_BFS);
11085 device_param->kernel_loops_max = MIN (device_param->kernel_loops_max, KERNEL_BFS);
11086 }
11087 }
11088 }
11089
11090 device_param->kernel_loops_min_sav = device_param->kernel_loops_min;
11091 device_param->kernel_loops_max_sav = device_param->kernel_loops_max;
11092
11093 /**
11094 * device properties
11095 */
11096
11097 const u32 device_processors = device_param->device_processors;
11098
11099 /**
11100 * device threads
11101 */
11102
11103 if (hashconfig->opts_type & OPTS_TYPE_MAXIMUM_THREADS)
11104 {
11105 // default for all, because the else branch is doing the same (nothing), but is actually used as a way to
11106 // disable the default native thread configuration for HIP
11107 // this can have negative performance if not tested on multiple different gpu architectures
11108 }
11109 else if (hashconfig->opts_type & OPTS_TYPE_NATIVE_THREADS)
11110 {
11111 u32 native_threads = 0;
11112
11113 if (device_param->opencl_device_type & CL_DEVICE_TYPE_CPU)
11114 {
11115 native_threads = 1;
11116 }
11117 else if (device_param->opencl_device_type & CL_DEVICE_TYPE_GPU)
11118 {
11119 native_threads = device_param->kernel_preferred_wgs_multiple;
11120 }
11121 else
11122 {
11123 // abort?
11124 }
11125
11126 if ((native_threads >= device_param->kernel_threads_min) && (native_threads <= device_param->kernel_threads_max))
11127 {
11128 device_param->kernel_threads_min = native_threads;
11129 device_param->kernel_threads_max = native_threads;
11130 }
11131 else
11132 {
11133 // abort?
11134 }
11135 }
11136 else
11137 {
11138 if (device_param->is_hip == true)
11139 {
11140 const u32 native_threads = device_param->kernel_preferred_wgs_multiple;
11141
11142 if ((native_threads >= device_param->kernel_threads_min) && (native_threads <= device_param->kernel_threads_max))
11143 {
11144 device_param->kernel_threads_min = native_threads;
11145 device_param->kernel_threads_max = native_threads;
11146 }
11147 else
11148 {
11149 // abort?
11150 }
11151 }
11152 }
11153
11154 // this seems to work always
11155
11156 if (device_param->opencl_device_type & CL_DEVICE_TYPE_CPU)
11157 {
11158 u32 native_threads = 1;
11159
11160 if ((native_threads >= device_param->kernel_threads_min) && (native_threads <= device_param->kernel_threads_max))
11161 {
11162 device_param->kernel_threads_min = native_threads;
11163 device_param->kernel_threads_max = native_threads;
11164 }
11165 }
11166
11167 /**
11168 * create context for each device
11169 */
11170
11171 if (device_param->is_cuda == true)
11172 {
11173 if (hc_cuCtxCreate (hashcat_ctx, &device_param->cuda_context, CU_CTX_SCHED_BLOCKING_SYNC, device_param->cuda_device) == -1)
11174 {
11175 device_param->skipped = true;
11176 continue;
11177 }
11178
11179 if (hc_cuCtxPushCurrent (hashcat_ctx, device_param->cuda_context) == -1)
11180 {
11181 device_param->skipped = true;
11182 continue;
11183 }
11184 }
11185
11186 if (device_param->is_hip == true)
11187 {
11188 if (hc_hipCtxCreate (hashcat_ctx, &device_param->hip_context, hipDeviceScheduleBlockingSync, device_param->hip_device) == -1)
11189 {
11190 device_param->skipped = true;
11191 continue;
11192 }
11193
11194 if (hc_hipCtxPushCurrent (hashcat_ctx, device_param->hip_context) == -1)
11195 {
11196 device_param->skipped = true;
11197 continue;
11198 }
11199 }
11200
11201 if (device_param->is_opencl == true)
11202 {
11203 /*
11204 cl_context_properties properties[3];
11205
11206 properties[0] = CL_CONTEXT_PLATFORM;
11207 properties[1] = (cl_context_properties) device_param->opencl_platform;
11208 properties[2] = 0;
11209
11210 CL_rc = hc_clCreateContext (hashcat_ctx, properties, 1, &device_param->opencl_device, NULL, NULL, &device_param->opencl_context);
11211 */
11212
11213 if (hc_clCreateContext (hashcat_ctx, NULL, 1, &device_param->opencl_device, NULL, NULL, &device_param->opencl_context) == -1)
11214 {
11215 device_param->skipped = true;
11216 continue;
11217 }
11218
11219 /**
11220 * create command-queue
11221 */
11222
11223 // not supported with NV
11224 // device_param->opencl_command_queue = hc_clCreateCommandQueueWithProperties (hashcat_ctx, device_param->opencl_device, NULL);
11225
11226 if (hc_clCreateCommandQueue (hashcat_ctx, device_param->opencl_context, device_param->opencl_device, CL_QUEUE_PROFILING_ENABLE, &device_param->opencl_command_queue) == -1)
11227 {
11228 device_param->skipped = true;
11229 continue;
11230 }
11231 }
11232
11233 /**
11234 * create stream for CUDA devices
11235 */
11236
11237 if (device_param->is_cuda == true)
11238 {
11239 if (hc_cuStreamCreate (hashcat_ctx, &device_param->cuda_stream, CU_STREAM_DEFAULT) == -1)
11240 {
11241 device_param->skipped = true;
11242 continue;
11243 }
11244 }
11245
11246 /**
11247 * create stream for HIP devices
11248 */
11249
11250 if (device_param->is_hip == true)
11251 {
11252 if (hc_hipStreamCreate (hashcat_ctx, &device_param->hip_stream, hipStreamDefault) == -1)
11253 {
11254 device_param->skipped = true;
11255 continue;
11256 }
11257 }
11258
11259 /**
11260 * create events for CUDA devices
11261 */
11262
11263 if (device_param->is_cuda == true)
11264 {
11265 if (hc_cuEventCreate (hashcat_ctx, &device_param->cuda_event1, CU_EVENT_BLOCKING_SYNC) == -1)
11266 {
11267 device_param->skipped = true;
11268 continue;
11269 }
11270
11271 if (hc_cuEventCreate (hashcat_ctx, &device_param->cuda_event2, CU_EVENT_BLOCKING_SYNC) == -1)
11272 {
11273 device_param->skipped = true;
11274 continue;
11275 }
11276
11277 if (hc_cuEventCreate (hashcat_ctx, &device_param->cuda_event3, CU_EVENT_DISABLE_TIMING) == -1)
11278 {
11279 device_param->skipped = true;
11280 continue;
11281 }
11282 }
11283
11284 /**
11285 * create events for HIP devices
11286 */
11287
11288 if (device_param->is_hip == true)
11289 {
11290 if (hc_hipEventCreate (hashcat_ctx, &device_param->hip_event1, hipEventBlockingSync) == -1)
11291 {
11292 device_param->skipped = true;
11293 continue;
11294 }
11295
11296 if (hc_hipEventCreate (hashcat_ctx, &device_param->hip_event2, hipEventBlockingSync) == -1)
11297 {
11298 device_param->skipped = true;
11299 continue;
11300 }
11301
11302 if (hc_hipEventCreate (hashcat_ctx, &device_param->hip_event3, hipEventDisableTiming) == -1)
11303 {
11304 device_param->skipped = true;
11305 continue;
11306 }
11307 }
11308
11309 /**
11310 * create input buffers on device : calculate size of fixed memory buffers
11311 */
11312
11313 u64 size_root_css = SP_PW_MAX * sizeof (cs_t);
11314 u64 size_markov_css = SP_PW_MAX * CHARSIZ * sizeof (cs_t);
11315
11316 device_param->size_root_css = size_root_css;
11317 device_param->size_markov_css = size_markov_css;
11318
11319 u64 size_results = sizeof (u32);
11320
11321 device_param->size_results = size_results;
11322
11323 u64 size_rules = (u64) straight_ctx->kernel_rules_cnt * sizeof (kernel_rule_t);
11324 u64 size_rules_c = (u64) KERNEL_RULES * sizeof (kernel_rule_t);
11325
11326 device_param->size_rules = size_rules;
11327 device_param->size_rules_c = size_rules_c;
11328
11329 u64 size_plains = (u64) hashes->digests_cnt * sizeof (plain_t);
11330 u64 size_salts = (u64) hashes->salts_cnt * sizeof (salt_t);
11331 u64 size_esalts = (u64) hashes->digests_cnt * hashconfig->esalt_size;
11332 u64 size_shown = (u64) hashes->digests_cnt * sizeof (u32);
11333 u64 size_digests = (u64) hashes->digests_cnt * (u64) hashconfig->dgst_size;
11334
11335 device_param->size_plains = size_plains;
11336 device_param->size_digests = size_digests;
11337 device_param->size_shown = size_shown;
11338 device_param->size_salts = size_salts;
11339 device_param->size_esalts = size_esalts;
11340
11341 u64 size_combs = KERNEL_COMBS * sizeof (pw_t);
11342 u64 size_bfs = KERNEL_BFS * sizeof (bf_t);
11343 u64 size_tm = 32 * sizeof (bs_word_t);
11344
11345 device_param->size_bfs = size_bfs;
11346 device_param->size_combs = size_combs;
11347 device_param->size_tm = size_tm;
11348
11349 u64 size_st_digests = 1 * hashconfig->dgst_size;
11350 u64 size_st_salts = 1 * sizeof (salt_t);
11351 u64 size_st_esalts = 1 * hashconfig->esalt_size;
11352
11353 device_param->size_st_digests = size_st_digests;
11354 device_param->size_st_salts = size_st_salts;
11355 device_param->size_st_esalts = size_st_esalts;
11356
11357 // extra buffer
11358
11359 u64 size_extra_buffer = 4;
11360
11361 if (module_ctx->module_extra_buffer_size != MODULE_DEFAULT)
11362 {
11363 const u64 extra_buffer_size = module_ctx->module_extra_buffer_size (hashconfig, user_options, user_options_extra, hashes, device_param);
11364
11365 if (extra_buffer_size == (u64) -1)
11366 {
11367 event_log_error (hashcat_ctx, "Invalid extra buffer size.");
11368
11369 device_param->skipped = true;
11370 continue;
11371 }
11372
11373 device_param->extra_buffer_size = extra_buffer_size;
11374
11375 // for the size we actually allocate we need to cheat a bit in order to make it more easy for plugin developer.
11376 //
11377 // we will divide this size by 4 to workaround opencl limitation.
11378 // this collides with a theoretical scenario (like -n1 -T1) where there's only one workitem,
11379 // because inside the kernel the target buffer is selected by workitem_id / 4.
11380 // but the maximum size of the buffer would be only 1/4 of what is needed -> overflow.
11381 //
11382 // to workaround this we make sure that there's always a full buffer in each of the 4 allocated buffers available.
11383
11384 const u64 kernel_power_max = ((hashconfig->opts_type & OPTS_TYPE_MP_MULTI_DISABLE) ? 1 : device_param->device_processors) * device_param->kernel_threads_max * device_param->kernel_accel_max;
11385
11386 const u64 extra_buffer_size_one = extra_buffer_size / kernel_power_max;
11387
11388 size_extra_buffer = extra_buffer_size + (extra_buffer_size_one * 4);
11389 }
11390
11391 // kern type
11392
11393 u32 kern_type = hashconfig->kern_type;
11394
11395 if (module_ctx->module_kern_type_dynamic != MODULE_DEFAULT)
11396 {
11397 if (user_options->benchmark == true)
11398 {
11399 }
11400 else
11401 {
11402 void *digests_buf = hashes->digests_buf;
11403 salt_t *salts_buf = hashes->salts_buf;
11404 void *esalts_buf = hashes->esalts_buf;
11405 void *hook_salts_buf = hashes->hook_salts_buf;
11406 hashinfo_t **hash_info = hashes->hash_info;
11407
11408 hashinfo_t *hash_info_ptr = NULL;
11409
11410 if (hash_info) hash_info_ptr = hash_info[0];
11411
11412 kern_type = (u32) module_ctx->module_kern_type_dynamic (hashconfig, digests_buf, salts_buf, esalts_buf, hook_salts_buf, hash_info_ptr);
11413 }
11414 }
11415
11416 // built options
11417
11418 const size_t build_options_sz = 4096;
11419
11420 char *build_options_buf = (char *) hcmalloc (build_options_sz);
11421
11422 int build_options_len = 0;
11423
11424 if ((device_param->is_cuda == true) || (device_param->is_hip == true))
11425 {
11426 // using a path with a space will break nvrtc_make_options_array_from_string()
11427 // we add it to options array in a clean way later
11428
11429 build_options_len += snprintf (build_options_buf + build_options_len, build_options_sz - build_options_len, "-D KERNEL_STATIC -I OpenCL ");
11430 }
11431 else
11432 {
11433 if (device_param->opencl_platform_vendor_id == VENDOR_ID_POCL)
11434 {
11435 // POCL doesn't like quotes in the include path, see:
11436 // https://github.com/hashcat/hashcat/issues/2950
11437 // Maybe related:
11438 // https://github.com/pocl/pocl/issues/962
11439
11440 build_options_len += snprintf (build_options_buf + build_options_len, build_options_sz - build_options_len, "-D KERNEL_STATIC -I OpenCL -I %s ", folder_config->cpath_real);
11441 }
11442 else
11443 {
11444 build_options_len += snprintf (build_options_buf + build_options_len, build_options_sz - build_options_len, "-D KERNEL_STATIC -I OpenCL -I \"%s\" ", folder_config->cpath_real);
11445 }
11446 }
11447
11448 /* currently disabled, hangs NEO drivers since 20.09.
11449 was required for NEO driver 20.08 to workaround the same issue!
11450 we go with the latest version
11451
11452 if (device_param->is_opencl == true)
11453 {
11454 if (device_param->use_opencl12 == true)
11455 {
11456 build_options_len += snprintf (build_options_buf + build_options_len, build_options_sz - build_options_len, "-cl-std=CL1.2 ");
11457 }
11458 else if (device_param->use_opencl20 == true)
11459 {
11460 build_options_len += snprintf (build_options_buf + build_options_len, build_options_sz - build_options_len, "-cl-std=CL2.0 ");
11461 }
11462 else if (device_param->use_opencl21 == true)
11463 {
11464 build_options_len += snprintf (build_options_buf + build_options_len, build_options_sz - build_options_len, "-cl-std=CL2.1 ");
11465 }
11466 }
11467 */
11468
11469 // we don't have sm_* on vendors not NV but it doesn't matter
11470
11471 #if defined (DEBUG)
11472 build_options_len += snprintf (build_options_buf + build_options_len, build_options_sz - build_options_len, "-D LOCAL_MEM_TYPE=%d -D VENDOR_ID=%u -D CUDA_ARCH=%u -D HAS_ADD=%u -D HAS_ADDC=%u -D HAS_SUB=%u -D HAS_SUBC=%u -D HAS_VADD=%u -D HAS_VADDC=%u -D HAS_VADD_CO=%u -D HAS_VADDC_CO=%u -D HAS_VSUB=%u -D HAS_VSUBB=%u -D HAS_VSUB_CO=%u -D HAS_VSUBB_CO=%u -D HAS_VPERM=%u -D HAS_VADD3=%u -D HAS_VBFE=%u -D HAS_BFE=%u -D HAS_LOP3=%u -D HAS_MOV64=%u -D HAS_PRMT=%u -D VECT_SIZE=%d -D DEVICE_TYPE=%u -D DGST_R0=%u -D DGST_R1=%u -D DGST_R2=%u -D DGST_R3=%u -D DGST_ELEM=%u -D KERN_TYPE=%u -D ATTACK_EXEC=%u -D ATTACK_KERN=%u -D ATTACK_MODE=%u ", device_param->device_local_mem_type, device_param->opencl_platform_vendor_id, (device_param->sm_major * 100) + (device_param->sm_minor * 10), device_param->has_add, device_param->has_addc, device_param->has_sub, device_param->has_subc, device_param->has_vadd, device_param->has_vaddc, device_param->has_vadd_co, device_param->has_vaddc_co, device_param->has_vsub, device_param->has_vsubb, device_param->has_vsub_co, device_param->has_vsubb_co, device_param->has_vperm, device_param->has_vadd3, device_param->has_vbfe, device_param->has_bfe, device_param->has_lop3, device_param->has_mov64, device_param->has_prmt, device_param->vector_width, (u32) device_param->opencl_device_type, hashconfig->dgst_pos0, hashconfig->dgst_pos1, hashconfig->dgst_pos2, hashconfig->dgst_pos3, hashconfig->dgst_size / 4, kern_type, hashconfig->attack_exec, user_options_extra->attack_kern, user_options->attack_mode);
11473 #else
11474 build_options_len += snprintf (build_options_buf + build_options_len, build_options_sz - build_options_len, "-D LOCAL_MEM_TYPE=%d -D VENDOR_ID=%u -D CUDA_ARCH=%u -D HAS_ADD=%u -D HAS_ADDC=%u -D HAS_SUB=%u -D HAS_SUBC=%u -D HAS_VADD=%u -D HAS_VADDC=%u -D HAS_VADD_CO=%u -D HAS_VADDC_CO=%u -D HAS_VSUB=%u -D HAS_VSUBB=%u -D HAS_VSUB_CO=%u -D HAS_VSUBB_CO=%u -D HAS_VPERM=%u -D HAS_VADD3=%u -D HAS_VBFE=%u -D HAS_BFE=%u -D HAS_LOP3=%u -D HAS_MOV64=%u -D HAS_PRMT=%u -D VECT_SIZE=%d -D DEVICE_TYPE=%u -D DGST_R0=%u -D DGST_R1=%u -D DGST_R2=%u -D DGST_R3=%u -D DGST_ELEM=%u -D KERN_TYPE=%u -D ATTACK_EXEC=%u -D ATTACK_KERN=%u -D ATTACK_MODE=%u -w ", device_param->device_local_mem_type, device_param->opencl_platform_vendor_id, (device_param->sm_major * 100) + (device_param->sm_minor * 10), device_param->has_add, device_param->has_addc, device_param->has_sub, device_param->has_subc, device_param->has_vadd, device_param->has_vaddc, device_param->has_vadd_co, device_param->has_vaddc_co, device_param->has_vsub, device_param->has_vsubb, device_param->has_vsub_co, device_param->has_vsubb_co, device_param->has_vperm, device_param->has_vadd3, device_param->has_vbfe, device_param->has_bfe, device_param->has_lop3, device_param->has_mov64, device_param->has_prmt, device_param->vector_width, (u32) device_param->opencl_device_type, hashconfig->dgst_pos0, hashconfig->dgst_pos1, hashconfig->dgst_pos2, hashconfig->dgst_pos3, hashconfig->dgst_size / 4, kern_type, hashconfig->attack_exec, user_options_extra->attack_kern, user_options->attack_mode);
11475 #endif
11476
11477 build_options_buf[build_options_len] = 0;
11478
11479 /*
11480 if (device_param->opencl_device_type & CL_DEVICE_TYPE_CPU)
11481 {
11482 if (device_param->opencl_platform_vendor_id == VENDOR_ID_INTEL_SDK)
11483 {
11484 strncat (build_options_buf, " -cl-opt-disable", 16);
11485 }
11486 }
11487 */
11488
11489 #if defined (DEBUG)
11490 if (user_options->quiet == false) event_log_warning (hashcat_ctx, "* Device #%u: build_options '%s'", device_id + 1, build_options_buf);
11491 #endif
11492
11493 /**
11494 * device_name_chksum_amp_mp
11495 */
11496
11497 char device_name_chksum_amp_mp[HCBUFSIZ_TINY] = { 0 };
11498
11499 const size_t dnclen_amp_mp = snprintf (device_name_chksum_amp_mp, HCBUFSIZ_TINY, "%d-%d-%d-%d-%u-%s-%s-%s-%u",
11500 backend_ctx->comptime,
11501 backend_ctx->cuda_driver_version,
11502 backend_ctx->hip_runtimeVersion,
11503 device_param->is_opencl,
11504 device_param->opencl_platform_vendor_id,
11505 device_param->device_name,
11506 device_param->opencl_device_version,
11507 device_param->opencl_driver_version,
11508 (user_options->kernel_threads_chgd == true) ? user_options->kernel_threads : device_param->kernel_threads_max);
11509
11510 md5_ctx_t md5_ctx;
11511
11512 md5_init (&md5_ctx);
11513 md5_update (&md5_ctx, (u32 *) device_name_chksum_amp_mp, dnclen_amp_mp);
11514 md5_final (&md5_ctx);
11515
11516 snprintf (device_name_chksum_amp_mp, HCBUFSIZ_TINY, "%08x", md5_ctx.h[0]);
11517
11518 /**
11519 * kernel cache
11520 */
11521
11522 bool cache_disable = false;
11523
11524 // Seems to be completely broken on Apple + (Intel?) CPU
11525 // To reproduce set cache_disable to false and run benchmark -b
11526
11527 if (device_param->opencl_platform_vendor_id == VENDOR_ID_APPLE)
11528 {
11529 if (device_param->opencl_device_type & CL_DEVICE_TYPE_CPU)
11530 {
11531 cache_disable = true;
11532 }
11533 }
11534
11535 if (module_ctx->module_jit_cache_disable != MODULE_DEFAULT)
11536 {
11537 cache_disable = module_ctx->module_jit_cache_disable (hashconfig, user_options, user_options_extra, hashes, device_param);
11538 }
11539
11540 #if defined (DEBUG)
11541 // https://github.com/hashcat/hashcat/issues/2750
11542 cache_disable = true;
11543 #endif
11544
11545 /**
11546 * shared kernel with no hashconfig dependencies
11547 */
11548
11549 {
11550 /**
11551 * kernel shared source filename
11552 */
11553
11554 char source_file[256] = { 0 };
11555
11556 generate_source_kernel_shared_filename (folder_config->shared_dir, source_file);
11557
11558 if (hc_path_read (source_file) == false)
11559 {
11560 event_log_error (hashcat_ctx, "%s: %s", source_file, strerror (errno));
11561
11562 return -1;
11563 }
11564
11565 /**
11566 * kernel shared cached filename
11567 */
11568
11569 char cached_file[256] = { 0 };
11570
11571 generate_cached_kernel_shared_filename (folder_config->cache_dir, device_name_chksum_amp_mp, cached_file);
11572
11573 const bool rc_load_kernel = load_kernel (hashcat_ctx, device_param, "shared_kernel", source_file, cached_file, build_options_buf, cache_disable, &device_param->opencl_program_shared, &device_param->cuda_module_shared, &device_param->hip_module_shared);
11574
11575 if (rc_load_kernel == false)
11576 {
11577 event_log_error (hashcat_ctx, "* Device #%u: Kernel %s build failed.", device_param->device_id + 1, source_file);
11578
11579 return -1;
11580 }
11581
11582 if (device_param->is_cuda == true)
11583 {
11584 // GPU memset
11585
11586 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function_memset, device_param->cuda_module_shared, "gpu_memset") == -1) return -1;
11587
11588 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function_memset, &device_param->kernel_wgs_memset) == -1) return -1;
11589
11590 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function_memset, &device_param->kernel_local_mem_size_memset) == -1) return -1;
11591
11592 device_param->kernel_dynamic_local_mem_size_memset = device_param->device_local_mem_size - device_param->kernel_local_mem_size_memset;
11593
11594 device_param->kernel_preferred_wgs_multiple_memset = device_param->cuda_warp_size;
11595
11596 // GPU bzero
11597
11598 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function_bzero, device_param->cuda_module_shared, "gpu_bzero") == -1) return -1;
11599
11600 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function_bzero, &device_param->kernel_wgs_bzero) == -1) return -1;
11601
11602 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function_bzero, &device_param->kernel_local_mem_size_bzero) == -1) return -1;
11603
11604 device_param->kernel_dynamic_local_mem_size_bzero = device_param->device_local_mem_size - device_param->kernel_local_mem_size_bzero;
11605
11606 device_param->kernel_preferred_wgs_multiple_bzero = device_param->cuda_warp_size;
11607
11608 // GPU autotune init
11609
11610 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function_atinit, device_param->cuda_module_shared, "gpu_atinit") == -1) return -1;
11611
11612 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function_atinit, &device_param->kernel_wgs_atinit) == -1) return -1;
11613
11614 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function_atinit, &device_param->kernel_local_mem_size_atinit) == -1) return -1;
11615
11616 device_param->kernel_dynamic_local_mem_size_atinit = device_param->device_local_mem_size - device_param->kernel_local_mem_size_atinit;
11617
11618 device_param->kernel_preferred_wgs_multiple_atinit = device_param->cuda_warp_size;
11619
11620 // CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_atinit, 0, sizeof (cl_mem), device_param->kernel_params_atinit[0]); if (CL_rc == -1) return -1;
11621 // CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_atinit, 1, sizeof (cl_ulong), device_param->kernel_params_atinit[1]); if (CL_rc == -1) return -1;
11622
11623 // GPU decompress
11624
11625 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function_decompress, device_param->cuda_module_shared, "gpu_decompress") == -1) return -1;
11626
11627 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function_decompress, &device_param->kernel_wgs_decompress) == -1) return -1;
11628
11629 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function_decompress, &device_param->kernel_local_mem_size_decompress) == -1) return -1;
11630
11631 device_param->kernel_dynamic_local_mem_size_decompress = device_param->device_local_mem_size - device_param->kernel_local_mem_size_decompress;
11632
11633 device_param->kernel_preferred_wgs_multiple_decompress = device_param->cuda_warp_size;
11634
11635 // GPU utf8 to utf16le conversion
11636
11637 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function_utf8toutf16le, device_param->cuda_module_shared, "gpu_utf8_to_utf16") == -1) return -1;
11638
11639 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function_utf8toutf16le, &device_param->kernel_wgs_utf8toutf16le) == -1) return -1;
11640
11641 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function_utf8toutf16le, &device_param->kernel_local_mem_size_utf8toutf16le) == -1) return -1;
11642
11643 device_param->kernel_dynamic_local_mem_size_utf8toutf16le = device_param->device_local_mem_size - device_param->kernel_local_mem_size_utf8toutf16le;
11644
11645 device_param->kernel_preferred_wgs_multiple_utf8toutf16le = device_param->cuda_warp_size;
11646 }
11647
11648 if (device_param->is_hip == true)
11649 {
11650 // GPU memset
11651
11652 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function_memset, device_param->hip_module_shared, "gpu_memset") == -1) return -1;
11653
11654 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function_memset, &device_param->kernel_wgs_memset) == -1) return -1;
11655
11656 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function_memset, &device_param->kernel_local_mem_size_memset) == -1) return -1;
11657
11658 device_param->kernel_dynamic_local_mem_size_memset = device_param->device_local_mem_size - device_param->kernel_local_mem_size_memset;
11659
11660 device_param->kernel_preferred_wgs_multiple_memset = device_param->hip_warp_size;
11661
11662 // GPU bzero
11663
11664 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function_bzero, device_param->hip_module_shared, "gpu_bzero") == -1) return -1;
11665
11666 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function_bzero, &device_param->kernel_wgs_bzero) == -1) return -1;
11667
11668 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function_bzero, &device_param->kernel_local_mem_size_bzero) == -1) return -1;
11669
11670 device_param->kernel_dynamic_local_mem_size_bzero = device_param->device_local_mem_size - device_param->kernel_local_mem_size_bzero;
11671
11672 device_param->kernel_preferred_wgs_multiple_bzero = device_param->hip_warp_size;
11673
11674 // GPU autotune init
11675
11676 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function_atinit, device_param->hip_module_shared, "gpu_atinit") == -1) return -1;
11677
11678 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function_atinit, &device_param->kernel_wgs_atinit) == -1) return -1;
11679
11680 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function_atinit, &device_param->kernel_local_mem_size_atinit) == -1) return -1;
11681
11682 device_param->kernel_dynamic_local_mem_size_atinit = device_param->device_local_mem_size - device_param->kernel_local_mem_size_atinit;
11683
11684 device_param->kernel_preferred_wgs_multiple_atinit = device_param->hip_warp_size;
11685
11686 // CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_atinit, 0, sizeof (cl_mem), device_param->kernel_params_atinit[0]); if (CL_rc == -1) return -1;
11687 // CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_atinit, 1, sizeof (cl_ulong), device_param->kernel_params_atinit[1]); if (CL_rc == -1) return -1;
11688
11689 // GPU decompress
11690
11691 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function_decompress, device_param->hip_module_shared, "gpu_decompress") == -1) return -1;
11692
11693 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function_decompress, &device_param->kernel_wgs_decompress) == -1) return -1;
11694
11695 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function_decompress, &device_param->kernel_local_mem_size_decompress) == -1) return -1;
11696
11697 device_param->kernel_dynamic_local_mem_size_decompress = device_param->device_local_mem_size - device_param->kernel_local_mem_size_decompress;
11698
11699 device_param->kernel_preferred_wgs_multiple_decompress = device_param->hip_warp_size;
11700
11701 // GPU utf8 to utf16le conversion
11702
11703 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function_utf8toutf16le, device_param->hip_module_shared, "gpu_utf8_to_utf16") == -1) return -1;
11704
11705 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function_utf8toutf16le, &device_param->kernel_wgs_utf8toutf16le) == -1) return -1;
11706
11707 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function_utf8toutf16le, &device_param->kernel_local_mem_size_utf8toutf16le) == -1) return -1;
11708
11709 device_param->kernel_dynamic_local_mem_size_utf8toutf16le = device_param->device_local_mem_size - device_param->kernel_local_mem_size_utf8toutf16le;
11710
11711 device_param->kernel_preferred_wgs_multiple_utf8toutf16le = device_param->hip_warp_size;
11712 }
11713
11714 if (device_param->is_opencl == true)
11715 {
11716 // GPU memset
11717
11718 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program_shared, "gpu_memset", &device_param->opencl_kernel_memset) == -1) return -1;
11719
11720 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel_memset, &device_param->kernel_wgs_memset) == -1) return -1;
11721
11722 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_memset, &device_param->kernel_local_mem_size_memset) == -1) return -1;
11723
11724 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_memset, &device_param->kernel_dynamic_local_mem_size_memset) == -1) return -1;
11725
11726 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel_memset, &device_param->kernel_preferred_wgs_multiple_memset) == -1) return -1;
11727
11728 // GPU bzero
11729
11730 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program_shared, "gpu_bzero", &device_param->opencl_kernel_bzero) == -1) return -1;
11731
11732 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel_bzero, &device_param->kernel_wgs_bzero) == -1) return -1;
11733
11734 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_bzero, &device_param->kernel_local_mem_size_bzero) == -1) return -1;
11735
11736 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_bzero, &device_param->kernel_dynamic_local_mem_size_bzero) == -1) return -1;
11737
11738 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel_bzero, &device_param->kernel_preferred_wgs_multiple_bzero) == -1) return -1;
11739
11740 // apple hack, but perhaps also an alternative for other vendors
11741
11742 if (device_param->kernel_preferred_wgs_multiple == 0) device_param->kernel_preferred_wgs_multiple = device_param->kernel_preferred_wgs_multiple_bzero;
11743
11744 // GPU autotune init
11745
11746 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program_shared, "gpu_atinit", &device_param->opencl_kernel_atinit) == -1) return -1;
11747
11748 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel_atinit, &device_param->kernel_wgs_atinit) == -1) return -1;
11749
11750 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_atinit, &device_param->kernel_local_mem_size_atinit) == -1) return -1;
11751
11752 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_atinit, &device_param->kernel_dynamic_local_mem_size_atinit) == -1) return -1;
11753
11754 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel_atinit, &device_param->kernel_preferred_wgs_multiple_atinit) == -1) return -1;
11755
11756 // GPU decompress
11757
11758 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program_shared, "gpu_decompress", &device_param->opencl_kernel_decompress) == -1) return -1;
11759
11760 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel_decompress, &device_param->kernel_wgs_decompress) == -1) return -1;
11761
11762 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_decompress, &device_param->kernel_local_mem_size_decompress) == -1) return -1;
11763
11764 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_decompress, &device_param->kernel_dynamic_local_mem_size_decompress) == -1) return -1;
11765
11766 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel_decompress, &device_param->kernel_preferred_wgs_multiple_decompress) == -1) return -1;
11767
11768 // GPU utf8 to utf16le conversion
11769
11770 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program_shared, "gpu_utf8_to_utf16", &device_param->opencl_kernel_utf8toutf16le) == -1) return -1;
11771
11772 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel_utf8toutf16le, &device_param->kernel_wgs_utf8toutf16le) == -1) return -1;
11773
11774 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_utf8toutf16le, &device_param->kernel_local_mem_size_utf8toutf16le) == -1) return -1;
11775
11776 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_utf8toutf16le, &device_param->kernel_dynamic_local_mem_size_utf8toutf16le) == -1) return -1;
11777
11778 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel_utf8toutf16le, &device_param->kernel_preferred_wgs_multiple_utf8toutf16le) == -1) return -1;
11779 }
11780 }
11781
11782 /**
11783 * main kernel
11784 */
11785
11786 {
11787 char *build_options_module_buf = (char *) hcmalloc (build_options_sz);
11788
11789 int build_options_module_len = 0;
11790
11791 build_options_module_len += snprintf (build_options_module_buf + build_options_module_len, build_options_sz - build_options_module_len, "%s ", build_options_buf);
11792
11793 if (module_ctx->module_jit_build_options != MODULE_DEFAULT)
11794 {
11795 char *jit_build_options = module_ctx->module_jit_build_options (hashconfig, user_options, user_options_extra, hashes, device_param);
11796
11797 if (jit_build_options != NULL)
11798 {
11799 build_options_module_len += snprintf (build_options_module_buf + build_options_module_len, build_options_sz - build_options_module_len, "%s", jit_build_options);
11800
11801 // this is a bit ugly
11802 // would be better to have the module return the value as value
11803
11804 u32 fixed_local_size = 0;
11805
11806 if (sscanf (jit_build_options, "-D FIXED_LOCAL_SIZE=%u", &fixed_local_size) == 1)
11807 {
11808 device_param->kernel_threads_min = fixed_local_size;
11809 device_param->kernel_threads_max = fixed_local_size;
11810 }
11811 else
11812 {
11813 // kernels specific minimum needs to be set so that self-test wont fail
11814
11815 if (sscanf (jit_build_options, "-D FIXED_LOCAL_SIZE_COMP=%u", &fixed_local_size) == 1)
11816 {
11817 device_param->kernel_threads_min = fixed_local_size;
11818 // device_param->kernel_threads_max = fixed_local_size;
11819 }
11820 }
11821 }
11822 }
11823
11824 build_options_module_buf[build_options_module_len] = 0;
11825
11826 #if defined (DEBUG)
11827 if (user_options->quiet == false) event_log_warning (hashcat_ctx, "* Device #%u: build_options_module '%s'", device_id + 1, build_options_module_buf);
11828 #endif
11829
11830 /**
11831 * device_name_chksum
11832 */
11833
11834 char device_name_chksum[HCBUFSIZ_TINY] = { 0 };
11835
11836 // The kernel source can depend on some JiT compiler macros which themself depend on the attack_modes.
11837 // ATM this is relevant only for ATTACK_MODE_ASSOCIATION which slightly modifies ATTACK_MODE_STRAIGHT kernels.
11838
11839 const u32 extra_value = (user_options->attack_mode == ATTACK_MODE_ASSOCIATION) ? ATTACK_MODE_ASSOCIATION : ATTACK_MODE_NONE;
11840
11841 const size_t dnclen = snprintf (device_name_chksum, HCBUFSIZ_TINY, "%d-%d-%d-%d-%u-%s-%s-%s-%d-%u-%u-%u-%s",
11842 backend_ctx->comptime,
11843 backend_ctx->cuda_driver_version,
11844 backend_ctx->hip_runtimeVersion,
11845 device_param->is_opencl,
11846 device_param->opencl_platform_vendor_id,
11847 device_param->device_name,
11848 device_param->opencl_device_version,
11849 device_param->opencl_driver_version,
11850 device_param->vector_width,
11851 hashconfig->kern_type,
11852 extra_value,
11853 (user_options->kernel_threads_chgd == true) ? user_options->kernel_threads : device_param->kernel_threads_max,
11854 build_options_module_buf);
11855
11856 md5_ctx_t md5_ctx;
11857
11858 md5_init (&md5_ctx);
11859 md5_update (&md5_ctx, (u32 *) device_name_chksum, dnclen);
11860 md5_final (&md5_ctx);
11861
11862 snprintf (device_name_chksum, HCBUFSIZ_TINY, "%08x", md5_ctx.h[0]);
11863
11864 /**
11865 * kernel source filename
11866 */
11867
11868 char source_file[256] = { 0 };
11869
11870 generate_source_kernel_filename (user_options->slow_candidates, hashconfig->attack_exec, user_options_extra->attack_kern, kern_type, hashconfig->opti_type, folder_config->shared_dir, source_file);
11871
11872 if (hc_path_read (source_file) == false)
11873 {
11874 event_log_error (hashcat_ctx, "%s: %s", source_file, strerror (errno));
11875
11876 return -1;
11877 }
11878
11879 /**
11880 * kernel cached filename
11881 */
11882
11883 char cached_file[256] = { 0 };
11884
11885 generate_cached_kernel_filename (user_options->slow_candidates, hashconfig->attack_exec, user_options_extra->attack_kern, kern_type, hashconfig->opti_type, folder_config->cache_dir, device_name_chksum, cached_file);
11886
11887 /**
11888 * load kernel
11889 */
11890
11891 const bool rc_load_kernel = load_kernel (hashcat_ctx, device_param, "main_kernel", source_file, cached_file, build_options_module_buf, cache_disable, &device_param->opencl_program, &device_param->cuda_module, &device_param->hip_module);
11892
11893 if (rc_load_kernel == false)
11894 {
11895 event_log_error (hashcat_ctx, "* Device #%u: Kernel %s build failed.", device_param->device_id + 1, source_file);
11896
11897 return -1;
11898 }
11899
11900 hcfree (build_options_module_buf);
11901 }
11902
11903 /**
11904 * word generator kernel
11905 */
11906
11907 if (user_options->slow_candidates == true)
11908 {
11909 }
11910 else
11911 {
11912 if ((user_options->attack_mode != ATTACK_MODE_STRAIGHT) && (user_options->attack_mode != ATTACK_MODE_ASSOCIATION))
11913 {
11914 /**
11915 * kernel mp source filename
11916 */
11917
11918 char source_file[256] = { 0 };
11919
11920 generate_source_kernel_mp_filename (hashconfig->opti_type, hashconfig->opts_type, folder_config->shared_dir, source_file);
11921
11922 if (hc_path_read (source_file) == false)
11923 {
11924 event_log_error (hashcat_ctx, "%s: %s", source_file, strerror (errno));
11925
11926 return -1;
11927 }
11928
11929 /**
11930 * kernel mp cached filename
11931 */
11932
11933 char cached_file[256] = { 0 };
11934
11935 generate_cached_kernel_mp_filename (hashconfig->opti_type, hashconfig->opts_type, folder_config->cache_dir, device_name_chksum_amp_mp, cached_file);
11936
11937 const bool rc_load_kernel = load_kernel (hashcat_ctx, device_param, "mp_kernel", source_file, cached_file, build_options_buf, cache_disable, &device_param->opencl_program_mp, &device_param->cuda_module_mp, &device_param->hip_module_mp);
11938
11939 if (rc_load_kernel == false)
11940 {
11941 event_log_error (hashcat_ctx, "* Device #%u: Kernel %s build failed.", device_param->device_id + 1, source_file);
11942
11943 return -1;
11944 }
11945 }
11946 }
11947
11948 /**
11949 * amplifier kernel
11950 */
11951
11952 if (user_options->slow_candidates == true)
11953 {
11954 }
11955 else
11956 {
11957 if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
11958 {
11959
11960 }
11961 else
11962 {
11963 /**
11964 * kernel amp source filename
11965 */
11966
11967 char source_file[256] = { 0 };
11968
11969 generate_source_kernel_amp_filename (user_options_extra->attack_kern, folder_config->shared_dir, source_file);
11970
11971 if (hc_path_read (source_file) == false)
11972 {
11973 event_log_error (hashcat_ctx, "%s: %s", source_file, strerror (errno));
11974
11975 return -1;
11976 }
11977
11978 /**
11979 * kernel amp cached filename
11980 */
11981
11982 char cached_file[256] = { 0 };
11983
11984 generate_cached_kernel_amp_filename (user_options_extra->attack_kern, folder_config->cache_dir, device_name_chksum_amp_mp, cached_file);
11985
11986 const bool rc_load_kernel = load_kernel (hashcat_ctx, device_param, "amp_kernel", source_file, cached_file, build_options_buf, cache_disable, &device_param->opencl_program_amp, &device_param->cuda_module_amp, &device_param->hip_module_amp);
11987
11988 if (rc_load_kernel == false)
11989 {
11990 event_log_error (hashcat_ctx, "* Device #%u: Kernel %s build failed.", device_param->device_id + 1, source_file);
11991
11992 return -1;
11993 }
11994
11995 hcfree (build_options_buf);
11996 }
11997 }
11998
11999 /**
12000 * no more need for the compiler. cuda doesn't offer this function.
12001 * from opencl specs:
12002 * Calls to clBuildProgram, clCompileProgram or clLinkProgram after clUnloadPlatformCompiler will reload the compiler, if necessary, to build the appropriate program executable.
12003 */
12004 // Disabled after user reporting weird errors like CL_OUT_OF_HOST_MEMORY after calling
12005 /*
12006 if (device_param->is_opencl == true)
12007 {
12008 cl_platform_id platform_id = backend_ctx->opencl_platforms[device_param->opencl_platform_id];
12009
12010 if (hc_clUnloadPlatformCompiler (hashcat_ctx, platform_id) == -1) return -1;
12011 }
12012 */
12013
12014 // some algorithm collide too fast, make that impossible
12015
12016 if (user_options->benchmark == true)
12017 {
12018 ((u32 *) hashes->digests_buf)[0] = -1U;
12019 ((u32 *) hashes->digests_buf)[1] = -1U;
12020 ((u32 *) hashes->digests_buf)[2] = -1U;
12021 ((u32 *) hashes->digests_buf)[3] = -1U;
12022 }
12023
12024 /**
12025 * global buffers
12026 */
12027
12028 const u64 size_total_fixed
12029 = bitmap_ctx->bitmap_size
12030 + bitmap_ctx->bitmap_size
12031 + bitmap_ctx->bitmap_size
12032 + bitmap_ctx->bitmap_size
12033 + bitmap_ctx->bitmap_size
12034 + bitmap_ctx->bitmap_size
12035 + bitmap_ctx->bitmap_size
12036 + bitmap_ctx->bitmap_size
12037 + size_plains
12038 + size_digests
12039 + size_shown
12040 + size_salts
12041 + size_results
12042 + size_extra_buffer
12043 + size_st_digests
12044 + size_st_salts
12045 + size_st_esalts
12046 + size_esalts
12047 + size_markov_css
12048 + size_root_css
12049 + size_rules
12050 + size_rules_c
12051 + size_tm;
12052
12053 if (size_total_fixed > device_param->device_available_mem)
12054 {
12055 event_log_error (hashcat_ctx, "* Device #%u: Not enough allocatable device memory for this hashlist/ruleset.", device_id + 1);
12056
12057 return -1;
12058 }
12059
12060 if (device_param->is_cuda == true)
12061 {
12062 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_bitmap_s1_a, bitmap_ctx->bitmap_size) == -1) return -1;
12063 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_bitmap_s1_b, bitmap_ctx->bitmap_size) == -1) return -1;
12064 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_bitmap_s1_c, bitmap_ctx->bitmap_size) == -1) return -1;
12065 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_bitmap_s1_d, bitmap_ctx->bitmap_size) == -1) return -1;
12066 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_bitmap_s2_a, bitmap_ctx->bitmap_size) == -1) return -1;
12067 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_bitmap_s2_b, bitmap_ctx->bitmap_size) == -1) return -1;
12068 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_bitmap_s2_c, bitmap_ctx->bitmap_size) == -1) return -1;
12069 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_bitmap_s2_d, bitmap_ctx->bitmap_size) == -1) return -1;
12070 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_plain_bufs, size_plains) == -1) return -1;
12071 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_digests_buf, size_digests) == -1) return -1;
12072 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_digests_shown, size_shown) == -1) return -1;
12073 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_salt_bufs, size_salts) == -1) return -1;
12074 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_result, size_results) == -1) return -1;
12075 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_extra0_buf, size_extra_buffer / 4) == -1) return -1;
12076 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_extra1_buf, size_extra_buffer / 4) == -1) return -1;
12077 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_extra2_buf, size_extra_buffer / 4) == -1) return -1;
12078 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_extra3_buf, size_extra_buffer / 4) == -1) return -1;
12079 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_st_digests_buf, size_st_digests) == -1) return -1;
12080 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_st_salts_buf, size_st_salts) == -1) return -1;
12081
12082 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_bitmap_s1_a, bitmap_ctx->bitmap_s1_a, bitmap_ctx->bitmap_size, device_param->cuda_stream) == -1) return -1;
12083 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_bitmap_s1_b, bitmap_ctx->bitmap_s1_b, bitmap_ctx->bitmap_size, device_param->cuda_stream) == -1) return -1;
12084 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_bitmap_s1_c, bitmap_ctx->bitmap_s1_c, bitmap_ctx->bitmap_size, device_param->cuda_stream) == -1) return -1;
12085 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_bitmap_s1_d, bitmap_ctx->bitmap_s1_d, bitmap_ctx->bitmap_size, device_param->cuda_stream) == -1) return -1;
12086 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_bitmap_s2_a, bitmap_ctx->bitmap_s2_a, bitmap_ctx->bitmap_size, device_param->cuda_stream) == -1) return -1;
12087 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_bitmap_s2_b, bitmap_ctx->bitmap_s2_b, bitmap_ctx->bitmap_size, device_param->cuda_stream) == -1) return -1;
12088 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_bitmap_s2_c, bitmap_ctx->bitmap_s2_c, bitmap_ctx->bitmap_size, device_param->cuda_stream) == -1) return -1;
12089 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_bitmap_s2_d, bitmap_ctx->bitmap_s2_d, bitmap_ctx->bitmap_size, device_param->cuda_stream) == -1) return -1;
12090 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_digests_buf, hashes->digests_buf, size_digests, device_param->cuda_stream) == -1) return -1;
12091 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_salt_bufs, hashes->salts_buf, size_salts, device_param->cuda_stream) == -1) return -1;
12092
12093 /**
12094 * special buffers
12095 */
12096
12097 if (user_options->slow_candidates == true)
12098 {
12099 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_rules_c, size_rules_c) == -1) return -1;
12100 }
12101 else
12102 {
12103 if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT)
12104 {
12105 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_rules, size_rules) == -1) return -1;
12106
12107 if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
12108 {
12109 size_t dummy = 0;
12110
12111 if (hc_cuModuleGetGlobal (hashcat_ctx, &device_param->cuda_d_rules_c, &dummy, device_param->cuda_module, "generic_constant") == -1) return -1;
12112 }
12113 else
12114 {
12115 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_rules_c, size_rules_c) == -1) return -1;
12116 }
12117
12118 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_rules, straight_ctx->kernel_rules_buf, size_rules, device_param->cuda_stream) == -1) return -1;
12119 }
12120 else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI)
12121 {
12122 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_combs, size_combs) == -1) return -1;
12123 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_combs_c, size_combs) == -1) return -1;
12124 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_root_css_buf, size_root_css) == -1) return -1;
12125 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_markov_css_buf, size_markov_css) == -1) return -1;
12126 }
12127 else if (user_options_extra->attack_kern == ATTACK_KERN_BF)
12128 {
12129 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_bfs, size_bfs) == -1) return -1;
12130 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_root_css_buf, size_root_css) == -1) return -1;
12131 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_markov_css_buf, size_markov_css) == -1) return -1;
12132
12133 if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
12134 {
12135 size_t dummy = 0;
12136
12137 if (hc_cuModuleGetGlobal (hashcat_ctx, &device_param->cuda_d_bfs_c, &dummy, device_param->cuda_module, "generic_constant") == -1) return -1;
12138
12139 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_tm_c, size_tm) == -1) return -1;
12140 }
12141 else
12142 {
12143 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_bfs_c, size_bfs) == -1) return -1;
12144 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_tm_c, size_tm) == -1) return -1;
12145 }
12146 }
12147 }
12148
12149 if (size_esalts)
12150 {
12151 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_esalt_bufs, size_esalts) == -1) return -1;
12152
12153 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_esalt_bufs, hashes->esalts_buf, size_esalts, device_param->cuda_stream) == -1) return -1;
12154 }
12155
12156 if (hashconfig->st_hash != NULL)
12157 {
12158 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_st_digests_buf, hashes->st_digests_buf, size_st_digests, device_param->cuda_stream) == -1) return -1;
12159 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_st_salts_buf, hashes->st_salts_buf, size_st_salts, device_param->cuda_stream) == -1) return -1;
12160
12161 if (size_esalts)
12162 {
12163 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_st_esalts_buf, size_st_esalts) == -1) return -1;
12164
12165 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_st_esalts_buf, hashes->st_esalts_buf, size_st_esalts, device_param->cuda_stream) == -1) return -1;
12166 }
12167 }
12168 }
12169
12170 if (device_param->is_hip == true)
12171 {
12172 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_bitmap_s1_a, bitmap_ctx->bitmap_size) == -1) return -1;
12173 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_bitmap_s1_b, bitmap_ctx->bitmap_size) == -1) return -1;
12174 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_bitmap_s1_c, bitmap_ctx->bitmap_size) == -1) return -1;
12175 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_bitmap_s1_d, bitmap_ctx->bitmap_size) == -1) return -1;
12176 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_bitmap_s2_a, bitmap_ctx->bitmap_size) == -1) return -1;
12177 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_bitmap_s2_b, bitmap_ctx->bitmap_size) == -1) return -1;
12178 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_bitmap_s2_c, bitmap_ctx->bitmap_size) == -1) return -1;
12179 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_bitmap_s2_d, bitmap_ctx->bitmap_size) == -1) return -1;
12180 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_plain_bufs, size_plains) == -1) return -1;
12181 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_digests_buf, size_digests) == -1) return -1;
12182 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_digests_shown, size_shown) == -1) return -1;
12183 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_salt_bufs, size_salts) == -1) return -1;
12184 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_result, size_results) == -1) return -1;
12185 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_extra0_buf, size_extra_buffer / 4) == -1) return -1;
12186 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_extra1_buf, size_extra_buffer / 4) == -1) return -1;
12187 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_extra2_buf, size_extra_buffer / 4) == -1) return -1;
12188 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_extra3_buf, size_extra_buffer / 4) == -1) return -1;
12189 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_st_digests_buf, size_st_digests) == -1) return -1;
12190 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_st_salts_buf, size_st_salts) == -1) return -1;
12191
12192 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_bitmap_s1_a, bitmap_ctx->bitmap_s1_a, bitmap_ctx->bitmap_size, device_param->hip_stream) == -1) return -1;
12193 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_bitmap_s1_b, bitmap_ctx->bitmap_s1_b, bitmap_ctx->bitmap_size, device_param->hip_stream) == -1) return -1;
12194 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_bitmap_s1_c, bitmap_ctx->bitmap_s1_c, bitmap_ctx->bitmap_size, device_param->hip_stream) == -1) return -1;
12195 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_bitmap_s1_d, bitmap_ctx->bitmap_s1_d, bitmap_ctx->bitmap_size, device_param->hip_stream) == -1) return -1;
12196 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_bitmap_s2_a, bitmap_ctx->bitmap_s2_a, bitmap_ctx->bitmap_size, device_param->hip_stream) == -1) return -1;
12197 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_bitmap_s2_b, bitmap_ctx->bitmap_s2_b, bitmap_ctx->bitmap_size, device_param->hip_stream) == -1) return -1;
12198 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_bitmap_s2_c, bitmap_ctx->bitmap_s2_c, bitmap_ctx->bitmap_size, device_param->hip_stream) == -1) return -1;
12199 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_bitmap_s2_d, bitmap_ctx->bitmap_s2_d, bitmap_ctx->bitmap_size, device_param->hip_stream) == -1) return -1;
12200 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_digests_buf, hashes->digests_buf, size_digests, device_param->hip_stream) == -1) return -1;
12201 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_salt_bufs, hashes->salts_buf, size_salts, device_param->hip_stream) == -1) return -1;
12202
12203 /**
12204 * special buffers
12205 */
12206
12207 if (user_options->slow_candidates == true)
12208 {
12209 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_rules_c, size_rules_c) == -1) return -1;
12210 }
12211 else
12212 {
12213 if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT)
12214 {
12215 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_rules, size_rules) == -1) return -1;
12216
12217 if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
12218 {
12219 size_t dummy = 0;
12220
12221 if (hc_hipModuleGetGlobal (hashcat_ctx, &device_param->hip_d_rules_c, &dummy, device_param->hip_module, "generic_constant") == -1) return -1;
12222 }
12223 else
12224 {
12225 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_rules_c, size_rules_c) == -1) return -1;
12226 }
12227
12228 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_rules, straight_ctx->kernel_rules_buf, size_rules, device_param->hip_stream) == -1) return -1;
12229 }
12230 else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI)
12231 {
12232 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_combs, size_combs) == -1) return -1;
12233 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_combs_c, size_combs) == -1) return -1;
12234 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_root_css_buf, size_root_css) == -1) return -1;
12235 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_markov_css_buf, size_markov_css) == -1) return -1;
12236 }
12237 else if (user_options_extra->attack_kern == ATTACK_KERN_BF)
12238 {
12239 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_bfs, size_bfs) == -1) return -1;
12240 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_root_css_buf, size_root_css) == -1) return -1;
12241 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_markov_css_buf, size_markov_css) == -1) return -1;
12242
12243 if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
12244 {
12245 size_t dummy = 0;
12246
12247 if (hc_hipModuleGetGlobal (hashcat_ctx, &device_param->hip_d_bfs_c, &dummy, device_param->hip_module, "generic_constant") == -1) return -1;
12248
12249 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_tm_c, size_tm) == -1) return -1;
12250 }
12251 else
12252 {
12253 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_bfs_c, size_bfs) == -1) return -1;
12254 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_tm_c, size_tm) == -1) return -1;
12255 }
12256 }
12257 }
12258
12259 if (size_esalts)
12260 {
12261 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_esalt_bufs, size_esalts) == -1) return -1;
12262
12263 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_esalt_bufs, hashes->esalts_buf, size_esalts, device_param->hip_stream) == -1) return -1;
12264 }
12265
12266 if (hashconfig->st_hash != NULL)
12267 {
12268 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_st_digests_buf, hashes->st_digests_buf, size_st_digests, device_param->hip_stream) == -1) return -1;
12269 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_st_salts_buf, hashes->st_salts_buf, size_st_salts, device_param->hip_stream) == -1) return -1;
12270
12271 if (size_esalts)
12272 {
12273 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_st_esalts_buf, size_st_esalts) == -1) return -1;
12274
12275 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_st_esalts_buf, hashes->st_esalts_buf, size_st_esalts, device_param->hip_stream) == -1) return -1;
12276 }
12277 }
12278 }
12279
12280 if (device_param->is_opencl == true)
12281 {
12282 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_ONLY, bitmap_ctx->bitmap_size, NULL, &device_param->opencl_d_bitmap_s1_a) == -1) return -1;
12283 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_ONLY, bitmap_ctx->bitmap_size, NULL, &device_param->opencl_d_bitmap_s1_b) == -1) return -1;
12284 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_ONLY, bitmap_ctx->bitmap_size, NULL, &device_param->opencl_d_bitmap_s1_c) == -1) return -1;
12285 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_ONLY, bitmap_ctx->bitmap_size, NULL, &device_param->opencl_d_bitmap_s1_d) == -1) return -1;
12286 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_ONLY, bitmap_ctx->bitmap_size, NULL, &device_param->opencl_d_bitmap_s2_a) == -1) return -1;
12287 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_ONLY, bitmap_ctx->bitmap_size, NULL, &device_param->opencl_d_bitmap_s2_b) == -1) return -1;
12288 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_ONLY, bitmap_ctx->bitmap_size, NULL, &device_param->opencl_d_bitmap_s2_c) == -1) return -1;
12289 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_ONLY, bitmap_ctx->bitmap_size, NULL, &device_param->opencl_d_bitmap_s2_d) == -1) return -1;
12290 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_WRITE, size_plains, NULL, &device_param->opencl_d_plain_bufs) == -1) return -1;
12291 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_ONLY, size_digests, NULL, &device_param->opencl_d_digests_buf) == -1) return -1;
12292 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_WRITE, size_shown, NULL, &device_param->opencl_d_digests_shown) == -1) return -1;
12293 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_ONLY, size_salts, NULL, &device_param->opencl_d_salt_bufs) == -1) return -1;
12294 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_WRITE, size_results, NULL, &device_param->opencl_d_result) == -1) return -1;
12295 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_WRITE, size_extra_buffer / 4, NULL, &device_param->opencl_d_extra0_buf) == -1) return -1;
12296 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_WRITE, size_extra_buffer / 4, NULL, &device_param->opencl_d_extra1_buf) == -1) return -1;
12297 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_WRITE, size_extra_buffer / 4, NULL, &device_param->opencl_d_extra2_buf) == -1) return -1;
12298 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_WRITE, size_extra_buffer / 4, NULL, &device_param->opencl_d_extra3_buf) == -1) return -1;
12299 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_ONLY, size_st_digests, NULL, &device_param->opencl_d_st_digests_buf) == -1) return -1;
12300 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_ONLY, size_st_salts, NULL, &device_param->opencl_d_st_salts_buf) == -1) return -1;
12301
12302 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_bitmap_s1_a, CL_FALSE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s1_a, 0, NULL, NULL) == -1) return -1;
12303 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_bitmap_s1_b, CL_FALSE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s1_b, 0, NULL, NULL) == -1) return -1;
12304 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_bitmap_s1_c, CL_FALSE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s1_c, 0, NULL, NULL) == -1) return -1;
12305 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_bitmap_s1_d, CL_FALSE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s1_d, 0, NULL, NULL) == -1) return -1;
12306 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_bitmap_s2_a, CL_FALSE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s2_a, 0, NULL, NULL) == -1) return -1;
12307 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_bitmap_s2_b, CL_FALSE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s2_b, 0, NULL, NULL) == -1) return -1;
12308 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_bitmap_s2_c, CL_FALSE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s2_c, 0, NULL, NULL) == -1) return -1;
12309 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_bitmap_s2_d, CL_FALSE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s2_d, 0, NULL, NULL) == -1) return -1;
12310 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_digests_buf, CL_FALSE, 0, size_digests, hashes->digests_buf, 0, NULL, NULL) == -1) return -1;
12311 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_salt_bufs, CL_FALSE, 0, size_salts, hashes->salts_buf, 0, NULL, NULL) == -1) return -1;
12312
12313 /**
12314 * special buffers
12315 */
12316
12317 if (user_options->slow_candidates == true)
12318 {
12319 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_ONLY, size_rules_c, NULL, &device_param->opencl_d_rules_c) == -1) return -1;
12320 }
12321 else
12322 {
12323 if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT)
12324 {
12325 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_ONLY, size_rules, NULL, &device_param->opencl_d_rules) == -1) return -1;
12326 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_ONLY, size_rules_c, NULL, &device_param->opencl_d_rules_c) == -1) return -1;
12327
12328 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_rules, CL_FALSE, 0, size_rules, straight_ctx->kernel_rules_buf, 0, NULL, NULL) == -1) return -1;
12329 }
12330 else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI)
12331 {
12332 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_ONLY, size_combs, NULL, &device_param->opencl_d_combs) == -1) return -1;
12333 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_ONLY, size_combs, NULL, &device_param->opencl_d_combs_c) == -1) return -1;
12334 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_ONLY, size_root_css, NULL, &device_param->opencl_d_root_css_buf) == -1) return -1;
12335 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_ONLY, size_markov_css, NULL, &device_param->opencl_d_markov_css_buf) == -1) return -1;
12336 }
12337 else if (user_options_extra->attack_kern == ATTACK_KERN_BF)
12338 {
12339 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_ONLY, size_bfs, NULL, &device_param->opencl_d_bfs) == -1) return -1;
12340 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_ONLY, size_bfs, NULL, &device_param->opencl_d_bfs_c) == -1) return -1;
12341 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_ONLY, size_tm, NULL, &device_param->opencl_d_tm_c) == -1) return -1;
12342 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_ONLY, size_root_css, NULL, &device_param->opencl_d_root_css_buf) == -1) return -1;
12343 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_ONLY, size_markov_css, NULL, &device_param->opencl_d_markov_css_buf) == -1) return -1;
12344 }
12345 }
12346
12347 if (size_esalts)
12348 {
12349 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_ONLY, size_esalts, NULL, &device_param->opencl_d_esalt_bufs) == -1) return -1;
12350
12351 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_esalt_bufs, CL_FALSE, 0, size_esalts, hashes->esalts_buf, 0, NULL, NULL) == -1) return -1;
12352 }
12353
12354 if (hashconfig->st_hash != NULL)
12355 {
12356 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_st_digests_buf, CL_FALSE, 0, size_st_digests, hashes->st_digests_buf, 0, NULL, NULL) == -1) return -1;
12357 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_st_salts_buf, CL_FALSE, 0, size_st_salts, hashes->st_salts_buf, 0, NULL, NULL) == -1) return -1;
12358
12359 if (size_esalts)
12360 {
12361 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_ONLY, size_st_esalts, NULL, &device_param->opencl_d_st_esalts_buf) == -1) return -1;
12362
12363 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_st_esalts_buf, CL_FALSE, 0, size_st_esalts, hashes->st_esalts_buf, 0, NULL, NULL) == -1) return -1;
12364 }
12365 }
12366
12367 if (hc_clFlush (hashcat_ctx, device_param->opencl_command_queue) == -1) return -1;
12368 }
12369
12370 /**
12371 * kernel args
12372 */
12373
12374 device_param->kernel_params_buf32[24] = bitmap_ctx->bitmap_mask;
12375 device_param->kernel_params_buf32[25] = bitmap_ctx->bitmap_shift1;
12376 device_param->kernel_params_buf32[26] = bitmap_ctx->bitmap_shift2;
12377 device_param->kernel_params_buf32[27] = 0; // salt_pos
12378 device_param->kernel_params_buf32[28] = 0; // loop_pos
12379 device_param->kernel_params_buf32[29] = 0; // loop_cnt
12380 device_param->kernel_params_buf32[30] = 0; // kernel_rules_cnt
12381 device_param->kernel_params_buf32[31] = 0; // digests_cnt
12382 device_param->kernel_params_buf32[32] = 0; // digests_offset
12383 device_param->kernel_params_buf32[33] = 0; // combs_mode
12384 device_param->kernel_params_buf32[34] = 0; // salt_repeat
12385 device_param->kernel_params_buf64[35] = 0; // pws_pos
12386 device_param->kernel_params_buf64[36] = 0; // gid_max
12387
12388 if (device_param->is_cuda == true)
12389 {
12390 device_param->kernel_params[ 0] = NULL; // &device_param->cuda_d_pws_buf;
12391 device_param->kernel_params[ 1] = &device_param->cuda_d_rules_c;
12392 device_param->kernel_params[ 2] = &device_param->cuda_d_combs_c;
12393 device_param->kernel_params[ 3] = &device_param->cuda_d_bfs_c;
12394 device_param->kernel_params[ 4] = NULL; // &device_param->cuda_d_tmps;
12395 device_param->kernel_params[ 5] = NULL; // &device_param->cuda_d_hooks;
12396 device_param->kernel_params[ 6] = &device_param->cuda_d_bitmap_s1_a;
12397 device_param->kernel_params[ 7] = &device_param->cuda_d_bitmap_s1_b;
12398 device_param->kernel_params[ 8] = &device_param->cuda_d_bitmap_s1_c;
12399 device_param->kernel_params[ 9] = &device_param->cuda_d_bitmap_s1_d;
12400 device_param->kernel_params[10] = &device_param->cuda_d_bitmap_s2_a;
12401 device_param->kernel_params[11] = &device_param->cuda_d_bitmap_s2_b;
12402 device_param->kernel_params[12] = &device_param->cuda_d_bitmap_s2_c;
12403 device_param->kernel_params[13] = &device_param->cuda_d_bitmap_s2_d;
12404 device_param->kernel_params[14] = &device_param->cuda_d_plain_bufs;
12405 device_param->kernel_params[15] = &device_param->cuda_d_digests_buf;
12406 device_param->kernel_params[16] = &device_param->cuda_d_digests_shown;
12407 device_param->kernel_params[17] = &device_param->cuda_d_salt_bufs;
12408 device_param->kernel_params[18] = &device_param->cuda_d_esalt_bufs;
12409 device_param->kernel_params[19] = &device_param->cuda_d_result;
12410 device_param->kernel_params[20] = &device_param->cuda_d_extra0_buf;
12411 device_param->kernel_params[21] = &device_param->cuda_d_extra1_buf;
12412 device_param->kernel_params[22] = &device_param->cuda_d_extra2_buf;
12413 device_param->kernel_params[23] = &device_param->cuda_d_extra3_buf;
12414 }
12415
12416 if (device_param->is_hip == true)
12417 {
12418 device_param->kernel_params[ 0] = NULL; // &device_param->hip_d_pws_buf;
12419 device_param->kernel_params[ 1] = &device_param->hip_d_rules_c;
12420 device_param->kernel_params[ 2] = &device_param->hip_d_combs_c;
12421 device_param->kernel_params[ 3] = &device_param->hip_d_bfs_c;
12422 device_param->kernel_params[ 4] = NULL; // &device_param->hip_d_tmps;
12423 device_param->kernel_params[ 5] = NULL; // &device_param->hip_d_hooks;
12424 device_param->kernel_params[ 6] = &device_param->hip_d_bitmap_s1_a;
12425 device_param->kernel_params[ 7] = &device_param->hip_d_bitmap_s1_b;
12426 device_param->kernel_params[ 8] = &device_param->hip_d_bitmap_s1_c;
12427 device_param->kernel_params[ 9] = &device_param->hip_d_bitmap_s1_d;
12428 device_param->kernel_params[10] = &device_param->hip_d_bitmap_s2_a;
12429 device_param->kernel_params[11] = &device_param->hip_d_bitmap_s2_b;
12430 device_param->kernel_params[12] = &device_param->hip_d_bitmap_s2_c;
12431 device_param->kernel_params[13] = &device_param->hip_d_bitmap_s2_d;
12432 device_param->kernel_params[14] = &device_param->hip_d_plain_bufs;
12433 device_param->kernel_params[15] = &device_param->hip_d_digests_buf;
12434 device_param->kernel_params[16] = &device_param->hip_d_digests_shown;
12435 device_param->kernel_params[17] = &device_param->hip_d_salt_bufs;
12436 device_param->kernel_params[18] = &device_param->hip_d_esalt_bufs;
12437 device_param->kernel_params[19] = &device_param->hip_d_result;
12438 device_param->kernel_params[20] = &device_param->hip_d_extra0_buf;
12439 device_param->kernel_params[21] = &device_param->hip_d_extra1_buf;
12440 device_param->kernel_params[22] = &device_param->hip_d_extra2_buf;
12441 device_param->kernel_params[23] = &device_param->hip_d_extra3_buf;
12442 }
12443
12444 if (device_param->is_opencl == true)
12445 {
12446 device_param->kernel_params[ 0] = NULL; // &device_param->opencl_d_pws_buf;
12447 device_param->kernel_params[ 1] = &device_param->opencl_d_rules_c;
12448 device_param->kernel_params[ 2] = &device_param->opencl_d_combs_c;
12449 device_param->kernel_params[ 3] = &device_param->opencl_d_bfs_c;
12450 device_param->kernel_params[ 4] = NULL; // &device_param->opencl_d_tmps;
12451 device_param->kernel_params[ 5] = NULL; // &device_param->opencl_d_hooks;
12452 device_param->kernel_params[ 6] = &device_param->opencl_d_bitmap_s1_a;
12453 device_param->kernel_params[ 7] = &device_param->opencl_d_bitmap_s1_b;
12454 device_param->kernel_params[ 8] = &device_param->opencl_d_bitmap_s1_c;
12455 device_param->kernel_params[ 9] = &device_param->opencl_d_bitmap_s1_d;
12456 device_param->kernel_params[10] = &device_param->opencl_d_bitmap_s2_a;
12457 device_param->kernel_params[11] = &device_param->opencl_d_bitmap_s2_b;
12458 device_param->kernel_params[12] = &device_param->opencl_d_bitmap_s2_c;
12459 device_param->kernel_params[13] = &device_param->opencl_d_bitmap_s2_d;
12460 device_param->kernel_params[14] = &device_param->opencl_d_plain_bufs;
12461 device_param->kernel_params[15] = &device_param->opencl_d_digests_buf;
12462 device_param->kernel_params[16] = &device_param->opencl_d_digests_shown;
12463 device_param->kernel_params[17] = &device_param->opencl_d_salt_bufs;
12464 device_param->kernel_params[18] = &device_param->opencl_d_esalt_bufs;
12465 device_param->kernel_params[19] = &device_param->opencl_d_result;
12466 device_param->kernel_params[20] = &device_param->opencl_d_extra0_buf;
12467 device_param->kernel_params[21] = &device_param->opencl_d_extra1_buf;
12468 device_param->kernel_params[22] = &device_param->opencl_d_extra2_buf;
12469 device_param->kernel_params[23] = &device_param->opencl_d_extra3_buf;
12470 }
12471
12472 device_param->kernel_params[24] = &device_param->kernel_params_buf32[24];
12473 device_param->kernel_params[25] = &device_param->kernel_params_buf32[25];
12474 device_param->kernel_params[26] = &device_param->kernel_params_buf32[26];
12475 device_param->kernel_params[27] = &device_param->kernel_params_buf32[27];
12476 device_param->kernel_params[28] = &device_param->kernel_params_buf32[28];
12477 device_param->kernel_params[29] = &device_param->kernel_params_buf32[29];
12478 device_param->kernel_params[30] = &device_param->kernel_params_buf32[30];
12479 device_param->kernel_params[31] = &device_param->kernel_params_buf32[31];
12480 device_param->kernel_params[32] = &device_param->kernel_params_buf32[32];
12481 device_param->kernel_params[33] = &device_param->kernel_params_buf32[33];
12482 device_param->kernel_params[34] = &device_param->kernel_params_buf32[34];
12483 device_param->kernel_params[35] = &device_param->kernel_params_buf64[35];
12484 device_param->kernel_params[36] = &device_param->kernel_params_buf64[36];
12485
12486 if (user_options->slow_candidates == true)
12487 {
12488 }
12489 else
12490 {
12491 device_param->kernel_params_mp_buf64[3] = 0;
12492 device_param->kernel_params_mp_buf32[4] = 0;
12493 device_param->kernel_params_mp_buf32[5] = 0;
12494 device_param->kernel_params_mp_buf32[6] = 0;
12495 device_param->kernel_params_mp_buf32[7] = 0;
12496 device_param->kernel_params_mp_buf64[8] = 0;
12497
12498 if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
12499 {
12500 if (device_param->is_cuda == true)
12501 {
12502 device_param->kernel_params_mp[0] = &device_param->cuda_d_combs;
12503 }
12504
12505 if (device_param->is_hip == true)
12506 {
12507 device_param->kernel_params_mp[0] = &device_param->hip_d_combs;
12508 }
12509
12510 if (device_param->is_opencl == true)
12511 {
12512 device_param->kernel_params_mp[0] = &device_param->opencl_d_combs;
12513 }
12514 }
12515 else
12516 {
12517 if (user_options->attack_mode == ATTACK_MODE_HYBRID1)
12518 {
12519 if (device_param->is_cuda == true)
12520 {
12521 device_param->kernel_params_mp[0] = &device_param->cuda_d_combs;
12522 }
12523
12524 if (device_param->is_hip == true)
12525 {
12526 device_param->kernel_params_mp[0] = &device_param->hip_d_combs;
12527 }
12528
12529 if (device_param->is_opencl == true)
12530 {
12531 device_param->kernel_params_mp[0] = &device_param->opencl_d_combs;
12532 }
12533 }
12534 else
12535 {
12536 device_param->kernel_params_mp[0] = NULL; // (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
12537 // ? &device_param->opencl_d_pws_buf
12538 // : &device_param->opencl_d_pws_amp_buf;
12539 }
12540 }
12541
12542 if (device_param->is_cuda == true)
12543 {
12544 device_param->kernel_params_mp[1] = &device_param->cuda_d_root_css_buf;
12545 device_param->kernel_params_mp[2] = &device_param->cuda_d_markov_css_buf;
12546 }
12547
12548 if (device_param->is_hip == true)
12549 {
12550 device_param->kernel_params_mp[1] = &device_param->hip_d_root_css_buf;
12551 device_param->kernel_params_mp[2] = &device_param->hip_d_markov_css_buf;
12552 }
12553
12554 if (device_param->is_opencl == true)
12555 {
12556 device_param->kernel_params_mp[1] = &device_param->opencl_d_root_css_buf;
12557 device_param->kernel_params_mp[2] = &device_param->opencl_d_markov_css_buf;
12558 }
12559
12560 device_param->kernel_params_mp[3] = &device_param->kernel_params_mp_buf64[3];
12561 device_param->kernel_params_mp[4] = &device_param->kernel_params_mp_buf32[4];
12562 device_param->kernel_params_mp[5] = &device_param->kernel_params_mp_buf32[5];
12563 device_param->kernel_params_mp[6] = &device_param->kernel_params_mp_buf32[6];
12564 device_param->kernel_params_mp[7] = &device_param->kernel_params_mp_buf32[7];
12565 device_param->kernel_params_mp[8] = &device_param->kernel_params_mp_buf64[8];
12566
12567 device_param->kernel_params_mp_l_buf64[3] = 0;
12568 device_param->kernel_params_mp_l_buf32[4] = 0;
12569 device_param->kernel_params_mp_l_buf32[5] = 0;
12570 device_param->kernel_params_mp_l_buf32[6] = 0;
12571 device_param->kernel_params_mp_l_buf32[7] = 0;
12572 device_param->kernel_params_mp_l_buf32[8] = 0;
12573 device_param->kernel_params_mp_l_buf64[9] = 0;
12574
12575 device_param->kernel_params_mp_l[0] = NULL; // (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
12576 // ? &device_param->opencl_d_pws_buf
12577 // : &device_param->opencl_d_pws_amp_buf;
12578
12579 if (device_param->is_cuda == true)
12580 {
12581 device_param->kernel_params_mp_l[1] = &device_param->cuda_d_root_css_buf;
12582 device_param->kernel_params_mp_l[2] = &device_param->cuda_d_markov_css_buf;
12583 }
12584
12585 if (device_param->is_hip == true)
12586 {
12587 device_param->kernel_params_mp_l[1] = &device_param->hip_d_root_css_buf;
12588 device_param->kernel_params_mp_l[2] = &device_param->hip_d_markov_css_buf;
12589 }
12590
12591 if (device_param->is_opencl == true)
12592 {
12593 device_param->kernel_params_mp_l[1] = &device_param->opencl_d_root_css_buf;
12594 device_param->kernel_params_mp_l[2] = &device_param->opencl_d_markov_css_buf;
12595 }
12596
12597 device_param->kernel_params_mp_l[3] = &device_param->kernel_params_mp_l_buf64[3];
12598 device_param->kernel_params_mp_l[4] = &device_param->kernel_params_mp_l_buf32[4];
12599 device_param->kernel_params_mp_l[5] = &device_param->kernel_params_mp_l_buf32[5];
12600 device_param->kernel_params_mp_l[6] = &device_param->kernel_params_mp_l_buf32[6];
12601 device_param->kernel_params_mp_l[7] = &device_param->kernel_params_mp_l_buf32[7];
12602 device_param->kernel_params_mp_l[8] = &device_param->kernel_params_mp_l_buf32[8];
12603 device_param->kernel_params_mp_l[9] = &device_param->kernel_params_mp_l_buf64[9];
12604
12605 device_param->kernel_params_mp_r_buf64[3] = 0;
12606 device_param->kernel_params_mp_r_buf32[4] = 0;
12607 device_param->kernel_params_mp_r_buf32[5] = 0;
12608 device_param->kernel_params_mp_r_buf32[6] = 0;
12609 device_param->kernel_params_mp_r_buf32[7] = 0;
12610 device_param->kernel_params_mp_r_buf64[8] = 0;
12611
12612 if (device_param->is_cuda == true)
12613 {
12614 device_param->kernel_params_mp_r[0] = &device_param->cuda_d_bfs;
12615 device_param->kernel_params_mp_r[1] = &device_param->cuda_d_root_css_buf;
12616 device_param->kernel_params_mp_r[2] = &device_param->cuda_d_markov_css_buf;
12617 }
12618
12619 if (device_param->is_hip == true)
12620 {
12621 device_param->kernel_params_mp_r[0] = &device_param->hip_d_bfs;
12622 device_param->kernel_params_mp_r[1] = &device_param->hip_d_root_css_buf;
12623 device_param->kernel_params_mp_r[2] = &device_param->hip_d_markov_css_buf;
12624 }
12625
12626 if (device_param->is_opencl == true)
12627 {
12628 device_param->kernel_params_mp_r[0] = &device_param->opencl_d_bfs;
12629 device_param->kernel_params_mp_r[1] = &device_param->opencl_d_root_css_buf;
12630 device_param->kernel_params_mp_r[2] = &device_param->opencl_d_markov_css_buf;
12631 }
12632
12633 device_param->kernel_params_mp_r[3] = &device_param->kernel_params_mp_r_buf64[3];
12634 device_param->kernel_params_mp_r[4] = &device_param->kernel_params_mp_r_buf32[4];
12635 device_param->kernel_params_mp_r[5] = &device_param->kernel_params_mp_r_buf32[5];
12636 device_param->kernel_params_mp_r[6] = &device_param->kernel_params_mp_r_buf32[6];
12637 device_param->kernel_params_mp_r[7] = &device_param->kernel_params_mp_r_buf32[7];
12638 device_param->kernel_params_mp_r[8] = &device_param->kernel_params_mp_r_buf64[8];
12639
12640 device_param->kernel_params_amp_buf32[5] = 0; // combs_mode
12641 device_param->kernel_params_amp_buf64[6] = 0; // gid_max
12642
12643 if (device_param->is_cuda == true)
12644 {
12645 device_param->kernel_params_amp[0] = NULL; // &device_param->cuda_d_pws_buf;
12646 device_param->kernel_params_amp[1] = NULL; // &device_param->cuda_d_pws_amp_buf;
12647 device_param->kernel_params_amp[2] = &device_param->cuda_d_rules_c;
12648 device_param->kernel_params_amp[3] = &device_param->cuda_d_combs_c;
12649 device_param->kernel_params_amp[4] = &device_param->cuda_d_bfs_c;
12650 }
12651
12652 if (device_param->is_hip == true)
12653 {
12654 device_param->kernel_params_amp[0] = NULL; // &device_param->hip_d_pws_buf;
12655 device_param->kernel_params_amp[1] = NULL; // &device_param->hip_d_pws_amp_buf;
12656 device_param->kernel_params_amp[2] = &device_param->hip_d_rules_c;
12657 device_param->kernel_params_amp[3] = &device_param->hip_d_combs_c;
12658 device_param->kernel_params_amp[4] = &device_param->hip_d_bfs_c;
12659 }
12660
12661 if (device_param->is_opencl == true)
12662 {
12663 device_param->kernel_params_amp[0] = NULL; // &device_param->opencl_d_pws_buf;
12664 device_param->kernel_params_amp[1] = NULL; // &device_param->opencl_d_pws_amp_buf;
12665 device_param->kernel_params_amp[2] = &device_param->opencl_d_rules_c;
12666 device_param->kernel_params_amp[3] = &device_param->opencl_d_combs_c;
12667 device_param->kernel_params_amp[4] = &device_param->opencl_d_bfs_c;
12668 }
12669
12670 device_param->kernel_params_amp[5] = &device_param->kernel_params_amp_buf32[5];
12671 device_param->kernel_params_amp[6] = &device_param->kernel_params_amp_buf64[6];
12672
12673 if (device_param->is_cuda == true)
12674 {
12675 device_param->kernel_params_tm[0] = &device_param->cuda_d_bfs_c;
12676 device_param->kernel_params_tm[1] = &device_param->cuda_d_tm_c;
12677 }
12678
12679 if (device_param->is_hip == true)
12680 {
12681 device_param->kernel_params_tm[0] = &device_param->hip_d_bfs_c;
12682 device_param->kernel_params_tm[1] = &device_param->hip_d_tm_c;
12683 }
12684
12685 if (device_param->is_opencl == true)
12686 {
12687 device_param->kernel_params_tm[0] = &device_param->opencl_d_bfs_c;
12688 device_param->kernel_params_tm[1] = &device_param->opencl_d_tm_c;
12689 }
12690 }
12691
12692 device_param->kernel_params_memset_buf32[1] = 0; // value
12693 device_param->kernel_params_memset_buf64[2] = 0; // gid_max
12694
12695 device_param->kernel_params_memset[0] = NULL;
12696 device_param->kernel_params_memset[1] = &device_param->kernel_params_memset_buf32[1];
12697 device_param->kernel_params_memset[2] = &device_param->kernel_params_memset_buf64[2];
12698
12699 device_param->kernel_params_bzero_buf64[1] = 0; // gid_max
12700
12701 device_param->kernel_params_bzero[0] = NULL;
12702 device_param->kernel_params_bzero[1] = &device_param->kernel_params_bzero_buf64[1];
12703
12704 device_param->kernel_params_atinit_buf64[1] = 0; // gid_max
12705
12706 device_param->kernel_params_atinit[0] = NULL;
12707 device_param->kernel_params_atinit[1] = &device_param->kernel_params_atinit_buf64[1];
12708
12709 device_param->kernel_params_utf8toutf16le_buf64[1] = 0; // gid_max
12710
12711 device_param->kernel_params_utf8toutf16le[0] = NULL;
12712 device_param->kernel_params_utf8toutf16le[1] = &device_param->kernel_params_utf8toutf16le_buf64[1];
12713
12714 device_param->kernel_params_decompress_buf64[3] = 0; // gid_max
12715
12716 if (device_param->is_cuda == true)
12717 {
12718 device_param->kernel_params_decompress[0] = NULL; // &device_param->cuda_d_pws_idx;
12719 device_param->kernel_params_decompress[1] = NULL; // &device_param->cuda_d_pws_comp_buf;
12720 device_param->kernel_params_decompress[2] = NULL; // (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
12721 // ? &device_param->cuda_d_pws_buf
12722 // : &device_param->cuda_d_pws_amp_buf;
12723 }
12724
12725 if (device_param->is_hip == true)
12726 {
12727 device_param->kernel_params_decompress[0] = NULL; // &device_param->hip_d_pws_idx;
12728 device_param->kernel_params_decompress[1] = NULL; // &device_param->hip_d_pws_comp_buf;
12729 device_param->kernel_params_decompress[2] = NULL; // (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
12730 // ? &device_param->hip_d_pws_buf
12731 // : &device_param->hip_d_pws_amp_buf;
12732 }
12733
12734 if (device_param->is_opencl == true)
12735 {
12736 device_param->kernel_params_decompress[0] = NULL; // &device_param->opencl_d_pws_idx;
12737 device_param->kernel_params_decompress[1] = NULL; // &device_param->opencl_d_pws_comp_buf;
12738 device_param->kernel_params_decompress[2] = NULL; // (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
12739 // ? &device_param->opencl_d_pws_buf
12740 // : &device_param->opencl_d_pws_amp_buf;
12741 }
12742
12743 device_param->kernel_params_decompress[3] = &device_param->kernel_params_decompress_buf64[3];
12744
12745 /**
12746 * kernel name
12747 */
12748
12749 if (device_param->is_cuda == true)
12750 {
12751 char kernel_name[64] = { 0 };
12752
12753 if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
12754 {
12755 if (hashconfig->opti_type & OPTI_TYPE_SINGLE_HASH)
12756 {
12757 if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
12758 {
12759 // kernel1
12760
12761 snprintf (kernel_name, sizeof (kernel_name), "m%05u_s%02d", kern_type, 4);
12762
12763 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function1, device_param->cuda_module, kernel_name) == -1) return -1;
12764
12765 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function1, &device_param->kernel_wgs1) == -1) return -1;
12766
12767 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function1, &device_param->kernel_local_mem_size1) == -1) return -1;
12768
12769 device_param->kernel_dynamic_local_mem_size1 = device_param->device_local_mem_size - device_param->kernel_local_mem_size1;
12770
12771 device_param->kernel_preferred_wgs_multiple1 = device_param->cuda_warp_size;
12772
12773 // kernel2
12774
12775 snprintf (kernel_name, sizeof (kernel_name), "m%05u_s%02d", kern_type, 8);
12776
12777 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function2, device_param->cuda_module, kernel_name) == -1) return -1;
12778
12779 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function2, &device_param->kernel_wgs2) == -1) return -1;
12780
12781 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function2, &device_param->kernel_local_mem_size2) == -1) return -1;
12782
12783 device_param->kernel_dynamic_local_mem_size2 = device_param->device_local_mem_size - device_param->kernel_local_mem_size2;
12784
12785 device_param->kernel_preferred_wgs_multiple2 = device_param->cuda_warp_size;
12786
12787 // kernel3
12788
12789 snprintf (kernel_name, sizeof (kernel_name), "m%05u_s%02d", kern_type, 16);
12790
12791 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function3, device_param->cuda_module, kernel_name) == -1) return -1;
12792
12793 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function3, &device_param->kernel_wgs3) == -1) return -1;
12794
12795 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function3, &device_param->kernel_local_mem_size3) == -1) return -1;
12796
12797 device_param->kernel_dynamic_local_mem_size3 = device_param->device_local_mem_size - device_param->kernel_local_mem_size3;
12798
12799 device_param->kernel_preferred_wgs_multiple3 = device_param->cuda_warp_size;
12800 }
12801 else
12802 {
12803 snprintf (kernel_name, sizeof (kernel_name), "m%05u_sxx", kern_type);
12804
12805 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function4, device_param->cuda_module, kernel_name) == -1) return -1;
12806
12807 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function4, &device_param->kernel_wgs4) == -1) return -1;
12808
12809 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function4, &device_param->kernel_local_mem_size4) == -1) return -1;
12810
12811 device_param->kernel_dynamic_local_mem_size4 = device_param->device_local_mem_size - device_param->kernel_local_mem_size4;
12812
12813 device_param->kernel_preferred_wgs_multiple4 = device_param->cuda_warp_size;
12814 }
12815 }
12816 else
12817 {
12818 if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
12819 {
12820 // kernel1
12821
12822 snprintf (kernel_name, sizeof (kernel_name), "m%05u_m%02d", kern_type, 4);
12823
12824 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function1, device_param->cuda_module, kernel_name) == -1) return -1;
12825
12826 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function1, &device_param->kernel_wgs1) == -1) return -1;
12827
12828 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function1, &device_param->kernel_local_mem_size1) == -1) return -1;
12829
12830 device_param->kernel_dynamic_local_mem_size1 = device_param->device_local_mem_size - device_param->kernel_local_mem_size1;
12831
12832 device_param->kernel_preferred_wgs_multiple1 = device_param->cuda_warp_size;
12833
12834 // kernel2
12835
12836 snprintf (kernel_name, sizeof (kernel_name), "m%05u_m%02d", kern_type, 8);
12837
12838 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function2, device_param->cuda_module, kernel_name) == -1) return -1;
12839
12840 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function2, &device_param->kernel_wgs2) == -1) return -1;
12841
12842 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function2, &device_param->kernel_local_mem_size2) == -1) return -1;
12843
12844 device_param->kernel_dynamic_local_mem_size2 = device_param->device_local_mem_size - device_param->kernel_local_mem_size2;
12845
12846 device_param->kernel_preferred_wgs_multiple2 = device_param->cuda_warp_size;
12847
12848 // kernel3
12849
12850 snprintf (kernel_name, sizeof (kernel_name), "m%05u_m%02d", kern_type, 16);
12851
12852 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function3, device_param->cuda_module, kernel_name) == -1) return -1;
12853
12854 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function3, &device_param->kernel_wgs3) == -1) return -1;
12855
12856 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function3, &device_param->kernel_local_mem_size3) == -1) return -1;
12857
12858 device_param->kernel_dynamic_local_mem_size3 = device_param->device_local_mem_size - device_param->kernel_local_mem_size3;
12859
12860 device_param->kernel_preferred_wgs_multiple3 = device_param->cuda_warp_size;
12861 }
12862 else
12863 {
12864 snprintf (kernel_name, sizeof (kernel_name), "m%05u_mxx", kern_type);
12865
12866 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function4, device_param->cuda_module, kernel_name) == -1) return -1;
12867
12868 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function4, &device_param->kernel_wgs4) == -1) return -1;
12869
12870 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function4, &device_param->kernel_local_mem_size4) == -1) return -1;
12871
12872 device_param->kernel_dynamic_local_mem_size4 = device_param->device_local_mem_size - device_param->kernel_local_mem_size4;
12873
12874 device_param->kernel_preferred_wgs_multiple4 = device_param->cuda_warp_size;
12875 }
12876 }
12877
12878 if (user_options->slow_candidates == true)
12879 {
12880 }
12881 else
12882 {
12883 if (user_options->attack_mode == ATTACK_MODE_BF)
12884 {
12885 if (hashconfig->opts_type & OPTS_TYPE_TM_KERNEL)
12886 {
12887 snprintf (kernel_name, sizeof (kernel_name), "m%05u_tm", kern_type);
12888
12889 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function_tm, device_param->cuda_module, kernel_name) == -1) return -1;
12890
12891 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function_tm, &device_param->kernel_wgs_tm) == -1) return -1;
12892
12893 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function_tm, &device_param->kernel_local_mem_size_tm) == -1) return -1;
12894
12895 device_param->kernel_dynamic_local_mem_size_tm = device_param->device_local_mem_size - device_param->kernel_local_mem_size_tm;
12896
12897 device_param->kernel_preferred_wgs_multiple_tm = device_param->cuda_warp_size;
12898 }
12899 }
12900 }
12901 }
12902 else
12903 {
12904 // kernel1
12905
12906 snprintf (kernel_name, sizeof (kernel_name), "m%05u_init", kern_type);
12907
12908 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function1, device_param->cuda_module, kernel_name) == -1) return -1;
12909
12910 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function1, &device_param->kernel_wgs1) == -1) return -1;
12911
12912 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function1, &device_param->kernel_local_mem_size1) == -1) return -1;
12913
12914 device_param->kernel_dynamic_local_mem_size1 = device_param->device_local_mem_size - device_param->kernel_local_mem_size1;
12915
12916 device_param->kernel_preferred_wgs_multiple1 = device_param->cuda_warp_size;
12917
12918 // kernel2
12919
12920 snprintf (kernel_name, sizeof (kernel_name), "m%05u_loop", kern_type);
12921
12922 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function2, device_param->cuda_module, kernel_name) == -1) return -1;
12923
12924 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function2, &device_param->kernel_wgs2) == -1) return -1;
12925
12926 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function2, &device_param->kernel_local_mem_size2) == -1) return -1;
12927
12928 device_param->kernel_dynamic_local_mem_size2 = device_param->device_local_mem_size - device_param->kernel_local_mem_size2;
12929
12930 device_param->kernel_preferred_wgs_multiple2 = device_param->cuda_warp_size;
12931
12932 // kernel3
12933
12934 snprintf (kernel_name, sizeof (kernel_name), "m%05u_comp", kern_type);
12935
12936 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function3, device_param->cuda_module, kernel_name) == -1) return -1;
12937
12938 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function3, &device_param->kernel_wgs3) == -1) return -1;
12939
12940 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function3, &device_param->kernel_local_mem_size3) == -1) return -1;
12941
12942 device_param->kernel_dynamic_local_mem_size3 = device_param->device_local_mem_size - device_param->kernel_local_mem_size3;
12943
12944 device_param->kernel_preferred_wgs_multiple3 = device_param->cuda_warp_size;
12945
12946 if (hashconfig->opts_type & OPTS_TYPE_LOOP_PREPARE)
12947 {
12948 // kernel2p
12949
12950 snprintf (kernel_name, sizeof (kernel_name), "m%05u_loop_prepare", kern_type);
12951
12952 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function2p, device_param->cuda_module, kernel_name) == -1) return -1;
12953
12954 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function2p, &device_param->kernel_wgs2p) == -1) return -1;
12955
12956 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function2p, &device_param->kernel_local_mem_size2p) == -1) return -1;
12957
12958 device_param->kernel_dynamic_local_mem_size2p = device_param->device_local_mem_size - device_param->kernel_local_mem_size2p;
12959
12960 device_param->kernel_preferred_wgs_multiple2p = device_param->cuda_warp_size;
12961 }
12962
12963 if (hashconfig->opts_type & OPTS_TYPE_LOOP_EXTENDED)
12964 {
12965 // kernel2e
12966
12967 snprintf (kernel_name, sizeof (kernel_name), "m%05u_loop_extended", kern_type);
12968
12969 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function2e, device_param->cuda_module, kernel_name) == -1) return -1;
12970
12971 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function2e, &device_param->kernel_wgs2e) == -1) return -1;
12972
12973 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function2e, &device_param->kernel_local_mem_size2e) == -1) return -1;
12974
12975 device_param->kernel_dynamic_local_mem_size2e = device_param->device_local_mem_size - device_param->kernel_local_mem_size2e;
12976
12977 device_param->kernel_preferred_wgs_multiple2e = device_param->cuda_warp_size;
12978 }
12979
12980 // kernel12
12981
12982 if (hashconfig->opts_type & OPTS_TYPE_HOOK12)
12983 {
12984 snprintf (kernel_name, sizeof (kernel_name), "m%05u_hook12", kern_type);
12985
12986 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function12, device_param->cuda_module, kernel_name) == -1) return -1;
12987
12988 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function12, &device_param->kernel_wgs12) == -1) return -1;
12989
12990 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function12, &device_param->kernel_local_mem_size12) == -1) return -1;
12991
12992 device_param->kernel_dynamic_local_mem_size12 = device_param->device_local_mem_size - device_param->kernel_local_mem_size12;
12993
12994 device_param->kernel_preferred_wgs_multiple12 = device_param->cuda_warp_size;
12995 }
12996
12997 // kernel23
12998
12999 if (hashconfig->opts_type & OPTS_TYPE_HOOK23)
13000 {
13001 snprintf (kernel_name, sizeof (kernel_name), "m%05u_hook23", kern_type);
13002
13003 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function23, device_param->cuda_module, kernel_name) == -1) return -1;
13004
13005 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function23, &device_param->kernel_wgs23) == -1) return -1;
13006
13007 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function23, &device_param->kernel_local_mem_size23) == -1) return -1;
13008
13009 device_param->kernel_dynamic_local_mem_size23 = device_param->device_local_mem_size - device_param->kernel_local_mem_size23;
13010
13011 device_param->kernel_preferred_wgs_multiple23 = device_param->cuda_warp_size;
13012 }
13013
13014 // init2
13015
13016 if (hashconfig->opts_type & OPTS_TYPE_INIT2)
13017 {
13018 snprintf (kernel_name, sizeof (kernel_name), "m%05u_init2", kern_type);
13019
13020 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function_init2, device_param->cuda_module, kernel_name) == -1) return -1;
13021
13022 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function_init2, &device_param->kernel_wgs_init2) == -1) return -1;
13023
13024 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function_init2, &device_param->kernel_local_mem_size_init2) == -1) return -1;
13025
13026 device_param->kernel_dynamic_local_mem_size_init2 = device_param->device_local_mem_size - device_param->kernel_local_mem_size_init2;
13027
13028 device_param->kernel_preferred_wgs_multiple_init2 = device_param->cuda_warp_size;
13029 }
13030
13031 // loop2 prepare
13032
13033 if (hashconfig->opts_type & OPTS_TYPE_LOOP2_PREPARE)
13034 {
13035 snprintf (kernel_name, sizeof (kernel_name), "m%05u_loop2_prepare", kern_type);
13036
13037 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function_loop2p, device_param->cuda_module, kernel_name) == -1) return -1;
13038
13039 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function_loop2p, &device_param->kernel_wgs_loop2p) == -1) return -1;
13040
13041 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function_loop2p, &device_param->kernel_local_mem_size_loop2p) == -1) return -1;
13042
13043 device_param->kernel_dynamic_local_mem_size_loop2p = device_param->device_local_mem_size - device_param->kernel_local_mem_size_loop2p;
13044
13045 device_param->kernel_preferred_wgs_multiple_loop2p = device_param->cuda_warp_size;
13046 }
13047
13048 // loop2
13049
13050 if (hashconfig->opts_type & OPTS_TYPE_LOOP2)
13051 {
13052 snprintf (kernel_name, sizeof (kernel_name), "m%05u_loop2", kern_type);
13053
13054 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function_loop2, device_param->cuda_module, kernel_name) == -1) return -1;
13055
13056 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function_loop2, &device_param->kernel_wgs_loop2) == -1) return -1;
13057
13058 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function_loop2, &device_param->kernel_local_mem_size_loop2) == -1) return -1;
13059
13060 device_param->kernel_dynamic_local_mem_size_loop2 = device_param->device_local_mem_size - device_param->kernel_local_mem_size_loop2;
13061
13062 device_param->kernel_preferred_wgs_multiple_loop2 = device_param->cuda_warp_size;
13063 }
13064
13065 // aux1
13066
13067 if (hashconfig->opts_type & OPTS_TYPE_AUX1)
13068 {
13069 snprintf (kernel_name, sizeof (kernel_name), "m%05u_aux1", kern_type);
13070
13071 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function_aux1, device_param->cuda_module, kernel_name) == -1) return -1;
13072
13073 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function_aux1, &device_param->kernel_wgs_aux1) == -1) return -1;
13074
13075 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function_aux1, &device_param->kernel_local_mem_size_aux1) == -1) return -1;
13076
13077 device_param->kernel_dynamic_local_mem_size_aux1 = device_param->device_local_mem_size - device_param->kernel_local_mem_size_aux1;
13078
13079 device_param->kernel_preferred_wgs_multiple_aux1 = device_param->cuda_warp_size;
13080 }
13081
13082 // aux2
13083
13084 if (hashconfig->opts_type & OPTS_TYPE_AUX2)
13085 {
13086 snprintf (kernel_name, sizeof (kernel_name), "m%05u_aux2", kern_type);
13087
13088 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function_aux2, device_param->cuda_module, kernel_name) == -1) return -1;
13089
13090 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function_aux2, &device_param->kernel_wgs_aux2) == -1) return -1;
13091
13092 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function_aux2, &device_param->kernel_local_mem_size_aux2) == -1) return -1;
13093
13094 device_param->kernel_dynamic_local_mem_size_aux2 = device_param->device_local_mem_size - device_param->kernel_local_mem_size_aux2;
13095
13096 device_param->kernel_preferred_wgs_multiple_aux2 = device_param->cuda_warp_size;
13097 }
13098
13099 // aux3
13100
13101 if (hashconfig->opts_type & OPTS_TYPE_AUX3)
13102 {
13103 snprintf (kernel_name, sizeof (kernel_name), "m%05u_aux3", kern_type);
13104
13105 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function_aux3, device_param->cuda_module, kernel_name) == -1) return -1;
13106
13107 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function_aux3, &device_param->kernel_wgs_aux3) == -1) return -1;
13108
13109 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function_aux3, &device_param->kernel_local_mem_size_aux3) == -1) return -1;
13110
13111 device_param->kernel_dynamic_local_mem_size_aux3 = device_param->device_local_mem_size - device_param->kernel_local_mem_size_aux3;
13112
13113 device_param->kernel_preferred_wgs_multiple_aux3 = device_param->cuda_warp_size;
13114 }
13115
13116 // aux4
13117
13118 if (hashconfig->opts_type & OPTS_TYPE_AUX4)
13119 {
13120 snprintf (kernel_name, sizeof (kernel_name), "m%05u_aux4", kern_type);
13121
13122 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function_aux4, device_param->cuda_module, kernel_name) == -1) return -1;
13123
13124 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function_aux4, &device_param->kernel_wgs_aux4) == -1) return -1;
13125
13126 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function_aux4, &device_param->kernel_local_mem_size_aux4) == -1) return -1;
13127
13128 device_param->kernel_dynamic_local_mem_size_aux4 = device_param->device_local_mem_size - device_param->kernel_local_mem_size_aux4;
13129
13130 device_param->kernel_preferred_wgs_multiple_aux4 = device_param->cuda_warp_size;
13131 }
13132 }
13133
13134 //CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_decompress, 0, sizeof (cl_mem), device_param->kernel_params_decompress[0]); if (CL_rc == -1) return -1;
13135 //CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_decompress, 1, sizeof (cl_mem), device_param->kernel_params_decompress[1]); if (CL_rc == -1) return -1;
13136 //CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_decompress, 2, sizeof (cl_mem), device_param->kernel_params_decompress[2]); if (CL_rc == -1) return -1;
13137 //CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_decompress, 3, sizeof (cl_ulong), device_param->kernel_params_decompress[3]); if (CL_rc == -1) return -1;
13138
13139 // MP start
13140
13141 if (user_options->slow_candidates == true)
13142 {
13143 }
13144 else
13145 {
13146 if (user_options->attack_mode == ATTACK_MODE_BF)
13147 {
13148 // mp_l
13149
13150 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function_mp_l, device_param->cuda_module_mp, "l_markov") == -1) return -1;
13151
13152 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function_mp_l, &device_param->kernel_wgs_mp_l) == -1) return -1;
13153
13154 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function_mp_l, &device_param->kernel_local_mem_size_mp_l) == -1) return -1;
13155
13156 device_param->kernel_dynamic_local_mem_size_mp_l = device_param->device_local_mem_size - device_param->kernel_local_mem_size_mp_l;
13157
13158 device_param->kernel_preferred_wgs_multiple_mp_l = device_param->cuda_warp_size;
13159
13160 // mp_r
13161
13162 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function_mp_r, device_param->cuda_module_mp, "r_markov") == -1) return -1;
13163
13164 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function_mp_r, &device_param->kernel_wgs_mp_r) == -1) return -1;
13165
13166 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function_mp_r, &device_param->kernel_local_mem_size_mp_r) == -1) return -1;
13167
13168 device_param->kernel_dynamic_local_mem_size_mp_r = device_param->device_local_mem_size - device_param->kernel_local_mem_size_mp_r;
13169
13170 device_param->kernel_preferred_wgs_multiple_mp_r = device_param->cuda_warp_size;
13171
13172 if (user_options->attack_mode == ATTACK_MODE_BF)
13173 {
13174 if (hashconfig->opts_type & OPTS_TYPE_TM_KERNEL)
13175 {
13176 //CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_tm, 0, sizeof (cl_mem), device_param->kernel_params_tm[0]); if (CL_rc == -1) return -1;
13177 //CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_tm, 1, sizeof (cl_mem), device_param->kernel_params_tm[1]); if (CL_rc == -1) return -1;
13178 }
13179 }
13180 }
13181 else if (user_options->attack_mode == ATTACK_MODE_HYBRID1)
13182 {
13183 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function_mp, device_param->cuda_module_mp, "C_markov") == -1) return -1;
13184
13185 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function_mp, &device_param->kernel_wgs_mp) == -1) return -1;
13186
13187 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function_mp, &device_param->kernel_local_mem_size_mp) == -1) return -1;
13188
13189 device_param->kernel_dynamic_local_mem_size_mp = device_param->device_local_mem_size - device_param->kernel_local_mem_size_mp;
13190
13191 device_param->kernel_preferred_wgs_multiple_mp = device_param->cuda_warp_size;
13192 }
13193 else if (user_options->attack_mode == ATTACK_MODE_HYBRID2)
13194 {
13195 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function_mp, device_param->cuda_module_mp, "C_markov") == -1) return -1;
13196
13197 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function_mp, &device_param->kernel_wgs_mp) == -1) return -1;
13198
13199 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function_mp, &device_param->kernel_local_mem_size_mp) == -1) return -1;
13200
13201 device_param->kernel_dynamic_local_mem_size_mp = device_param->device_local_mem_size - device_param->kernel_local_mem_size_mp;
13202
13203 device_param->kernel_preferred_wgs_multiple_mp = device_param->cuda_warp_size;
13204 }
13205 }
13206
13207 if (user_options->slow_candidates == true)
13208 {
13209 }
13210 else
13211 {
13212 if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
13213 {
13214 // nothing to do
13215 }
13216 else
13217 {
13218 if (hc_cuModuleGetFunction (hashcat_ctx, &device_param->cuda_function_amp, device_param->cuda_module_amp, "amp") == -1) return -1;
13219
13220 if (get_cuda_kernel_wgs (hashcat_ctx, device_param->cuda_function_amp, &device_param->kernel_wgs_amp) == -1) return -1;
13221
13222 if (get_cuda_kernel_local_mem_size (hashcat_ctx, device_param->cuda_function_amp, &device_param->kernel_local_mem_size_amp) == -1) return -1;
13223
13224 device_param->kernel_dynamic_local_mem_size_amp = device_param->device_local_mem_size - device_param->kernel_local_mem_size_amp;
13225
13226 device_param->kernel_preferred_wgs_multiple_amp = device_param->cuda_warp_size;
13227 }
13228
13229 /*
13230 if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
13231 {
13232 // nothing to do
13233 }
13234 else
13235 {
13236 for (u32 i = 0; i < 5; i++)
13237 {
13238 //CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_amp, i, sizeof (cl_mem), device_param->kernel_params_amp[i]);
13239
13240 //if (CL_rc == -1) return -1;
13241 }
13242
13243 for (u32 i = 5; i < 6; i++)
13244 {
13245 //CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_amp, i, sizeof (cl_uint), device_param->kernel_params_amp[i]);
13246
13247 //if (CL_rc == -1) return -1;
13248 }
13249
13250 for (u32 i = 6; i < 7; i++)
13251 {
13252 //CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_amp, i, sizeof (cl_ulong), device_param->kernel_params_amp[i]);
13253
13254 //if (CL_rc == -1) return -1;
13255 }
13256 }
13257 */
13258 }
13259
13260 // zero some data buffers
13261
13262 if (run_cuda_kernel_bzero (hashcat_ctx, device_param, device_param->cuda_d_plain_bufs, device_param->size_plains) == -1) return -1;
13263 if (run_cuda_kernel_bzero (hashcat_ctx, device_param, device_param->cuda_d_digests_shown, device_param->size_shown) == -1) return -1;
13264 if (run_cuda_kernel_bzero (hashcat_ctx, device_param, device_param->cuda_d_result, device_param->size_results) == -1) return -1;
13265
13266 /**
13267 * special buffers
13268 */
13269
13270 if (user_options->slow_candidates == true)
13271 {
13272 if (run_cuda_kernel_bzero (hashcat_ctx, device_param, device_param->cuda_d_rules_c, size_rules_c) == -1) return -1;
13273 }
13274 else
13275 {
13276 if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT)
13277 {
13278 if (run_cuda_kernel_bzero (hashcat_ctx, device_param, device_param->cuda_d_rules_c, size_rules_c) == -1) return -1;
13279 }
13280 else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI)
13281 {
13282 if (run_cuda_kernel_bzero (hashcat_ctx, device_param, device_param->cuda_d_combs, size_combs) == -1) return -1;
13283 if (run_cuda_kernel_bzero (hashcat_ctx, device_param, device_param->cuda_d_combs_c, size_combs) == -1) return -1;
13284 if (run_cuda_kernel_bzero (hashcat_ctx, device_param, device_param->cuda_d_root_css_buf, size_root_css) == -1) return -1;
13285 if (run_cuda_kernel_bzero (hashcat_ctx, device_param, device_param->cuda_d_markov_css_buf, size_markov_css) == -1) return -1;
13286 }
13287 else if (user_options_extra->attack_kern == ATTACK_KERN_BF)
13288 {
13289 if (run_cuda_kernel_bzero (hashcat_ctx, device_param, device_param->cuda_d_bfs, size_bfs) == -1) return -1;
13290 if (run_cuda_kernel_bzero (hashcat_ctx, device_param, device_param->cuda_d_bfs_c, size_bfs) == -1) return -1;
13291 if (run_cuda_kernel_bzero (hashcat_ctx, device_param, device_param->cuda_d_tm_c, size_tm) == -1) return -1;
13292 if (run_cuda_kernel_bzero (hashcat_ctx, device_param, device_param->cuda_d_root_css_buf, size_root_css) == -1) return -1;
13293 if (run_cuda_kernel_bzero (hashcat_ctx, device_param, device_param->cuda_d_markov_css_buf, size_markov_css) == -1) return -1;
13294 }
13295 }
13296
13297 if (user_options->slow_candidates == true)
13298 {
13299 }
13300 else
13301 {
13302 if ((user_options->attack_mode == ATTACK_MODE_HYBRID1) || (user_options->attack_mode == ATTACK_MODE_HYBRID2))
13303 {
13304 /**
13305 * prepare mp
13306 */
13307
13308 if (user_options->attack_mode == ATTACK_MODE_HYBRID1)
13309 {
13310 device_param->kernel_params_mp_buf32[5] = 0;
13311 device_param->kernel_params_mp_buf32[6] = 0;
13312 device_param->kernel_params_mp_buf32[7] = 0;
13313
13314 if (hashconfig->opts_type & OPTS_TYPE_PT_ADD01) device_param->kernel_params_mp_buf32[5] = full01;
13315 if (hashconfig->opts_type & OPTS_TYPE_PT_ADD06) device_param->kernel_params_mp_buf32[5] = full06;
13316 if (hashconfig->opts_type & OPTS_TYPE_PT_ADD80) device_param->kernel_params_mp_buf32[5] = full80;
13317 if (hashconfig->opts_type & OPTS_TYPE_PT_ADDBITS14) device_param->kernel_params_mp_buf32[6] = 1;
13318 if (hashconfig->opts_type & OPTS_TYPE_PT_ADDBITS15) device_param->kernel_params_mp_buf32[7] = 1;
13319 }
13320 else if (user_options->attack_mode == ATTACK_MODE_HYBRID2)
13321 {
13322 device_param->kernel_params_mp_buf32[5] = 0;
13323 device_param->kernel_params_mp_buf32[6] = 0;
13324 device_param->kernel_params_mp_buf32[7] = 0;
13325 }
13326
13327 //for (u32 i = 0; i < 3; i++) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp, i, sizeof (cl_mem), device_param->kernel_params_mp[i]); if (CL_rc == -1) return -1; }
13328 }
13329 else if (user_options->attack_mode == ATTACK_MODE_BF)
13330 {
13331 /**
13332 * prepare mp_r and mp_l
13333 */
13334
13335 device_param->kernel_params_mp_l_buf32[6] = 0;
13336 device_param->kernel_params_mp_l_buf32[7] = 0;
13337 device_param->kernel_params_mp_l_buf32[8] = 0;
13338
13339 if (hashconfig->opts_type & OPTS_TYPE_PT_ADD01) device_param->kernel_params_mp_l_buf32[6] = full01;
13340 if (hashconfig->opts_type & OPTS_TYPE_PT_ADD06) device_param->kernel_params_mp_l_buf32[6] = full06;
13341 if (hashconfig->opts_type & OPTS_TYPE_PT_ADD80) device_param->kernel_params_mp_l_buf32[6] = full80;
13342 if (hashconfig->opts_type & OPTS_TYPE_PT_ADDBITS14) device_param->kernel_params_mp_l_buf32[7] = 1;
13343 if (hashconfig->opts_type & OPTS_TYPE_PT_ADDBITS15) device_param->kernel_params_mp_l_buf32[8] = 1;
13344
13345 //for (u32 i = 0; i < 3; i++) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp_l, i, sizeof (cl_mem), device_param->kernel_params_mp_l[i]); if (CL_rc == -1) return -1; }
13346 //for (u32 i = 0; i < 3; i++) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp_r, i, sizeof (cl_mem), device_param->kernel_params_mp_r[i]); if (CL_rc == -1) return -1; }
13347 }
13348 }
13349 }
13350
13351 if (device_param->is_hip == true)
13352 {
13353 char kernel_name[64] = { 0 };
13354
13355 if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
13356 {
13357 if (hashconfig->opti_type & OPTI_TYPE_SINGLE_HASH)
13358 {
13359 if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
13360 {
13361 // kernel1
13362
13363 snprintf (kernel_name, sizeof (kernel_name), "m%05u_s%02d", kern_type, 4);
13364
13365 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function1, device_param->hip_module, kernel_name) == -1) return -1;
13366
13367 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function1, &device_param->kernel_wgs1) == -1) return -1;
13368
13369 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function1, &device_param->kernel_local_mem_size1) == -1) return -1;
13370
13371 device_param->kernel_dynamic_local_mem_size1 = device_param->device_local_mem_size - device_param->kernel_local_mem_size1;
13372
13373 device_param->kernel_preferred_wgs_multiple1 = device_param->hip_warp_size;
13374
13375 // kernel2
13376
13377 snprintf (kernel_name, sizeof (kernel_name), "m%05u_s%02d", kern_type, 8);
13378
13379 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function2, device_param->hip_module, kernel_name) == -1) return -1;
13380
13381 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function2, &device_param->kernel_wgs2) == -1) return -1;
13382
13383 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function2, &device_param->kernel_local_mem_size2) == -1) return -1;
13384
13385 device_param->kernel_dynamic_local_mem_size2 = device_param->device_local_mem_size - device_param->kernel_local_mem_size2;
13386
13387 device_param->kernel_preferred_wgs_multiple2 = device_param->hip_warp_size;
13388
13389 // kernel3
13390
13391 snprintf (kernel_name, sizeof (kernel_name), "m%05u_s%02d", kern_type, 16);
13392
13393 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function3, device_param->hip_module, kernel_name) == -1) return -1;
13394
13395 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function3, &device_param->kernel_wgs3) == -1) return -1;
13396
13397 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function3, &device_param->kernel_local_mem_size3) == -1) return -1;
13398
13399 device_param->kernel_dynamic_local_mem_size3 = device_param->device_local_mem_size - device_param->kernel_local_mem_size3;
13400
13401 device_param->kernel_preferred_wgs_multiple3 = device_param->hip_warp_size;
13402 }
13403 else
13404 {
13405 snprintf (kernel_name, sizeof (kernel_name), "m%05u_sxx", kern_type);
13406
13407 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function4, device_param->hip_module, kernel_name) == -1) return -1;
13408
13409 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function4, &device_param->kernel_wgs4) == -1) return -1;
13410
13411 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function4, &device_param->kernel_local_mem_size4) == -1) return -1;
13412
13413 device_param->kernel_dynamic_local_mem_size4 = device_param->device_local_mem_size - device_param->kernel_local_mem_size4;
13414
13415 device_param->kernel_preferred_wgs_multiple4 = device_param->hip_warp_size;
13416 }
13417 }
13418 else
13419 {
13420 if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
13421 {
13422 // kernel1
13423
13424 snprintf (kernel_name, sizeof (kernel_name), "m%05u_m%02d", kern_type, 4);
13425
13426 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function1, device_param->hip_module, kernel_name) == -1) return -1;
13427
13428 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function1, &device_param->kernel_wgs1) == -1) return -1;
13429
13430 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function1, &device_param->kernel_local_mem_size1) == -1) return -1;
13431
13432 device_param->kernel_dynamic_local_mem_size1 = device_param->device_local_mem_size - device_param->kernel_local_mem_size1;
13433
13434 device_param->kernel_preferred_wgs_multiple1 = device_param->hip_warp_size;
13435
13436 // kernel2
13437
13438 snprintf (kernel_name, sizeof (kernel_name), "m%05u_m%02d", kern_type, 8);
13439
13440 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function2, device_param->hip_module, kernel_name) == -1) return -1;
13441
13442 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function2, &device_param->kernel_wgs2) == -1) return -1;
13443
13444 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function2, &device_param->kernel_local_mem_size2) == -1) return -1;
13445
13446 device_param->kernel_dynamic_local_mem_size2 = device_param->device_local_mem_size - device_param->kernel_local_mem_size2;
13447
13448 device_param->kernel_preferred_wgs_multiple2 = device_param->hip_warp_size;
13449
13450 // kernel3
13451
13452 snprintf (kernel_name, sizeof (kernel_name), "m%05u_m%02d", kern_type, 16);
13453
13454 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function3, device_param->hip_module, kernel_name) == -1) return -1;
13455
13456 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function3, &device_param->kernel_wgs3) == -1) return -1;
13457
13458 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function3, &device_param->kernel_local_mem_size3) == -1) return -1;
13459
13460 device_param->kernel_dynamic_local_mem_size3 = device_param->device_local_mem_size - device_param->kernel_local_mem_size3;
13461
13462 device_param->kernel_preferred_wgs_multiple3 = device_param->hip_warp_size;
13463 }
13464 else
13465 {
13466 snprintf (kernel_name, sizeof (kernel_name), "m%05u_mxx", kern_type);
13467
13468 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function4, device_param->hip_module, kernel_name) == -1) return -1;
13469
13470 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function4, &device_param->kernel_wgs4) == -1) return -1;
13471
13472 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function4, &device_param->kernel_local_mem_size4) == -1) return -1;
13473
13474 device_param->kernel_dynamic_local_mem_size4 = device_param->device_local_mem_size - device_param->kernel_local_mem_size4;
13475
13476 device_param->kernel_preferred_wgs_multiple4 = device_param->hip_warp_size;
13477 }
13478 }
13479
13480 if (user_options->slow_candidates == true)
13481 {
13482 }
13483 else
13484 {
13485 if (user_options->attack_mode == ATTACK_MODE_BF)
13486 {
13487 if (hashconfig->opts_type & OPTS_TYPE_TM_KERNEL)
13488 {
13489 snprintf (kernel_name, sizeof (kernel_name), "m%05u_tm", kern_type);
13490
13491 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function_tm, device_param->hip_module, kernel_name) == -1) return -1;
13492
13493 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function_tm, &device_param->kernel_wgs_tm) == -1) return -1;
13494
13495 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function_tm, &device_param->kernel_local_mem_size_tm) == -1) return -1;
13496
13497 device_param->kernel_dynamic_local_mem_size_tm = device_param->device_local_mem_size - device_param->kernel_local_mem_size_tm;
13498
13499 device_param->kernel_preferred_wgs_multiple_tm = device_param->hip_warp_size;
13500 }
13501 }
13502 }
13503 }
13504 else
13505 {
13506 // kernel1
13507
13508 snprintf (kernel_name, sizeof (kernel_name), "m%05u_init", kern_type);
13509
13510 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function1, device_param->hip_module, kernel_name) == -1) return -1;
13511
13512 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function1, &device_param->kernel_wgs1) == -1) return -1;
13513
13514 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function1, &device_param->kernel_local_mem_size1) == -1) return -1;
13515
13516 device_param->kernel_dynamic_local_mem_size1 = device_param->device_local_mem_size - device_param->kernel_local_mem_size1;
13517
13518 device_param->kernel_preferred_wgs_multiple1 = device_param->hip_warp_size;
13519
13520 // kernel2
13521
13522 snprintf (kernel_name, sizeof (kernel_name), "m%05u_loop", kern_type);
13523
13524 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function2, device_param->hip_module, kernel_name) == -1) return -1;
13525
13526 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function2, &device_param->kernel_wgs2) == -1) return -1;
13527
13528 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function2, &device_param->kernel_local_mem_size2) == -1) return -1;
13529
13530 device_param->kernel_dynamic_local_mem_size2 = device_param->device_local_mem_size - device_param->kernel_local_mem_size2;
13531
13532 device_param->kernel_preferred_wgs_multiple2 = device_param->hip_warp_size;
13533
13534 // kernel3
13535
13536 snprintf (kernel_name, sizeof (kernel_name), "m%05u_comp", kern_type);
13537
13538 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function3, device_param->hip_module, kernel_name) == -1) return -1;
13539
13540 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function3, &device_param->kernel_wgs3) == -1) return -1;
13541
13542 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function3, &device_param->kernel_local_mem_size3) == -1) return -1;
13543
13544 device_param->kernel_dynamic_local_mem_size3 = device_param->device_local_mem_size - device_param->kernel_local_mem_size3;
13545
13546 device_param->kernel_preferred_wgs_multiple3 = device_param->hip_warp_size;
13547
13548 if (hashconfig->opts_type & OPTS_TYPE_LOOP_PREPARE)
13549 {
13550 // kernel2p
13551
13552 snprintf (kernel_name, sizeof (kernel_name), "m%05u_loop_prepare", kern_type);
13553
13554 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function2p, device_param->hip_module, kernel_name) == -1) return -1;
13555
13556 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function2p, &device_param->kernel_wgs2p) == -1) return -1;
13557
13558 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function2p, &device_param->kernel_local_mem_size2p) == -1) return -1;
13559
13560 device_param->kernel_dynamic_local_mem_size2p = device_param->device_local_mem_size - device_param->kernel_local_mem_size2p;
13561
13562 device_param->kernel_preferred_wgs_multiple2p = device_param->hip_warp_size;
13563 }
13564
13565 if (hashconfig->opts_type & OPTS_TYPE_LOOP_EXTENDED)
13566 {
13567 // kernel2e
13568
13569 snprintf (kernel_name, sizeof (kernel_name), "m%05u_loop_extended", kern_type);
13570
13571 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function2e, device_param->hip_module, kernel_name) == -1) return -1;
13572
13573 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function2e, &device_param->kernel_wgs2e) == -1) return -1;
13574
13575 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function2e, &device_param->kernel_local_mem_size2e) == -1) return -1;
13576
13577 device_param->kernel_dynamic_local_mem_size2e = device_param->device_local_mem_size - device_param->kernel_local_mem_size2e;
13578
13579 device_param->kernel_preferred_wgs_multiple2e = device_param->hip_warp_size;
13580 }
13581
13582 // kernel12
13583
13584 if (hashconfig->opts_type & OPTS_TYPE_HOOK12)
13585 {
13586 snprintf (kernel_name, sizeof (kernel_name), "m%05u_hook12", kern_type);
13587
13588 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function12, device_param->hip_module, kernel_name) == -1) return -1;
13589
13590 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function12, &device_param->kernel_wgs12) == -1) return -1;
13591
13592 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function12, &device_param->kernel_local_mem_size12) == -1) return -1;
13593
13594 device_param->kernel_dynamic_local_mem_size12 = device_param->device_local_mem_size - device_param->kernel_local_mem_size12;
13595
13596 device_param->kernel_preferred_wgs_multiple12 = device_param->hip_warp_size;
13597 }
13598
13599 // kernel23
13600
13601 if (hashconfig->opts_type & OPTS_TYPE_HOOK23)
13602 {
13603 snprintf (kernel_name, sizeof (kernel_name), "m%05u_hook23", kern_type);
13604
13605 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function23, device_param->hip_module, kernel_name) == -1) return -1;
13606
13607 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function23, &device_param->kernel_wgs23) == -1) return -1;
13608
13609 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function23, &device_param->kernel_local_mem_size23) == -1) return -1;
13610
13611 device_param->kernel_dynamic_local_mem_size23 = device_param->device_local_mem_size - device_param->kernel_local_mem_size23;
13612
13613 device_param->kernel_preferred_wgs_multiple23 = device_param->hip_warp_size;
13614 }
13615
13616 // init2
13617
13618 if (hashconfig->opts_type & OPTS_TYPE_INIT2)
13619 {
13620 snprintf (kernel_name, sizeof (kernel_name), "m%05u_init2", kern_type);
13621
13622 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function_init2, device_param->hip_module, kernel_name) == -1) return -1;
13623
13624 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function_init2, &device_param->kernel_wgs_init2) == -1) return -1;
13625
13626 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function_init2, &device_param->kernel_local_mem_size_init2) == -1) return -1;
13627
13628 device_param->kernel_dynamic_local_mem_size_init2 = device_param->device_local_mem_size - device_param->kernel_local_mem_size_init2;
13629
13630 device_param->kernel_preferred_wgs_multiple_init2 = device_param->hip_warp_size;
13631 }
13632
13633 // loop2 prepare
13634
13635 if (hashconfig->opts_type & OPTS_TYPE_LOOP2_PREPARE)
13636 {
13637 snprintf (kernel_name, sizeof (kernel_name), "m%05u_loop2_prepare", kern_type);
13638
13639 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function_loop2p, device_param->hip_module, kernel_name) == -1) return -1;
13640
13641 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function_loop2p, &device_param->kernel_wgs_loop2p) == -1) return -1;
13642
13643 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function_loop2p, &device_param->kernel_local_mem_size_loop2p) == -1) return -1;
13644
13645 device_param->kernel_dynamic_local_mem_size_loop2p = device_param->device_local_mem_size - device_param->kernel_local_mem_size_loop2p;
13646
13647 device_param->kernel_preferred_wgs_multiple_loop2p = device_param->hip_warp_size;
13648 }
13649
13650 // loop2
13651
13652 if (hashconfig->opts_type & OPTS_TYPE_LOOP2)
13653 {
13654 snprintf (kernel_name, sizeof (kernel_name), "m%05u_loop2", kern_type);
13655
13656 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function_loop2, device_param->hip_module, kernel_name) == -1) return -1;
13657
13658 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function_loop2, &device_param->kernel_wgs_loop2) == -1) return -1;
13659
13660 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function_loop2, &device_param->kernel_local_mem_size_loop2) == -1) return -1;
13661
13662 device_param->kernel_dynamic_local_mem_size_loop2 = device_param->device_local_mem_size - device_param->kernel_local_mem_size_loop2;
13663
13664 device_param->kernel_preferred_wgs_multiple_loop2 = device_param->hip_warp_size;
13665 }
13666
13667 // aux1
13668
13669 if (hashconfig->opts_type & OPTS_TYPE_AUX1)
13670 {
13671 snprintf (kernel_name, sizeof (kernel_name), "m%05u_aux1", kern_type);
13672
13673 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function_aux1, device_param->hip_module, kernel_name) == -1) return -1;
13674
13675 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function_aux1, &device_param->kernel_wgs_aux1) == -1) return -1;
13676
13677 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function_aux1, &device_param->kernel_local_mem_size_aux1) == -1) return -1;
13678
13679 device_param->kernel_dynamic_local_mem_size_aux1 = device_param->device_local_mem_size - device_param->kernel_local_mem_size_aux1;
13680
13681 device_param->kernel_preferred_wgs_multiple_aux1 = device_param->hip_warp_size;
13682 }
13683
13684 // aux2
13685
13686 if (hashconfig->opts_type & OPTS_TYPE_AUX2)
13687 {
13688 snprintf (kernel_name, sizeof (kernel_name), "m%05u_aux2", kern_type);
13689
13690 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function_aux2, device_param->hip_module, kernel_name) == -1) return -1;
13691
13692 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function_aux2, &device_param->kernel_wgs_aux2) == -1) return -1;
13693
13694 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function_aux2, &device_param->kernel_local_mem_size_aux2) == -1) return -1;
13695
13696 device_param->kernel_dynamic_local_mem_size_aux2 = device_param->device_local_mem_size - device_param->kernel_local_mem_size_aux2;
13697
13698 device_param->kernel_preferred_wgs_multiple_aux2 = device_param->hip_warp_size;
13699 }
13700
13701 // aux3
13702
13703 if (hashconfig->opts_type & OPTS_TYPE_AUX3)
13704 {
13705 snprintf (kernel_name, sizeof (kernel_name), "m%05u_aux3", kern_type);
13706
13707 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function_aux3, device_param->hip_module, kernel_name) == -1) return -1;
13708
13709 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function_aux3, &device_param->kernel_wgs_aux3) == -1) return -1;
13710
13711 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function_aux3, &device_param->kernel_local_mem_size_aux3) == -1) return -1;
13712
13713 device_param->kernel_dynamic_local_mem_size_aux3 = device_param->device_local_mem_size - device_param->kernel_local_mem_size_aux3;
13714
13715 device_param->kernel_preferred_wgs_multiple_aux3 = device_param->hip_warp_size;
13716 }
13717
13718 // aux4
13719
13720 if (hashconfig->opts_type & OPTS_TYPE_AUX4)
13721 {
13722 snprintf (kernel_name, sizeof (kernel_name), "m%05u_aux4", kern_type);
13723
13724 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function_aux4, device_param->hip_module, kernel_name) == -1) return -1;
13725
13726 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function_aux4, &device_param->kernel_wgs_aux4) == -1) return -1;
13727
13728 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function_aux4, &device_param->kernel_local_mem_size_aux4) == -1) return -1;
13729
13730 device_param->kernel_dynamic_local_mem_size_aux4 = device_param->device_local_mem_size - device_param->kernel_local_mem_size_aux4;
13731
13732 device_param->kernel_preferred_wgs_multiple_aux4 = device_param->hip_warp_size;
13733 }
13734 }
13735
13736 //CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_decompress, 0, sizeof (cl_mem), device_param->kernel_params_decompress[0]); if (CL_rc == -1) return -1;
13737 //CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_decompress, 1, sizeof (cl_mem), device_param->kernel_params_decompress[1]); if (CL_rc == -1) return -1;
13738 //CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_decompress, 2, sizeof (cl_mem), device_param->kernel_params_decompress[2]); if (CL_rc == -1) return -1;
13739 //CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_decompress, 3, sizeof (cl_ulong), device_param->kernel_params_decompress[3]); if (CL_rc == -1) return -1;
13740
13741 // MP start
13742
13743 if (user_options->slow_candidates == true)
13744 {
13745 }
13746 else
13747 {
13748 if (user_options->attack_mode == ATTACK_MODE_BF)
13749 {
13750 // mp_l
13751
13752 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function_mp_l, device_param->hip_module_mp, "l_markov") == -1) return -1;
13753
13754 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function_mp_l, &device_param->kernel_wgs_mp_l) == -1) return -1;
13755
13756 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function_mp_l, &device_param->kernel_local_mem_size_mp_l) == -1) return -1;
13757
13758 device_param->kernel_dynamic_local_mem_size_mp_l = device_param->device_local_mem_size - device_param->kernel_local_mem_size_mp_l;
13759
13760 device_param->kernel_preferred_wgs_multiple_mp_l = device_param->hip_warp_size;
13761
13762 // mp_r
13763
13764 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function_mp_r, device_param->hip_module_mp, "r_markov") == -1) return -1;
13765
13766 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function_mp_r, &device_param->kernel_wgs_mp_r) == -1) return -1;
13767
13768 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function_mp_r, &device_param->kernel_local_mem_size_mp_r) == -1) return -1;
13769
13770 device_param->kernel_dynamic_local_mem_size_mp_r = device_param->device_local_mem_size - device_param->kernel_local_mem_size_mp_r;
13771
13772 device_param->kernel_preferred_wgs_multiple_mp_r = device_param->hip_warp_size;
13773
13774 if (user_options->attack_mode == ATTACK_MODE_BF)
13775 {
13776 if (hashconfig->opts_type & OPTS_TYPE_TM_KERNEL)
13777 {
13778 //CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_tm, 0, sizeof (cl_mem), device_param->kernel_params_tm[0]); if (CL_rc == -1) return -1;
13779 //CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_tm, 1, sizeof (cl_mem), device_param->kernel_params_tm[1]); if (CL_rc == -1) return -1;
13780 }
13781 }
13782 }
13783 else if (user_options->attack_mode == ATTACK_MODE_HYBRID1)
13784 {
13785 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function_mp, device_param->hip_module_mp, "C_markov") == -1) return -1;
13786
13787 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function_mp, &device_param->kernel_wgs_mp) == -1) return -1;
13788
13789 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function_mp, &device_param->kernel_local_mem_size_mp) == -1) return -1;
13790
13791 device_param->kernel_dynamic_local_mem_size_mp = device_param->device_local_mem_size - device_param->kernel_local_mem_size_mp;
13792
13793 device_param->kernel_preferred_wgs_multiple_mp = device_param->hip_warp_size;
13794 }
13795 else if (user_options->attack_mode == ATTACK_MODE_HYBRID2)
13796 {
13797 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function_mp, device_param->hip_module_mp, "C_markov") == -1) return -1;
13798
13799 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function_mp, &device_param->kernel_wgs_mp) == -1) return -1;
13800
13801 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function_mp, &device_param->kernel_local_mem_size_mp) == -1) return -1;
13802
13803 device_param->kernel_dynamic_local_mem_size_mp = device_param->device_local_mem_size - device_param->kernel_local_mem_size_mp;
13804
13805 device_param->kernel_preferred_wgs_multiple_mp = device_param->hip_warp_size;
13806 }
13807 }
13808
13809 if (user_options->slow_candidates == true)
13810 {
13811 }
13812 else
13813 {
13814 if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
13815 {
13816 // nothing to do
13817 }
13818 else
13819 {
13820 if (hc_hipModuleGetFunction (hashcat_ctx, &device_param->hip_function_amp, device_param->hip_module_amp, "amp") == -1) return -1;
13821
13822 if (get_hip_kernel_wgs (hashcat_ctx, device_param->hip_function_amp, &device_param->kernel_wgs_amp) == -1) return -1;
13823
13824 if (get_hip_kernel_local_mem_size (hashcat_ctx, device_param->hip_function_amp, &device_param->kernel_local_mem_size_amp) == -1) return -1;
13825
13826 device_param->kernel_dynamic_local_mem_size_amp = device_param->device_local_mem_size - device_param->kernel_local_mem_size_amp;
13827
13828 device_param->kernel_preferred_wgs_multiple_amp = device_param->hip_warp_size;
13829 }
13830
13831 /*
13832 if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
13833 {
13834 // nothing to do
13835 }
13836 else
13837 {
13838 for (u32 i = 0; i < 5; i++)
13839 {
13840 //CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_amp, i, sizeof (cl_mem), device_param->kernel_params_amp[i]);
13841
13842 //if (CL_rc == -1) return -1;
13843 }
13844
13845 for (u32 i = 5; i < 6; i++)
13846 {
13847 //CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_amp, i, sizeof (cl_uint), device_param->kernel_params_amp[i]);
13848
13849 //if (CL_rc == -1) return -1;
13850 }
13851
13852 for (u32 i = 6; i < 7; i++)
13853 {
13854 //CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_amp, i, sizeof (cl_ulong), device_param->kernel_params_amp[i]);
13855
13856 //if (CL_rc == -1) return -1;
13857 }
13858 }
13859 */
13860 }
13861
13862 // zero some data buffers
13863
13864 if (run_hip_kernel_bzero (hashcat_ctx, device_param, device_param->hip_d_plain_bufs, device_param->size_plains) == -1) return -1;
13865 if (run_hip_kernel_bzero (hashcat_ctx, device_param, device_param->hip_d_digests_shown, device_param->size_shown) == -1) return -1;
13866 if (run_hip_kernel_bzero (hashcat_ctx, device_param, device_param->hip_d_result, device_param->size_results) == -1) return -1;
13867
13868 /**
13869 * special buffers
13870 */
13871
13872 if (user_options->slow_candidates == true)
13873 {
13874 if (run_hip_kernel_bzero (hashcat_ctx, device_param, device_param->hip_d_rules_c, size_rules_c) == -1) return -1;
13875 }
13876 else
13877 {
13878 if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT)
13879 {
13880 if (run_hip_kernel_bzero (hashcat_ctx, device_param, device_param->hip_d_rules_c, size_rules_c) == -1) return -1;
13881 }
13882 else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI)
13883 {
13884 if (run_hip_kernel_bzero (hashcat_ctx, device_param, device_param->hip_d_combs, size_combs) == -1) return -1;
13885 if (run_hip_kernel_bzero (hashcat_ctx, device_param, device_param->hip_d_combs_c, size_combs) == -1) return -1;
13886 if (run_hip_kernel_bzero (hashcat_ctx, device_param, device_param->hip_d_root_css_buf, size_root_css) == -1) return -1;
13887 if (run_hip_kernel_bzero (hashcat_ctx, device_param, device_param->hip_d_markov_css_buf, size_markov_css) == -1) return -1;
13888 }
13889 else if (user_options_extra->attack_kern == ATTACK_KERN_BF)
13890 {
13891 if (run_hip_kernel_bzero (hashcat_ctx, device_param, device_param->hip_d_bfs, size_bfs) == -1) return -1;
13892 if (run_hip_kernel_bzero (hashcat_ctx, device_param, device_param->hip_d_bfs_c, size_bfs) == -1) return -1;
13893 if (run_hip_kernel_bzero (hashcat_ctx, device_param, device_param->hip_d_tm_c, size_tm) == -1) return -1;
13894 if (run_hip_kernel_bzero (hashcat_ctx, device_param, device_param->hip_d_root_css_buf, size_root_css) == -1) return -1;
13895 if (run_hip_kernel_bzero (hashcat_ctx, device_param, device_param->hip_d_markov_css_buf, size_markov_css) == -1) return -1;
13896 }
13897 }
13898
13899 if (user_options->slow_candidates == true)
13900 {
13901 }
13902 else
13903 {
13904 if ((user_options->attack_mode == ATTACK_MODE_HYBRID1) || (user_options->attack_mode == ATTACK_MODE_HYBRID2))
13905 {
13906 /**
13907 * prepare mp
13908 */
13909
13910 if (user_options->attack_mode == ATTACK_MODE_HYBRID1)
13911 {
13912 device_param->kernel_params_mp_buf32[5] = 0;
13913 device_param->kernel_params_mp_buf32[6] = 0;
13914 device_param->kernel_params_mp_buf32[7] = 0;
13915
13916 if (hashconfig->opts_type & OPTS_TYPE_PT_ADD01) device_param->kernel_params_mp_buf32[5] = full01;
13917 if (hashconfig->opts_type & OPTS_TYPE_PT_ADD06) device_param->kernel_params_mp_buf32[5] = full06;
13918 if (hashconfig->opts_type & OPTS_TYPE_PT_ADD80) device_param->kernel_params_mp_buf32[5] = full80;
13919 if (hashconfig->opts_type & OPTS_TYPE_PT_ADDBITS14) device_param->kernel_params_mp_buf32[6] = 1;
13920 if (hashconfig->opts_type & OPTS_TYPE_PT_ADDBITS15) device_param->kernel_params_mp_buf32[7] = 1;
13921 }
13922 else if (user_options->attack_mode == ATTACK_MODE_HYBRID2)
13923 {
13924 device_param->kernel_params_mp_buf32[5] = 0;
13925 device_param->kernel_params_mp_buf32[6] = 0;
13926 device_param->kernel_params_mp_buf32[7] = 0;
13927 }
13928
13929 //for (u32 i = 0; i < 3; i++) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp, i, sizeof (cl_mem), device_param->kernel_params_mp[i]); if (CL_rc == -1) return -1; }
13930 }
13931 else if (user_options->attack_mode == ATTACK_MODE_BF)
13932 {
13933 /**
13934 * prepare mp_r and mp_l
13935 */
13936
13937 device_param->kernel_params_mp_l_buf32[6] = 0;
13938 device_param->kernel_params_mp_l_buf32[7] = 0;
13939 device_param->kernel_params_mp_l_buf32[8] = 0;
13940
13941 if (hashconfig->opts_type & OPTS_TYPE_PT_ADD01) device_param->kernel_params_mp_l_buf32[6] = full01;
13942 if (hashconfig->opts_type & OPTS_TYPE_PT_ADD06) device_param->kernel_params_mp_l_buf32[6] = full06;
13943 if (hashconfig->opts_type & OPTS_TYPE_PT_ADD80) device_param->kernel_params_mp_l_buf32[6] = full80;
13944 if (hashconfig->opts_type & OPTS_TYPE_PT_ADDBITS14) device_param->kernel_params_mp_l_buf32[7] = 1;
13945 if (hashconfig->opts_type & OPTS_TYPE_PT_ADDBITS15) device_param->kernel_params_mp_l_buf32[8] = 1;
13946
13947 //for (u32 i = 0; i < 3; i++) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp_l, i, sizeof (cl_mem), device_param->kernel_params_mp_l[i]); if (CL_rc == -1) return -1; }
13948 //for (u32 i = 0; i < 3; i++) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp_r, i, sizeof (cl_mem), device_param->kernel_params_mp_r[i]); if (CL_rc == -1) return -1; }
13949 }
13950 }
13951 }
13952
13953 if (device_param->is_opencl == true)
13954 {
13955 // GPU autotune init
13956
13957 if (hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_atinit, 0, sizeof (cl_mem), device_param->kernel_params_atinit[0]) == -1) return -1;
13958 if (hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_atinit, 1, sizeof (cl_ulong), device_param->kernel_params_atinit[1]) == -1) return -1;
13959
13960 // GPU utf8 to utf16le init
13961
13962 if (hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_utf8toutf16le, 0, sizeof (cl_mem), device_param->kernel_params_utf8toutf16le[0]) == -1) return -1;
13963 if (hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_utf8toutf16le, 1, sizeof (cl_ulong), device_param->kernel_params_utf8toutf16le[1]) == -1) return -1;
13964
13965 // GPU decompress
13966
13967 if (hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_decompress, 0, sizeof (cl_mem), device_param->kernel_params_decompress[0]) == -1) return -1;
13968 if (hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_decompress, 1, sizeof (cl_mem), device_param->kernel_params_decompress[1]) == -1) return -1;
13969 if (hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_decompress, 2, sizeof (cl_mem), device_param->kernel_params_decompress[2]) == -1) return -1;
13970 if (hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_decompress, 3, sizeof (cl_ulong), device_param->kernel_params_decompress[3]) == -1) return -1;
13971
13972 char kernel_name[64] = { 0 };
13973
13974 if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
13975 {
13976 if (hashconfig->opti_type & OPTI_TYPE_SINGLE_HASH)
13977 {
13978 if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
13979 {
13980 // kernel1
13981
13982 snprintf (kernel_name, sizeof (kernel_name), "m%05u_s%02d", kern_type, 4);
13983
13984 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program, kernel_name, &device_param->opencl_kernel1) == -1) return -1;
13985
13986 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel1, &device_param->kernel_wgs1) == -1) return -1;
13987
13988 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel1, &device_param->kernel_local_mem_size1) == -1) return -1;
13989
13990 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel1, &device_param->kernel_dynamic_local_mem_size1) == -1) return -1;
13991
13992 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel1, &device_param->kernel_preferred_wgs_multiple1) == -1) return -1;
13993
13994 // kernel2
13995
13996 snprintf (kernel_name, sizeof (kernel_name), "m%05u_s%02d", kern_type, 8);
13997
13998 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program, kernel_name, &device_param->opencl_kernel2) == -1) return -1;
13999
14000 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel2, &device_param->kernel_wgs2) == -1) return -1;
14001
14002 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel2, &device_param->kernel_local_mem_size2) == -1) return -1;
14003
14004 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel2, &device_param->kernel_dynamic_local_mem_size2) == -1) return -1;
14005
14006 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel2, &device_param->kernel_preferred_wgs_multiple2) == -1) return -1;
14007
14008 // kernel3
14009
14010 snprintf (kernel_name, sizeof (kernel_name), "m%05u_s%02d", kern_type, 16);
14011
14012 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program, kernel_name, &device_param->opencl_kernel3) == -1) return -1;
14013
14014 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel3, &device_param->kernel_wgs3) == -1) return -1;
14015
14016 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel3, &device_param->kernel_local_mem_size3) == -1) return -1;
14017
14018 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel3, &device_param->kernel_dynamic_local_mem_size3) == -1) return -1;
14019
14020 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel3, &device_param->kernel_preferred_wgs_multiple3) == -1) return -1;
14021 }
14022 else
14023 {
14024 snprintf (kernel_name, sizeof (kernel_name), "m%05u_sxx", kern_type);
14025
14026 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program, kernel_name, &device_param->opencl_kernel4) == -1) return -1;
14027
14028 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel4, &device_param->kernel_wgs4) == -1) return -1;
14029
14030 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel4, &device_param->kernel_local_mem_size4) == -1) return -1;
14031
14032 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel4, &device_param->kernel_dynamic_local_mem_size4) == -1) return -1;
14033
14034 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel4, &device_param->kernel_preferred_wgs_multiple4) == -1) return -1;
14035 }
14036 }
14037 else
14038 {
14039 if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
14040 {
14041 // kernel1
14042
14043 snprintf (kernel_name, sizeof (kernel_name), "m%05u_m%02d", kern_type, 4);
14044
14045 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program, kernel_name, &device_param->opencl_kernel1) == -1) return -1;
14046
14047 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel1, &device_param->kernel_wgs1) == -1) return -1;
14048
14049 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel1, &device_param->kernel_local_mem_size1) == -1) return -1;
14050
14051 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel1, &device_param->kernel_dynamic_local_mem_size1) == -1) return -1;
14052
14053 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel1, &device_param->kernel_preferred_wgs_multiple1) == -1) return -1;
14054
14055 // kernel2
14056
14057 snprintf (kernel_name, sizeof (kernel_name), "m%05u_m%02d", kern_type, 8);
14058
14059 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program, kernel_name, &device_param->opencl_kernel2) == -1) return -1;
14060
14061 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel2, &device_param->kernel_wgs2) == -1) return -1;
14062
14063 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel2, &device_param->kernel_local_mem_size2) == -1) return -1;
14064
14065 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel2, &device_param->kernel_dynamic_local_mem_size2) == -1) return -1;
14066
14067 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel2, &device_param->kernel_preferred_wgs_multiple2) == -1) return -1;
14068
14069 // kernel3
14070
14071 snprintf (kernel_name, sizeof (kernel_name), "m%05u_m%02d", kern_type, 16);
14072
14073 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program, kernel_name, &device_param->opencl_kernel3) == -1) return -1;
14074
14075 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel3, &device_param->kernel_wgs3) == -1) return -1;
14076
14077 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel3, &device_param->kernel_local_mem_size3) == -1) return -1;
14078
14079 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel3, &device_param->kernel_dynamic_local_mem_size3) == -1) return -1;
14080
14081 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel3, &device_param->kernel_preferred_wgs_multiple3) == -1) return -1;
14082 }
14083 else
14084 {
14085 snprintf (kernel_name, sizeof (kernel_name), "m%05u_mxx", kern_type);
14086
14087 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program, kernel_name, &device_param->opencl_kernel4) == -1) return -1;
14088
14089 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel4, &device_param->kernel_wgs4) == -1) return -1;
14090
14091 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel4, &device_param->kernel_local_mem_size4) == -1) return -1;
14092
14093 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel4, &device_param->kernel_dynamic_local_mem_size4) == -1) return -1;
14094
14095 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel4, &device_param->kernel_preferred_wgs_multiple4) == -1) return -1;
14096 }
14097 }
14098
14099 if (user_options->slow_candidates == true)
14100 {
14101 }
14102 else
14103 {
14104 if (user_options->attack_mode == ATTACK_MODE_BF)
14105 {
14106 if (hashconfig->opts_type & OPTS_TYPE_TM_KERNEL)
14107 {
14108 snprintf (kernel_name, sizeof (kernel_name), "m%05u_tm", kern_type);
14109
14110 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program, kernel_name, &device_param->opencl_kernel_tm) == -1) return -1;
14111
14112 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel_tm, &device_param->kernel_wgs_tm) == -1) return -1;
14113
14114 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_tm, &device_param->kernel_local_mem_size_tm) == -1) return -1;
14115
14116 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_tm, &device_param->kernel_dynamic_local_mem_size_tm) == -1) return -1;
14117
14118 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel_tm, &device_param->kernel_preferred_wgs_multiple_tm) == -1) return -1;
14119 }
14120 }
14121 }
14122 }
14123 else
14124 {
14125 // kernel1
14126
14127 snprintf (kernel_name, sizeof (kernel_name), "m%05u_init", kern_type);
14128
14129 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program, kernel_name, &device_param->opencl_kernel1) == -1) return -1;
14130
14131 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel1, &device_param->kernel_wgs1) == -1) return -1;
14132
14133 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel1, &device_param->kernel_local_mem_size1) == -1) return -1;
14134
14135 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel1, &device_param->kernel_dynamic_local_mem_size1) == -1) return -1;
14136
14137 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel1, &device_param->kernel_preferred_wgs_multiple1) == -1) return -1;
14138
14139 // kernel2
14140
14141 snprintf (kernel_name, sizeof (kernel_name), "m%05u_loop", kern_type);
14142
14143 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program, kernel_name, &device_param->opencl_kernel2) == -1) return -1;
14144
14145 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel2, &device_param->kernel_wgs2) == -1) return -1;
14146
14147 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel2, &device_param->kernel_local_mem_size2) == -1) return -1;
14148
14149 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel2, &device_param->kernel_dynamic_local_mem_size2) == -1) return -1;
14150
14151 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel2, &device_param->kernel_preferred_wgs_multiple2) == -1) return -1;
14152
14153 // kernel3
14154
14155 snprintf (kernel_name, sizeof (kernel_name), "m%05u_comp", kern_type);
14156
14157 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program, kernel_name, &device_param->opencl_kernel3) == -1) return -1;
14158
14159 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel3, &device_param->kernel_wgs3) == -1) return -1;
14160
14161 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel3, &device_param->kernel_local_mem_size3) == -1) return -1;
14162
14163 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel3, &device_param->kernel_dynamic_local_mem_size3) == -1) return -1;
14164
14165 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel3, &device_param->kernel_preferred_wgs_multiple3) == -1) return -1;
14166
14167 // aux1
14168
14169 if (hashconfig->opts_type & OPTS_TYPE_LOOP_PREPARE)
14170 {
14171 snprintf (kernel_name, sizeof (kernel_name), "m%05u_loop_prepare", kern_type);
14172
14173 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program, kernel_name, &device_param->opencl_kernel2p) == -1) return -1;
14174
14175 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel2p, &device_param->kernel_wgs2p) == -1) return -1;
14176
14177 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel2p, &device_param->kernel_local_mem_size2p) == -1) return -1;
14178
14179 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel2p, &device_param->kernel_dynamic_local_mem_size2p) == -1) return -1;
14180
14181 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel2p, &device_param->kernel_preferred_wgs_multiple2p) == -1) return -1;
14182 }
14183
14184 if (hashconfig->opts_type & OPTS_TYPE_LOOP_EXTENDED)
14185 {
14186 snprintf (kernel_name, sizeof (kernel_name), "m%05u_loop_extended", kern_type);
14187
14188 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program, kernel_name, &device_param->opencl_kernel2e) == -1) return -1;
14189
14190 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel2e, &device_param->kernel_wgs2e) == -1) return -1;
14191
14192 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel2e, &device_param->kernel_local_mem_size2e) == -1) return -1;
14193
14194 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel2e, &device_param->kernel_dynamic_local_mem_size2e) == -1) return -1;
14195
14196 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel2e, &device_param->kernel_preferred_wgs_multiple2e) == -1) return -1;
14197 }
14198
14199 // kernel12
14200
14201 if (hashconfig->opts_type & OPTS_TYPE_HOOK12)
14202 {
14203 snprintf (kernel_name, sizeof (kernel_name), "m%05u_hook12", kern_type);
14204
14205 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program, kernel_name, &device_param->opencl_kernel12) == -1) return -1;
14206
14207 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel12, &device_param->kernel_wgs12) == -1) return -1;
14208
14209 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel12, &device_param->kernel_local_mem_size12) == -1) return -1;
14210
14211 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel12, &device_param->kernel_dynamic_local_mem_size12) == -1) return -1;
14212
14213 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel12, &device_param->kernel_preferred_wgs_multiple12) == -1) return -1;
14214 }
14215
14216 // kernel23
14217
14218 if (hashconfig->opts_type & OPTS_TYPE_HOOK23)
14219 {
14220 snprintf (kernel_name, sizeof (kernel_name), "m%05u_hook23", kern_type);
14221
14222 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program, kernel_name, &device_param->opencl_kernel23) == -1) return -1;
14223
14224 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel23, &device_param->kernel_wgs23) == -1) return -1;
14225
14226 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel23, &device_param->kernel_local_mem_size23) == -1) return -1;
14227
14228 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel23, &device_param->kernel_dynamic_local_mem_size23) == -1) return -1;
14229
14230 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel23, &device_param->kernel_preferred_wgs_multiple23) == -1) return -1;
14231 }
14232
14233 // init2
14234
14235 if (hashconfig->opts_type & OPTS_TYPE_INIT2)
14236 {
14237 snprintf (kernel_name, sizeof (kernel_name), "m%05u_init2", kern_type);
14238
14239 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program, kernel_name, &device_param->opencl_kernel_init2) == -1) return -1;
14240
14241 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel_init2, &device_param->kernel_wgs_init2) == -1) return -1;
14242
14243 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_init2, &device_param->kernel_local_mem_size_init2) == -1) return -1;
14244
14245 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_init2, &device_param->kernel_dynamic_local_mem_size_init2) == -1) return -1;
14246
14247 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel_init2, &device_param->kernel_preferred_wgs_multiple_init2) == -1) return -1;
14248 }
14249
14250 // loop2 prepare
14251
14252 if (hashconfig->opts_type & OPTS_TYPE_LOOP2_PREPARE)
14253 {
14254 snprintf (kernel_name, sizeof (kernel_name), "m%05u_loop2_prepare", kern_type);
14255
14256 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program, kernel_name, &device_param->opencl_kernel_loop2p) == -1) return -1;
14257
14258 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel_loop2p, &device_param->kernel_wgs_loop2p) == -1) return -1;
14259
14260 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_loop2p, &device_param->kernel_local_mem_size_loop2p) == -1) return -1;
14261
14262 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_loop2p, &device_param->kernel_dynamic_local_mem_size_loop2p) == -1) return -1;
14263
14264 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel_loop2p, &device_param->kernel_preferred_wgs_multiple_loop2p) == -1) return -1;
14265 }
14266
14267 // loop2
14268
14269 if (hashconfig->opts_type & OPTS_TYPE_LOOP2)
14270 {
14271 snprintf (kernel_name, sizeof (kernel_name), "m%05u_loop2", kern_type);
14272
14273 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program, kernel_name, &device_param->opencl_kernel_loop2) == -1) return -1;
14274
14275 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel_loop2, &device_param->kernel_wgs_loop2) == -1) return -1;
14276
14277 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_loop2, &device_param->kernel_local_mem_size_loop2) == -1) return -1;
14278
14279 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_loop2, &device_param->kernel_dynamic_local_mem_size_loop2) == -1) return -1;
14280
14281 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel_loop2, &device_param->kernel_preferred_wgs_multiple_loop2) == -1) return -1;
14282 }
14283
14284 // aux1
14285
14286 if (hashconfig->opts_type & OPTS_TYPE_AUX1)
14287 {
14288 snprintf (kernel_name, sizeof (kernel_name), "m%05u_aux1", kern_type);
14289
14290 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program, kernel_name, &device_param->opencl_kernel_aux1) == -1) return -1;
14291
14292 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel_aux1, &device_param->kernel_wgs_aux1) == -1) return -1;
14293
14294 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_aux1, &device_param->kernel_local_mem_size_aux1) == -1) return -1;
14295
14296 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_aux1, &device_param->kernel_dynamic_local_mem_size_aux1) == -1) return -1;
14297
14298 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel_aux1, &device_param->kernel_preferred_wgs_multiple_aux1) == -1) return -1;
14299 }
14300
14301 // aux2
14302
14303 if (hashconfig->opts_type & OPTS_TYPE_AUX2)
14304 {
14305 snprintf (kernel_name, sizeof (kernel_name), "m%05u_aux2", kern_type);
14306
14307 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program, kernel_name, &device_param->opencl_kernel_aux2) == -1) return -1;
14308
14309 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel_aux2, &device_param->kernel_wgs_aux2) == -1) return -1;
14310
14311 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_aux2, &device_param->kernel_local_mem_size_aux2) == -1) return -1;
14312
14313 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_aux2, &device_param->kernel_dynamic_local_mem_size_aux2) == -1) return -1;
14314
14315 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel_aux2, &device_param->kernel_preferred_wgs_multiple_aux2) == -1) return -1;
14316 }
14317
14318 // aux3
14319
14320 if (hashconfig->opts_type & OPTS_TYPE_AUX3)
14321 {
14322 snprintf (kernel_name, sizeof (kernel_name), "m%05u_aux3", kern_type);
14323
14324 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program, kernel_name, &device_param->opencl_kernel_aux3) == -1) return -1;
14325
14326 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel_aux3, &device_param->kernel_wgs_aux3) == -1) return -1;
14327
14328 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_aux3, &device_param->kernel_local_mem_size_aux3) == -1) return -1;
14329
14330 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_aux3, &device_param->kernel_dynamic_local_mem_size_aux3) == -1) return -1;
14331
14332 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel_aux3, &device_param->kernel_preferred_wgs_multiple_aux3) == -1) return -1;
14333 }
14334
14335 // aux4
14336
14337 if (hashconfig->opts_type & OPTS_TYPE_AUX4)
14338 {
14339 snprintf (kernel_name, sizeof (kernel_name), "m%05u_aux4", kern_type);
14340
14341 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program, kernel_name, &device_param->opencl_kernel_aux4) == -1) return -1;
14342
14343 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel_aux4, &device_param->kernel_wgs_aux4) == -1) return -1;
14344
14345 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_aux4, &device_param->kernel_local_mem_size_aux4) == -1) return -1;
14346
14347 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_aux4, &device_param->kernel_dynamic_local_mem_size_aux4) == -1) return -1;
14348
14349 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel_aux4, &device_param->kernel_preferred_wgs_multiple_aux4) == -1) return -1;
14350 }
14351 }
14352
14353 // MP start
14354
14355 if (user_options->slow_candidates == true)
14356 {
14357 }
14358 else
14359 {
14360 if (user_options->attack_mode == ATTACK_MODE_BF)
14361 {
14362 // mp_l
14363
14364 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program_mp, "l_markov", &device_param->opencl_kernel_mp_l) == -1) return -1;
14365
14366 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel_mp_l, &device_param->kernel_wgs_mp_l) == -1) return -1;
14367
14368 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_mp_l, &device_param->kernel_local_mem_size_mp_l) == -1) return -1;
14369
14370 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_mp_l, &device_param->kernel_dynamic_local_mem_size_mp_l) == -1) return -1;
14371
14372 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel_mp_l, &device_param->kernel_preferred_wgs_multiple_mp_l) == -1) return -1;
14373
14374 // mp_r
14375
14376 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program_mp, "r_markov", &device_param->opencl_kernel_mp_r) == -1) return -1;
14377
14378 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel_mp_r, &device_param->kernel_wgs_mp_r) == -1) return -1;
14379
14380 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_mp_r, &device_param->kernel_local_mem_size_mp_r) == -1) return -1;
14381
14382 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_mp_r, &device_param->kernel_dynamic_local_mem_size_mp_r) == -1) return -1;
14383
14384 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel_mp_r, &device_param->kernel_preferred_wgs_multiple_mp_r) == -1) return -1;
14385
14386 if (user_options->attack_mode == ATTACK_MODE_BF)
14387 {
14388 if (hashconfig->opts_type & OPTS_TYPE_TM_KERNEL)
14389 {
14390 if (hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_tm, 0, sizeof (cl_mem), device_param->kernel_params_tm[0]) == -1) return -1;
14391 if (hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_tm, 1, sizeof (cl_mem), device_param->kernel_params_tm[1]) == -1) return -1;
14392 }
14393 }
14394 }
14395 else if (user_options->attack_mode == ATTACK_MODE_HYBRID1)
14396 {
14397 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program_mp, "C_markov", &device_param->opencl_kernel_mp) == -1) return -1;
14398
14399 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel_mp, &device_param->kernel_wgs_mp) == -1) return -1;
14400
14401 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_mp, &device_param->kernel_local_mem_size_mp) == -1) return -1;
14402
14403 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_mp, &device_param->kernel_dynamic_local_mem_size_mp) == -1) return -1;
14404
14405 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel_mp, &device_param->kernel_preferred_wgs_multiple_mp) == -1) return -1;
14406 }
14407 else if (user_options->attack_mode == ATTACK_MODE_HYBRID2)
14408 {
14409 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program_mp, "C_markov", &device_param->opencl_kernel_mp) == -1) return -1;
14410
14411 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel_mp, &device_param->kernel_wgs_mp) == -1) return -1;
14412
14413 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_mp, &device_param->kernel_local_mem_size_mp) == -1) return -1;
14414
14415 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_mp, &device_param->kernel_dynamic_local_mem_size_mp) == -1) return -1;
14416
14417 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel_mp, &device_param->kernel_preferred_wgs_multiple_mp) == -1) return -1;
14418 }
14419 }
14420
14421 if (user_options->slow_candidates == true)
14422 {
14423 }
14424 else
14425 {
14426 if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
14427 {
14428 // nothing to do
14429 }
14430 else
14431 {
14432 if (hc_clCreateKernel (hashcat_ctx, device_param->opencl_program_amp, "amp", &device_param->opencl_kernel_amp) == -1) return -1;
14433
14434 if (get_opencl_kernel_wgs (hashcat_ctx, device_param, device_param->opencl_kernel_amp, &device_param->kernel_wgs_amp) == -1) return -1;
14435
14436 if (get_opencl_kernel_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_amp, &device_param->kernel_local_mem_size_amp) == -1) return -1;
14437
14438 if (get_opencl_kernel_dynamic_local_mem_size (hashcat_ctx, device_param, device_param->opencl_kernel_amp, &device_param->kernel_dynamic_local_mem_size_amp) == -1) return -1;
14439
14440 if (get_opencl_kernel_preferred_wgs_multiple (hashcat_ctx, device_param, device_param->opencl_kernel_amp, &device_param->kernel_preferred_wgs_multiple_amp) == -1) return -1;
14441 }
14442
14443 if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
14444 {
14445 // nothing to do
14446 }
14447 else
14448 {
14449 for (u32 i = 0; i < 5; i++)
14450 {
14451 if (hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_amp, i, sizeof (cl_mem), device_param->kernel_params_amp[i]) == -1) return -1;
14452 }
14453
14454 for (u32 i = 5; i < 6; i++)
14455 {
14456 if (hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_amp, i, sizeof (cl_uint), device_param->kernel_params_amp[i]) == -1) return -1;
14457 }
14458
14459 for (u32 i = 6; i < 7; i++)
14460 {
14461 if (hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_amp, i, sizeof (cl_ulong), device_param->kernel_params_amp[i]) == -1) return -1;
14462 }
14463 }
14464 }
14465
14466 // zero some data buffers
14467
14468 if (run_opencl_kernel_bzero (hashcat_ctx, device_param, device_param->opencl_d_plain_bufs, device_param->size_plains) == -1) return -1;
14469 if (run_opencl_kernel_bzero (hashcat_ctx, device_param, device_param->opencl_d_digests_shown, device_param->size_shown) == -1) return -1;
14470 if (run_opencl_kernel_bzero (hashcat_ctx, device_param, device_param->opencl_d_result, device_param->size_results) == -1) return -1;
14471
14472 /**
14473 * special buffers
14474 */
14475
14476 if (user_options->slow_candidates == true)
14477 {
14478 if (run_opencl_kernel_bzero (hashcat_ctx, device_param, device_param->opencl_d_rules_c, size_rules_c) == -1) return -1;
14479 }
14480 else
14481 {
14482 if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT)
14483 {
14484 if (run_opencl_kernel_bzero (hashcat_ctx, device_param, device_param->opencl_d_rules_c, size_rules_c) == -1) return -1;
14485 }
14486 else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI)
14487 {
14488 if (run_opencl_kernel_bzero (hashcat_ctx, device_param, device_param->opencl_d_combs, size_combs) == -1) return -1;
14489 if (run_opencl_kernel_bzero (hashcat_ctx, device_param, device_param->opencl_d_combs_c, size_combs) == -1) return -1;
14490 if (run_opencl_kernel_bzero (hashcat_ctx, device_param, device_param->opencl_d_root_css_buf, size_root_css) == -1) return -1;
14491 if (run_opencl_kernel_bzero (hashcat_ctx, device_param, device_param->opencl_d_markov_css_buf, size_markov_css) == -1) return -1;
14492 }
14493 else if (user_options_extra->attack_kern == ATTACK_KERN_BF)
14494 {
14495 if (run_opencl_kernel_bzero (hashcat_ctx, device_param, device_param->opencl_d_bfs, size_bfs) == -1) return -1;
14496 if (run_opencl_kernel_bzero (hashcat_ctx, device_param, device_param->opencl_d_bfs_c, size_bfs) == -1) return -1;
14497 if (run_opencl_kernel_bzero (hashcat_ctx, device_param, device_param->opencl_d_tm_c, size_tm) == -1) return -1;
14498 if (run_opencl_kernel_bzero (hashcat_ctx, device_param, device_param->opencl_d_root_css_buf, size_root_css) == -1) return -1;
14499 if (run_opencl_kernel_bzero (hashcat_ctx, device_param, device_param->opencl_d_markov_css_buf, size_markov_css) == -1) return -1;
14500 }
14501 }
14502
14503 if (user_options->slow_candidates == true)
14504 {
14505 }
14506 else
14507 {
14508 if ((user_options->attack_mode == ATTACK_MODE_HYBRID1) || (user_options->attack_mode == ATTACK_MODE_HYBRID2))
14509 {
14510 /**
14511 * prepare mp
14512 */
14513
14514 if (user_options->attack_mode == ATTACK_MODE_HYBRID1)
14515 {
14516 device_param->kernel_params_mp_buf32[5] = 0;
14517 device_param->kernel_params_mp_buf32[6] = 0;
14518 device_param->kernel_params_mp_buf32[7] = 0;
14519
14520 if (hashconfig->opts_type & OPTS_TYPE_PT_ADD01) device_param->kernel_params_mp_buf32[5] = full01;
14521 if (hashconfig->opts_type & OPTS_TYPE_PT_ADD06) device_param->kernel_params_mp_buf32[5] = full06;
14522 if (hashconfig->opts_type & OPTS_TYPE_PT_ADD80) device_param->kernel_params_mp_buf32[5] = full80;
14523 if (hashconfig->opts_type & OPTS_TYPE_PT_ADDBITS14) device_param->kernel_params_mp_buf32[6] = 1;
14524 if (hashconfig->opts_type & OPTS_TYPE_PT_ADDBITS15) device_param->kernel_params_mp_buf32[7] = 1;
14525 }
14526 else if (user_options->attack_mode == ATTACK_MODE_HYBRID2)
14527 {
14528 device_param->kernel_params_mp_buf32[5] = 0;
14529 device_param->kernel_params_mp_buf32[6] = 0;
14530 device_param->kernel_params_mp_buf32[7] = 0;
14531 }
14532
14533 for (u32 i = 0; i < 3; i++) { if (hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp, i, sizeof (cl_mem), device_param->kernel_params_mp[i]) == -1) return -1; }
14534 }
14535 else if (user_options->attack_mode == ATTACK_MODE_BF)
14536 {
14537 /**
14538 * prepare mp_r and mp_l
14539 */
14540
14541 device_param->kernel_params_mp_l_buf32[6] = 0;
14542 device_param->kernel_params_mp_l_buf32[7] = 0;
14543 device_param->kernel_params_mp_l_buf32[8] = 0;
14544
14545 if (hashconfig->opts_type & OPTS_TYPE_PT_ADD01) device_param->kernel_params_mp_l_buf32[6] = full01;
14546 if (hashconfig->opts_type & OPTS_TYPE_PT_ADD06) device_param->kernel_params_mp_l_buf32[6] = full06;
14547 if (hashconfig->opts_type & OPTS_TYPE_PT_ADD80) device_param->kernel_params_mp_l_buf32[6] = full80;
14548 if (hashconfig->opts_type & OPTS_TYPE_PT_ADDBITS14) device_param->kernel_params_mp_l_buf32[7] = 1;
14549 if (hashconfig->opts_type & OPTS_TYPE_PT_ADDBITS15) device_param->kernel_params_mp_l_buf32[8] = 1;
14550
14551 for (u32 i = 0; i < 3; i++) { if (hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp_l, i, sizeof (cl_mem), device_param->kernel_params_mp_l[i]) == -1) return -1; }
14552 for (u32 i = 0; i < 3; i++) { if (hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp_r, i, sizeof (cl_mem), device_param->kernel_params_mp_r[i]) == -1) return -1; }
14553 }
14554 }
14555 }
14556
14557 // this is required because inside the kernels there is this:
14558 // __local pw_t s_pws[64];
14559
14560 if ((user_options->attack_mode == ATTACK_MODE_STRAIGHT)
14561 || (user_options->attack_mode == ATTACK_MODE_ASSOCIATION)
14562 || (user_options->slow_candidates == true))
14563 {
14564 if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
14565 {
14566 if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
14567 {
14568 // not required
14569 }
14570 else
14571 {
14572 device_param->kernel_threads_min = MIN (device_param->kernel_threads_min, 64);
14573 device_param->kernel_threads_max = MIN (device_param->kernel_threads_max, 64);
14574 }
14575 }
14576 }
14577
14578 /**
14579 * now everything that depends on threads and accel, basically dynamic workload
14580 */
14581
14582 // u32 kernel_threads = get_kernel_threads (device_param);
14583
14584 if (user_options->attack_mode == ATTACK_MODE_ASSOCIATION)
14585 {
14586 // the smaller the kernel_threads the more accurate we can set kernel_accel
14587 // in autotune. in this attack mode kernel_power is limited by salts_cnt so we
14588 // do not have a lot of options left.
14589
14590 device_param->kernel_threads_min = MIN (device_param->kernel_threads_min, 64);
14591 device_param->kernel_threads_max = MIN (device_param->kernel_threads_max, 64);
14592 }
14593
14594 // device_param->kernel_threads = kernel_threads;
14595 device_param->kernel_threads = 0;
14596
14597 u32 hardware_power_max = ((hashconfig->opts_type & OPTS_TYPE_MP_MULTI_DISABLE) ? 1 : device_processors) * device_param->kernel_threads_max;
14598
14599 u32 kernel_accel_min = device_param->kernel_accel_min;
14600 u32 kernel_accel_max = device_param->kernel_accel_max;
14601
14602 // We need to deal with the situation that the total video RAM > total host RAM.
14603 // For the opposite direction, we do that in the loop section below.
14604 // Especially in multi-GPU setups that is very likely.
14605 // The buffers which actually take a lot of memory (except for SCRYPT) are the ones for the password candidates.
14606 // They are stored in an aligned order for better performance, but this increases the memory pressure.
14607 // The best way to keep these buffers to a reasonable size is by controlling the kernel_accel parameter.
14608 //
14609 // In theory this check could be disabled if we check if total video RAM < total host RAM,
14610 // but at this point of initialization phase we don't have this information available.
14611
14612 // We need to hard-code some value, let's assume that (in 2021) the host has at least 4GB ram per active GPU
14613
14614 const u64 SIZE_4GB = 4ULL * 1024 * 1024 * 1024;
14615
14616 u64 accel_limit = SIZE_4GB;
14617
14618 // in slow candidate mode we need to keep the buffers on the host alive
14619 // a high accel value doesn't help much here anyway
14620
14621 if (user_options->slow_candidates == true)
14622 {
14623 // Tested with NTLM, almost no difference in performance
14624
14625 accel_limit /= 8;
14626 }
14627
14628 // this is device_processors * kernel_threads
14629
14630 accel_limit /= hardware_power_max;
14631
14632 // single password candidate size
14633
14634 accel_limit /= sizeof (pw_t);
14635
14636 // pws[], pws_comp[] and pw_pre[] are some large blocks with password candidates
14637
14638 accel_limit /= 3;
14639
14640 // Is possible that the GPU simply has too much hardware resources and 8GB per GPU is not enough, but OTOH we can't get lower than 1
14641
14642 accel_limit = MAX (accel_limit, 1);
14643
14644 // I think vector size is not required because vector_size is dividing the pws_cnt in run_kernel()
14645
14646 kernel_accel_max = MIN (kernel_accel_max, accel_limit);
14647
14648 if (kernel_accel_min > kernel_accel_max)
14649 {
14650 event_log_error (hashcat_ctx, "* Device #%u: Too many compute units to keep minimum kernel accel limit.", device_id + 1);
14651 event_log_error (hashcat_ctx, " Retry with lower --backend-kernel-threads value.");
14652
14653 return -1;
14654 }
14655
14656 // Opposite direction check: find out if we would request too much memory on memory blocks which are based on kernel_accel
14657
14658 u64 size_pws = 4;
14659 u64 size_pws_amp = 4;
14660 u64 size_pws_comp = 4;
14661 u64 size_pws_idx = 4;
14662 u64 size_pws_pre = 4;
14663 u64 size_pws_base = 4;
14664 u64 size_tmps = 4;
14665 u64 size_hooks = 4;
14666 #ifdef WITH_BRAIN
14667 u64 size_brain_link_in = 4;
14668 u64 size_brain_link_out = 4;
14669 #endif
14670
14671 while (kernel_accel_max >= kernel_accel_min)
14672 {
14673 const u64 kernel_power_max = hardware_power_max * kernel_accel_max;
14674
14675 // size_pws
14676
14677 size_pws = kernel_power_max * sizeof (pw_t);
14678
14679 size_pws_amp = (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL) ? 1 : size_pws;
14680
14681 // size_pws_comp
14682
14683 size_pws_comp = kernel_power_max * (sizeof (u32) * 64);
14684
14685 // size_pws_idx
14686
14687 size_pws_idx = (u64) (kernel_power_max + 1) * sizeof (pw_idx_t);
14688
14689 // size_tmps
14690
14691 size_tmps = kernel_power_max * hashconfig->tmp_size;
14692
14693 // size_hooks
14694
14695 size_hooks = kernel_power_max * hashconfig->hook_size;
14696
14697 #ifdef WITH_BRAIN
14698 // size_brains
14699
14700 size_brain_link_in = kernel_power_max * 1;
14701 size_brain_link_out = kernel_power_max * 8;
14702 #endif
14703
14704 if (user_options->slow_candidates == true)
14705 {
14706 // size_pws_pre
14707
14708 size_pws_pre = kernel_power_max * sizeof (pw_pre_t);
14709
14710 // size_pws_base
14711
14712 size_pws_base = kernel_power_max * sizeof (pw_pre_t);
14713 }
14714
14715 // now check if all device-memory sizes which depend on the kernel_accel_max amplifier are within its boundaries
14716 // if not, decrease amplifier and try again
14717
14718 int memory_limit_hit = 0;
14719
14720 // sometimes device_available_mem and device_maxmem_alloc reported back from the opencl runtime are a bit inaccurate.
14721 // let's add some extra space just to be sure.
14722 // now depends on the kernel-accel value (where scrypt and similar benefits), but also hard minimum 64mb and maximum 1024mb limit
14723
14724 u64 EXTRA_SPACE = (1024ULL * 1024ULL) * kernel_accel_max;
14725
14726 EXTRA_SPACE = MAX (EXTRA_SPACE, ( 256ULL * 1024ULL * 1024ULL));
14727 EXTRA_SPACE = MIN (EXTRA_SPACE, (1024ULL * 1024ULL * 1024ULL));
14728
14729 if ((size_pws + EXTRA_SPACE) > device_param->device_maxmem_alloc) memory_limit_hit = 1;
14730 if ((size_tmps + EXTRA_SPACE) > device_param->device_maxmem_alloc) memory_limit_hit = 1;
14731 if ((size_hooks + EXTRA_SPACE) > device_param->device_maxmem_alloc) memory_limit_hit = 1;
14732
14733 // work around, for some reason apple opencl can't have buffers larger 2^31
14734 // typically runs into trap 6
14735 // maybe 32/64 bit problem affecting size_t?
14736
14737 if (device_param->opencl_platform_vendor_id == VENDOR_ID_APPLE)
14738 {
14739 const size_t undocumented_single_allocation_apple = 0x7fffffff;
14740
14741 if (bitmap_ctx->bitmap_size > undocumented_single_allocation_apple) memory_limit_hit = 1;
14742 if (bitmap_ctx->bitmap_size > undocumented_single_allocation_apple) memory_limit_hit = 1;
14743 if (bitmap_ctx->bitmap_size > undocumented_single_allocation_apple) memory_limit_hit = 1;
14744 if (bitmap_ctx->bitmap_size > undocumented_single_allocation_apple) memory_limit_hit = 1;
14745 if (bitmap_ctx->bitmap_size > undocumented_single_allocation_apple) memory_limit_hit = 1;
14746 if (bitmap_ctx->bitmap_size > undocumented_single_allocation_apple) memory_limit_hit = 1;
14747 if (bitmap_ctx->bitmap_size > undocumented_single_allocation_apple) memory_limit_hit = 1;
14748 if (bitmap_ctx->bitmap_size > undocumented_single_allocation_apple) memory_limit_hit = 1;
14749 if (size_bfs > undocumented_single_allocation_apple) memory_limit_hit = 1;
14750 if (size_combs > undocumented_single_allocation_apple) memory_limit_hit = 1;
14751 if (size_digests > undocumented_single_allocation_apple) memory_limit_hit = 1;
14752 if (size_esalts > undocumented_single_allocation_apple) memory_limit_hit = 1;
14753 if (size_hooks > undocumented_single_allocation_apple) memory_limit_hit = 1;
14754 if (size_markov_css > undocumented_single_allocation_apple) memory_limit_hit = 1;
14755 if (size_plains > undocumented_single_allocation_apple) memory_limit_hit = 1;
14756 if (size_pws > undocumented_single_allocation_apple) memory_limit_hit = 1;
14757 if (size_pws_amp > undocumented_single_allocation_apple) memory_limit_hit = 1;
14758 if (size_pws_comp > undocumented_single_allocation_apple) memory_limit_hit = 1;
14759 if (size_pws_idx > undocumented_single_allocation_apple) memory_limit_hit = 1;
14760 if (size_results > undocumented_single_allocation_apple) memory_limit_hit = 1;
14761 if (size_root_css > undocumented_single_allocation_apple) memory_limit_hit = 1;
14762 if (size_rules > undocumented_single_allocation_apple) memory_limit_hit = 1;
14763 if (size_rules_c > undocumented_single_allocation_apple) memory_limit_hit = 1;
14764 if (size_salts > undocumented_single_allocation_apple) memory_limit_hit = 1;
14765 if (size_extra_buffer > undocumented_single_allocation_apple) memory_limit_hit = 1;
14766 if (size_shown > undocumented_single_allocation_apple) memory_limit_hit = 1;
14767 if (size_tm > undocumented_single_allocation_apple) memory_limit_hit = 1;
14768 if (size_tmps > undocumented_single_allocation_apple) memory_limit_hit = 1;
14769 if (size_st_digests > undocumented_single_allocation_apple) memory_limit_hit = 1;
14770 if (size_st_salts > undocumented_single_allocation_apple) memory_limit_hit = 1;
14771 if (size_st_esalts > undocumented_single_allocation_apple) memory_limit_hit = 1;
14772 }
14773
14774 const u64 size_total
14775 = bitmap_ctx->bitmap_size
14776 + bitmap_ctx->bitmap_size
14777 + bitmap_ctx->bitmap_size
14778 + bitmap_ctx->bitmap_size
14779 + bitmap_ctx->bitmap_size
14780 + bitmap_ctx->bitmap_size
14781 + bitmap_ctx->bitmap_size
14782 + bitmap_ctx->bitmap_size
14783 + size_bfs
14784 + size_combs
14785 + size_digests
14786 + size_esalts
14787 + size_hooks
14788 + size_markov_css
14789 + size_plains
14790 + size_pws
14791 + size_pws_amp
14792 + size_pws_comp
14793 + size_pws_idx
14794 + size_results
14795 + size_root_css
14796 + size_rules
14797 + size_rules_c
14798 + size_salts
14799 + size_extra_buffer
14800 + size_shown
14801 + size_tm
14802 + size_tmps
14803 + size_st_digests
14804 + size_st_salts
14805 + size_st_esalts;
14806
14807 if ((size_total + EXTRA_SPACE) > device_param->device_available_mem) memory_limit_hit = 1;
14808
14809 if (memory_limit_hit == 1)
14810 {
14811 kernel_accel_max--;
14812
14813 continue;
14814 }
14815
14816 const u64 size_total_host
14817 = size_pws_comp
14818 + size_pws_idx
14819 + size_hooks
14820 #ifdef WITH_BRAIN
14821 + size_brain_link_in
14822 + size_brain_link_out
14823 #endif
14824 + size_pws_pre
14825 + size_pws_base;
14826
14827 size_total_host_all += size_total_host;
14828
14829 break;
14830 }
14831
14832 if (kernel_accel_max < kernel_accel_min)
14833 {
14834 event_log_error (hashcat_ctx, "* Device #%u: Not enough allocatable device memory for this attack.", device_id + 1);
14835
14836 return -1;
14837 }
14838
14839 // similar process for association attack
14840 // there's no need to have a device_power > salts_cnt since salt_pos is set to GID in kernel
14841
14842 if (user_options->attack_mode == ATTACK_MODE_ASSOCIATION)
14843 {
14844 while (kernel_accel_max > kernel_accel_min)
14845 {
14846 const u64 kernel_power_max = hardware_power_max * kernel_accel_max;
14847
14848 if (kernel_power_max > hashes->salts_cnt)
14849 {
14850 kernel_accel_max--;
14851
14852 continue;
14853 }
14854
14855 break;
14856 }
14857 }
14858
14859 device_param->kernel_accel_min = kernel_accel_min;
14860 device_param->kernel_accel_max = kernel_accel_max;
14861
14862 device_param->size_pws = size_pws;
14863 device_param->size_pws_amp = size_pws_amp;
14864 device_param->size_pws_comp = size_pws_comp;
14865 device_param->size_pws_idx = size_pws_idx;
14866 device_param->size_pws_pre = size_pws_pre;
14867 device_param->size_pws_base = size_pws_base;
14868 device_param->size_tmps = size_tmps;
14869 device_param->size_hooks = size_hooks;
14870 #ifdef WITH_BRAIN
14871 device_param->size_brain_link_in = size_brain_link_in;
14872 device_param->size_brain_link_out = size_brain_link_out;
14873 #endif
14874
14875 if (device_param->is_cuda == true)
14876 {
14877 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_pws_buf, size_pws) == -1) return -1;
14878 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_pws_amp_buf, size_pws_amp) == -1) return -1;
14879 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_pws_comp_buf, size_pws_comp) == -1) return -1;
14880 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_pws_idx, size_pws_idx) == -1) return -1;
14881 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_tmps, size_tmps) == -1) return -1;
14882 if (hc_cuMemAlloc (hashcat_ctx, &device_param->cuda_d_hooks, size_hooks) == -1) return -1;
14883
14884 if (run_cuda_kernel_bzero (hashcat_ctx, device_param, device_param->cuda_d_pws_buf, device_param->size_pws) == -1) return -1;
14885 if (run_cuda_kernel_bzero (hashcat_ctx, device_param, device_param->cuda_d_pws_amp_buf, device_param->size_pws_amp) == -1) return -1;
14886 if (run_cuda_kernel_bzero (hashcat_ctx, device_param, device_param->cuda_d_pws_comp_buf, device_param->size_pws_comp) == -1) return -1;
14887 if (run_cuda_kernel_bzero (hashcat_ctx, device_param, device_param->cuda_d_pws_idx, device_param->size_pws_idx) == -1) return -1;
14888 if (run_cuda_kernel_bzero (hashcat_ctx, device_param, device_param->cuda_d_tmps, device_param->size_tmps) == -1) return -1;
14889 if (run_cuda_kernel_bzero (hashcat_ctx, device_param, device_param->cuda_d_hooks, device_param->size_hooks) == -1) return -1;
14890 }
14891
14892 if (device_param->is_hip == true)
14893 {
14894 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_pws_buf, size_pws) == -1) return -1;
14895 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_pws_amp_buf, size_pws_amp) == -1) return -1;
14896 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_pws_comp_buf, size_pws_comp) == -1) return -1;
14897 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_pws_idx, size_pws_idx) == -1) return -1;
14898 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_tmps, size_tmps) == -1) return -1;
14899 if (hc_hipMemAlloc (hashcat_ctx, &device_param->hip_d_hooks, size_hooks) == -1) return -1;
14900
14901 if (run_hip_kernel_bzero (hashcat_ctx, device_param, device_param->hip_d_pws_buf, device_param->size_pws) == -1) return -1;
14902 if (run_hip_kernel_bzero (hashcat_ctx, device_param, device_param->hip_d_pws_amp_buf, device_param->size_pws_amp) == -1) return -1;
14903 if (run_hip_kernel_bzero (hashcat_ctx, device_param, device_param->hip_d_pws_comp_buf, device_param->size_pws_comp) == -1) return -1;
14904 if (run_hip_kernel_bzero (hashcat_ctx, device_param, device_param->hip_d_pws_idx, device_param->size_pws_idx) == -1) return -1;
14905 if (run_hip_kernel_bzero (hashcat_ctx, device_param, device_param->hip_d_tmps, device_param->size_tmps) == -1) return -1;
14906 if (run_hip_kernel_bzero (hashcat_ctx, device_param, device_param->hip_d_hooks, device_param->size_hooks) == -1) return -1;
14907 }
14908
14909 if (device_param->is_opencl == true)
14910 {
14911 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_WRITE, size_pws, NULL, &device_param->opencl_d_pws_buf) == -1) return -1;
14912 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_WRITE, size_pws_amp, NULL, &device_param->opencl_d_pws_amp_buf) == -1) return -1;
14913 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_ONLY, size_pws_comp, NULL, &device_param->opencl_d_pws_comp_buf) == -1) return -1;
14914 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_ONLY, size_pws_idx, NULL, &device_param->opencl_d_pws_idx) == -1) return -1;
14915 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_WRITE, size_tmps, NULL, &device_param->opencl_d_tmps) == -1) return -1;
14916 if (hc_clCreateBuffer (hashcat_ctx, device_param->opencl_context, CL_MEM_READ_WRITE, size_hooks, NULL, &device_param->opencl_d_hooks) == -1) return -1;
14917
14918 if (run_opencl_kernel_bzero (hashcat_ctx, device_param, device_param->opencl_d_pws_buf, device_param->size_pws) == -1) return -1;
14919 if (run_opencl_kernel_bzero (hashcat_ctx, device_param, device_param->opencl_d_pws_amp_buf, device_param->size_pws_amp) == -1) return -1;
14920 if (run_opencl_kernel_bzero (hashcat_ctx, device_param, device_param->opencl_d_pws_comp_buf, device_param->size_pws_comp) == -1) return -1;
14921 if (run_opencl_kernel_bzero (hashcat_ctx, device_param, device_param->opencl_d_pws_idx, device_param->size_pws_idx) == -1) return -1;
14922 if (run_opencl_kernel_bzero (hashcat_ctx, device_param, device_param->opencl_d_tmps, device_param->size_tmps) == -1) return -1;
14923 if (run_opencl_kernel_bzero (hashcat_ctx, device_param, device_param->opencl_d_hooks, device_param->size_hooks) == -1) return -1;
14924 }
14925
14926 /**
14927 * main host data
14928 */
14929
14930 u32 *pws_comp = (u32 *) hcmalloc (size_pws_comp);
14931
14932 device_param->pws_comp = pws_comp;
14933
14934 pw_idx_t *pws_idx = (pw_idx_t *) hcmalloc (size_pws_idx);
14935
14936 device_param->pws_idx = pws_idx;
14937
14938 pw_t *combs_buf = (pw_t *) hccalloc (KERNEL_COMBS, sizeof (pw_t));
14939
14940 device_param->combs_buf = combs_buf;
14941
14942 void *hooks_buf = hcmalloc (size_hooks);
14943
14944 device_param->hooks_buf = hooks_buf;
14945
14946 char *scratch_buf = (char *) hcmalloc (HCBUFSIZ_LARGE);
14947
14948 device_param->scratch_buf = scratch_buf;
14949
14950 #ifdef WITH_BRAIN
14951
14952 u8 *brain_link_in_buf = (u8 *) hcmalloc (size_brain_link_in);
14953
14954 device_param->brain_link_in_buf = brain_link_in_buf;
14955
14956 u32 *brain_link_out_buf = (u32 *) hcmalloc (size_brain_link_out);
14957
14958 device_param->brain_link_out_buf = brain_link_out_buf;
14959 #endif
14960
14961 pw_pre_t *pws_pre_buf = (pw_pre_t *) hcmalloc (size_pws_pre);
14962
14963 device_param->pws_pre_buf = pws_pre_buf;
14964
14965 pw_pre_t *pws_base_buf = (pw_pre_t *) hcmalloc (size_pws_base);
14966
14967 device_param->pws_base_buf = pws_base_buf;
14968
14969 /**
14970 * kernel args
14971 */
14972
14973 if (device_param->is_cuda == true)
14974 {
14975 device_param->kernel_params[ 0] = &device_param->cuda_d_pws_buf;
14976 device_param->kernel_params[ 4] = &device_param->cuda_d_tmps;
14977 device_param->kernel_params[ 5] = &device_param->cuda_d_hooks;
14978 }
14979
14980 if (device_param->is_hip == true)
14981 {
14982 device_param->kernel_params[ 0] = &device_param->hip_d_pws_buf;
14983 device_param->kernel_params[ 4] = &device_param->hip_d_tmps;
14984 device_param->kernel_params[ 5] = &device_param->hip_d_hooks;
14985 }
14986
14987 if (device_param->is_opencl == true)
14988 {
14989 device_param->kernel_params[ 0] = &device_param->opencl_d_pws_buf;
14990 device_param->kernel_params[ 4] = &device_param->opencl_d_tmps;
14991 device_param->kernel_params[ 5] = &device_param->opencl_d_hooks;
14992 }
14993
14994 if (user_options->slow_candidates == true)
14995 {
14996 }
14997 else
14998 {
14999 if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
15000 {
15001 // nothing to do
15002 }
15003 else
15004 {
15005 if (user_options->attack_mode == ATTACK_MODE_HYBRID2)
15006 {
15007 if (device_param->is_cuda == true)
15008 {
15009 device_param->kernel_params_mp[0] = (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
15010 ? &device_param->cuda_d_pws_buf
15011 : &device_param->cuda_d_pws_amp_buf;
15012
15013 //CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp, 0, sizeof (cl_mem), device_param->kernel_params_mp[0]); if (CL_rc == -1) return -1;
15014 }
15015
15016 if (device_param->is_hip == true)
15017 {
15018 device_param->kernel_params_mp[0] = (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
15019 ? &device_param->hip_d_pws_buf
15020 : &device_param->hip_d_pws_amp_buf;
15021
15022 //CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp, 0, sizeof (cl_mem), device_param->kernel_params_mp[0]); if (CL_rc == -1) return -1;
15023 }
15024
15025 if (device_param->is_opencl == true)
15026 {
15027 device_param->kernel_params_mp[0] = (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
15028 ? &device_param->opencl_d_pws_buf
15029 : &device_param->opencl_d_pws_amp_buf;
15030
15031 if (hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp, 0, sizeof (cl_mem), device_param->kernel_params_mp[0]) == -1) return -1;
15032 }
15033 }
15034 }
15035
15036 if (user_options->attack_mode == ATTACK_MODE_BF)
15037 {
15038 if (device_param->is_cuda == true)
15039 {
15040 device_param->kernel_params_mp_l[0] = (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
15041 ? &device_param->cuda_d_pws_buf
15042 : &device_param->cuda_d_pws_amp_buf;
15043
15044 //CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp_l, 0, sizeof (cl_mem), device_param->kernel_params_mp_l[0]); if (CL_rc == -1) return -1;
15045 }
15046
15047 if (device_param->is_hip == true)
15048 {
15049 device_param->kernel_params_mp_l[0] = (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
15050 ? &device_param->hip_d_pws_buf
15051 : &device_param->hip_d_pws_amp_buf;
15052
15053 //CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp_l, 0, sizeof (cl_mem), device_param->kernel_params_mp_l[0]); if (CL_rc == -1) return -1;
15054 }
15055
15056 if (device_param->is_opencl == true)
15057 {
15058 device_param->kernel_params_mp_l[0] = (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
15059 ? &device_param->opencl_d_pws_buf
15060 : &device_param->opencl_d_pws_amp_buf;
15061
15062 if (hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp_l, 0, sizeof (cl_mem), device_param->kernel_params_mp_l[0]) == -1) return -1;
15063 }
15064 }
15065
15066 if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
15067 {
15068 // nothing to do
15069 }
15070 else
15071 {
15072 if (device_param->is_cuda == true)
15073 {
15074 device_param->kernel_params_amp[0] = &device_param->cuda_d_pws_buf;
15075 device_param->kernel_params_amp[1] = &device_param->cuda_d_pws_amp_buf;
15076
15077 //CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_amp, 0, sizeof (cl_mem), device_param->kernel_params_amp[0]); if (CL_rc == -1) return -1;
15078 //CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_amp, 1, sizeof (cl_mem), device_param->kernel_params_amp[1]); if (CL_rc == -1) return -1;
15079 }
15080
15081 if (device_param->is_hip == true)
15082 {
15083 device_param->kernel_params_amp[0] = &device_param->hip_d_pws_buf;
15084 device_param->kernel_params_amp[1] = &device_param->hip_d_pws_amp_buf;
15085
15086 //CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_amp, 0, sizeof (cl_mem), device_param->kernel_params_amp[0]); if (CL_rc == -1) return -1;
15087 //CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_amp, 1, sizeof (cl_mem), device_param->kernel_params_amp[1]); if (CL_rc == -1) return -1;
15088 }
15089
15090 if (device_param->is_opencl == true)
15091 {
15092 device_param->kernel_params_amp[0] = &device_param->opencl_d_pws_buf;
15093 device_param->kernel_params_amp[1] = &device_param->opencl_d_pws_amp_buf;
15094
15095 if (hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_amp, 0, sizeof (cl_mem), device_param->kernel_params_amp[0]) == -1) return -1;
15096 if (hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_amp, 1, sizeof (cl_mem), device_param->kernel_params_amp[1]) == -1) return -1;
15097 }
15098 }
15099 }
15100
15101 if (device_param->is_cuda == true)
15102 {
15103 device_param->kernel_params_decompress[0] = &device_param->cuda_d_pws_idx;
15104 device_param->kernel_params_decompress[1] = &device_param->cuda_d_pws_comp_buf;
15105 device_param->kernel_params_decompress[2] = (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
15106 ? &device_param->cuda_d_pws_buf
15107 : &device_param->cuda_d_pws_amp_buf;
15108
15109 //CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_decompress, 0, sizeof (cl_mem), device_param->kernel_params_decompress[0]); if (CL_rc == -1) return -1;
15110 //CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_decompress, 1, sizeof (cl_mem), device_param->kernel_params_decompress[1]); if (CL_rc == -1) return -1;
15111 //CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_decompress, 2, sizeof (cl_mem), device_param->kernel_params_decompress[2]); if (CL_rc == -1) return -1;
15112 }
15113
15114 if (device_param->is_hip == true)
15115 {
15116 device_param->kernel_params_decompress[0] = &device_param->hip_d_pws_idx;
15117 device_param->kernel_params_decompress[1] = &device_param->hip_d_pws_comp_buf;
15118 device_param->kernel_params_decompress[2] = (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
15119 ? &device_param->hip_d_pws_buf
15120 : &device_param->hip_d_pws_amp_buf;
15121
15122 //CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_decompress, 0, sizeof (cl_mem), device_param->kernel_params_decompress[0]); if (CL_rc == -1) return -1;
15123 //CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_decompress, 1, sizeof (cl_mem), device_param->kernel_params_decompress[1]); if (CL_rc == -1) return -1;
15124 //CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_decompress, 2, sizeof (cl_mem), device_param->kernel_params_decompress[2]); if (CL_rc == -1) return -1;
15125 }
15126
15127 if (device_param->is_opencl == true)
15128 {
15129 device_param->kernel_params_decompress[0] = &device_param->opencl_d_pws_idx;
15130 device_param->kernel_params_decompress[1] = &device_param->opencl_d_pws_comp_buf;
15131 device_param->kernel_params_decompress[2] = (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL)
15132 ? &device_param->opencl_d_pws_buf
15133 : &device_param->opencl_d_pws_amp_buf;
15134
15135 if (hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_decompress, 0, sizeof (cl_mem), device_param->kernel_params_decompress[0]) == -1) return -1;
15136 if (hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_decompress, 1, sizeof (cl_mem), device_param->kernel_params_decompress[1]) == -1) return -1;
15137 if (hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_decompress, 2, sizeof (cl_mem), device_param->kernel_params_decompress[2]) == -1) return -1;
15138 }
15139
15140 // context
15141
15142 if (device_param->is_cuda == true)
15143 {
15144 if (hc_cuCtxPopCurrent (hashcat_ctx, &device_param->cuda_context) == -1)
15145 {
15146 device_param->skipped = true;
15147 continue;
15148 }
15149 }
15150
15151 if (device_param->is_hip == true)
15152 {
15153 if (hc_hipCtxPopCurrent (hashcat_ctx, &device_param->hip_context) == -1)
15154 {
15155 device_param->skipped = true;
15156 continue;
15157 }
15158 }
15159
15160 hardware_power_all += hardware_power_max;
15161
15162 EVENT_DATA (EVENT_BACKEND_DEVICE_INIT_POST, &backend_devices_idx, sizeof (int));
15163 }
15164
15165 if (user_options->benchmark == false)
15166 {
15167 if (hardware_power_all == 0) return -1;
15168 }
15169
15170 backend_ctx->hardware_power_all = hardware_power_all;
15171
15172 EVENT_DATA (EVENT_BACKEND_SESSION_HOSTMEM, &size_total_host_all, sizeof (u64));
15173
15174 return 0;
15175 }
15176
backend_session_destroy(hashcat_ctx_t * hashcat_ctx)15177 void backend_session_destroy (hashcat_ctx_t *hashcat_ctx)
15178 {
15179 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
15180
15181 if (backend_ctx->enabled == false) return;
15182
15183 for (int backend_devices_idx = 0; backend_devices_idx < backend_ctx->backend_devices_cnt; backend_devices_idx++)
15184 {
15185 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
15186
15187 if (device_param->skipped == true) continue;
15188
15189 hcfree (device_param->pws_comp);
15190 hcfree (device_param->pws_idx);
15191 hcfree (device_param->pws_pre_buf);
15192 hcfree (device_param->pws_base_buf);
15193 hcfree (device_param->combs_buf);
15194 hcfree (device_param->hooks_buf);
15195 hcfree (device_param->scratch_buf);
15196 #ifdef WITH_BRAIN
15197 hcfree (device_param->brain_link_in_buf);
15198 hcfree (device_param->brain_link_out_buf);
15199 #endif
15200
15201 if (device_param->is_cuda == true)
15202 {
15203 if (device_param->cuda_d_pws_buf) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_pws_buf);
15204 if (device_param->cuda_d_pws_amp_buf) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_pws_amp_buf);
15205 if (device_param->cuda_d_pws_comp_buf) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_pws_comp_buf);
15206 if (device_param->cuda_d_pws_idx) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_pws_idx);
15207 if (device_param->cuda_d_rules) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_rules);
15208 //if (device_param->cuda_d_rules_c) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_rules_c);
15209 if (device_param->cuda_d_combs) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_combs);
15210 if (device_param->cuda_d_combs_c) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_combs_c);
15211 if (device_param->cuda_d_bfs) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_bfs);
15212 //if (device_param->cuda_d_bfs_c) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_bfs_c);
15213 if (device_param->cuda_d_bitmap_s1_a) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_bitmap_s1_a);
15214 if (device_param->cuda_d_bitmap_s1_b) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_bitmap_s1_b);
15215 if (device_param->cuda_d_bitmap_s1_c) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_bitmap_s1_c);
15216 if (device_param->cuda_d_bitmap_s1_d) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_bitmap_s1_d);
15217 if (device_param->cuda_d_bitmap_s2_a) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_bitmap_s2_a);
15218 if (device_param->cuda_d_bitmap_s2_b) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_bitmap_s2_b);
15219 if (device_param->cuda_d_bitmap_s2_c) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_bitmap_s2_c);
15220 if (device_param->cuda_d_bitmap_s2_d) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_bitmap_s2_d);
15221 if (device_param->cuda_d_plain_bufs) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_plain_bufs);
15222 if (device_param->cuda_d_digests_buf) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_digests_buf);
15223 if (device_param->cuda_d_digests_shown) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_digests_shown);
15224 if (device_param->cuda_d_salt_bufs) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_salt_bufs);
15225 if (device_param->cuda_d_esalt_bufs) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_esalt_bufs);
15226 if (device_param->cuda_d_tmps) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_tmps);
15227 if (device_param->cuda_d_hooks) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_hooks);
15228 if (device_param->cuda_d_result) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_result);
15229 if (device_param->cuda_d_extra0_buf) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_extra0_buf);
15230 if (device_param->cuda_d_extra1_buf) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_extra1_buf);
15231 if (device_param->cuda_d_extra2_buf) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_extra2_buf);
15232 if (device_param->cuda_d_extra3_buf) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_extra3_buf);
15233 if (device_param->cuda_d_root_css_buf) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_root_css_buf);
15234 if (device_param->cuda_d_markov_css_buf) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_markov_css_buf);
15235 if (device_param->cuda_d_tm_c) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_tm_c);
15236 if (device_param->cuda_d_st_digests_buf) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_st_digests_buf);
15237 if (device_param->cuda_d_st_salts_buf) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_st_salts_buf);
15238 if (device_param->cuda_d_st_esalts_buf) hc_cuMemFree (hashcat_ctx, device_param->cuda_d_st_esalts_buf);
15239
15240 if (device_param->cuda_event1) hc_cuEventDestroy (hashcat_ctx, device_param->cuda_event1);
15241 if (device_param->cuda_event2) hc_cuEventDestroy (hashcat_ctx, device_param->cuda_event2);
15242 if (device_param->cuda_event3) hc_cuEventDestroy (hashcat_ctx, device_param->cuda_event3);
15243
15244 if (device_param->cuda_stream) hc_cuStreamDestroy (hashcat_ctx, device_param->cuda_stream);
15245
15246 if (device_param->cuda_module) hc_cuModuleUnload (hashcat_ctx, device_param->cuda_module);
15247 if (device_param->cuda_module_mp) hc_cuModuleUnload (hashcat_ctx, device_param->cuda_module_mp);
15248 if (device_param->cuda_module_amp) hc_cuModuleUnload (hashcat_ctx, device_param->cuda_module_amp);
15249 if (device_param->cuda_module_shared) hc_cuModuleUnload (hashcat_ctx, device_param->cuda_module_shared);
15250
15251 if (device_param->cuda_context) hc_cuCtxDestroy (hashcat_ctx, device_param->cuda_context);
15252
15253 device_param->cuda_d_pws_buf = 0;
15254 device_param->cuda_d_pws_amp_buf = 0;
15255 device_param->cuda_d_pws_comp_buf = 0;
15256 device_param->cuda_d_pws_idx = 0;
15257 device_param->cuda_d_rules = 0;
15258 device_param->cuda_d_rules_c = 0;
15259 device_param->cuda_d_combs = 0;
15260 device_param->cuda_d_combs_c = 0;
15261 device_param->cuda_d_bfs = 0;
15262 device_param->cuda_d_bfs_c = 0;
15263 device_param->cuda_d_bitmap_s1_a = 0;
15264 device_param->cuda_d_bitmap_s1_b = 0;
15265 device_param->cuda_d_bitmap_s1_c = 0;
15266 device_param->cuda_d_bitmap_s1_d = 0;
15267 device_param->cuda_d_bitmap_s2_a = 0;
15268 device_param->cuda_d_bitmap_s2_b = 0;
15269 device_param->cuda_d_bitmap_s2_c = 0;
15270 device_param->cuda_d_bitmap_s2_d = 0;
15271 device_param->cuda_d_plain_bufs = 0;
15272 device_param->cuda_d_digests_buf = 0;
15273 device_param->cuda_d_digests_shown = 0;
15274 device_param->cuda_d_salt_bufs = 0;
15275 device_param->cuda_d_esalt_bufs = 0;
15276 device_param->cuda_d_tmps = 0;
15277 device_param->cuda_d_hooks = 0;
15278 device_param->cuda_d_result = 0;
15279 device_param->cuda_d_extra0_buf = 0;
15280 device_param->cuda_d_extra1_buf = 0;
15281 device_param->cuda_d_extra2_buf = 0;
15282 device_param->cuda_d_extra3_buf = 0;
15283 device_param->cuda_d_root_css_buf = 0;
15284 device_param->cuda_d_markov_css_buf = 0;
15285 device_param->cuda_d_tm_c = 0;
15286 device_param->cuda_d_st_digests_buf = 0;
15287 device_param->cuda_d_st_salts_buf = 0;
15288 device_param->cuda_d_st_esalts_buf = 0;
15289
15290 device_param->cuda_function1 = NULL;
15291 device_param->cuda_function12 = NULL;
15292 device_param->cuda_function2p = NULL;
15293 device_param->cuda_function2 = NULL;
15294 device_param->cuda_function2e = NULL;
15295 device_param->cuda_function23 = NULL;
15296 device_param->cuda_function3 = NULL;
15297 device_param->cuda_function4 = NULL;
15298 device_param->cuda_function_init2 = NULL;
15299 device_param->cuda_function_loop2p = NULL;
15300 device_param->cuda_function_loop2 = NULL;
15301 device_param->cuda_function_mp = NULL;
15302 device_param->cuda_function_mp_l = NULL;
15303 device_param->cuda_function_mp_r = NULL;
15304 device_param->cuda_function_tm = NULL;
15305 device_param->cuda_function_amp = NULL;
15306 device_param->cuda_function_memset = NULL;
15307 device_param->cuda_function_bzero = NULL;
15308 device_param->cuda_function_atinit = NULL;
15309 device_param->cuda_function_utf8toutf16le = NULL;
15310 device_param->cuda_function_decompress = NULL;
15311 device_param->cuda_function_aux1 = NULL;
15312 device_param->cuda_function_aux2 = NULL;
15313 device_param->cuda_function_aux3 = NULL;
15314 device_param->cuda_function_aux4 = NULL;
15315
15316 device_param->cuda_event1 = NULL;
15317 device_param->cuda_event2 = NULL;
15318 device_param->cuda_event3 = NULL;
15319
15320 device_param->cuda_stream = NULL;
15321
15322 device_param->cuda_module = NULL;
15323 device_param->cuda_module_mp = NULL;
15324 device_param->cuda_module_amp = NULL;
15325 device_param->cuda_module_shared = NULL;
15326
15327 device_param->cuda_context = NULL;
15328 }
15329
15330 if (device_param->is_hip == true)
15331 {
15332 if (device_param->hip_d_pws_buf) hc_hipMemFree (hashcat_ctx, device_param->hip_d_pws_buf);
15333 if (device_param->hip_d_pws_amp_buf) hc_hipMemFree (hashcat_ctx, device_param->hip_d_pws_amp_buf);
15334 if (device_param->hip_d_pws_comp_buf) hc_hipMemFree (hashcat_ctx, device_param->hip_d_pws_comp_buf);
15335 if (device_param->hip_d_pws_idx) hc_hipMemFree (hashcat_ctx, device_param->hip_d_pws_idx);
15336 if (device_param->hip_d_rules) hc_hipMemFree (hashcat_ctx, device_param->hip_d_rules);
15337 //if (device_param->hip_d_rules_c) hc_hipMemFree (hashcat_ctx, device_param->hip_d_rules_c);
15338 if (device_param->hip_d_combs) hc_hipMemFree (hashcat_ctx, device_param->hip_d_combs);
15339 if (device_param->hip_d_combs_c) hc_hipMemFree (hashcat_ctx, device_param->hip_d_combs_c);
15340 if (device_param->hip_d_bfs) hc_hipMemFree (hashcat_ctx, device_param->hip_d_bfs);
15341 //if (device_param->hip_d_bfs_c) hc_hipMemFree (hashcat_ctx, device_param->hip_d_bfs_c);
15342 if (device_param->hip_d_bitmap_s1_a) hc_hipMemFree (hashcat_ctx, device_param->hip_d_bitmap_s1_a);
15343 if (device_param->hip_d_bitmap_s1_b) hc_hipMemFree (hashcat_ctx, device_param->hip_d_bitmap_s1_b);
15344 if (device_param->hip_d_bitmap_s1_c) hc_hipMemFree (hashcat_ctx, device_param->hip_d_bitmap_s1_c);
15345 if (device_param->hip_d_bitmap_s1_d) hc_hipMemFree (hashcat_ctx, device_param->hip_d_bitmap_s1_d);
15346 if (device_param->hip_d_bitmap_s2_a) hc_hipMemFree (hashcat_ctx, device_param->hip_d_bitmap_s2_a);
15347 if (device_param->hip_d_bitmap_s2_b) hc_hipMemFree (hashcat_ctx, device_param->hip_d_bitmap_s2_b);
15348 if (device_param->hip_d_bitmap_s2_c) hc_hipMemFree (hashcat_ctx, device_param->hip_d_bitmap_s2_c);
15349 if (device_param->hip_d_bitmap_s2_d) hc_hipMemFree (hashcat_ctx, device_param->hip_d_bitmap_s2_d);
15350 if (device_param->hip_d_plain_bufs) hc_hipMemFree (hashcat_ctx, device_param->hip_d_plain_bufs);
15351 if (device_param->hip_d_digests_buf) hc_hipMemFree (hashcat_ctx, device_param->hip_d_digests_buf);
15352 if (device_param->hip_d_digests_shown) hc_hipMemFree (hashcat_ctx, device_param->hip_d_digests_shown);
15353 if (device_param->hip_d_salt_bufs) hc_hipMemFree (hashcat_ctx, device_param->hip_d_salt_bufs);
15354 if (device_param->hip_d_esalt_bufs) hc_hipMemFree (hashcat_ctx, device_param->hip_d_esalt_bufs);
15355 if (device_param->hip_d_tmps) hc_hipMemFree (hashcat_ctx, device_param->hip_d_tmps);
15356 if (device_param->hip_d_hooks) hc_hipMemFree (hashcat_ctx, device_param->hip_d_hooks);
15357 if (device_param->hip_d_result) hc_hipMemFree (hashcat_ctx, device_param->hip_d_result);
15358 if (device_param->hip_d_extra0_buf) hc_hipMemFree (hashcat_ctx, device_param->hip_d_extra0_buf);
15359 if (device_param->hip_d_extra1_buf) hc_hipMemFree (hashcat_ctx, device_param->hip_d_extra1_buf);
15360 if (device_param->hip_d_extra2_buf) hc_hipMemFree (hashcat_ctx, device_param->hip_d_extra2_buf);
15361 if (device_param->hip_d_extra3_buf) hc_hipMemFree (hashcat_ctx, device_param->hip_d_extra3_buf);
15362 if (device_param->hip_d_root_css_buf) hc_hipMemFree (hashcat_ctx, device_param->hip_d_root_css_buf);
15363 if (device_param->hip_d_markov_css_buf) hc_hipMemFree (hashcat_ctx, device_param->hip_d_markov_css_buf);
15364 if (device_param->hip_d_tm_c) hc_hipMemFree (hashcat_ctx, device_param->hip_d_tm_c);
15365 if (device_param->hip_d_st_digests_buf) hc_hipMemFree (hashcat_ctx, device_param->hip_d_st_digests_buf);
15366 if (device_param->hip_d_st_salts_buf) hc_hipMemFree (hashcat_ctx, device_param->hip_d_st_salts_buf);
15367 if (device_param->hip_d_st_esalts_buf) hc_hipMemFree (hashcat_ctx, device_param->hip_d_st_esalts_buf);
15368
15369 if (device_param->hip_event1) hc_hipEventDestroy (hashcat_ctx, device_param->hip_event1);
15370 if (device_param->hip_event2) hc_hipEventDestroy (hashcat_ctx, device_param->hip_event2);
15371 if (device_param->hip_event3) hc_hipEventDestroy (hashcat_ctx, device_param->hip_event3);
15372
15373 if (device_param->hip_stream) hc_hipStreamDestroy (hashcat_ctx, device_param->hip_stream);
15374
15375 if (device_param->hip_module) hc_hipModuleUnload (hashcat_ctx, device_param->hip_module);
15376 if (device_param->hip_module_mp) hc_hipModuleUnload (hashcat_ctx, device_param->hip_module_mp);
15377 if (device_param->hip_module_amp) hc_hipModuleUnload (hashcat_ctx, device_param->hip_module_amp);
15378 if (device_param->hip_module_shared) hc_hipModuleUnload (hashcat_ctx, device_param->hip_module_shared);
15379
15380 if (device_param->hip_context) hc_hipCtxDestroy (hashcat_ctx, device_param->hip_context);
15381
15382 device_param->hip_d_pws_buf = 0;
15383 device_param->hip_d_pws_amp_buf = 0;
15384 device_param->hip_d_pws_comp_buf = 0;
15385 device_param->hip_d_pws_idx = 0;
15386 device_param->hip_d_rules = 0;
15387 device_param->hip_d_rules_c = 0;
15388 device_param->hip_d_combs = 0;
15389 device_param->hip_d_combs_c = 0;
15390 device_param->hip_d_bfs = 0;
15391 device_param->hip_d_bfs_c = 0;
15392 device_param->hip_d_bitmap_s1_a = 0;
15393 device_param->hip_d_bitmap_s1_b = 0;
15394 device_param->hip_d_bitmap_s1_c = 0;
15395 device_param->hip_d_bitmap_s1_d = 0;
15396 device_param->hip_d_bitmap_s2_a = 0;
15397 device_param->hip_d_bitmap_s2_b = 0;
15398 device_param->hip_d_bitmap_s2_c = 0;
15399 device_param->hip_d_bitmap_s2_d = 0;
15400 device_param->hip_d_plain_bufs = 0;
15401 device_param->hip_d_digests_buf = 0;
15402 device_param->hip_d_digests_shown = 0;
15403 device_param->hip_d_salt_bufs = 0;
15404 device_param->hip_d_esalt_bufs = 0;
15405 device_param->hip_d_tmps = 0;
15406 device_param->hip_d_hooks = 0;
15407 device_param->hip_d_result = 0;
15408 device_param->hip_d_extra0_buf = 0;
15409 device_param->hip_d_extra1_buf = 0;
15410 device_param->hip_d_extra2_buf = 0;
15411 device_param->hip_d_extra3_buf = 0;
15412 device_param->hip_d_root_css_buf = 0;
15413 device_param->hip_d_markov_css_buf = 0;
15414 device_param->hip_d_tm_c = 0;
15415 device_param->hip_d_st_digests_buf = 0;
15416 device_param->hip_d_st_salts_buf = 0;
15417 device_param->hip_d_st_esalts_buf = 0;
15418
15419 device_param->hip_function1 = NULL;
15420 device_param->hip_function12 = NULL;
15421 device_param->hip_function2p = NULL;
15422 device_param->hip_function2 = NULL;
15423 device_param->hip_function2e = NULL;
15424 device_param->hip_function23 = NULL;
15425 device_param->hip_function3 = NULL;
15426 device_param->hip_function4 = NULL;
15427 device_param->hip_function_init2 = NULL;
15428 device_param->hip_function_loop2p = NULL;
15429 device_param->hip_function_loop2 = NULL;
15430 device_param->hip_function_mp = NULL;
15431 device_param->hip_function_mp_l = NULL;
15432 device_param->hip_function_mp_r = NULL;
15433 device_param->hip_function_tm = NULL;
15434 device_param->hip_function_amp = NULL;
15435 device_param->hip_function_memset = NULL;
15436 device_param->hip_function_bzero = NULL;
15437 device_param->hip_function_atinit = NULL;
15438 device_param->hip_function_utf8toutf16le = NULL;
15439 device_param->hip_function_decompress = NULL;
15440 device_param->hip_function_aux1 = NULL;
15441 device_param->hip_function_aux2 = NULL;
15442 device_param->hip_function_aux3 = NULL;
15443 device_param->hip_function_aux4 = NULL;
15444
15445 device_param->hip_event1 = NULL;
15446 device_param->hip_event2 = NULL;
15447 device_param->hip_event3 = NULL;
15448
15449 device_param->hip_stream = NULL;
15450
15451 device_param->hip_module = NULL;
15452 device_param->hip_module_mp = NULL;
15453 device_param->hip_module_amp = NULL;
15454 device_param->hip_module_shared = NULL;
15455
15456 device_param->hip_context = NULL;
15457 }
15458
15459 if (device_param->is_opencl == true)
15460 {
15461 if (device_param->opencl_d_pws_buf) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_pws_buf);
15462 if (device_param->opencl_d_pws_amp_buf) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_pws_amp_buf);
15463 if (device_param->opencl_d_pws_comp_buf) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_pws_comp_buf);
15464 if (device_param->opencl_d_pws_idx) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_pws_idx);
15465 if (device_param->opencl_d_rules) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_rules);
15466 if (device_param->opencl_d_rules_c) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_rules_c);
15467 if (device_param->opencl_d_combs) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_combs);
15468 if (device_param->opencl_d_combs_c) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_combs_c);
15469 if (device_param->opencl_d_bfs) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_bfs);
15470 if (device_param->opencl_d_bfs_c) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_bfs_c);
15471 if (device_param->opencl_d_bitmap_s1_a) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_bitmap_s1_a);
15472 if (device_param->opencl_d_bitmap_s1_b) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_bitmap_s1_b);
15473 if (device_param->opencl_d_bitmap_s1_c) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_bitmap_s1_c);
15474 if (device_param->opencl_d_bitmap_s1_d) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_bitmap_s1_d);
15475 if (device_param->opencl_d_bitmap_s2_a) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_bitmap_s2_a);
15476 if (device_param->opencl_d_bitmap_s2_b) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_bitmap_s2_b);
15477 if (device_param->opencl_d_bitmap_s2_c) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_bitmap_s2_c);
15478 if (device_param->opencl_d_bitmap_s2_d) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_bitmap_s2_d);
15479 if (device_param->opencl_d_plain_bufs) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_plain_bufs);
15480 if (device_param->opencl_d_digests_buf) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_digests_buf);
15481 if (device_param->opencl_d_digests_shown) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_digests_shown);
15482 if (device_param->opencl_d_salt_bufs) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_salt_bufs);
15483 if (device_param->opencl_d_esalt_bufs) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_esalt_bufs);
15484 if (device_param->opencl_d_tmps) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_tmps);
15485 if (device_param->opencl_d_hooks) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_hooks);
15486 if (device_param->opencl_d_result) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_result);
15487 if (device_param->opencl_d_extra0_buf) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_extra0_buf);
15488 if (device_param->opencl_d_extra1_buf) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_extra1_buf);
15489 if (device_param->opencl_d_extra2_buf) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_extra2_buf);
15490 if (device_param->opencl_d_extra3_buf) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_extra3_buf);
15491 if (device_param->opencl_d_root_css_buf) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_root_css_buf);
15492 if (device_param->opencl_d_markov_css_buf) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_markov_css_buf);
15493 if (device_param->opencl_d_tm_c) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_tm_c);
15494 if (device_param->opencl_d_st_digests_buf) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_st_digests_buf);
15495 if (device_param->opencl_d_st_salts_buf) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_st_salts_buf);
15496 if (device_param->opencl_d_st_esalts_buf) hc_clReleaseMemObject (hashcat_ctx, device_param->opencl_d_st_esalts_buf);
15497
15498 if (device_param->opencl_kernel1) hc_clReleaseKernel (hashcat_ctx, device_param->opencl_kernel1);
15499 if (device_param->opencl_kernel12) hc_clReleaseKernel (hashcat_ctx, device_param->opencl_kernel12);
15500 if (device_param->opencl_kernel2p) hc_clReleaseKernel (hashcat_ctx, device_param->opencl_kernel2p);
15501 if (device_param->opencl_kernel2) hc_clReleaseKernel (hashcat_ctx, device_param->opencl_kernel2);
15502 if (device_param->opencl_kernel2e) hc_clReleaseKernel (hashcat_ctx, device_param->opencl_kernel2e);
15503 if (device_param->opencl_kernel23) hc_clReleaseKernel (hashcat_ctx, device_param->opencl_kernel23);
15504 if (device_param->opencl_kernel3) hc_clReleaseKernel (hashcat_ctx, device_param->opencl_kernel3);
15505 if (device_param->opencl_kernel4) hc_clReleaseKernel (hashcat_ctx, device_param->opencl_kernel4);
15506 if (device_param->opencl_kernel_init2) hc_clReleaseKernel (hashcat_ctx, device_param->opencl_kernel_init2);
15507 if (device_param->opencl_kernel_loop2p) hc_clReleaseKernel (hashcat_ctx, device_param->opencl_kernel_loop2p);
15508 if (device_param->opencl_kernel_loop2) hc_clReleaseKernel (hashcat_ctx, device_param->opencl_kernel_loop2);
15509 if (device_param->opencl_kernel_mp) hc_clReleaseKernel (hashcat_ctx, device_param->opencl_kernel_mp);
15510 if (device_param->opencl_kernel_mp_l) hc_clReleaseKernel (hashcat_ctx, device_param->opencl_kernel_mp_l);
15511 if (device_param->opencl_kernel_mp_r) hc_clReleaseKernel (hashcat_ctx, device_param->opencl_kernel_mp_r);
15512 if (device_param->opencl_kernel_tm) hc_clReleaseKernel (hashcat_ctx, device_param->opencl_kernel_tm);
15513 if (device_param->opencl_kernel_amp) hc_clReleaseKernel (hashcat_ctx, device_param->opencl_kernel_amp);
15514 if (device_param->opencl_kernel_memset) hc_clReleaseKernel (hashcat_ctx, device_param->opencl_kernel_memset);
15515 if (device_param->opencl_kernel_bzero) hc_clReleaseKernel (hashcat_ctx, device_param->opencl_kernel_bzero);
15516 if (device_param->opencl_kernel_atinit) hc_clReleaseKernel (hashcat_ctx, device_param->opencl_kernel_atinit);
15517 if (device_param->opencl_kernel_utf8toutf16le) hc_clReleaseKernel (hashcat_ctx, device_param->opencl_kernel_utf8toutf16le);
15518 if (device_param->opencl_kernel_decompress)hc_clReleaseKernel (hashcat_ctx, device_param->opencl_kernel_decompress);
15519 if (device_param->opencl_kernel_aux1) hc_clReleaseKernel (hashcat_ctx, device_param->opencl_kernel_aux1);
15520 if (device_param->opencl_kernel_aux2) hc_clReleaseKernel (hashcat_ctx, device_param->opencl_kernel_aux2);
15521 if (device_param->opencl_kernel_aux3) hc_clReleaseKernel (hashcat_ctx, device_param->opencl_kernel_aux3);
15522 if (device_param->opencl_kernel_aux4) hc_clReleaseKernel (hashcat_ctx, device_param->opencl_kernel_aux4);
15523
15524 if (device_param->opencl_program) hc_clReleaseProgram (hashcat_ctx, device_param->opencl_program);
15525 if (device_param->opencl_program_mp) hc_clReleaseProgram (hashcat_ctx, device_param->opencl_program_mp);
15526 if (device_param->opencl_program_amp) hc_clReleaseProgram (hashcat_ctx, device_param->opencl_program_amp);
15527 if (device_param->opencl_program_shared) hc_clReleaseProgram (hashcat_ctx, device_param->opencl_program_shared);
15528
15529 if (device_param->opencl_command_queue) hc_clReleaseCommandQueue (hashcat_ctx, device_param->opencl_command_queue);
15530
15531 if (device_param->opencl_context) hc_clReleaseContext (hashcat_ctx, device_param->opencl_context);
15532
15533 device_param->opencl_d_pws_buf = NULL;
15534 device_param->opencl_d_pws_amp_buf = NULL;
15535 device_param->opencl_d_pws_comp_buf = NULL;
15536 device_param->opencl_d_pws_idx = NULL;
15537 device_param->opencl_d_rules = NULL;
15538 device_param->opencl_d_rules_c = NULL;
15539 device_param->opencl_d_combs = NULL;
15540 device_param->opencl_d_combs_c = NULL;
15541 device_param->opencl_d_bfs = NULL;
15542 device_param->opencl_d_bfs_c = NULL;
15543 device_param->opencl_d_bitmap_s1_a = NULL;
15544 device_param->opencl_d_bitmap_s1_b = NULL;
15545 device_param->opencl_d_bitmap_s1_c = NULL;
15546 device_param->opencl_d_bitmap_s1_d = NULL;
15547 device_param->opencl_d_bitmap_s2_a = NULL;
15548 device_param->opencl_d_bitmap_s2_b = NULL;
15549 device_param->opencl_d_bitmap_s2_c = NULL;
15550 device_param->opencl_d_bitmap_s2_d = NULL;
15551 device_param->opencl_d_plain_bufs = NULL;
15552 device_param->opencl_d_digests_buf = NULL;
15553 device_param->opencl_d_digests_shown = NULL;
15554 device_param->opencl_d_salt_bufs = NULL;
15555 device_param->opencl_d_esalt_bufs = NULL;
15556 device_param->opencl_d_tmps = NULL;
15557 device_param->opencl_d_hooks = NULL;
15558 device_param->opencl_d_result = NULL;
15559 device_param->opencl_d_extra0_buf = NULL;
15560 device_param->opencl_d_extra1_buf = NULL;
15561 device_param->opencl_d_extra2_buf = NULL;
15562 device_param->opencl_d_extra3_buf = NULL;
15563 device_param->opencl_d_root_css_buf = NULL;
15564 device_param->opencl_d_markov_css_buf = NULL;
15565 device_param->opencl_d_tm_c = NULL;
15566 device_param->opencl_d_st_digests_buf = NULL;
15567 device_param->opencl_d_st_salts_buf = NULL;
15568 device_param->opencl_d_st_esalts_buf = NULL;
15569 device_param->opencl_kernel1 = NULL;
15570 device_param->opencl_kernel12 = NULL;
15571 device_param->opencl_kernel2p = NULL;
15572 device_param->opencl_kernel2 = NULL;
15573 device_param->opencl_kernel2e = NULL;
15574 device_param->opencl_kernel23 = NULL;
15575 device_param->opencl_kernel3 = NULL;
15576 device_param->opencl_kernel4 = NULL;
15577 device_param->opencl_kernel_init2 = NULL;
15578 device_param->opencl_kernel_loop2p = NULL;
15579 device_param->opencl_kernel_loop2 = NULL;
15580 device_param->opencl_kernel_mp = NULL;
15581 device_param->opencl_kernel_mp_l = NULL;
15582 device_param->opencl_kernel_mp_r = NULL;
15583 device_param->opencl_kernel_tm = NULL;
15584 device_param->opencl_kernel_amp = NULL;
15585 device_param->opencl_kernel_memset = NULL;
15586 device_param->opencl_kernel_bzero = NULL;
15587 device_param->opencl_kernel_atinit = NULL;
15588 device_param->opencl_kernel_utf8toutf16le = NULL;
15589 device_param->opencl_kernel_decompress = NULL;
15590 device_param->opencl_kernel_aux1 = NULL;
15591 device_param->opencl_kernel_aux2 = NULL;
15592 device_param->opencl_kernel_aux3 = NULL;
15593 device_param->opencl_kernel_aux4 = NULL;
15594 device_param->opencl_program = NULL;
15595 device_param->opencl_program_mp = NULL;
15596 device_param->opencl_program_amp = NULL;
15597 device_param->opencl_program_shared = NULL;
15598 device_param->opencl_command_queue = NULL;
15599 device_param->opencl_context = NULL;
15600 }
15601
15602 device_param->pws_comp = NULL;
15603 device_param->pws_idx = NULL;
15604 device_param->pws_pre_buf = NULL;
15605 device_param->pws_base_buf = NULL;
15606 device_param->combs_buf = NULL;
15607 device_param->hooks_buf = NULL;
15608 device_param->scratch_buf = NULL;
15609 #ifdef WITH_BRAIN
15610 device_param->brain_link_in_buf = NULL;
15611 device_param->brain_link_out_buf = NULL;
15612 #endif
15613 }
15614 }
15615
backend_session_reset(hashcat_ctx_t * hashcat_ctx)15616 void backend_session_reset (hashcat_ctx_t *hashcat_ctx)
15617 {
15618 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
15619
15620 if (backend_ctx->enabled == false) return;
15621
15622 for (int backend_devices_idx = 0; backend_devices_idx < backend_ctx->backend_devices_cnt; backend_devices_idx++)
15623 {
15624 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
15625
15626 if (device_param->skipped == true) continue;
15627
15628 device_param->speed_pos = 0;
15629
15630 memset (device_param->speed_cnt, 0, SPEED_CACHE * sizeof (u64));
15631 memset (device_param->speed_msec, 0, SPEED_CACHE * sizeof (double));
15632
15633 device_param->speed_only_finish = false;
15634
15635 device_param->exec_pos = 0;
15636
15637 memset (device_param->exec_msec, 0, EXEC_CACHE * sizeof (double));
15638
15639 device_param->outerloop_msec = 0;
15640 device_param->outerloop_pos = 0;
15641 device_param->outerloop_left = 0;
15642 device_param->innerloop_pos = 0;
15643 device_param->innerloop_left = 0;
15644
15645 // some more resets:
15646
15647 if (device_param->pws_comp) memset (device_param->pws_comp, 0, device_param->size_pws_comp);
15648 if (device_param->pws_idx) memset (device_param->pws_idx, 0, device_param->size_pws_idx);
15649
15650 device_param->pws_cnt = 0;
15651
15652 device_param->words_off = 0;
15653 device_param->words_done = 0;
15654
15655 #if defined (_WIN)
15656 device_param->timer_speed.QuadPart = 0;
15657 #else
15658 device_param->timer_speed.tv_sec = 0;
15659 #endif
15660
15661 device_param->kernel_power = 0;
15662 device_param->hardware_power = 0;
15663 }
15664
15665 backend_ctx->kernel_power_all = 0;
15666 backend_ctx->kernel_power_final = 0;
15667 }
15668
backend_session_update_combinator(hashcat_ctx_t * hashcat_ctx)15669 int backend_session_update_combinator (hashcat_ctx_t *hashcat_ctx)
15670 {
15671 combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx;
15672 hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
15673 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
15674 user_options_t *user_options = hashcat_ctx->user_options;
15675
15676 if (backend_ctx->enabled == false) return 0;
15677
15678 for (int backend_devices_idx = 0; backend_devices_idx < backend_ctx->backend_devices_cnt; backend_devices_idx++)
15679 {
15680 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
15681
15682 if (device_param->skipped == true) continue;
15683
15684 if (device_param->skipped_warning == true) continue;
15685
15686 // kernel_params
15687
15688 device_param->kernel_params_buf32[33] = combinator_ctx->combs_mode;
15689
15690 /*
15691 if (device_param->is_opencl == true)
15692 {
15693 CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel1, 33, sizeof (cl_uint), device_param->kernel_params[33]); if (CL_rc == -1) return -1;
15694 CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel2, 33, sizeof (cl_uint), device_param->kernel_params[33]); if (CL_rc == -1) return -1;
15695 CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel3, 33, sizeof (cl_uint), device_param->kernel_params[33]); if (CL_rc == -1) return -1;
15696 CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel4, 33, sizeof (cl_uint), device_param->kernel_params[33]); if (CL_rc == -1) return -1;
15697
15698 if (hashconfig->opts_type & OPTS_TYPE_HOOK12) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel12, 33, sizeof (cl_uint), device_param->kernel_params[33]); if (CL_rc == -1) return -1; }
15699 if (hashconfig->opts_type & OPTS_TYPE_HOOK23) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel23, 33, sizeof (cl_uint), device_param->kernel_params[33]); if (CL_rc == -1) return -1; }
15700 if (hashconfig->opts_type & OPTS_TYPE_INIT2) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_init2, 33, sizeof (cl_uint), device_param->kernel_params[33]); if (CL_rc == -1) return -1; }
15701 if (hashconfig->opts_type & OPTS_TYPE_LOOP2) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_loop2, 33, sizeof (cl_uint), device_param->kernel_params[33]); if (CL_rc == -1) return -1; }
15702 }
15703 */
15704
15705 // kernel_params_amp
15706
15707 if (user_options->slow_candidates == true)
15708 {
15709 }
15710 else
15711 {
15712 device_param->kernel_params_amp_buf32[5] = combinator_ctx->combs_mode;
15713
15714 if (hashconfig->attack_exec == ATTACK_EXEC_OUTSIDE_KERNEL)
15715 {
15716 if (device_param->is_opencl == true)
15717 {
15718 const int rc_clSetKernelArg = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_amp, 5, sizeof (cl_uint), device_param->kernel_params_amp[5]);
15719
15720 if (rc_clSetKernelArg == -1) return -1;
15721 }
15722 }
15723 }
15724 }
15725
15726 return 0;
15727 }
15728
backend_session_update_mp(hashcat_ctx_t * hashcat_ctx)15729 int backend_session_update_mp (hashcat_ctx_t *hashcat_ctx)
15730 {
15731 mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx;
15732 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
15733 user_options_t *user_options = hashcat_ctx->user_options;
15734
15735 if (backend_ctx->enabled == false) return 0;
15736
15737 if (user_options->slow_candidates == true) return 0;
15738
15739 for (int backend_devices_idx = 0; backend_devices_idx < backend_ctx->backend_devices_cnt; backend_devices_idx++)
15740 {
15741 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
15742
15743 if (device_param->skipped == true) continue;
15744
15745 if (device_param->skipped_warning == true) continue;
15746
15747 device_param->kernel_params_mp_buf64[3] = 0;
15748 device_param->kernel_params_mp_buf32[4] = mask_ctx->css_cnt;
15749
15750 if (device_param->is_cuda == true)
15751 {
15752 //for (u32 i = 3; i < 4; i++) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp, i, sizeof (cl_ulong), device_param->kernel_params_mp[i]); if (CL_rc == -1) return -1; }
15753 //for (u32 i = 4; i < 8; i++) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp, i, sizeof (cl_uint), device_param->kernel_params_mp[i]); if (CL_rc == -1) return -1; }
15754
15755 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_root_css_buf, mask_ctx->root_css_buf, device_param->size_root_css, device_param->cuda_stream) == -1) return -1;
15756 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_markov_css_buf, mask_ctx->markov_css_buf, device_param->size_markov_css, device_param->cuda_stream) == -1) return -1;
15757 }
15758
15759 if (device_param->is_hip == true)
15760 {
15761 //for (u32 i = 3; i < 4; i++) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp, i, sizeof (cl_ulong), device_param->kernel_params_mp[i]); if (CL_rc == -1) return -1; }
15762 //for (u32 i = 4; i < 8; i++) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp, i, sizeof (cl_uint), device_param->kernel_params_mp[i]); if (CL_rc == -1) return -1; }
15763
15764 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_root_css_buf, mask_ctx->root_css_buf, device_param->size_root_css, device_param->hip_stream) == -1) return -1;
15765 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_markov_css_buf, mask_ctx->markov_css_buf, device_param->size_markov_css, device_param->hip_stream) == -1) return -1;
15766 }
15767
15768 if (device_param->is_opencl == true)
15769 {
15770 for (u32 i = 3; i < 4; i++) { if (hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp, i, sizeof (cl_ulong), device_param->kernel_params_mp[i]) == -1) return -1; }
15771 for (u32 i = 4; i < 8; i++) { if (hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp, i, sizeof (cl_uint), device_param->kernel_params_mp[i]) == -1) return -1; }
15772
15773 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_root_css_buf, CL_FALSE, 0, device_param->size_root_css, mask_ctx->root_css_buf, 0, NULL, NULL) == -1) return -1;
15774 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_markov_css_buf, CL_FALSE, 0, device_param->size_markov_css, mask_ctx->markov_css_buf, 0, NULL, NULL) == -1) return -1;
15775
15776 if (hc_clFlush (hashcat_ctx, device_param->opencl_command_queue) == -1) return -1;
15777 }
15778 }
15779
15780 return 0;
15781 }
15782
backend_session_update_mp_rl(hashcat_ctx_t * hashcat_ctx,const u32 css_cnt_l,const u32 css_cnt_r)15783 int backend_session_update_mp_rl (hashcat_ctx_t *hashcat_ctx, const u32 css_cnt_l, const u32 css_cnt_r)
15784 {
15785 mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx;
15786 backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
15787 user_options_t *user_options = hashcat_ctx->user_options;
15788
15789 if (backend_ctx->enabled == false) return 0;
15790
15791 if (user_options->slow_candidates == true) return 0;
15792
15793 for (int backend_devices_idx = 0; backend_devices_idx < backend_ctx->backend_devices_cnt; backend_devices_idx++)
15794 {
15795 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
15796
15797 if (device_param->skipped == true) continue;
15798
15799 if (device_param->skipped_warning == true) continue;
15800
15801 device_param->kernel_params_mp_l_buf64[3] = 0;
15802 device_param->kernel_params_mp_l_buf32[4] = css_cnt_l;
15803 device_param->kernel_params_mp_l_buf32[5] = css_cnt_r;
15804
15805 device_param->kernel_params_mp_r_buf64[3] = 0;
15806 device_param->kernel_params_mp_r_buf32[4] = css_cnt_r;
15807
15808 if (device_param->is_cuda == true)
15809 {
15810 //for (u32 i = 3; i < 4; i++) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp_l, i, sizeof (cl_ulong), device_param->kernel_params_mp_l[i]); if (CL_rc == -1) return -1; }
15811 //for (u32 i = 4; i < 8; i++) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp_l, i, sizeof (cl_uint), device_param->kernel_params_mp_l[i]); if (CL_rc == -1) return -1; }
15812 //for (u32 i = 9; i < 9; i++) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp_l, i, sizeof (cl_ulong), device_param->kernel_params_mp_l[i]); if (CL_rc == -1) return -1; }
15813
15814 //for (u32 i = 3; i < 4; i++) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp_r, i, sizeof (cl_ulong), device_param->kernel_params_mp_r[i]); if (CL_rc == -1) return -1; }
15815 //for (u32 i = 4; i < 7; i++) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp_r, i, sizeof (cl_uint), device_param->kernel_params_mp_r[i]); if (CL_rc == -1) return -1; }
15816 //for (u32 i = 8; i < 8; i++) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp_r, i, sizeof (cl_ulong), device_param->kernel_params_mp_r[i]); if (CL_rc == -1) return -1; }
15817
15818 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_root_css_buf, mask_ctx->root_css_buf, device_param->size_root_css, device_param->cuda_stream) == -1) return -1;
15819 if (hc_cuMemcpyHtoDAsync (hashcat_ctx, device_param->cuda_d_markov_css_buf, mask_ctx->markov_css_buf, device_param->size_markov_css, device_param->cuda_stream) == -1) return -1;
15820 }
15821
15822 if (device_param->is_hip == true)
15823 {
15824 //for (u32 i = 3; i < 4; i++) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp_l, i, sizeof (cl_ulong), device_param->kernel_params_mp_l[i]); if (CL_rc == -1) return -1; }
15825 //for (u32 i = 4; i < 8; i++) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp_l, i, sizeof (cl_uint), device_param->kernel_params_mp_l[i]); if (CL_rc == -1) return -1; }
15826 //for (u32 i = 9; i < 9; i++) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp_l, i, sizeof (cl_ulong), device_param->kernel_params_mp_l[i]); if (CL_rc == -1) return -1; }
15827
15828 //for (u32 i = 3; i < 4; i++) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp_r, i, sizeof (cl_ulong), device_param->kernel_params_mp_r[i]); if (CL_rc == -1) return -1; }
15829 //for (u32 i = 4; i < 7; i++) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp_r, i, sizeof (cl_uint), device_param->kernel_params_mp_r[i]); if (CL_rc == -1) return -1; }
15830 //for (u32 i = 8; i < 8; i++) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp_r, i, sizeof (cl_ulong), device_param->kernel_params_mp_r[i]); if (CL_rc == -1) return -1; }
15831
15832 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_root_css_buf, mask_ctx->root_css_buf, device_param->size_root_css, device_param->hip_stream) == -1) return -1;
15833 if (hc_hipMemcpyHtoDAsync (hashcat_ctx, device_param->hip_d_markov_css_buf, mask_ctx->markov_css_buf, device_param->size_markov_css, device_param->hip_stream) == -1) return -1;
15834 }
15835
15836 if (device_param->is_opencl == true)
15837 {
15838 for (u32 i = 3; i < 4; i++) { if (hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp_l, i, sizeof (cl_ulong), device_param->kernel_params_mp_l[i]) == -1) return -1; }
15839 for (u32 i = 4; i < 8; i++) { if (hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp_l, i, sizeof (cl_uint), device_param->kernel_params_mp_l[i]) == -1) return -1; }
15840 for (u32 i = 9; i < 9; i++) { if (hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp_l, i, sizeof (cl_ulong), device_param->kernel_params_mp_l[i]) == -1) return -1; }
15841
15842 for (u32 i = 3; i < 4; i++) { if (hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp_r, i, sizeof (cl_ulong), device_param->kernel_params_mp_r[i]) == -1) return -1; }
15843 for (u32 i = 4; i < 7; i++) { if (hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp_r, i, sizeof (cl_uint), device_param->kernel_params_mp_r[i]) == -1) return -1; }
15844 for (u32 i = 8; i < 8; i++) { if (hc_clSetKernelArg (hashcat_ctx, device_param->opencl_kernel_mp_r, i, sizeof (cl_ulong), device_param->kernel_params_mp_r[i]) == -1) return -1; }
15845
15846 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_root_css_buf, CL_FALSE, 0, device_param->size_root_css, mask_ctx->root_css_buf, 0, NULL, NULL) == -1) return -1;
15847 if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, device_param->opencl_d_markov_css_buf, CL_FALSE, 0, device_param->size_markov_css, mask_ctx->markov_css_buf, 0, NULL, NULL) == -1) return -1;
15848
15849 if (hc_clFlush (hashcat_ctx, device_param->opencl_command_queue) == -1) return -1;
15850 }
15851 }
15852
15853 return 0;
15854 }
15855
hook12_thread(void * p)15856 void *hook12_thread (void *p)
15857 {
15858 hook_thread_param_t *hook_thread_param = (hook_thread_param_t *) p;
15859
15860 module_ctx_t *module_ctx = hook_thread_param->module_ctx;
15861 status_ctx_t *status_ctx = hook_thread_param->status_ctx;
15862
15863 const u64 tid = hook_thread_param->tid;
15864 const u64 tsz = hook_thread_param->tsz;
15865 const u64 pws_cnt = hook_thread_param->pws_cnt;
15866
15867 for (u64 pw_pos = tid; pw_pos < pws_cnt; pw_pos += tsz)
15868 {
15869 while (status_ctx->devices_status == STATUS_PAUSED) sleep (1);
15870
15871 if (status_ctx->devices_status == STATUS_RUNNING)
15872 {
15873 module_ctx->module_hook12 (hook_thread_param->device_param, hook_thread_param->hook_extra_param, hook_thread_param->hook_salts_buf, hook_thread_param->salt_pos, pw_pos);
15874 }
15875 }
15876
15877 return NULL;
15878 }
15879
hook23_thread(void * p)15880 void *hook23_thread (void *p)
15881 {
15882 hook_thread_param_t *hook_thread_param = (hook_thread_param_t *) p;
15883
15884 module_ctx_t *module_ctx = hook_thread_param->module_ctx;
15885 status_ctx_t *status_ctx = hook_thread_param->status_ctx;
15886
15887 const u64 tid = hook_thread_param->tid;
15888 const u64 tsz = hook_thread_param->tsz;
15889 const u64 pws_cnt = hook_thread_param->pws_cnt;
15890
15891 for (u64 pw_pos = tid; pw_pos < pws_cnt; pw_pos += tsz)
15892 {
15893 while (status_ctx->devices_status == STATUS_PAUSED) sleep (1);
15894
15895 if (status_ctx->devices_status == STATUS_RUNNING)
15896 {
15897 module_ctx->module_hook23 (hook_thread_param->device_param, hook_thread_param->hook_extra_param, hook_thread_param->hook_salts_buf, hook_thread_param->salt_pos, pw_pos);
15898 }
15899 }
15900
15901 return NULL;
15902 }
15903