From 1edb649c1f3205988ad57ec29bf335c81c40e99c Mon Sep 17 00:00:00 2001 From: Jukka Ojanen Date: Mon, 9 Aug 2021 18:48:20 +0300 Subject: [PATCH] Remove duplicate conditions --- src/backend.c | 115 +++++++++++++++++++++++--------------------------- 1 file changed, 52 insertions(+), 63 deletions(-) diff --git a/src/backend.c b/src/backend.c index 3f1a91362..4f7eb7b10 100644 --- a/src/backend.c +++ b/src/backend.c @@ -161,8 +161,6 @@ static int backend_ctx_find_alias_devices (hashcat_ctx_t *hashcat_ctx) static bool is_same_device_type (const hc_device_param_t *src, const hc_device_param_t *dst) { - if (strcmp (src->device_name, dst->device_name) != 0) return false; - if (src->is_cuda != dst->is_cuda) return false; if (src->is_hip != dst->is_hip) return false; if (src->is_opencl != dst->is_opencl) return false; @@ -5281,30 +5279,27 @@ int run_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, con { CUfunction cuda_function = NULL; - if (device_param->is_cuda == true) + switch (kern_run) { - switch (kern_run) - { - case KERN_RUN_1: cuda_function = device_param->cuda_function1; break; - case KERN_RUN_12: cuda_function = device_param->cuda_function12; break; - case KERN_RUN_2P: cuda_function = device_param->cuda_function2p; break; - case KERN_RUN_2: cuda_function = device_param->cuda_function2; break; - case KERN_RUN_2E: cuda_function = device_param->cuda_function2e; break; - case KERN_RUN_23: cuda_function = device_param->cuda_function23; break; - case KERN_RUN_3: cuda_function = device_param->cuda_function3; break; - case KERN_RUN_4: cuda_function = device_param->cuda_function4; break; - case KERN_RUN_INIT2: cuda_function = device_param->cuda_function_init2; break; - case KERN_RUN_LOOP2P: cuda_function = device_param->cuda_function_loop2p; break; - case KERN_RUN_LOOP2: cuda_function = device_param->cuda_function_loop2; break; - case KERN_RUN_AUX1: cuda_function = device_param->cuda_function_aux1; break; - case KERN_RUN_AUX2: cuda_function = device_param->cuda_function_aux2; break; - case KERN_RUN_AUX3: cuda_function = device_param->cuda_function_aux3; break; - case KERN_RUN_AUX4: cuda_function = device_param->cuda_function_aux4; break; - } - - if (hc_cuFuncSetAttribute (hashcat_ctx, cuda_function, CU_FUNC_ATTRIBUTE_MAX_DYNAMIC_SHARED_SIZE_BYTES, dynamic_shared_mem) == -1) return -1; + case KERN_RUN_1: cuda_function = device_param->cuda_function1; break; + case KERN_RUN_12: cuda_function = device_param->cuda_function12; break; + case KERN_RUN_2P: cuda_function = device_param->cuda_function2p; break; + case KERN_RUN_2: cuda_function = device_param->cuda_function2; break; + case KERN_RUN_2E: cuda_function = device_param->cuda_function2e; break; + case KERN_RUN_23: cuda_function = device_param->cuda_function23; break; + case KERN_RUN_3: cuda_function = device_param->cuda_function3; break; + case KERN_RUN_4: cuda_function = device_param->cuda_function4; break; + case KERN_RUN_INIT2: cuda_function = device_param->cuda_function_init2; break; + case KERN_RUN_LOOP2P: cuda_function = device_param->cuda_function_loop2p; break; + case KERN_RUN_LOOP2: cuda_function = device_param->cuda_function_loop2; break; + case KERN_RUN_AUX1: cuda_function = device_param->cuda_function_aux1; break; + case KERN_RUN_AUX2: cuda_function = device_param->cuda_function_aux2; break; + case KERN_RUN_AUX3: cuda_function = device_param->cuda_function_aux3; break; + case KERN_RUN_AUX4: cuda_function = device_param->cuda_function_aux4; break; } + if (hc_cuFuncSetAttribute (hashcat_ctx, cuda_function, CU_FUNC_ATTRIBUTE_MAX_DYNAMIC_SHARED_SIZE_BYTES, dynamic_shared_mem) == -1) return -1; + if (kernel_threads == 0) kernel_threads = 1; num_elements = CEILDIV (num_elements, kernel_threads); @@ -5380,30 +5375,27 @@ int run_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, con { hipFunction_t hip_function = NULL; - if (device_param->is_hip == true) + switch (kern_run) { - switch (kern_run) - { - case KERN_RUN_1: hip_function = device_param->hip_function1; break; - case KERN_RUN_12: hip_function = device_param->hip_function12; break; - case KERN_RUN_2P: hip_function = device_param->hip_function2p; break; - case KERN_RUN_2: hip_function = device_param->hip_function2; break; - case KERN_RUN_2E: hip_function = device_param->hip_function2e; break; - case KERN_RUN_23: hip_function = device_param->hip_function23; break; - case KERN_RUN_3: hip_function = device_param->hip_function3; break; - case KERN_RUN_4: hip_function = device_param->hip_function4; break; - case KERN_RUN_INIT2: hip_function = device_param->hip_function_init2; break; - case KERN_RUN_LOOP2P: hip_function = device_param->hip_function_loop2p; break; - case KERN_RUN_LOOP2: hip_function = device_param->hip_function_loop2; break; - case KERN_RUN_AUX1: hip_function = device_param->hip_function_aux1; break; - case KERN_RUN_AUX2: hip_function = device_param->hip_function_aux2; break; - case KERN_RUN_AUX3: hip_function = device_param->hip_function_aux3; break; - case KERN_RUN_AUX4: hip_function = device_param->hip_function_aux4; break; - } - - //if (hc_hipFuncSetAttribute (hashcat_ctx, hip_function, HIP_FUNC_ATTRIBUTE_MAX_DYNAMIC_SHARED_SIZE_BYTES, dynamic_shared_mem) == -1) return -1; + case KERN_RUN_1: hip_function = device_param->hip_function1; break; + case KERN_RUN_12: hip_function = device_param->hip_function12; break; + case KERN_RUN_2P: hip_function = device_param->hip_function2p; break; + case KERN_RUN_2: hip_function = device_param->hip_function2; break; + case KERN_RUN_2E: hip_function = device_param->hip_function2e; break; + case KERN_RUN_23: hip_function = device_param->hip_function23; break; + case KERN_RUN_3: hip_function = device_param->hip_function3; break; + case KERN_RUN_4: hip_function = device_param->hip_function4; break; + case KERN_RUN_INIT2: hip_function = device_param->hip_function_init2; break; + case KERN_RUN_LOOP2P: hip_function = device_param->hip_function_loop2p; break; + case KERN_RUN_LOOP2: hip_function = device_param->hip_function_loop2; break; + case KERN_RUN_AUX1: hip_function = device_param->hip_function_aux1; break; + case KERN_RUN_AUX2: hip_function = device_param->hip_function_aux2; break; + case KERN_RUN_AUX3: hip_function = device_param->hip_function_aux3; break; + case KERN_RUN_AUX4: hip_function = device_param->hip_function_aux4; break; } + //if (hc_hipFuncSetAttribute (hashcat_ctx, hip_function, HIP_FUNC_ATTRIBUTE_MAX_DYNAMIC_SHARED_SIZE_BYTES, dynamic_shared_mem) == -1) return -1; + if (kernel_threads == 0) kernel_threads = 1; num_elements = CEILDIV (num_elements, kernel_threads); @@ -5477,26 +5469,23 @@ int run_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, con { cl_kernel opencl_kernel = NULL; - if (device_param->is_opencl == true) + switch (kern_run) { - switch (kern_run) - { - case KERN_RUN_1: opencl_kernel = device_param->opencl_kernel1; break; - case KERN_RUN_12: opencl_kernel = device_param->opencl_kernel12; break; - case KERN_RUN_2P: opencl_kernel = device_param->opencl_kernel2p; break; - case KERN_RUN_2: opencl_kernel = device_param->opencl_kernel2; break; - case KERN_RUN_2E: opencl_kernel = device_param->opencl_kernel2e; break; - case KERN_RUN_23: opencl_kernel = device_param->opencl_kernel23; break; - case KERN_RUN_3: opencl_kernel = device_param->opencl_kernel3; break; - case KERN_RUN_4: opencl_kernel = device_param->opencl_kernel4; break; - case KERN_RUN_INIT2: opencl_kernel = device_param->opencl_kernel_init2; break; - case KERN_RUN_LOOP2P: opencl_kernel = device_param->opencl_kernel_loop2p; break; - case KERN_RUN_LOOP2: opencl_kernel = device_param->opencl_kernel_loop2; break; - case KERN_RUN_AUX1: opencl_kernel = device_param->opencl_kernel_aux1; break; - case KERN_RUN_AUX2: opencl_kernel = device_param->opencl_kernel_aux2; break; - case KERN_RUN_AUX3: opencl_kernel = device_param->opencl_kernel_aux3; break; - case KERN_RUN_AUX4: opencl_kernel = device_param->opencl_kernel_aux4; break; - } + case KERN_RUN_1: opencl_kernel = device_param->opencl_kernel1; break; + case KERN_RUN_12: opencl_kernel = device_param->opencl_kernel12; break; + case KERN_RUN_2P: opencl_kernel = device_param->opencl_kernel2p; break; + case KERN_RUN_2: opencl_kernel = device_param->opencl_kernel2; break; + case KERN_RUN_2E: opencl_kernel = device_param->opencl_kernel2e; break; + case KERN_RUN_23: opencl_kernel = device_param->opencl_kernel23; break; + case KERN_RUN_3: opencl_kernel = device_param->opencl_kernel3; break; + case KERN_RUN_4: opencl_kernel = device_param->opencl_kernel4; break; + case KERN_RUN_INIT2: opencl_kernel = device_param->opencl_kernel_init2; break; + case KERN_RUN_LOOP2P: opencl_kernel = device_param->opencl_kernel_loop2p; break; + case KERN_RUN_LOOP2: opencl_kernel = device_param->opencl_kernel_loop2; break; + case KERN_RUN_AUX1: opencl_kernel = device_param->opencl_kernel_aux1; break; + case KERN_RUN_AUX2: opencl_kernel = device_param->opencl_kernel_aux2; break; + case KERN_RUN_AUX3: opencl_kernel = device_param->opencl_kernel_aux3; break; + case KERN_RUN_AUX4: opencl_kernel = device_param->opencl_kernel_aux4; break; } for (u32 i = 0; i <= 23; i++)